abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r600426 - in /incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates: Evaluator.java Operation.java Template.java
Date Mon, 03 Dec 2007 04:33:23 GMT
Author: jmsnell
Date: Sun Dec  2 20:33:20 2007
New Revision: 600426

URL: http://svn.apache.org/viewvc?rev=600426&view=rev
Log:
Additional tweaks for bidi support. This should be about finished.

Modified:
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Operation.java
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Template.java

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java?rev=600426&r1=600425&r2=600426&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java
Sun Dec  2 20:33:20 2007
@@ -17,6 +17,7 @@
 */
 package org.apache.abdera.i18n.templates;
 
+import java.io.IOException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -45,10 +46,12 @@
   
   /**
    * Writes a plain-text description of the template token
+   * @throws IOException 
    */
   void explain(
     String token, 
-    StringBuilder buf) {
+    Appendable buf) 
+      throws IOException {
     Matcher matcher = PATTERN.matcher(token);
     if (matcher.find()) {
       String op = matcher.group(1);

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Operation.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Operation.java?rev=600426&r1=600425&r2=600426&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Operation.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Operation.java
Sun Dec  2 20:33:20 2007
@@ -51,7 +51,7 @@
   
   public abstract String evaluate(String var, String arg, Context context);
   
-  public abstract void explain(String var, String arg, StringBuilder buf);
+  public abstract void explain(String var, String arg, Appendable buf) throws IOException;
   
   public String[] getVariables(String var) {
     List<String> list = new ArrayList<String>();
@@ -328,10 +328,10 @@
     public String evaluate(String var, String arg, Context context) {
       return eval(var, context);
     }
-    public void explain(String var, String arg, StringBuilder buf) {
-      buf.append("Replaced with the value of '");
-      buf.append(var);
-      buf.append("'");
+    public void explain(String var, String arg, Appendable buf) throws IOException {
+      buf.append("Replaced with the value of '")
+         .append(var)
+         .append("'");
     }
   }
   
@@ -342,14 +342,14 @@
       String value = eval(var,context);
       return value == null || value.length() == 0 ? "" : arg != null ? arg + value : value;
     }
-    public void explain(String var, String arg, StringBuilder buf) {
-      buf.append("If '");
-      buf.append(var);
-      buf.append("' is defined then prefix the value of '");
-      buf.append(var);
-      buf.append("' with '");
-      buf.append(arg);
-      buf.append("'");
+    public void explain(String var, String arg, Appendable buf) throws IOException {
+      buf.append("If '")
+         .append(var)
+         .append("' is defined then prefix the value of '")
+         .append(var)
+         .append("' with '")
+         .append(arg)
+         .append("'");
     }
   }
   
@@ -360,14 +360,14 @@
       String value = eval(var,context);
       return value == null || value.length() == 0 ? "" : arg != null ? value + arg : value;
     }
-    public void explain(String var, String arg, StringBuilder buf) {
-      buf.append("If '");
-      buf.append(var);
-      buf.append("' is defined then append '");
-      buf.append(arg);
-      buf.append("' to the value of '");
-      buf.append(var);
-      buf.append("'");
+    public void explain(String var, String arg, Appendable buf) throws IOException {
+      buf.append("If '")
+         .append(var)
+         .append("' is defined then append '")
+         .append(arg)
+         .append("' to the value of '")
+         .append(var)
+         .append("'");
     }
   }
   
@@ -389,16 +389,16 @@
       String value = buf.toString();
       return value;
     }
