Return-Path: X-Original-To: apmail-myfaces-commits-archive@www.apache.org Delivered-To: apmail-myfaces-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 803C310FED for ; Fri, 23 Aug 2013 13:28:34 +0000 (UTC) Received: (qmail 61820 invoked by uid 500); 23 Aug 2013 13:28:34 -0000 Delivered-To: apmail-myfaces-commits-archive@myfaces.apache.org Received: (qmail 61765 invoked by uid 500); 23 Aug 2013 13:28:33 -0000 Mailing-List: contact commits-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Development" Delivered-To: mailing list commits@myfaces.apache.org Received: (qmail 61758 invoked by uid 99); 23 Aug 2013 13:28:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Aug 2013 13:28:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Aug 2013 13:28:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CA2E7238888A; Fri, 23 Aug 2013 13:27:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1516844 [1/2] - in /myfaces/tobago/trunk: ./ src/docbook/ tobago-core/ tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/ tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ tobago-core/src/test/java/org... Date: Fri, 23 Aug 2013 13:27:57 -0000 To: commits@myfaces.apache.org From: lofwyr@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130823132758.CA2E7238888A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: lofwyr Date: Fri Aug 23 13:27:56 2013 New Revision: 1516844 URL: http://svn.apache.org/r1516844 Log: TOBAGO-1298: Re-implement TobagoConfigParser now parsing with SAXParser no longer need commons-digester Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigEntityResolver.java myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigVersion.java myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserUnitTest.java - copied, changed from r1515387, myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-1.0.30.xml myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-1.5.xml myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-2.0.xml myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-fail-1.0.30.xml myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-fail-1.5.xml myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-fail-2.0.xml myfaces/tobago/trunk/tobago-core/src/test/resources/tobago-config-fail-unknown-version.xml Removed: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/ThemeParser.java myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java Modified: myfaces/tobago/trunk/pom.xml myfaces/tobago/trunk/src/docbook/tobago-tutorial.xml myfaces/tobago/trunk/tobago-core/pom.xml myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RendererConfig.java myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfig.java myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfigImpl.java myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ThemeBuilder.java myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockRenderersConfig.java myfaces/tobago/trunk/tobago-core/src/test/resources/theme-config.xml myfaces/tobago/trunk/tobago-core/src/test/resources/theme-config2.xml myfaces/tobago/trunk/tobago-core/src/test/resources/theme-config3.xml myfaces/tobago/trunk/tobago-core/src/test/resources/theme-config4.xml Modified: myfaces/tobago/trunk/pom.xml URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/pom.xml?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/pom.xml (original) +++ myfaces/tobago/trunk/pom.xml Fri Aug 23 13:27:56 2013 @@ -183,8 +183,6 @@ http://jakarta.apache.org/commons/collections/api-${commons-collection.version}/ http://jakarta.apache.org/commons/lang/api-${commons-lang.version}/ http://jakarta.apache.org/commons/fileupload/apidocs - http://jakarta.apache.org/commons/digester/commons-digester-${commons-digester.version}/docs/api/ - http://jakarta.apache.org/commons/io/api-${commons-io.version}/ http://jakarta.apache.org/commons/logging/commons-logging-${commons-logging.version}/apidocs/ http://www.slf4j.org/apidocs @@ -476,11 +474,6 @@ provided - commons-digester - commons-digester - ${commons-digester.version} - - commons-fileupload commons-fileupload 1.2.2 @@ -883,10 +876,14 @@ maven-surefire-plugin 2.9 - + + -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y +--> @@ -1752,8 +1749,6 @@ 2.4 2.6 1.1.1 - - 1.8.1 3.2.1 1.5 1.5 Modified: myfaces/tobago/trunk/src/docbook/tobago-tutorial.xml URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/src/docbook/tobago-tutorial.xml?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/src/docbook/tobago-tutorial.xml (original) +++ myfaces/tobago/trunk/src/docbook/tobago-tutorial.xml Fri Aug 23 13:27:56 2013 @@ -107,12 +107,12 @@ </theme-config> </tobago-config> - A Tobago web application needs to package many libraries. First of + A Tobago web application needs to package some libraries. First of all, the Tobago core jar and theme jars should be made available in the application. Some themes depend on each other, for example to be able to use the Speyside theme the Scarborough theme and Standard theme have to be included as well. These dependencies are defined in the - META-INF/tobago-theme.xml files inside the theme jars. + META-INF/tobago-config.xml files inside the theme jars. Tobago depends on several Jakarta Commons libraries: @@ -126,7 +126,7 @@ - commons-digester + commons-digester (only Tobago 1.x) Modified: myfaces/tobago/trunk/tobago-core/pom.xml URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/pom.xml?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/pom.xml (original) +++ myfaces/tobago/trunk/tobago-core/pom.xml Fri Aug 23 13:27:56 2013 @@ -225,16 +225,6 @@ provided - commons-digester - commons-digester - - - xml-apis - xml-apis - - - - commons-fileupload commons-fileupload Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RendererConfig.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RendererConfig.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RendererConfig.java (original) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RendererConfig.java Fri Aug 23 13:27:56 2013 @@ -19,10 +19,10 @@ package org.apache.myfaces.tobago.internal.config; +import org.apache.commons.lang.StringUtils; import org.apache.myfaces.tobago.context.Markup; import java.io.Serializable; -import java.util.Locale; public class RendererConfig implements Serializable { @@ -36,7 +36,7 @@ public class RendererConfig implements S } public void setName(String name) { - this.name = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1); + this.name = StringUtils.uncapitalize(name); } public boolean equals(Object o) { Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfig.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfig.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfig.java (original) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfig.java Fri Aug 23 13:27:56 2013 @@ -19,12 +19,12 @@ package org.apache.myfaces.tobago.internal.config; -import java.util.Collection; +import java.util.List; public interface RenderersConfig { boolean isMarkupSupported(String rendererName, String markup); - Collection getRendererConfigs(); + List getRendererConfigs(); } Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfigImpl.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfigImpl.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfigImpl.java (original) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/RenderersConfigImpl.java Fri Aug 23 13:27:56 2013 @@ -23,8 +23,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; public class RenderersConfigImpl implements RenderersConfig, Serializable { @@ -45,8 +47,10 @@ public class RenderersConfigImpl impleme this.merged = merged; } - public Collection getRendererConfigs() { - return rendererMap.values(); + public List getRendererConfigs() { + final ArrayList result = new ArrayList(); + result.addAll(rendererMap.values()); + return result; } public void addRenderer(RendererConfig rendererConfig) { @@ -60,7 +64,7 @@ public class RenderersConfigImpl impleme public boolean isMarkupSupported(String rendererName, String markup) { if (LOG.isDebugEnabled()) { - LOG.debug("calling isMarkupSupported('{}', '{}')", rendererName, markup); + LOG.debug("Calling isMarkupSupported('{}', '{}')", rendererName, markup); } RendererConfig rendererConfig = rendererMap.get(rendererName); if (rendererConfig != null) { Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java (original) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java Fri Aug 23 13:27:56 2013 @@ -21,7 +21,6 @@ package org.apache.myfaces.tobago.intern import org.apache.commons.collections.CollectionUtils; import org.apache.myfaces.tobago.config.TobagoConfig; -import org.apache.myfaces.tobago.context.ThemeImpl; import org.apache.myfaces.tobago.internal.context.ResourceManagerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +28,9 @@ import org.xml.sax.SAXException; import javax.servlet.ServletContext; import javax.servlet.ServletException; +import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -40,14 +41,11 @@ public class TobagoConfigBuilder { private static final String WEB_INF_TOBAGO_CONFIG_XML = "WEB-INF/tobago-config.xml"; private static final String META_INF_TOBAGO_CONFIG_XML = "META-INF/tobago-config.xml"; - /** - * @deprecated Since 1.5.0 - */ - private static final String META_INF_TOBAGO_THEME_XML = "META-INF/tobago-theme.xml"; private List list; - private TobagoConfigBuilder(ServletContext servletContext) throws ServletException, IOException, SAXException { + private TobagoConfigBuilder(ServletContext servletContext) + throws ServletException, IOException, SAXException, ParserConfigurationException, URISyntaxException { list = new ArrayList(); configFromClasspath(); configFromWebInf(servletContext); @@ -79,9 +77,10 @@ public class TobagoConfigBuilder { } } - private void configFromWebInf(ServletContext servletContext) throws IOException, SAXException { + private void configFromWebInf(ServletContext servletContext) + throws IOException, SAXException, ParserConfigurationException, URISyntaxException { - final URL url = servletContext.getResource("/WEB-INF/tobago-config.xml"); + final URL url = servletContext.getResource("/" + WEB_INF_TOBAGO_CONFIG_XML); if (url != null) { list.add(new TobagoConfigParser().parse(url)); } @@ -89,43 +88,31 @@ public class TobagoConfigBuilder { private void configFromClasspath() throws ServletException { - ThemeParser parser = new ThemeParser(); try { if (LOG.isInfoEnabled()) { - LOG.info("Searching for '" + META_INF_TOBAGO_THEME_XML + "' and '" + META_INF_TOBAGO_CONFIG_XML + "'"); + LOG.info("Searching for '" + META_INF_TOBAGO_CONFIG_XML + "'"); } - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - List urls = new ArrayList(); + final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + final List urls = new ArrayList(); CollectionUtils.addAll(urls, classLoader.getResources(META_INF_TOBAGO_CONFIG_XML)); - CollectionUtils.addAll(urls, classLoader.getResources(META_INF_TOBAGO_THEME_XML)); - for (URL themeUrl : urls) { - TobagoConfigFragment tobagoConfig; - if (themeUrl.toString().endsWith(META_INF_TOBAGO_CONFIG_XML)) { - tobagoConfig = new TobagoConfigParser().parse(themeUrl); - } else { - // the old way - tobagoConfig = new TobagoConfigFragment(); - final ThemeImpl theme = parser.parse(themeUrl); - tobagoConfig.addThemeDefinition(theme); - } - tobagoConfig.setUrl(themeUrl); - String protocol = themeUrl.getProtocol(); + for (final URL themeUrl : urls) { + final TobagoConfigFragment fragment = new TobagoConfigParser().parse(themeUrl); + fragment.setUrl(themeUrl); + list.add(fragment); + // tomcat uses jar // weblogic uses zip // IBM WebSphere uses wsjar + final String protocol = themeUrl.getProtocol(); if (!"jar".equals(protocol) && !"zip".equals(protocol) && !"wsjar".equals(protocol)) { LOG.warn("Unknown protocol '" + themeUrl + "'"); } - - list.add(tobagoConfig); } } catch (Exception e) { - String msg = "while loading "; + final String msg = "while loading "; LOG.error(msg, e); throw new ServletException(msg, e); } } - - } Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigEntityResolver.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigEntityResolver.java?rev=1516844&view=auto ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigEntityResolver.java (added) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigEntityResolver.java Fri Aug 23 13:27:56 2013 @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.myfaces.tobago.internal.config; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +import java.io.IOException; +import java.io.InputStream; + +public class TobagoConfigEntityResolver extends DefaultHandler { + + private static final String TOBAGO_CONFIG_DTD_1_0 = "/org/apache/myfaces/tobago/config/tobago-config_1_0.dtd"; + private static final String TOBAGO_CONFIG_DTD_1_0_29 = "/org/apache/myfaces/tobago/config/tobago-config-1.0.29.dtd"; + private static final String TOBAGO_CONFIG_DTD_1_0_30 = "/org/apache/myfaces/tobago/config/tobago-config-1.0.30.dtd"; + private static final String TOBAGO_CONFIG_DTD_1_0_34 = "/org/apache/myfaces/tobago/config/tobago-config-1.0.34.dtd"; + protected static final String TOBAGO_CONFIG_XSD_1_5 = "/org/apache/myfaces/tobago/config/tobago-config-1.5.xsd"; + @Deprecated + protected static final String TOBAGO_CONFIG_XSD_1_6 = "/org/apache/myfaces/tobago/config/tobago-config-1.6.xsd"; + protected static final String TOBAGO_CONFIG_XSD_2_0 = "/org/apache/myfaces/tobago/config/tobago-config-2.0.xsd"; + + private static final Logger LOG = LoggerFactory.getLogger(TobagoConfigEntityResolver.class); + + @Override + public InputSource resolveEntity(final String publicId, final String systemId) throws IOException, SAXException { + if (LOG.isInfoEnabled()) { + LOG.info("Resolving publicId='" + publicId + "' and systemId='" + systemId + "'."); + } + final InputStream localStream; + if (systemId.equals("http://myfaces.apache.org/tobago/tobago-config_1_0.dtd")) { + localStream = getClass().getResourceAsStream(TOBAGO_CONFIG_DTD_1_0); + } else if (systemId.equals("http://myfaces.apache.org/tobago/tobago-config-1.0.29.dtd")) { + localStream = getClass().getResourceAsStream(TOBAGO_CONFIG_DTD_1_0_29); + } else if (systemId.equals("http://myfaces.apache.org/tobago/tobago-config-1.0.30.dtd")) { + localStream = getClass().getResourceAsStream(TOBAGO_CONFIG_DTD_1_0_30); + } else if (systemId.equals("http://myfaces.apache.org/tobago/tobago-config-1.0.34.dtd")) { + localStream = getClass().getResourceAsStream(TOBAGO_CONFIG_DTD_1_0_34); + } else { + localStream = null; + } + if (localStream != null) { + return new InputSource(localStream); + } else { + LOG.warn("Didn't find local resource for publicId='" + publicId + "' and systemId='" + systemId + "'. " + + "Trying to load with parent resolver (might be loaded over the internet)."); + return super.resolveEntity(publicId, systemId); + } + } +} Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java (original) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java Fri Aug 23 13:27:56 2013 @@ -96,8 +96,8 @@ public class TobagoConfigImpl extends To } if (defaultTheme == null) { String error = "Did not found any theme! " - + "Please ensure you have a tobago-theme.xml file in your " - + "theme jar. Please add a theme jar to your WEB-INF/lib"; + + "Please ensure you have a tobago-config.xml with a theme-definition in your " + + "theme JAR. Please add a theme JAR to your WEB-INF/lib"; LOG.error(error); throw new RuntimeException(error); } else { @@ -122,8 +122,8 @@ public class TobagoConfigImpl extends To private void checkThemeIsAvailable(String name, Theme theme) { if (theme == null) { String error = "Theme not found! name: '" + name + "'. " - + "Please ensure you have a tobago-theme.xml file in your " - + "theme jar. Found the following themes: " + availableThemes.keySet(); + + "Please ensure you have a tobago-config.xml with a theme-definition in your " + + "theme JAR. Found the following themes: " + availableThemes.keySet(); LOG.error(error); throw new RuntimeException(error); } Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java (original) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java Fri Aug 23 13:27:56 2013 @@ -19,185 +19,356 @@ package org.apache.myfaces.tobago.internal.config; -import org.apache.commons.digester.Digester; import org.apache.commons.io.IOUtils; import org.apache.myfaces.tobago.context.ThemeImpl; -import org.apache.myfaces.tobago.context.ThemeResources; import org.apache.myfaces.tobago.context.ThemeScript; import org.apache.myfaces.tobago.context.ThemeStyle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.xml.sax.Attributes; import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; import javax.faces.FacesException; +import javax.xml.XMLConstants; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.net.URL; +import java.util.Stack; -public class TobagoConfigParser { +public class TobagoConfigParser extends TobagoConfigEntityResolver { private static final Logger LOG = LoggerFactory.getLogger(TobagoConfigParser.class); - private static final String TOBAGO_CONFIG_DTD_1_0 = "/org/apache/myfaces/tobago/config/tobago-config_1_0.dtd"; - private static final String TOBAGO_CONFIG_DTD_1_0_29 = "/org/apache/myfaces/tobago/config/tobago-config-1.0.29.dtd"; - private static final String TOBAGO_CONFIG_DTD_1_0_30 = "/org/apache/myfaces/tobago/config/tobago-config-1.0.30.dtd"; - private static final String TOBAGO_CONFIG_DTD_1_0_34 = "/org/apache/myfaces/tobago/config/tobago-config-1.0.34.dtd"; - private static final String TOBAGO_CONFIG_XSD_1_5 = "/org/apache/myfaces/tobago/config/tobago-config-1.5.xsd"; - @Deprecated - private static final String TOBAGO_CONFIG_XSD_1_6 = "/org/apache/myfaces/tobago/config/tobago-config-1.6.xsd"; - private static final String TOBAGO_CONFIG_XSD_2_0 = "/org/apache/myfaces/tobago/config/tobago-config-2.0.xsd"; + private static final int TOBAGO_CONFIG = -1498874611; + private static final int NAME = 3373707; + private static final int ORDERING = 1234314708; + private static final int BEFORE = -1392885889; + private static final int AFTER = 92734940; + private static final int THEME_CONFIG = 1930630086; + private static final int DEFAULT_THEME = -114431171; + private static final int SUPPORTED_THEME = -822303766; + private static final int RESOURCE_DIR = -385546674; + private static final int CREATE_SESSION_SECRET = 413906616; + private static final int CHECK_SESSION_SECRET = 275994924; + private static final int PREVENT_FRAME_ATTACKS = 270456726; + private static final int CONTENT_SECURITY_POLICY = 1207440139; + private static final int DIRECTIVE = -962590641; + private static final int RENDERERS = 1839650832; + private static final int RENDERER = -494845757; + private static final int SUPPORTED_MARKUP = 71904295; + private static final int MARKUP = -1081305560; + private static final int THEME_DEFINITIONS = -255617156; + private static final int THEME_DEFINITION = 1515774935; + private static final int DISPLAY_NAME = 1568910518; + private static final int RESOURCE_PATH = 933304964; + private static final int FALLBACK = 761243362; + private static final int VERSIONED = -1407102089; + private static final int RESOURCES = -1983070683; + private static final int SCRIPT = -907685685; + private static final int STYLE = 109780401; + + private TobagoConfigFragment tobagoConfig; + private RendererConfig currentRenderer; + private ThemeImpl currentTheme; + private Boolean production; + private String text; - private Digester digester; + private Stack stack; public TobagoConfigParser() { - digester = new Digester(); - digester.setUseContextClassLoader(true); - configure(); - registerDtds(); } - public TobagoConfigFragment parse(URL url) throws IOException, SAXException, FacesException { + public TobagoConfigFragment parse(URL url) + throws IOException, SAXException, FacesException, ParserConfigurationException, URISyntaxException { if (LOG.isInfoEnabled()) { LOG.info("Parsing configuration file: '{}'", url); } - TobagoConfigFragment tobagoConfig = new TobagoConfigFragment(); - digester.push(tobagoConfig); + final TobagoConfigVersion version = new TobagoConfigVersion(url); + + // todo: Is there a solution that validate with both, DTD and XSD? + + if (version.isSchema()) { + validate(url, version); + } + InputStream inputStream = null; try { - configureValidation(url); inputStream = url.openStream(); - digester.parse(inputStream); + final SAXParserFactory factory = SAXParserFactory.newInstance(); + if (!version.isSchema()) { + factory.setValidating(true); + } + final SAXParser saxParser = factory.newSAXParser(); + saxParser.parse(inputStream, this); } finally { IOUtils.closeQuietly(inputStream); } return tobagoConfig; } - private void configureValidation(URL url) { - // TODO: validating is turned of in case of a schema - try { - final String xml = IOUtils.toString(url.openStream()); - if (xml.indexOf("tobago-config-1.5.xsd") > 0 - || xml.indexOf("tobago-config-1.6.xsd") > 0 - || xml.indexOf("tobago-config-2.0.xsd") > 0) { - digester.setValidating(false); - return; - } - } catch (Exception e) { - LOG.warn("Error while checking: '" + url + "'", e); - } - digester.setValidating(true); + @Override + public void startDocument() throws SAXException { + stack = new Stack(); } - private Digester configure() { + @Override + public void endDocument() throws SAXException { + assert stack.empty(); + stack = null; + } - // ordering - digester.addCallMethod("tobago-config/name", "setName", 0); - digester.addCallMethod("tobago-config/ordering/before/name", "addBefore", 0); - digester.addCallMethod("tobago-config/ordering/after/name", "addAfter", 0); - - // theme-config - digester.addCallMethod("tobago-config/theme-config/default-theme", "setDefaultThemeName", 0); - digester.addCallMethod("tobago-config/theme-config/supported-theme", "addSupportedThemeName", 0); - - // resource dirs - digester.addCallMethod("tobago-config/resource-dir", "addResourceDir", 0); - - // enable ajax - digester.addCallMethod("tobago-config/ajax-enabled", "setAjaxEnabled", 0); - - // see bug TOBAGO-912 - digester.addCallMethod("tobago-config/fix-resource-order", "setFixResourceOrder", 0); - - // see bug TOBAGO-916 - digester.addCallMethod("tobago-config/fix-layout-transparency", "setFixLayoutTransparency", 0); - - // session secret - digester.addCallMethod("tobago-config/create-session-secret", "setCreateSessionSecret", 0); - digester.addCallMethod("tobago-config/check-session-secret", "setCheckSessionSecret", 0); - - // frame attacks - digester.addBeanPropertySetter("tobago-config/prevent-frame-attacks", "preventFrameAttacks"); - - // content-security-policy - digester.addCallMethod("tobago-config/content-security-policy/directive", "addContentSecurityPolicy", 0); - - // renderer config - digester.addObjectCreate("tobago-config/renderers", RenderersConfigImpl.class); - digester.addSetNext("tobago-config/renderers", "setRenderersConfig"); - digester.addObjectCreate("tobago-config/renderers/renderer", RendererConfig.class); - digester.addSetNext("tobago-config/renderers/renderer", "addRenderer"); - digester.addCallMethod("tobago-config/renderers/renderer/name", "setName", 0); - digester.addCallMethod("tobago-config/renderers/renderer/supported-markup/markup", "addSupportedMarkup", 0); - - // theme definition - digester.addObjectCreate("tobago-config/theme-definitions/theme-definition", ThemeImpl.class); - digester.addSetNext("tobago-config/theme-definitions/theme-definition", "addThemeDefinition"); - digester.addCallMethod("tobago-config/theme-definitions/theme-definition/name", "setName", 0); - digester.addCallMethod("tobago-config/theme-definitions/theme-definition/display-name", "setDisplayName", 0); - digester.addCallMethod("tobago-config/theme-definitions/theme-definition/resource-path", "setResourcePath", 0); - digester.addCallMethod("tobago-config/theme-definitions/theme-definition/fallback", "setFallbackName", 0); - digester.addBeanPropertySetter("tobago-config/theme-definitions/theme-definition/versioned", - "versioned"); - digester.addObjectCreate("tobago-config/theme-definitions/theme-definition/renderers", RenderersConfigImpl.class); - digester.addSetNext("tobago-config/theme-definitions/theme-definition/renderers", "setRenderersConfig"); - digester.addObjectCreate( - "tobago-config/theme-definitions/theme-definition/renderers/renderer", RendererConfig.class); - digester.addSetNext("tobago-config/theme-definitions/theme-definition/renderers/renderer", "addRenderer"); - digester.addCallMethod("tobago-config/theme-definitions/theme-definition/renderers/renderer/name", "setName", 0); - digester.addCallMethod( - "tobago-config/theme-definitions/theme-definition/renderers/renderer/supported-markup/markup", - "addSupportedMarkup", 0); - digester.addObjectCreate("tobago-config/theme-definitions/theme-definition/resources", ThemeResources.class); - digester.addSetProperties("tobago-config/theme-definitions/theme-definition/resources"); - digester.addSetNext("tobago-config/theme-definitions/theme-definition/resources", "addResources"); - digester.addObjectCreate("tobago-config/theme-definitions/theme-definition/resources/script", ThemeScript.class); - digester.addSetProperties("tobago-config/theme-definitions/theme-definition/resources/script"); - digester.addSetNext("tobago-config/theme-definitions/theme-definition/resources/script", "addScript"); - digester.addObjectCreate("tobago-config/theme-definitions/theme-definition/resources/style", ThemeStyle.class); - digester.addSetProperties("tobago-config/theme-definitions/theme-definition/resources/style"); - digester.addSetNext("tobago-config/theme-definitions/theme-definition/resources/style", "addStyle"); - - return digester; - } - - private void registerDtds() { - registerDtd("-//Atanion GmbH//DTD Tobago Config 1.0//EN", TOBAGO_CONFIG_DTD_1_0); - registerDtd("-//The Apache Software Foundation//DTD Tobago Config 1.0//EN", TOBAGO_CONFIG_DTD_1_0); - registerDtd("-//The Apache Software Foundation//DTD Tobago Config 1.0.29//EN", TOBAGO_CONFIG_DTD_1_0_29); - registerDtd("-//The Apache Software Foundation//DTD Tobago Config 1.0.30//EN", TOBAGO_CONFIG_DTD_1_0_30); - registerDtd("-//The Apache Software Foundation//DTD Tobago Config 1.0.34//EN", TOBAGO_CONFIG_DTD_1_0_34); - // todo: find a way to register the schema - // registerDtd("http://myfaces.apache.org/tobago/tobago-config", TOBAGO_CONFIG_XSD_1_5); - // registerXsd("http://myfaces.apache.org/tobago/tobago-config", TOBAGO_CONFIG_XSD_1_5); - } - - private void registerDtd(String publicId, String entityUrl) { - URL url = TobagoConfigParser.class.getResource(entityUrl); - if (LOG.isDebugEnabled()) { - LOG.debug("Registering dtd: url='{}'", url); - } - if (null != url) { - digester.register(publicId, url.toString()); - } else { - LOG.warn("Unable to retrieve local DTD '" + entityUrl + "'; trying external URL"); + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { + + stack.add(qName); + + switch (qName.hashCode()) { + + case TOBAGO_CONFIG: + tobagoConfig = new TobagoConfigFragment(); + break; + + case CONTENT_SECURITY_POLICY: + LOG.warn("todo: not implemented yet!"); // todo + attributes.getValue("disabled"); + attributes.getValue("replace"); + break; + + case RENDERERS: + if (currentTheme != null) { + currentTheme.setRenderersConfig(new RenderersConfigImpl()); + } else { + tobagoConfig.setRenderersConfig(new RenderersConfigImpl()); + } + break; + + case RENDERER: + currentRenderer = new RendererConfig(); + break; + + case THEME_DEFINITION: + currentTheme = new ThemeImpl(); + tobagoConfig.addThemeDefinition(currentTheme); + break; + + case RESOURCES: + production = Boolean.parseBoolean(attributes.getValue("production")); + break; + + case SCRIPT: + final ThemeScript script = new ThemeScript(); + script.setName(attributes.getValue("name")); + if (production) { + currentTheme.getProductionResources().addScript(script); + } else { + currentTheme.getResources().addScript(script); + } + break; + + case STYLE: + final ThemeStyle style = new ThemeStyle(); + style.setName(attributes.getValue("name")); + if (production) { + currentTheme.getProductionResources().addStyle(style); + } else { + currentTheme.getResources().addStyle(style); + } + break; + + case NAME: + case ORDERING: + case BEFORE: + case AFTER: + case RESOURCE_DIR: + case THEME_CONFIG: + case DEFAULT_THEME: + case SUPPORTED_THEME: + case SUPPORTED_MARKUP: + case MARKUP: + case CREATE_SESSION_SECRET: + case CHECK_SESSION_SECRET: + case PREVENT_FRAME_ATTACKS: + case DIRECTIVE: + case THEME_DEFINITIONS: + case DISPLAY_NAME: + case RESOURCE_PATH: + case VERSIONED: + case FALLBACK: + break; + + default: + LOG.warn("Ignoring unknown start tag <" + qName + ">"); } } -/* - private void registerXsd(String publicId, String entityUrl) { - URL url = TobagoConfigParser.class.getResource(entityUrl); - if (LOG.isDebugEnabled()) { - LOG.debug("Registering dtd: url='{}'", url); + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + text = new String(ch, start, length); + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + assert qName.equals(stack.peek()); + + switch (qName.hashCode()) { + + case NAME: + final String parent = stack.get(stack.size() - 2); + switch (parent.hashCode()) { + + case TOBAGO_CONFIG: + tobagoConfig.setName(text); + break; + + case BEFORE: + tobagoConfig.addBefore(text); + break; + + case AFTER: + tobagoConfig.addAfter(text); + break; + + case RENDERER: + currentRenderer.setName(text); + if (currentTheme != null) { + ((RenderersConfigImpl) currentTheme.getRenderersConfig()).addRenderer(currentRenderer); + } else { + ((RenderersConfigImpl) tobagoConfig.getRenderersConfig()).addRenderer(currentRenderer); + } + break; + + case THEME_DEFINITION: + currentTheme.setName(text); + break; + + default: + LOG.warn("Ignoring unknown parent <" + qName + "> of tag "); + } + break; + + case DEFAULT_THEME: + tobagoConfig.setDefaultThemeName(text); + break; + + case SUPPORTED_THEME: + tobagoConfig.addSupportedThemeName(text); + break; + + case RESOURCE_DIR: + tobagoConfig.addResourceDir(text); + break; + + case CREATE_SESSION_SECRET: + tobagoConfig.setCreateSessionSecret(text); + break; + + case CHECK_SESSION_SECRET: + tobagoConfig.setCheckSessionSecret(text); + break; + + case PREVENT_FRAME_ATTACKS: + tobagoConfig.setPreventFrameAttacks(Boolean.parseBoolean(text)); + break; + + case DIRECTIVE: + tobagoConfig.addContentSecurityPolicy(text); + break; + + case MARKUP: + currentRenderer.addSupportedMarkup(text); + break; + + case DISPLAY_NAME: + currentTheme.setDisplayName(text); + break; + + case RESOURCE_PATH: + currentTheme.setResourcePath(text); + break; + + case FALLBACK: + currentTheme.setFallbackName(text); + break; + + case THEME_DEFINITION: + currentTheme = null; + break; + + case VERSIONED: + currentTheme.setVersioned(Boolean.parseBoolean(text)); + break; + + case RESOURCES: + production = null; + break; + + case TOBAGO_CONFIG: + case THEME_CONFIG: + case ORDERING: + case BEFORE: + case AFTER: + case SUPPORTED_MARKUP: + case CONTENT_SECURITY_POLICY: + case THEME_DEFINITIONS: + case RENDERERS: + case RENDERER: + case SCRIPT: + case STYLE: + break; + + default: + LOG.warn("Ignoring unknown end tag <" + qName + ">"); } - if (null != url) { - digester.setSchema(publicId); - // digester.setSchemaLanguage(); + + stack.pop(); + } + + @Override + public void warning(SAXParseException e) throws SAXException { + throw e; + } + + @Override + public void error(SAXParseException e) throws SAXException { + throw e; + } + + @Override + public void fatalError(SAXParseException e) throws SAXException { + throw e; + } + + private void validate(final URL url, final TobagoConfigVersion version) + throws URISyntaxException, SAXException, IOException { + + final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + final Schema schema; + if ("2.0".equals(version.getVersion())) { + schema = schemaFactory.newSchema(getClass().getResource(TOBAGO_CONFIG_XSD_2_0)); + } else if ("1.6".equals(version.getVersion())) { + LOG.warn("Using deprecated schema with version attribute 1.6 in file: '" + url + "'"); + schema = schemaFactory.newSchema(getClass().getResource(TOBAGO_CONFIG_XSD_1_6)); + } else if ("1.5".equals(version.getVersion())) { + schema = schemaFactory.newSchema(getClass().getResource(TOBAGO_CONFIG_XSD_1_5)); } else { - LOG.warn("Unable to retrieve local DTD '" + entityUrl + "'; trying external URL"); + throw new SAXException("Using unknown version attribute '" + version.getVersion() + "' in file: '" + url + "'"); } + final Validator validator = schema.newValidator(); + final Source source = new StreamSource(url.openStream()); + + validator.validate(source); } -*/ + } Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigVersion.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigVersion.java?rev=1516844&view=auto ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigVersion.java (added) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigVersion.java Fri Aug 23 13:27:56 2013 @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.myfaces.tobago.internal.config; + +import org.apache.commons.io.IOUtils; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +public class TobagoConfigVersion extends TobagoConfigEntityResolver { + + /** Schema or DTD? */ + private boolean schema; + + private String version; + + public TobagoConfigVersion(URL url) throws ParserConfigurationException, SAXException, IOException { + + // simple reading with no validation, at this time + InputStream inputStream = null; + try { + inputStream = url.openStream(); + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser saxParser = factory.newSAXParser(); + saxParser.parse(inputStream, this); + } finally { + IOUtils.closeQuietly(inputStream); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) { + if ("tobago-config".equals(qName)) { + version = attributes.getValue("version"); + schema = version != null; + } + } + + public boolean isSchema() { + return schema; + } + + public String getVersion() { + return version; + } +} Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java (original) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java Fri Aug 23 13:27:56 2013 @@ -19,16 +19,12 @@ package org.apache.myfaces.tobago.internal.context; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.IOUtils; import org.apache.myfaces.tobago.context.ThemeImpl; -import org.apache.myfaces.tobago.internal.config.ThemeParser; import org.apache.myfaces.tobago.internal.config.TobagoConfigFragment; import org.apache.myfaces.tobago.internal.config.TobagoConfigParser; -import org.apache.myfaces.tobago.internal.util.Deprecation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.xml.sax.SAXException; import javax.servlet.ServletContext; import javax.servlet.ServletException; @@ -40,9 +36,7 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.ArrayList; import java.util.Enumeration; -import java.util.List; import java.util.Properties; import java.util.Set; import java.util.zip.ZipEntry; @@ -59,7 +53,6 @@ class ResourceLocator { private static final Logger LOG = LoggerFactory.getLogger(ResourceLocator.class); private static final String META_INF_TOBAGO_CONFIG_XML = "META-INF/tobago-config.xml"; - private static final String META_INF_TOBAGO_THEME_XML = "META-INF/tobago-theme.xml"; private static final String META_INF_RESOURCES = "META-INF/resources"; private ServletContext servletContext; @@ -75,7 +68,7 @@ class ResourceLocator { public void locate() throws ServletException { - // TODO should the resourcedir used from tobago-config.xml? + // TBD should the resource dir used from tobago-config.xml? locateResourcesInWar(servletContext, resourceManager, "/"); locateResourcesFromClasspath(resourceManager); locateResourcesServlet30Alike(resourceManager); @@ -137,61 +130,52 @@ class ResourceLocator { private void locateResourcesFromClasspath(ResourceManagerImpl resources) throws ServletException { - ThemeParser parser = new ThemeParser(); try { if (LOG.isInfoEnabled()) { - LOG.info("Searching for '" + META_INF_TOBAGO_THEME_XML + "' and '" + META_INF_TOBAGO_CONFIG_XML +"'"); + LOG.info("Searching for and '" + META_INF_TOBAGO_CONFIG_XML +"'"); } - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - List urls = new ArrayList(); - CollectionUtils.addAll(urls, classLoader.getResources(META_INF_TOBAGO_CONFIG_XML)); - CollectionUtils.addAll(urls, classLoader.getResources(META_INF_TOBAGO_THEME_XML)); - - for (URL themeUrl : urls) { - if (themeUrl.toString().endsWith(META_INF_TOBAGO_CONFIG_XML)) { - TobagoConfigFragment tobagoConfig = new TobagoConfigParser().parse(themeUrl); - for (ThemeImpl theme : tobagoConfig.getThemeDefinitions()) { - if (theme.isVersioned()) { - String themeUrlStr = themeUrl.toString(); - int index = themeUrlStr.indexOf(META_INF_TOBAGO_CONFIG_XML); - String metaInf = themeUrlStr.substring(0, index) + "META-INF/MANIFEST.MF"; - Properties properties = new Properties(); - final URL url = new URL(metaInf); - InputStream inputStream = null; - String version = null; - try { - inputStream = url.openStream(); - properties.load(inputStream); - version = properties.getProperty("Implementation-Version"); - } catch (FileNotFoundException e) { - // may happen (e. g. in tests) - LOG.error("No Manifest-File found."); - } finally { - IOUtils.closeQuietly(inputStream); - } - if (version != null) { - theme.setVersion(version); - } else { - theme.setVersioned(false); - LOG.error("No Implementation-Version found in Manifest-File for theme: '" + theme.getName() - + "'. Resetting the theme to unversioned. Please correct the Manifest-File."); - } + final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + final Enumeration urls = classLoader.getResources(META_INF_TOBAGO_CONFIG_XML); + + while (urls.hasMoreElements()) { + URL themeUrl = urls.nextElement(); + TobagoConfigFragment tobagoConfig = new TobagoConfigParser().parse(themeUrl); + for (ThemeImpl theme : tobagoConfig.getThemeDefinitions()) { + if (theme.isVersioned()) { + String themeUrlStr = themeUrl.toString(); + int index = themeUrlStr.indexOf(META_INF_TOBAGO_CONFIG_XML); + String metaInf = themeUrlStr.substring(0, index) + "META-INF/MANIFEST.MF"; + Properties properties = new Properties(); + final URL url = new URL(metaInf); + InputStream inputStream = null; + String version = null; + try { + inputStream = url.openStream(); + properties.load(inputStream); + version = properties.getProperty("Implementation-Version"); + } catch (FileNotFoundException e) { + // may happen (e. g. in tests) + LOG.error("No Manifest-File found."); + } finally { + IOUtils.closeQuietly(inputStream); + } + if (version != null) { + theme.setVersion(version); + } else { + theme.setVersioned(false); + LOG.error("No Implementation-Version found in Manifest-File for theme: '" + theme.getName() + + "'. Resetting the theme to unversioned. Please correct the Manifest-File."); } - addThemeResources(resources, themeUrl, theme); } - } else { - // the old way - addThemeResources(resources, themeUrl, parser.parse(themeUrl)); + addThemeResources(resources, themeUrl, theme); } } - } catch (IOException e) { - String msg = "while loading "; - LOG.error(msg, e); - throw new ServletException(msg, e); - } catch (SAXException e) { - String msg = "while loading "; - LOG.error(msg, e); - throw new ServletException(msg, e); + } catch (Exception e) { + if (e instanceof ServletException) { + throw (ServletException) e; + } else { + throw new ServletException(e); + } } } @@ -256,10 +240,6 @@ class ResourceLocator { private void addResources(ResourceManagerImpl resources, URL themeUrl, String prefix, int skipPrefix) throws IOException, ServletException { String fileName = themeUrl.toString(); - if (fileName.endsWith(META_INF_TOBAGO_THEME_XML)) { - Deprecation.LOG.warn( - "The use of 'tobago-theme.xml' is deprecated, please use 'tobago-config.xml' to define a theme!"); - } int index = fileName.indexOf("!"); String protocol = themeUrl.getProtocol(); if (index != -1) { @@ -270,8 +250,7 @@ class ResourceLocator { } // JBoss 5.0.0 introduced vfszip protocol - if (!protocol.equals("vfszip") - && (fileName.endsWith(META_INF_TOBAGO_THEME_XML) || fileName.endsWith(META_INF_TOBAGO_CONFIG_XML))) { + if (!protocol.equals("vfszip") && fileName.endsWith(META_INF_TOBAGO_CONFIG_XML)) { try { URI uri = themeUrl.toURI(); File tobagoThemeXml = new File(uri); @@ -324,19 +303,21 @@ class ResourceLocator { private void resolveTheme(ResourceManagerImpl resources, File directoryFile, String resourcePath, String prefix, boolean inResourcePath) throws ServletException { File[] files = directoryFile.listFiles(); - for (File file : files) { - if (file.isDirectory()) { - String currentResourcePath = resourcePath + File.separator + file.getName(); - if (!inResourcePath && currentResourcePath.startsWith(prefix)) { - inResourcePath = true; - } - resolveTheme(resources, file, currentResourcePath, prefix, inResourcePath); - } else { - if (LOG.isInfoEnabled()) { - LOG.info(resourcePath + File.separator + file.getName()); - } - if (inResourcePath) { - addResource(resources, resourcePath + File.separator + file.getName(), 0); + if (files != null) { + for (File file : files) { + if (file.isDirectory()) { + String currentResourcePath = resourcePath + File.separator + file.getName(); + if (!inResourcePath && currentResourcePath.startsWith(prefix)) { + inResourcePath = true; + } + resolveTheme(resources, file, currentResourcePath, prefix, inResourcePath); + } else { + if (LOG.isInfoEnabled()) { + LOG.info(resourcePath + File.separator + file.getName()); + } + if (inResourcePath) { + addResource(resources, resourcePath + File.separator + file.getName(), 0); + } } } } Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ThemeBuilder.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ThemeBuilder.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ThemeBuilder.java (original) +++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ThemeBuilder.java Fri Aug 23 13:27:56 2013 @@ -45,7 +45,9 @@ class ThemeBuilder { public void resolveThemes() { Map map = new HashMap(); for (ThemeImpl theme : availableThemes) { - LOG.debug("theme from tobago-theme.xml files: {} ", theme.getName()); + if (LOG.isDebugEnabled()) { + LOG.debug("Theme from XML files: {} ", theme.getName()); + } map.put(theme.getName(), theme); } for (ThemeImpl theme : availableThemes) { Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java (original) +++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigMergingUnitTest.java Fri Aug 23 13:27:56 2013 @@ -23,7 +23,9 @@ import org.junit.Assert; import org.junit.Test; import org.xml.sax.SAXException; +import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.List; @@ -31,7 +33,8 @@ import java.util.List; public class TobagoConfigMergingUnitTest { @Test - public void testPreventFrameAttacksCascadingDefault() throws IOException, SAXException { + public void testPreventFrameAttacksCascadingDefault() + throws IOException, SAXException, ParserConfigurationException, URISyntaxException { final TobagoConfigImpl config = loadAndMerge( "tobago-config-0.xml", @@ -41,24 +44,25 @@ public class TobagoConfigMergingUnitTest } @Test - public void testPreventFrameAttacks() throws IOException, SAXException { + public void testPreventFrameAttacks() + throws IOException, SAXException, ParserConfigurationException, URISyntaxException { - final TobagoConfigImpl config = loadAndMerge( - "tobago-config-0.xml"); + final TobagoConfigImpl config = loadAndMerge("tobago-config-0.xml"); Assert.assertFalse(config.isPreventFrameAttacks()); } @Test - public void testPreventFrameAttacksDefault() throws IOException, SAXException { + public void testPreventFrameAttacksDefault() + throws IOException, SAXException, ParserConfigurationException, URISyntaxException { - final TobagoConfigImpl config = loadAndMerge( - "tobago-config-1.xml"); + final TobagoConfigImpl config = loadAndMerge("tobago-config-1.xml"); Assert.assertTrue(config.isPreventFrameAttacks()); } - private TobagoConfigImpl loadAndMerge(String... names) throws IOException, SAXException { + private TobagoConfigImpl loadAndMerge(String... names) + throws IOException, SAXException, ParserConfigurationException, URISyntaxException { final List list = new ArrayList(); Added: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java?rev=1516844&view=auto ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java (added) +++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParserUnitTest.java Fri Aug 23 13:27:56 2013 @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.myfaces.tobago.internal.config; + +import junit.framework.Assert; +import org.apache.myfaces.tobago.context.ThemeImpl; +import org.junit.Test; +import org.xml.sax.SAXException; + +import java.lang.reflect.Field; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class TobagoConfigParserUnitTest { + + @Test + public void testParser() throws Exception { + + final URL url = getClass().getClassLoader().getResource("tobago-config-2.0.xml"); + final TobagoConfigParser parser = new TobagoConfigParser(); + + final TobagoConfigFragment fragment = parser.parse(url); + + Assert.assertEquals("my-name", fragment.getName()); + + Assert.assertEquals(1, fragment.getAfter().size()); + Assert.assertEquals("my-after", fragment.getAfter().get(0)); + + Assert.assertEquals(2, fragment.getBefore().size()); + Assert.assertEquals("my-before-1", fragment.getBefore().get(0)); + Assert.assertEquals("my-before-2", fragment.getBefore().get(1)); + + Assert.assertEquals(2, fragment.getResourceDirs().size()); + Assert.assertEquals("my-resource-1", fragment.getResourceDirs().get(0)); + Assert.assertEquals("my-resource-2", fragment.getResourceDirs().get(1)); + + Assert.assertEquals(false, fragment.getCreateSessionSecret().booleanValue()); + Assert.assertEquals(false, fragment.getCheckSessionSecret().booleanValue()); + Assert.assertEquals(false, fragment.getPreventFrameAttacks().booleanValue()); + + Assert.assertEquals(2, fragment.getContentSecurityPolicy().size()); + Assert.assertEquals("default-src 'self'", fragment.getContentSecurityPolicy().get(0)); + Assert.assertEquals("frame-src http://apache.org", fragment.getContentSecurityPolicy().get(1)); + // todo: disabled + // todo: replace + + Assert.assertEquals(2, fragment.getRenderersConfig().getRendererConfigs().size()); + Assert.assertTrue(fragment.getRenderersConfig().isMarkupSupported("myRenderer-1", "my-markup-1")); + Assert.assertTrue(fragment.getRenderersConfig().isMarkupSupported("myRenderer-2", "my-markup-2-1")); + Assert.assertTrue(fragment.getRenderersConfig().isMarkupSupported("myRenderer-2", "my-markup-2-2")); + + Assert.assertEquals(2, fragment.getThemeDefinitions().size()); + final ThemeImpl theme1 = fragment.getThemeDefinitions().get(0); + Assert.assertEquals("my-theme-1", theme1.getName()); + Assert.assertEquals("My Theme 1", theme1.getDisplayName()); + Assert.assertEquals("/my/path-1", theme1.getResourcePath()); + Assert.assertTrue(theme1.isVersioned()); + Assert.assertTrue(theme1.getRenderersConfig().isMarkupSupported("themeRenderer", "theme-markup")); + Assert.assertTrue(theme1.getProductionResources().isProduction()); + Assert.assertEquals("script.js", theme1.getProductionResources().getScriptList().get(0).getName()); + Assert.assertEquals("style.css", theme1.getProductionResources().getStyleList().get(0).getName()); + + final ThemeImpl theme2 = fragment.getThemeDefinitions().get(1); + Assert.assertEquals("my-theme-2", theme2.getName()); + Assert.assertEquals("my-theme-1", theme2.getFallbackName()); + Assert.assertEquals("/my/path-2", theme2.getResourcePath()); + Assert.assertFalse(theme2.isVersioned()); + Assert.assertFalse(theme2.getResources().isProduction()); + Assert.assertEquals(0, theme2.getResources().getScriptList().size()); + Assert.assertEquals(0, theme2.getResources().getStyleList().size()); + Assert.assertEquals(0, theme2.getProductionResources().getScriptList().size()); + Assert.assertEquals(0, theme2.getProductionResources().getStyleList().size()); + } + + @Test + public void testParserFor10() throws Exception { + final URL url = getClass().getClassLoader().getResource("tobago-config-1.0.30.xml"); + final TobagoConfigParser parser = new TobagoConfigParser(); + final TobagoConfigFragment fragment = parser.parse(url); + Assert.assertEquals("speyside", fragment.getDefaultThemeName()); + } + + @Test + public void testFailParserFor10() throws Exception { + final URL url = getClass().getClassLoader().getResource("tobago-config-fail-1.0.30.xml"); + final TobagoConfigParser parser = new TobagoConfigParser(); + try { + parser.parse(url); + Assert.fail("No SAXParseException thrown!"); + } catch (SAXException e) { + // okay + } + } + + @Test + public void testParserFor15() throws Exception { + final URL url = getClass().getClassLoader().getResource("tobago-config-1.5.xml"); + final TobagoConfigParser parser = new TobagoConfigParser(); + final TobagoConfigFragment fragment = parser.parse(url); + Assert.assertEquals("speyside", fragment.getDefaultThemeName()); + } + + @Test + public void testFailParserFor15() throws Exception { + final URL url = getClass().getClassLoader().getResource("tobago-config-fail-1.5.xml"); + final TobagoConfigParser parser = new TobagoConfigParser(); + try { + parser.parse(url); + Assert.fail("No SAXParseException thrown!"); + } catch (SAXException e) { + // okay + } + } + + @Test + public void testFailParserFor20() throws Exception { + final URL url = getClass().getClassLoader().getResource("tobago-config-fail-2.0.xml"); + final TobagoConfigParser parser = new TobagoConfigParser(); + try { + parser.parse(url); + Assert.fail("No SAXParseException thrown!"); + } catch (SAXException e) { + // okay + } + } + + @Test + public void testFailParserForUnknownVersion() throws Exception { + final URL url = getClass().getClassLoader().getResource("tobago-config-fail-unknown-version.xml"); + final TobagoConfigParser parser = new TobagoConfigParser(); + try { + parser.parse(url); + Assert.fail("No SAXParseException thrown!"); + } catch (SAXException e) { + // okay + } + } + + @Test + public void testUniqueness() throws IllegalAccessException { + final Field[] all = TobagoConfigParser.class.getFields(); + final List fields = new ArrayList(); + for (Field field : all) { + if (field.getType().equals(Integer.TYPE)) { + fields.add(field); + } + } + // uniqueness + TobagoConfigParser dummy = new TobagoConfigParser(); + Set hashCodes = new HashSet(); + for (Field field : fields) { + hashCodes.add(field.getInt(dummy)); + } + Assert.assertEquals("All used hash codes must be unique", fields.size(), hashCodes.size()); + + // check hash code values + for (Field field : fields) { + int hash = field.getInt(dummy); + String name = field.getName().toLowerCase().replace('_', '-'); + Assert.assertEquals("Are the constants correct?", name.hashCode(), hash); + } + } + +} Copied: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserUnitTest.java (from r1515387, myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java) URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserUnitTest.java?p2=myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserUnitTest.java&p1=myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java&r1=1515387&r2=1516844&rev=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java (original) +++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserUnitTest.java Fri Aug 23 13:27:56 2013 @@ -21,30 +21,32 @@ package org.apache.myfaces.tobago.intern import org.apache.myfaces.tobago.context.ThemeImpl; import org.apache.myfaces.tobago.context.ThemeResources; -import org.apache.myfaces.tobago.internal.config.ThemeParser; import org.apache.myfaces.tobago.internal.config.TobagoConfigImpl; +import org.apache.myfaces.tobago.internal.config.TobagoConfigParser; import org.junit.Assert; import org.junit.Test; import org.xml.sax.SAXException; +import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; +import java.net.URISyntaxException; import java.net.URL; import java.util.Enumeration; -public class ThemeParserTest { +public class ThemeParserUnitTest { @Test - public void test() throws IOException, SAXException { + public void test() throws IOException, SAXException, ParserConfigurationException, URISyntaxException { TobagoConfigImpl config = new TobagoConfigImpl(); ThemeBuilder themeBuilder = new ThemeBuilder(config); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Enumeration urls = classLoader.getResources("theme-config.xml"); - ThemeParser parser = new ThemeParser(); + TobagoConfigParser parser = new TobagoConfigParser(); ThemeImpl theme = null; if (urls.hasMoreElements()) { URL themeUrl = urls.nextElement(); - theme = parser.parse(themeUrl); + theme = parser.parse(themeUrl).getThemeDefinitions().get(0); Assert.assertEquals("test", theme.getName()); Assert.assertNotNull(theme.getResources()); Assert.assertNotNull(theme.getProductionResources()); @@ -66,7 +68,7 @@ public class ThemeParserTest { ThemeImpl theme2 = null; if (urls.hasMoreElements()) { URL themeUrl = urls.nextElement(); - theme2 = parser.parse(themeUrl); + theme2 = parser.parse(themeUrl).getThemeDefinitions().get(0); Assert.assertEquals("test2", theme2.getName()); Assert.assertNotNull(theme2.getResources()); Assert.assertEquals(1, theme2.getResources().getScriptList().size()); @@ -81,7 +83,7 @@ public class ThemeParserTest { ThemeImpl theme3 = null; if (urls.hasMoreElements()) { URL themeUrl = urls.nextElement(); - theme3 = parser.parse(themeUrl); + theme3 = parser.parse(themeUrl).getThemeDefinitions().get(0); Assert.assertEquals("test3", theme3.getName()); Assert.assertEquals(0, theme3.getResources().getScriptList().size()); Assert.assertEquals(0, theme3.getResources().getStyleList().size()); @@ -95,7 +97,7 @@ public class ThemeParserTest { ThemeImpl theme4 = null; if (urls.hasMoreElements()) { URL themeUrl = urls.nextElement(); - theme4 = parser.parse(themeUrl); + theme4 = parser.parse(themeUrl).getThemeDefinitions().get(0); Assert.assertEquals("test4", theme4.getName()); Assert.assertEquals(0, theme4.getResources().getScriptList().size()); Assert.assertEquals(0, theme4.getResources().getStyleList().size()); Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockRenderersConfig.java URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockRenderersConfig.java?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockRenderersConfig.java (original) +++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockRenderersConfig.java Fri Aug 23 13:27:56 2013 @@ -22,7 +22,7 @@ package org.apache.myfaces.tobago.intern import org.apache.myfaces.tobago.internal.config.RendererConfig; import org.apache.myfaces.tobago.internal.config.RenderersConfig; -import java.util.Collection; +import java.util.List; public class MockRenderersConfig implements RenderersConfig { @@ -33,7 +33,7 @@ public class MockRenderersConfig impleme return markup.length() < 10; } - public Collection getRendererConfigs() { + public List getRendererConfigs() { return null; } } Modified: myfaces/tobago/trunk/tobago-core/src/test/resources/theme-config.xml URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/resources/theme-config.xml?rev=1516844&r1=1516843&r2=1516844&view=diff ============================================================================== --- myfaces/tobago/trunk/tobago-core/src/test/resources/theme-config.xml (original) +++ myfaces/tobago/trunk/tobago-core/src/test/resources/theme-config.xml Fri Aug 23 13:27:56 2013 @@ -17,17 +17,25 @@ * limitations under the License. --> - - test - Test - Test - -