[seam-commits] Seam SVN: r8580 - in trunk: ui/src/main/java/org/jboss/seam/ui/facelet and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Aug 5 12:22:46 EDT 2008


Author: pete.muir at jboss.org
Date: 2008-08-05 12:22:46 -0400 (Tue, 05 Aug 2008)
New Revision: 8580

Modified:
   trunk/src/main/org/jboss/seam/mock/MockServletContext.java
   trunk/ui/src/main/java/org/jboss/seam/ui/facelet/FaceletCompiler.java
Log:
JBSEAM-3014

Modified: trunk/src/main/org/jboss/seam/mock/MockServletContext.java
===================================================================
--- trunk/src/main/org/jboss/seam/mock/MockServletContext.java	2008-08-05 16:19:32 UTC (rev 8579)
+++ trunk/src/main/org/jboss/seam/mock/MockServletContext.java	2008-08-05 16:22:46 UTC (rev 8580)
@@ -10,6 +10,7 @@
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -18,13 +19,16 @@
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Node;
+import org.dom4j.io.SAXReader;
 import org.jboss.seam.util.IteratorEnumeration;
 
 public class MockServletContext implements ServletContext
 {
 
    private Map<String, String> initParameters = new HashMap<String, String>();
-
    private Map<String, Object> attributes = new HashMap<String, Object>();
    
    private File webappRoot;
@@ -45,33 +49,56 @@
                webappRoot = webInfRoot.getParentFile();
             }
          }
+         // call processing of context parameters
+         processContextParameters();
       }
       catch (URISyntaxException e)
       {
          throw new IllegalStateException(e);
       }
    }
+   
+   private void processContextParameters()
+   {
+      SAXReader reader = new SAXReader();
+      Document document;
+      try
+      {
+         document = reader.read(getClass().getResourceAsStream("/WEB-INF/web.xml"));
 
+         List<Node> nodes = document.selectNodes("//*[name()='context-param']");
+         for (Node node : nodes)
+         {
+            getInitParameters().put(node.selectSingleNode("*[name()='param-name']").getText(), node.selectSingleNode("*[name()='param-value']").getText());
+         }
+      }
+      catch (DocumentException e)
+      {
+         throw new RuntimeException("Error processing web.xml", e);
+      }
+
+   }
+   
    public Map<String, String> getInitParameters()
    {
       return initParameters;
    }
-
+   
    public Map<String, Object> getAttributes()
    {
       return attributes;
    }
-
+   
    public ServletContext getContext(String name)
    {
       return this;
    }
-
+   
    public int getMajorVersion()
    {
       return 2;
    }
-
+   
    public int getMinorVersion()
    {
       return 4;
@@ -81,7 +108,7 @@
    {
       return null;
    }
-
+   
    public Set getResourcePaths(String name)
    {
       Enumeration<URL> enumeration = null;
@@ -107,7 +134,7 @@
       }
       return result;
    }
-
+   
    private static void addPaths(Set<String> result, File[] files, String rootPath)
    {
       for (File file : files)
@@ -125,38 +152,37 @@
    }
 
    /**
-    * Get the URL for a particular resource that is relative to the web app root directory.
+    * Get the URL for a particular resource that is relative to the web app root
+    * directory.
     * 
-    * @param name
-    *            The name of the resource to get
+    * @param name The name of the resource to get
     * @return The resource, or null if resource not found
-    * @throws MalformedURLException
-    *             If the URL is invalid
+    * @throws MalformedURLException If the URL is invalid
     */
    public URL getResource(String name) throws MalformedURLException
    {
-      File f = getFile(name, webappRoot);
+      File file = getFile(name, webappRoot);
       
-      if (f == null)
+      if (file == null)
       {
-         f = getFile(name, webInfRoot);
+         file = getFile(name, webInfRoot);
       }
       
-      if (f == null)
+      if (file == null)
       {
-         f = getFile(name, webInfClassesRoot);
+         file = getFile(name, webInfClassesRoot);
       }
       
-      if (f != null)
+      if (file != null)
       {
-         return f.toURI().toURL();
+         return file.toURI().toURL();
       }
       else
       {
          return null;
       }
    }
