You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2009/10/08 23:29:27 UTC

svn commit: r823333 - in /myfaces/core/trunk/impl/src/main: java/org/apache/myfaces/view/facelets/ java/org/apache/myfaces/view/facelets/compiler/ old/facelets/ resources/META-INF/facelets/

Author: lu4242
Date: Thu Oct  8 21:29:27 2009
New Revision: 823333

URL: http://svn.apache.org/viewvc?rev=823333&view=rev
Log:
MYFACES-2329 Add Facelet taglib 2.0 schema (add core libraries to be loaded programatically remove unused xml files, also commented code related to this issue that cause performance problems)

Added:
    myfaces/core/trunk/impl/src/main/old/facelets/
    myfaces/core/trunk/impl/src/main/old/facelets/faces-config.xml
    myfaces/core/trunk/impl/src/main/old/facelets/jsf-core.taglib.xml
    myfaces/core/trunk/impl/src/main/old/facelets/jsf-html.taglib.xml
    myfaces/core/trunk/impl/src/main/old/facelets/jsf-ui.taglib.xml
    myfaces/core/trunk/impl/src/main/old/facelets/jstl-core.taglib.xml
    myfaces/core/trunk/impl/src/main/old/facelets/jstl-fn.taglib.xml
Removed:
    myfaces/core/trunk/impl/src/main/resources/META-INF/facelets/
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TagLibraryConfig.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=823333&r1=823332&r2=823333&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java Thu Oct  8 21:29:27 2009
@@ -98,7 +98,12 @@
 import org.apache.myfaces.view.facelets.tag.composite.CompositeLibrary;
 import org.apache.myfaces.view.facelets.tag.composite.CompositeResourceLibrary;
 import org.apache.myfaces.view.facelets.tag.jsf.core.AjaxHandler;
+import org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary;
+import org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary;
+import org.apache.myfaces.view.facelets.tag.jstl.core.JstlCoreLibrary;
+import org.apache.myfaces.view.facelets.tag.jstl.fn.JstlFnLibrary;
 import org.apache.myfaces.view.facelets.tag.ui.UIDebug;
+import org.apache.myfaces.view.facelets.tag.ui.UILibrary;
 import org.apache.myfaces.view.facelets.util.DevTools;
 import org.apache.myfaces.view.facelets.util.ReflectionUtil;
 
@@ -1321,8 +1326,11 @@
     {
         ExternalContext eContext = context.getExternalContext();
         
-        // TODO: We don't need to add default libraries from xml files. It is better
-        // to add it here and remove the referenced xml files from META-INF/facelets/
+        compiler.addTagLibrary(new CoreLibrary());
+        compiler.addTagLibrary(new HtmlLibrary());
+        compiler.addTagLibrary(new UILibrary());
+        compiler.addTagLibrary(new JstlCoreLibrary());
+        compiler.addTagLibrary(new JstlFnLibrary());
         compiler.addTagLibrary(new CompositeLibrary());
         compiler.addTagLibrary(new CompositeResourceLibrary());
 
@@ -1339,7 +1347,11 @@
                         throw new FileNotFoundException(library);
                     }
 
-                    compiler.addTagLibrary(TagLibraryConfig.create(src));
+                    TagLibrary tl = TagLibraryConfig.create(src);
+                    if (tl != null)
+                    {
+                        compiler.addTagLibrary(tl);
+                    }
                     if (log.isDebugEnabled())
                     {
                         log.debug("Successfully loaded library: " + library);

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TagLibraryConfig.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TagLibraryConfig.java?rev=823333&r1=823332&r2=823333&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TagLibraryConfig.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/TagLibraryConfig.java Thu Oct  8 21:29:27 2009
@@ -26,6 +26,7 @@
 import java.util.logging.Logger;
 
 import javax.faces.FacesException;
+import javax.faces.application.ProjectStage;
 import javax.faces.application.Resource;
 import javax.faces.application.ResourceHandler;
 import javax.faces.context.FacesContext;
@@ -251,7 +252,6 @@
      * a pre-2.0 document.  If it is, we really need to construct a DTD validating, non-namespace
      * aware parser. Otherwise, we have to construct a schema validating, namespace-aware parser.
      */
-    
     private static class VersionCheckHandler extends DefaultHandler
     {
         private boolean version20OrLater;
@@ -281,8 +281,9 @@
                 
                 // Throw a dummy parsing exception to terminate parsing as there really isn't any need to go any
                 // further.
-                
-                throw new SAXException();
+                // -= Leonardo Uribe =- THIS IS NOT GOOD PRACTICE! It is better to let the checker continue that                
+                // throw an exception, and run this one only when project stage != production.
+                //throw new SAXException();
             }
         }
     }
@@ -318,6 +319,8 @@
         private String functionSignature;
         
         private String compositeLibraryName;
