Modified: struts/struts1/trunk/tiles/src/main/java/org/apache/struts/tiles/xmlDefinition/XmlParser.java URL: http://svn.apache.org/viewvc/struts/struts1/trunk/tiles/src/main/java/org/apache/struts/tiles/xmlDefinition/XmlParser.java?view=diff&rev=471754&r1=471753&r2=471754 ============================================================================== --- struts/struts1/trunk/tiles/src/main/java/org/apache/struts/tiles/xmlDefinition/XmlParser.java (original) +++ struts/struts1/trunk/tiles/src/main/java/org/apache/struts/tiles/xmlDefinition/XmlParser.java Mon Nov 6 06:55:09 2006 @@ -1,22 +1,24 @@ /* - * $Id$ + * $Id$ * - * Copyright 1999-2004 The Apache Software Foundation. - * - * 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. + * 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.struts.tiles.xmlDefinition; import java.io.BufferedInputStream; @@ -59,11 +61,11 @@ */ public XmlParser() { - digester = new Digester(); - digester.setValidating(validating); - digester.setNamespaceAware(true); - digester.setUseContextClassLoader(true); - // Register our local copy of the DTDs that we can find + digester = new Digester(); + digester.setValidating(validating); + digester.setNamespaceAware(true); + digester.setUseContextClassLoader(true); + // Register our local copy of the DTDs that we can find for (int i = 0; i < registrations.length; i += 2) { URL url = this.getClass().getResource(registrations[i+1]); if (url != null) @@ -91,7 +93,7 @@ */ private void initDigesterForComponentsDefinitionsSyntax( Digester digester ) { - // Common constants + // Common constants String PACKAGE_NAME = "org.apache.struts.tiles.xmlDefinition"; String DEFINITION_TAG = "component-definitions/definition"; String definitionHandlerClass = PACKAGE_NAME + ".XmlDefinition"; @@ -105,25 +107,25 @@ String ADD_LIST_ELE_TAG = LIST_TAG + "/add"; // syntax rules - digester.addObjectCreate( DEFINITION_TAG, definitionHandlerClass ); - digester.addSetProperties( DEFINITION_TAG); - digester.addSetNext( DEFINITION_TAG, "putDefinition", definitionHandlerClass); + digester.addObjectCreate( DEFINITION_TAG, definitionHandlerClass ); + digester.addSetProperties( DEFINITION_TAG); + digester.addSetNext( DEFINITION_TAG, "putDefinition", definitionHandlerClass); // put / putAttribute rules - digester.addObjectCreate( PUT_TAG, putAttributeHandlerClass); - digester.addSetNext( PUT_TAG, "addAttribute", putAttributeHandlerClass); - digester.addSetProperties( PUT_TAG); - digester.addCallMethod( PUT_TAG, "setBody", 0); + digester.addObjectCreate( PUT_TAG, putAttributeHandlerClass); + digester.addSetNext( PUT_TAG, "addAttribute", putAttributeHandlerClass); + digester.addSetProperties( PUT_TAG); + digester.addCallMethod( PUT_TAG, "setBody", 0); // list rules - digester.addObjectCreate( LIST_TAG, listHandlerClass); - digester.addSetProperties( LIST_TAG); - digester.addSetNext( LIST_TAG, "addAttribute", putAttributeHandlerClass); + digester.addObjectCreate( LIST_TAG, listHandlerClass); + digester.addSetProperties( LIST_TAG); + digester.addSetNext( LIST_TAG, "addAttribute", putAttributeHandlerClass); // list elements rules // We use Attribute class to avoid rewriting a new class. // Name part can't be used in listElement attribute. - digester.addObjectCreate( ADD_LIST_ELE_TAG, putAttributeHandlerClass); - digester.addSetNext( ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass); - digester.addSetProperties( ADD_LIST_ELE_TAG); - digester.addCallMethod( ADD_LIST_ELE_TAG, "setBody", 0); + digester.addObjectCreate( ADD_LIST_ELE_TAG, putAttributeHandlerClass); + digester.addSetNext( ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass); + digester.addSetProperties( ADD_LIST_ELE_TAG); + digester.addCallMethod( ADD_LIST_ELE_TAG, "setBody", 0); } /** @@ -133,7 +135,7 @@ */ private void initDigesterForTilesDefinitionsSyntax( Digester digester ) { - // Common constants + // Common constants String PACKAGE_NAME = "org.apache.struts.tiles.xmlDefinition"; String DEFINITION_TAG = "tiles-definitions/definition"; String definitionHandlerClass = PACKAGE_NAME + ".XmlDefinition"; @@ -150,37 +152,37 @@ String ADD_LIST_ELE_TAG = "*/" + LIST_TAG + "/add"; // syntax rules - digester.addObjectCreate( DEFINITION_TAG, definitionHandlerClass ); - digester.addSetProperties( DEFINITION_TAG); - digester.addSetNext( DEFINITION_TAG, "putDefinition", definitionHandlerClass); + digester.addObjectCreate( DEFINITION_TAG, definitionHandlerClass ); + digester.addSetProperties( DEFINITION_TAG); + digester.addSetNext( DEFINITION_TAG, "putDefinition", definitionHandlerClass); // put / putAttribute rules // Rules for a same pattern are called in order, but rule.end() are called // in reverse order. // SetNext and CallMethod use rule.end() method. So, placing SetNext in // first position ensure it will be called last (sic). - digester.addObjectCreate( PUT_TAG, putAttributeHandlerClass); - digester.addSetNext( PUT_TAG, "addAttribute", putAttributeHandlerClass); - digester.addSetProperties( PUT_TAG); - digester.addCallMethod( PUT_TAG, "setBody", 0); + digester.addObjectCreate( PUT_TAG, putAttributeHandlerClass); + digester.addSetNext( PUT_TAG, "addAttribute", putAttributeHandlerClass); + digester.addSetProperties( PUT_TAG); + digester.addCallMethod( PUT_TAG, "setBody", 0); // Definition level list rules // This is rules for lists nested in a definition - digester.addObjectCreate( DEF_LIST_TAG, listHandlerClass); - digester.addSetProperties( DEF_LIST_TAG); - digester.addSetNext( DEF_LIST_TAG, "addAttribute", putAttributeHandlerClass); + digester.addObjectCreate( DEF_LIST_TAG, listHandlerClass); + digester.addSetProperties( DEF_LIST_TAG); + digester.addSetNext( DEF_LIST_TAG, "addAttribute", putAttributeHandlerClass); // list elements rules // We use Attribute class to avoid rewriting a new class. // Name part can't be used in listElement attribute. - digester.addObjectCreate( ADD_LIST_ELE_TAG, putAttributeHandlerClass); - digester.addSetNext( ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass); - digester.addSetProperties( ADD_LIST_ELE_TAG); - digester.addCallMethod( ADD_LIST_ELE_TAG, "setBody", 0); + digester.addObjectCreate( ADD_LIST_ELE_TAG, putAttributeHandlerClass); + digester.addSetNext( ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass); + digester.addSetProperties( ADD_LIST_ELE_TAG); + digester.addCallMethod( ADD_LIST_ELE_TAG, "setBody", 0); // nested list elements rules // Create a list handler, and add it to parent list String NESTED_LIST = "*/" + LIST_TAG + "/" + LIST_TAG; - digester.addObjectCreate( NESTED_LIST, listHandlerClass); - digester.addSetProperties( NESTED_LIST); - digester.addSetNext( NESTED_LIST, "add", putAttributeHandlerClass); + digester.addObjectCreate( NESTED_LIST, listHandlerClass); + digester.addSetProperties( NESTED_LIST); + digester.addSetNext( NESTED_LIST, "add", putAttributeHandlerClass); // item elements rules // We use Attribute class to avoid rewriting a new class. @@ -189,16 +191,16 @@ // non String ADD_WILDCARD = LIST_TAG + "/addx*"; String ADD_WILDCARD = "*/item"; String menuItemDefaultClass = "org.apache.struts.tiles.beans.SimpleMenuItem"; - digester.addObjectCreate( ADD_WILDCARD, menuItemDefaultClass, "classtype"); - digester.addSetNext( ADD_WILDCARD, "add", "java.lang.Object"); - digester.addSetProperties( ADD_WILDCARD); + digester.addObjectCreate( ADD_WILDCARD, menuItemDefaultClass, "classtype"); + digester.addSetNext( ADD_WILDCARD, "add", "java.lang.Object"); + digester.addSetProperties( ADD_WILDCARD); // bean elements rules String BEAN_TAG = "*/bean"; String beanDefaultClass = "org.apache.struts.tiles.beans.SimpleMenuItem"; - digester.addObjectCreate( BEAN_TAG, beanDefaultClass, "classtype"); - digester.addSetNext( BEAN_TAG, "add", "java.lang.Object"); - digester.addSetProperties( BEAN_TAG); + digester.addObjectCreate( BEAN_TAG, beanDefaultClass, "classtype"); + digester.addSetNext( BEAN_TAG, "add", "java.lang.Object"); + digester.addSetProperties( BEAN_TAG); // Set properties to surrounding element digester.addSetProperty(BEAN_TAG+ "/set-property", "property", "value"); @@ -212,7 +214,7 @@ */ private void initDigesterForInstancesSyntax( Digester digester ) { - // Build a digester to process our configuration resource + // Build a digester to process our configuration resource String PACKAGE_NAME = "org.apache.struts.tiles.xmlDefinition"; String INSTANCE_TAG = "component-instances/instance"; String instanceHandlerClass = PACKAGE_NAME + ".XmlDefinition"; @@ -227,27 +229,27 @@ String ADD_LIST_ELE_TAG = LIST_TAG + "/add"; // component instance rules - digester.addObjectCreate( INSTANCE_TAG, instanceHandlerClass ); - digester.addSetProperties( INSTANCE_TAG); - digester.addSetNext( INSTANCE_TAG, "putDefinition", instanceHandlerClass); + digester.addObjectCreate( INSTANCE_TAG, instanceHandlerClass ); + digester.addSetProperties( INSTANCE_TAG); + digester.addSetNext( INSTANCE_TAG, "putDefinition", instanceHandlerClass); // put / putAttribute rules - digester.addObjectCreate( PUTATTRIBUTE_TAG, putAttributeHandlerClass); - digester.addSetProperties( PUTATTRIBUTE_TAG); - digester.addSetNext( PUTATTRIBUTE_TAG, "addAttribute", putAttributeHandlerClass); + digester.addObjectCreate( PUTATTRIBUTE_TAG, putAttributeHandlerClass); + digester.addSetProperties( PUTATTRIBUTE_TAG); + digester.addSetNext( PUTATTRIBUTE_TAG, "addAttribute", putAttributeHandlerClass); // put / putAttribute rules - digester.addObjectCreate( PUT_TAG, putAttributeHandlerClass); - digester.addSetProperties( PUT_TAG); - digester.addSetNext( PUT_TAG, "addAttribute", putAttributeHandlerClass); + digester.addObjectCreate( PUT_TAG, putAttributeHandlerClass); + digester.addSetProperties( PUT_TAG); + digester.addSetNext( PUT_TAG, "addAttribute", putAttributeHandlerClass); // list rules - digester.addObjectCreate( LIST_TAG, listHandlerClass); - digester.addSetProperties( LIST_TAG); - digester.addSetNext( LIST_TAG, "addAttribute", putAttributeHandlerClass); + digester.addObjectCreate( LIST_TAG, listHandlerClass); + digester.addSetProperties( LIST_TAG); + digester.addSetNext( LIST_TAG, "addAttribute", putAttributeHandlerClass); // list elements rules // We use Attribute class to avoid rewriting a new class. // Name part can't be used in listElement attribute. - digester.addObjectCreate( ADD_LIST_ELE_TAG, putAttributeHandlerClass); - digester.addSetProperties( ADD_LIST_ELE_TAG); - digester.addSetNext( ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass); + digester.addObjectCreate( ADD_LIST_ELE_TAG, putAttributeHandlerClass); + digester.addSetProperties( ADD_LIST_ELE_TAG); + digester.addSetNext( ADD_LIST_ELE_TAG, "add", putAttributeHandlerClass); } /** @@ -270,20 +272,20 @@ */ public void parse( InputStream in, XmlDefinitionsSet definitions ) throws IOException, SAXException { - try + try { // set first object in stack //digester.clear(); digester.push(definitions); // parse - digester.parse(in); - in.close(); - } + digester.parse(in); + in.close(); + } catch (SAXException e) { - //throw new ServletException( "Error while parsing " + mappingConfig, e); + //throw new ServletException( "Error while parsing " + mappingConfig, e); throw e; - } + } } @@ -311,9 +313,9 @@ // Open file try { - input = new BufferedInputStream( + input = new BufferedInputStream( new FileInputStream( filename) ); - // input2 = new BufferedInputStream( + // input2 = new BufferedInputStream( // new FileInputStream( filename2) ); } catch( IOException ex ) @@ -323,7 +325,7 @@ // Check file syntax try { - XmlParser parser = new XmlParser(); + XmlParser parser = new XmlParser(); parser.setValidating(true); XmlDefinitionsSet definitions = new XmlDefinitionsSet(); System.out.println( " Parse file" );
Modified: struts/struts1/trunk/tiles/src/test/java/org/apache/struts/tiles/CustomI18nFactorySet.java URL: http://svn.apache.org/viewvc/struts/struts1/trunk/tiles/src/test/java/org/apache/struts/tiles/CustomI18nFactorySet.java?view=diff&rev=471754&r1=471753&r2=471754 ============================================================================== --- struts/struts1/trunk/tiles/src/test/java/org/apache/struts/tiles/CustomI18nFactorySet.java (original) +++ struts/struts1/trunk/tiles/src/test/java/org/apache/struts/tiles/CustomI18nFactorySet.java Mon Nov 6 06:55:09 2006 @@ -1,21 +1,23 @@ /* * $Id$ * - * Copyright 2005 The Apache Software Foundation. + * 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 * - * 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 * - * 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. + * 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.struts.tiles; Modified: struts/struts1/trunk/tiles/src/test/java/org/apache/struts/tiles/TestTilesPlugin.java URL: http://svn.apache.org/viewvc/struts/struts1/trunk/tiles/src/test/java/org/apache/struts/tiles/TestTilesPlugin.java?view=diff&rev=471754&r1=471753&r2=471754 ============================================================================== --- struts/struts1/trunk/tiles/src/test/java/org/apache/struts/tiles/TestTilesPlugin.java (original) +++ struts/struts1/trunk/tiles/src/test/java/org/apache/struts/tiles/TestTilesPlugin.java Mon Nov 6 06:55:09 2006 @@ -1,50 +1,43 @@ /* - * $Id$ + * $Id$ * - * Copyright 1999-2005 The Apache Software Foundation. - * - * 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. + * 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.struts.tiles; - -import javax.servlet.ServletException; -import junit.framework.Test; -import junit.framework.TestSuite; - -import java.util.Map; -import java.util.HashMap; -import java.util.Locale; -import javax.servlet.ServletContext; -import javax.servlet.ServletRequest; -import org.apache.commons.beanutils.BeanUtils; -import org.apache.struts.Globals; -import org.apache.struts.action.PlugIn; import org.apache.struts.config.ModuleConfig; import org.apache.struts.config.ModuleConfigFactory; import org.apache.struts.config.PlugInConfig; import org.apache.struts.mock.MockActionServlet; import org.apache.struts.mock.TestMockBase; -import org.apache.struts.util.RequestUtils; +import org.apache.struts.Globals; import org.apache.struts.tiles.xmlDefinition.I18nFactorySet; +import org.apache.struts.util.RequestUtils; +import org.apache.struts.action.PlugIn; +import org.apache.commons.beanutils.BeanUtils; +import junit.framework.Test; +import junit.framework.TestSuite; -/** - * <p>Unit tests for <code>org.apache.struts.tiles.*</code>.</p> - * - * @version $Rev$ $Date$ - */ +import javax.servlet.ServletException; +import java.util.Locale; +import java.util.Map; +import java.util.HashMap; public class TestTilesPlugin extends TestMockBase { @@ -103,34 +96,34 @@ * @param moduleName */ public ModuleConfig createModuleConfig( - String moduleName, - String configFileName, - boolean moduleAware) { - - ModuleConfig moduleConfig = - ModuleConfigFactory.createFactory().createModuleConfig(moduleName); - - context.setAttribute(Globals.MODULE_KEY + moduleName, moduleConfig); - - // Set tiles plugin - PlugInConfig pluginConfig = new PlugInConfig(); - pluginConfig.setClassName("org.apache.struts.tiles.TilesPlugin"); - - pluginConfig.addProperty( - "moduleAware", - (moduleAware == true ? "true" : "false")); - - pluginConfig.addProperty( - "definitions-config", - "/org/apache/struts/tiles/config/" + configFileName); - - moduleConfig.addPlugInConfig(pluginConfig); - return moduleConfig; + String moduleName, + String configFileName, + boolean moduleAware) { + + ModuleConfig moduleConfig = + ModuleConfigFactory.createFactory().createModuleConfig(moduleName); + + context.setAttribute(Globals.MODULE_KEY + moduleName, moduleConfig); + + // Set tiles plugin + PlugInConfig pluginConfig = new PlugInConfig(); + pluginConfig.setClassName("org.apache.struts.tiles.TilesPlugin"); + + pluginConfig.addProperty( + "moduleAware", + (moduleAware == true ? "true" : "false")); + + pluginConfig.addProperty( + "definitions-config", + "/org/apache/struts/tiles/config/" + configFileName); + + moduleConfig.addPlugInConfig(pluginConfig); + return moduleConfig; } /** * Fake call to init module plugins - * @param config + * @param moduleConfig */ public void initModulePlugIns( ModuleConfig moduleConfig) { @@ -141,7 +134,7 @@ for (int i = 0; i < plugIns.length; i++) { try { plugIns[i] = - (PlugIn)RequestUtils.applicationInstance(plugInConfigs[i].getClassName()); + (PlugIn) RequestUtils.applicationInstance(plugInConfigs[i].getClassName()); BeanUtils.populate(plugIns[i], plugInConfigs[i].getProperties()); // Pass the current plugIn config object to the PlugIn. // The property is set only if the plugin declares it. @@ -166,39 +159,39 @@ * Test multi factory creation when moduleAware=true. */ public void testMultiFactory() { - // init TilesPlugin - module1 = createModuleConfig("/module1", "tiles-defs.xml", true); - module2 = createModuleConfig("/module2", "tiles-defs.xml", true); - initModulePlugIns(module1); - initModulePlugIns(module2); - - // mock request context - request.setAttribute(Globals.MODULE_KEY, module1); - request.setPathElements("/myapp", "/module1/foo.do", null, null); - // Retrieve factory for module1 - DefinitionsFactory factory1 = - TilesUtil.getDefinitionsFactory(request, context); - - assertNotNull("factory found", factory1); - assertEquals( - "factory name", - "/module1", - factory1.getConfig().getFactoryName()); - - // mock request context - request.setAttribute(Globals.MODULE_KEY, module2); - request.setPathElements("/myapp", "/module2/foo.do", null, null); - // Retrieve factory for module2 - DefinitionsFactory factory2 = - TilesUtil.getDefinitionsFactory(request, context); - assertNotNull("factory found", factory2); - assertEquals( - "factory name", - "/module2", - factory2.getConfig().getFactoryName()); - - // Check that factory are different - assertNotSame("Factory from different modules", factory1, factory2); + // init TilesPlugin + module1 = createModuleConfig("/module1", "tiles-defs.xml", true); + module2 = createModuleConfig("/module2", "tiles-defs.xml", true); + initModulePlugIns(module1); + initModulePlugIns(module2); + + // mock request context + request.setAttribute(Globals.MODULE_KEY, module1); + request.setPathElements("/myapp", "/module1/foo.do", null, null); + // Retrieve factory for module1 + DefinitionsFactory factory1 = + TilesUtil.getDefinitionsFactory(request, context); + + assertNotNull("factory found", factory1); + assertEquals( + "factory name", + "/module1", + factory1.getConfig().getFactoryName()); + + // mock request context + request.setAttribute(Globals.MODULE_KEY, module2); + request.setPathElements("/myapp", "/module2/foo.do", null, null); + // Retrieve factory for module2 + DefinitionsFactory factory2 = + TilesUtil.getDefinitionsFactory(request, context); + assertNotNull("factory found", factory2); + assertEquals( + "factory name", + "/module2", + factory2.getConfig().getFactoryName()); + + // Check that factory are different + assertNotSame("Factory from different modules", factory1, factory2); } /** @@ -379,7 +372,7 @@ * just a variant being incorrectly displayed. */ private String print(Locale locale) { - + return locale.getLanguage() + "_" + locale.getCountry() + "_" + locale.getVariant();