[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui ...

Christian Bauer christian at hibernate.org
Wed Mar 21 13:32:24 EDT 2007


  User: cbauer  
  Date: 07/03/21 13:32:24

  Modified:    examples/wiki/src/main/org/jboss/seam/wiki/core/ui 
                        UIWikiFormattedText.java
  Log:
  Support EL value bindings in plugin CSS files
  
  Revision  Changes    Path
  1.8       +24 -3     jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/UIWikiFormattedText.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIWikiFormattedText.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/ui/UIWikiFormattedText.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- UIWikiFormattedText.java	20 Mar 2007 02:38:14 -0000	1.7
  +++ UIWikiFormattedText.java	21 Mar 2007 17:32:24 -0000	1.8
  @@ -3,6 +3,8 @@
   import java.io.*;
   import java.net.URL;
   import java.util.*;
  +import java.util.regex.Pattern;
  +import java.util.regex.Matcher;
   
   import javax.faces.component.UIOutput;
   import javax.faces.context.FacesContext;
  @@ -13,8 +15,8 @@
   import org.jboss.seam.util.Resources;
   import org.jboss.seam.ui.JSF;
   import org.jboss.seam.wiki.core.model.GlobalPreferences;
  -import org.jboss.seam.annotations.In;
   import org.jboss.seam.Component;
  +import org.jboss.seam.core.Expressions;
   
   import antlr.ANTLRException;
   import com.sun.facelets.Facelet;
  @@ -104,13 +106,32 @@
               InputStream is = Resources.getResourceAsStream(includeViewCSS);
               if (is != null) {
                   output.append("<style type=\"text/css\">\n");
  +
                   BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  +                StringBuilder css = new StringBuilder();
                   String line;
                   while ( (line = reader.readLine()) != null) {
  -                    output.append(line);
  -                    output.append("\n");
  +                    css.append(line);
  +                    css.append("\n");
                   }
                   is.close();
  +
  +                // Resolve any EL value binding expression present in CSS text
  +                StringBuffer resolvedCSS = new StringBuffer(css.length());
  +                Matcher matcher =
  +                    Pattern.compile(
  +                        "#" +Pattern.quote("{") + "(.*)" + Pattern.quote("}")
  +                    ).matcher(css);
  +
  +                // Replace with [Link Text=>Page Name] or replace with BROKENLINK "page name"
  +                while (matcher.find()) {
  +                    Expressions.ValueBinding valueMethod = Expressions.instance().createValueBinding("#{"+matcher.group(1)+"}");
  +                    String result = (String)valueMethod.getValue();
  +                    matcher.appendReplacement(resolvedCSS, result);
  +                }
  +                matcher.appendTail(resolvedCSS);
  +                output.append(resolvedCSS);
  +
                   output.append("</style>\n");
               }
   
  
  
  



More information about the jboss-cvs-commits mailing list