+        
+        private boolean version20OrLater;
 
         public LibraryHandler(URL source)
         {
@@ -327,7 +330,11 @@
 
         public TagLibrary getLibrary()
         {
-            return this.library;
+            if (this.version20OrLater)
+            {
+                return this.library;
+            }
+            return null;
         }
 
         public void endElement(String uri, String localName, String qName) throws SAXException
@@ -337,6 +344,10 @@
                 if ("facelet-taglib".equals(qName))
                 {
                     ; // Nothing to do
+                }                
+                else if (!version20OrLater)
+                {
+                    return;
                 }
                 else if ("library-class".equals(qName))
                 {
@@ -590,6 +601,25 @@
         public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
         {
             this.buffer.setLength(0);
+            if ("facelet-taglib".equals(qName))
+            {
+                int length = attributes.getLength();
+                
+                for (int i = 0; i < length; ++i)
+                {
+                    if (attributes.getLocalName (i).equals ("version"))
+                    {
+                        // This document has a "version" attribute in the <facelet-taglib> element, so
+                        // it must be a 2.0 or later document as this attribute was never required before.
+
+                        this.version20OrLater = true;
+                    }
+                }
+            }
+            else if (!version20OrLater)
+            {
+                return;
+            }
             if ("tag".equals(qName))
             {
                 this.handlerClass = null;
@@ -674,7 +704,11 @@
         {
             try
             {
-                compiler.addTagLibrary(create(urls[i]));
+                TagLibrary tl = create(urls[i]);
+                if (tl != null)
+                {
+                    compiler.addTagLibrary(tl);
+                }
                 if (log.isLoggable(Level.FINE))
                 {
                     log.fine("Added Library from: " + urls[i]);
@@ -691,38 +725,51 @@
             ParserConfigurationException
     {
         SAXParserFactory factory = SAXParserFactory.newInstance();
-        
-        // We have to make two different parsers depending on whether or not the facelets taglib
-        // document is version 2.0 or later.  If pre-version 2.0, then the parser must not be
-        // namespace-aware and must be DTD validating.  If verison 2.0 or later, the parser must be
-        // namespace-aware and must be schema validating.
-        
-        if (!isTaglibDocument20OrLater (url))
-        {
-            factory.setNamespaceAware(false);
-            factory.setFeature("http://xml.org/sax/features/validation", true);
-            factory.setValidating(true);
-        }
-        
-        else
-        {
-            // TODO: CJH: the Facelets project does not make the 2.0 schema available via their
-            // CVS.  The schema is also not available at its URL.  For now, 2.0 documents will simply
-            // have no validation.  We must get a copy of their schema once they release it and set up
-            // the parser to use it.
-            
+       
+        // -= Leonardo Uribe =- this code is commented because it is not mandatory to
+        // validate facelets tag lib and this cause performance issues. Maybe we can 
+        // refactor this part an use SchemaFactory for validation instead the proposed here
+        // only on ProjectStage.Development time before parse it (on create(URL) method).
+        //if (FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Development))
+        //{
+            // We have to make two different parsers depending on whether or not the facelets taglib
+            // document is version 2.0 or later.  If pre-version 2.0, then the parser must not be
+            // namespace-aware and must be DTD validating.  If verison 2.0 or later, the parser must be
+            // namespace-aware and must be schema validating.
+            //if (!isTaglibDocument20OrLater (url))
+            //{
+            //    factory.setNamespaceAware(false);
+            //    factory.setFeature("http://xml.org/sax/features/validation", true);
+            //    factory.setValidating(true);
+            //}
+            //else
+            //{
+                // TODO: CJH: the Facelets project does not make the 2.0 schema available via their
+                // CVS.  The schema is also not available at its URL.  For now, 2.0 documents will simply
+                // have no validation.  We must get a copy of their schema once they release it and set up
+                // the parser to use it.
+                
+                //factory.setNamespaceAware(true);
+                //factory.setFeature("http://xml.org/sax/features/validation", false);
+                //factory.setValidating(false);
+            //}
+        //}
+        //else
+        //{
+            //Just parse it and do not validate, because it is not necessary.
             factory.setNamespaceAware(true);
             factory.setFeature("http://xml.org/sax/features/validation", false);
             factory.setValidating(false);
-        }
-        
+        //}
+
         SAXParser parser = factory.newSAXParser();
         XMLReader reader = parser.getXMLReader();
         reader.setErrorHandler(handler);
         reader.setEntityResolver(handler);
         return parser;
     }
-    
+
+    /*
     private static final boolean isTaglibDocument20OrLater (URL url)
     {
         InputStream input = null;
@@ -779,5 +826,5 @@
         }
         
         return result;
-    }
+    }*/
 }

Added: myfaces/core/trunk/impl/src/main/old/facelets/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/old/facelets/faces-config.xml?rev=823333&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/old/facelets/faces-config.xml (added)
+++ myfaces/core/trunk/impl/src/main/old/facelets/faces-config.xml Thu Oct  8 21:29:27 2009
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+
+<!DOCTYPE faces-config PUBLIC
+ "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
+ "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
+
+<faces-config>
+    <component>
+		<component-type>facelets.ui.Repeat</component-type>
+		<component-class>org.apache.myfaces.view.facelets.component.UIRepeat</component-class>
+	</component>
+	<component>
+		<component-type>facelets.ui.ComponentRef</component-type>
+		<component-class>org.apache.myfaces.view.facelets.tag.ui.ComponentRef</component-class>
+	</component>
+	<component>
+		<component-type>facelets.ui.Debug</component-type>
+		<component-class>org.apache.myfaces.view.facelets.tag.ui.UIDebug</component-class>
+	</component>
+	<render-kit>
+        <render-kit-id>HTML_BASIC</render-kit-id>
+        <renderer>
+            <component-family>facelets</component-family>
+            <renderer-type>facelets.ui.Repeat</renderer-type>
+            <renderer-class>org.apache.myfaces.view.facelets.component.RepeatRenderer</renderer-class>
+        </renderer>
+    </render-kit>
+</faces-config>
\ No newline at end of file

Added: myfaces/core/trunk/impl/src/main/old/facelets/jsf-core.taglib.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/old/facelets/jsf-core.taglib.xml?rev=823333&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/old/facelets/jsf-core.taglib.xml (added)
+++ myfaces/core/trunk/impl/src/main/old/facelets/jsf-core.taglib.xml Thu Oct  8 21:29:27 2009
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ $Id: jsf-core.taglib.xml,v 1.4 2008/07/13 19:01:45 rlubke Exp $
+-->
+
+<!DOCTYPE facelet-taglib PUBLIC
+  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
+  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
+
+<facelet-taglib>
+	<library-class>org.apache.myfaces.view.facelets.tag.jsf.core.CoreLibrary</library-class>
+</facelet-taglib>
\ No newline at end of file

Added: myfaces/core/trunk/impl/src/main/old/facelets/jsf-html.taglib.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/old/facelets/jsf-html.taglib.xml?rev=823333&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/old/facelets/jsf-html.taglib.xml (added)
+++ myfaces/core/trunk/impl/src/main/old/facelets/jsf-html.taglib.xml Thu Oct  8 21:29:27 2009
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ $Id: jsf-html.taglib.xml,v 1.4 2008/07/13 19:01:45 rlubke Exp $
+-->
+
+<!DOCTYPE facelet-taglib PUBLIC
+  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
+  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
+
+<facelet-taglib>
+	<library-class>org.apache.myfaces.view.facelets.tag.jsf.html.HtmlLibrary</library-class>
+</facelet-taglib>
\ No newline at end of file

Added: myfaces/core/trunk/impl/src/main/old/facelets/jsf-ui.taglib.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/old/facelets/jsf-ui.taglib.xml?rev=823333&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/old/facelets/jsf-ui.taglib.xml (added)
+++ myfaces/core/trunk/impl/src/main/old/facelets/jsf-ui.taglib.xml Thu Oct  8 21:29:27 2009
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ $Id: jsf-ui.taglib.xml,v 1.3 2008/07/13 19:01:45 rlubke Exp $
+-->
+
+<!DOCTYPE facelet-taglib PUBLIC
+  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
+  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
+
+<facelet-taglib>
+	<library-class>org.apache.myfaces.view.facelets.tag.ui.UILibrary</library-class>
+</facelet-taglib>
\ No newline at end of file

Added: myfaces/core/trunk/impl/src/main/old/facelets/jstl-core.taglib.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/old/facelets/jstl-core.taglib.xml?rev=823333&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/old/facelets/jstl-core.taglib.xml (added)
+++ myfaces/core/trunk/impl/src/main/old/facelets/jstl-core.taglib.xml Thu Oct  8 21:29:27 2009
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ $Id: jstl-core.taglib.xml,v 1.3 2008/07/13 19:01:45 rlubke Exp $
+-->
+
+<!DOCTYPE facelet-taglib PUBLIC
+  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
+  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
+
+<facelet-taglib>
+	<library-class>org.apache.myfaces.view.facelets.tag.jstl.core.JstlCoreLibrary</library-class>
+</facelet-taglib>
\ No newline at end of file

Added: myfaces/core/trunk/impl/src/main/old/facelets/jstl-fn.taglib.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/old/facelets/jstl-fn.taglib.xml?rev=823333&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/old/facelets/jstl-fn.taglib.xml (added)
+++ myfaces/core/trunk/impl/src/main/old/facelets/jstl-fn.taglib.xml Thu Oct  8 21:29:27 2009
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ $Id: jstl-fn.taglib.xml,v 1.2 2008/07/13 19:01:45 rlubke Exp $
+-->
+
+<!DOCTYPE facelet-taglib PUBLIC
+  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
+  "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
+
+<facelet-taglib>
+	<library-class>org.apache.myfaces.view.facelets.tag.jstl.fn.JstlFnLibrary</library-class>
+</facelet-taglib>
\ No newline at end of file