-   
+
    private static File getFile(String name, File root)
    {
       if (root == null)
@@ -168,7 +194,7 @@
       {
          name = name.substring(1);
       }
-
+      
       File f = new File(root, name);
       if (!f.exists())
       {

Modified: trunk/ui/src/main/java/org/jboss/seam/ui/facelet/FaceletCompiler.java
===================================================================
--- trunk/ui/src/main/java/org/jboss/seam/ui/facelet/FaceletCompiler.java	2008-08-05 16:19:32 UTC (rev 8579)
+++ trunk/ui/src/main/java/org/jboss/seam/ui/facelet/FaceletCompiler.java	2008-08-05 16:22:46 UTC (rev 8580)
@@ -1,7 +1,17 @@
 package org.jboss.seam.ui.facelet;
 
+import static com.sun.facelets.FaceletViewHandler.PARAM_DECORATORS;
+import static com.sun.facelets.FaceletViewHandler.PARAM_LIBRARIES;
+import static com.sun.facelets.FaceletViewHandler.PARAM_SKIP_COMMENTS;
 import static org.jboss.seam.ScopeType.APPLICATION;
 
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URL;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
 import org.jboss.seam.Component;
 import org.jboss.seam.ScopeType;
 import org.jboss.seam.annotations.AutoCreate;
@@ -12,9 +22,15 @@
 import org.jboss.seam.annotations.Unwrap;
 import org.jboss.seam.annotations.intercept.BypassInterceptors;
 import org.jboss.seam.contexts.Contexts;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
 
 import com.sun.facelets.compiler.Compiler;
 import com.sun.facelets.compiler.SAXCompiler;
+import com.sun.facelets.compiler.TagLibraryConfig;
+import com.sun.facelets.tag.TagDecorator;
+import com.sun.facelets.tag.TagLibrary;
+import com.sun.facelets.util.ReflectionUtil;
 
 @Name("org.jboss.seam.ui.facelet.faceletCompiler")
 @Scope(APPLICATION)
@@ -23,15 +39,84 @@
 @Install(value = true, precedence = Install.BUILT_IN, classDependencies="com.sun.facelets.Facelet")
 public class FaceletCompiler
 {
-
+   
+   private LogProvider log = Logging.getLogProvider(FaceletCompiler.class);
    private Compiler compiler;
    
    @Create
    public void create()
    {
       compiler = new SAXCompiler();
+     // fill the necessary parameters 
+      initializeCompiler(compiler);
    }
    
+   /*
+    * This method cribbed from FaceletViewHandler 
+    */
+   protected void initializeCompiler(Compiler compiler) 
+   {
+      FacesContext facesContext = FacesContext.getCurrentInstance();
+      ExternalContext externalContext = facesContext.getExternalContext();
+
+      // load libraries
+      String libraryParameter = externalContext.getInitParameter(PARAM_LIBRARIES);
+      if (libraryParameter != null) 
+      {
+         libraryParameter = libraryParameter.trim();
+         String[] libraries = libraryParameter.split(";");
+         URL src;
+         TagLibrary libraryObject;
+         for (int i = 0; i < libraries.length; i++) 
+         {
+            try
+            {
+               src = externalContext.getResource(libraries[i].trim());
+               if (src == null) 
+               {
+                  throw new FileNotFoundException(libraries[i]);
+               }
+               libraryObject = TagLibraryConfig.create(src);
+               compiler.addTagLibrary(libraryObject);
+               log.trace("Successfully Loaded Library: " + libraries[i]);
+            }
+            catch (IOException e) 
+            {
+               log.error("Error Loading Library: " + libraries[i], e);
+            }
+         }
+      }
+
+      // load decorators
+      String decoratorParameter = externalContext.getInitParameter(PARAM_DECORATORS);
+      if (decoratorParameter != null) 
+      {
+         decoratorParameter = decoratorParameter.trim();
+         String[] decorators = decoratorParameter.split(";");
+         TagDecorator decoratorObject;
+         for (int i = 0; i < decorators.length; i++) 
+         {
+            try 
+            {
+               decoratorObject = (TagDecorator) ReflectionUtil.forName(decorators[i]).newInstance();
+               compiler.addTagDecorator(decoratorObject);
+               log.trace("Successfully Loaded Decorator: " + decorators[i]);
+            } 
+            catch (Exception e) 
+            {
+               log.error("Error Loading Decorator: " + decorators[i], e);
+            }
+         }
+      }
+
+      // skip params?
+      String skipParameters = externalContext.getInitParameter(PARAM_SKIP_COMMENTS);
+      if (skipParameters != null && "true".equals(skipParameters)) 
+      {
+         compiler.setTrimmingComments(true);
+      }
+   }
+   
    @Unwrap
    public Compiler unwrap()
    {




More information about the seam-commits mailing list