-    public void explain(String var, String arg, StringBuilder buf) {
+    public void explain(String var, String arg, Appendable buf) throws IOException {
       buf.append("Join 'var=value' with '" + arg + "' for each variable in [");
       String[] vars = getVariables(var);
       boolean b = false;
       for (String v : vars) {
         if (b) buf.append(',');
         else b = true;
-        buf.append("'");
-        buf.append(v);
-        buf.append("'");
+        buf.append("'")
+           .append(v)
+           .append("'");
       }
       buf.append("]");
     }
@@ -410,12 +410,12 @@
     public String evaluate(String var, String arg, Context context) {
       return evallist(var,context,arg);
     }
-    public void explain(String var, String arg, StringBuilder buf) {
-      buf.append("Join the members of the list '");
-      buf.append(var);
-      buf.append("' together with '");
-      buf.append(arg);
-      buf.append("'");
+    public void explain(String var, String arg, Appendable buf) throws IOException {
+      buf.append("Join the members of the list '")
+         .append(var)
+         .append("' together with '")
+         .append(arg)
+         .append("'");
     }
   }
   
@@ -429,20 +429,20 @@
       }
       return null;
     }
-    public void explain(String var, String arg, StringBuilder buf) {
+    public void explain(String var, String arg, Appendable buf) throws IOException {
       buf.append("If [");
       String[] vars = getVariables(var);
       boolean b = false;
       for (String v : vars) {
         if (b) buf.append(',');
         else b = true;
-        buf.append("'");
-        buf.append(v);
-        buf.append("'");
-      }
-      buf.append("] is defined and a string, or a list with one or more members, then insert
'");
-      buf.append(arg);
-      buf.append("'");
+        buf.append("'")
+           .append(v)
+           .append("'");
+      }
+      buf.append("] is defined and a string, or a list with one or more members, then insert
'")
+         .append(arg)
+         .append("'");
     }
   }
   
@@ -456,20 +456,20 @@
       }
       return null;
     }
-    public void explain(String var, String arg, StringBuilder buf) {
+    public void explain(String var, String arg, Appendable buf) throws IOException {
       buf.append("If [");
       String[] vars = getVariables(var);
       boolean b = false;
       for (String v : vars) {
         if (b) buf.append(',');
         else b = true;
-        buf.append("'");
-        buf.append(v);
-        buf.append("'");
-      }
-      buf.append("] is undefined, or a zero length list, then insert '");
-      buf.append(arg);
-      buf.append("'");
+        buf.append("'")
+           .append(v)
+           .append("'");
+      }
+      buf.append("] is undefined, or a zero length list, then insert '")
+         .append(arg)
+         .append("'");
     }
   }
   

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Template.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Template.java?rev=600426&r1=600425&r2=600426&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Template.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Template.java
Sun Dec  2 20:33:20 2007
@@ -17,6 +17,7 @@
 */
 package org.apache.abdera.i18n.templates;
 
+import java.io.IOException;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -239,7 +240,25 @@
 
   @Override
   public String toString() {
-   StringBuilder buf = new StringBuilder();
+    StringBuilder buf = new StringBuilder();
+    buf.append("V:" + getPatternForDisplay());
+    buf.append('\n');
+    buf.append("L:" + CharUtils.bidiLRO(getPattern()));
+    buf.append('\n');
+    return buf.toString();
+  }
+  
+  public String explain() {
+    StringBuilder buf = new StringBuilder();
+    try {
+      explain(buf);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    }
+    return buf.toString();
+  }
+  
+  public void explain(Appendable buf) throws IOException {
    buf.append("Template:");
    buf.append('\n');
    buf.append("\t"+getPatternForDisplay());
@@ -258,7 +277,7 @@
    buf.append('\n');
    for (String token : this) {
      buf.append('\t');
-     buf.append("{" + token + "} \n\t\t ");
+     buf.append(forDisplay(token) + " \n\t\t ");
      EVALUATOR.explain(token, buf);
      buf.append('\n');
    }
@@ -310,8 +329,6 @@
    }
    buf.append('\n');
    buf.append("\t" + expand(c));
-   
-   return buf.toString();
   }
   
   public static String expand(String pattern, Context context) {
@@ -346,7 +363,13 @@
   }
   
   public static String explain(String pattern) {
-    Template template = new Template(pattern);
-    return template.toString();
+    return new Template(pattern).explain();
+  }
+  
+  public static void explain(
+    String pattern, 
+    Appendable buf) 
+      throws IOException {
+    new Template(pattern).explain(buf);
   }
 }



Mime
View raw message