You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ap...@apache.org on 2006/10/16 13:33:39 UTC
svn commit: r464448 - in /struts/sandbox/trunk/tiles/tiles-core/src:
main/java/org/apache/tiles/ main/java/org/apache/tiles/definition/
test/java/org/apache/tiles/ test/java/org/apache/tiles/mock/
Author: apetrelli
Date: Mon Oct 16 04:33:35 2006
New Revision: 464448
URL: http://svn.apache.org/viewvc?view=rev&rev=464448
Log:
SB-28
Added changes to make Tiles extension easier
Added:
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockOnlyLocaleTilesContext.java
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java
Modified:
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java
struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java
Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java?view=diff&rev=464448&r1=464447&r2=464448
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/ComponentDefinition.java Mon Oct 16 04:33:35 2006
@@ -557,13 +557,25 @@
}
/**
- * Set isVisited.
+ * Sets the visit flag, used during inheritance resolution.
+ *
+ * @param isVisited <code>true</code> is the definition has been visited.
*
*/
public void setIsVisited( boolean isVisited )
{
this.isVisited = isVisited;
}
+
+ /**
+ * Returns the visit flag, used during inheritance resolution.
+ *
+ * @return isVisited <code>true</code> is the definition has been visited.
+ */
+ public boolean isIsVisited()
+ {
+ return isVisited;
+ }
/**
* Resolve inheritance.
@@ -571,6 +583,8 @@
* Also copy attributes setted in parent, and not set in child
* If instance doesn't extend anything, do nothing.
* @throws NoSuchDefinitionException If an inheritance can not be solved.
+ * @deprecated Each {@link ComponentDefinitions} should provide its own
+ * strategy to resolve inheritances.
*/
public void resolveInheritance( ComponentDefinitions definitionsSet )
throws NoSuchDefinitionException
@@ -626,6 +640,8 @@
* Also copy attributes setted in parent, and not set in child
* If instance doesn't extend anything, do nothing.
* @throws NoSuchDefinitionException If an inheritance can not be solved.
+ * @deprecated Each {@link ComponentDefinitions} should provide its own
+ * strategy to resolve inheritances.
*/
public void resolveInheritance( ComponentDefinitions definitionsSet, Locale locale)
throws NoSuchDefinitionException
Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java?view=diff&rev=464448&r1=464447&r2=464448
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/DefinitionsFactory.java Mon Oct 16 04:33:35 2006
@@ -58,6 +58,19 @@
public void init(Map params) throws DefinitionsFactoryException;
/**
+ * Returns a ComponentDefinition object that matches the given name and
+ * Tiles context
+ *
+ * @param name The name of the ComponentDefinition to return.
+ * @param tilesContext The Tiles context to use to resolve the definition.
+ * @return the ComponentDefinition matching the given name or null if none
+ * is found.
+ * @throws DefinitionsFactoryException if an error occurs reading definitions.
+ */
+ public ComponentDefinition getDefinition(String name,
+ TilesContext tilesContext) throws DefinitionsFactoryException;
+
+ /**
* Adds a source where ComponentDefinition objects are stored.
*
* Implementations should publish what type of source object they expect.
@@ -82,29 +95,4 @@
*/
public ComponentDefinitions readDefinitions()
throws DefinitionsFactoryException;
-
- /**
- * Appends locale-specific {@link ComponentDefinition} objects to an existing
- * {@link ComponentDefinitions} set by reading locale-specific versions of
- * the applied sources.
- *
- * @param definitions The ComponentDefinitions object to append to.
- * @param locale The requested locale.
- * @throws DefinitionsFactoryException if an error occurs reading definitions.
- */
- public void addDefinitions(ComponentDefinitions definitions, Locale locale)
- throws DefinitionsFactoryException;
-
- /**
- * Indicates whether a given locale has been processed or not.
- *
- * This method can be used to avoid unnecessary synchronization of the
- * DefinitionsFactory in multi-threaded situations. Check the return of
- * isLoacaleProcessed before synchronizing the object and reading
- * locale-specific definitions.
- *
- * @param locale The locale to check.
- * @return true if the given lcoale has been processed and false otherwise.
- */
- public boolean isLocaleProcessed(Locale locale);
}
Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java?view=diff&rev=464448&r1=464447&r2=464448
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/TilesUtilImpl.java Mon Oct 16 04:33:35 2006
@@ -202,27 +202,7 @@
try {
DefinitionsFactory factory = getDefinitionsFactory(tilesContext);
- ComponentDefinitions definitions = (ComponentDefinitions)
- tilesContext.getApplicationScope().get(TilesUtilImpl.DEFINITIONS_OBJECT);
- ComponentDefinition definition = definitions.getDefinition(
- definitionName, tilesContext.getRequestLocale());
-
- if (definition == null) {
- if (!factory.isLocaleProcessed(tilesContext.getRequestLocale())) {
- // FIXME This will modify the factory as well as the definitions
- // but we are only locking the definitions.
- //
- // We'll have to refactor again to remove this issue.
- synchronized (definitions) {
- factory.addDefinitions(definitions, tilesContext.getRequestLocale());
- }
- }
-
- definition = definitions.getDefinition(
- definitionName, tilesContext.getRequestLocale());
- }
-
- return definition;
+ return factory.getDefinition(definitionName, tilesContext);
} catch (NullPointerException ex) { // Factory not found in context
throw new FactoryNotFoundException("Can't get definitions factory from context.");
}
Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java?view=diff&rev=464448&r1=464447&r2=464448
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/ComponentDefinitionsImpl.java Mon Oct 16 04:33:35 2006
@@ -22,6 +22,9 @@
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.tiles.ComponentAttribute;
import org.apache.tiles.ComponentDefinition;
import org.apache.tiles.ComponentDefinitions;
@@ -32,6 +35,12 @@
* @version $Rev$ $Date$
*/
public class ComponentDefinitionsImpl implements ComponentDefinitions {
+
+ /**
+ * Commons Logging instance.
+ */
+ private static Log log = LogFactory.getLog(ComponentDefinitionsImpl.class);
+
/**
* The base set of ComponentDefinition objects not discriminated by locale.
*/
@@ -112,7 +121,7 @@
Iterator i = baseDefinitions.values().iterator();
while( i.hasNext() ) {
ComponentDefinition definition = (ComponentDefinition)i.next();
- definition.resolveInheritance( this );
+ resolveInheritance( definition );
} // end loop
}
@@ -127,7 +136,7 @@
Iterator i = map.values().iterator();
while( i.hasNext() ) {
ComponentDefinition definition = (ComponentDefinition)i.next();
- definition.resolveInheritance( this, locale );
+ resolveInheritance( definition, locale );
} // end loop
}
}
@@ -150,7 +159,6 @@
public void resolveAttributeDependencies() {
Iterator i = this.baseDefinitions.values().iterator();
- // FIXME: Need to repeat the following for locale-specific defs.
while (i.hasNext()) {
ComponentDefinition def = (ComponentDefinition) i.next();
Map attributes = def.getAttributes();
@@ -250,5 +258,113 @@
}
return retValue;
+ }
+
+ /**
+ * Resolve inheritance.
+ * First, resolve parent's inheritance, then set path to the parent's path.
+ * Also copy attributes setted in parent, and not set in child
+ * If instance doesn't extend anything, do nothing.
+ * @throws NoSuchDefinitionException If an inheritance can not be solved.
+ */
+ protected void resolveInheritance(ComponentDefinition definition)
+ throws NoSuchDefinitionException {
+ // Already done, or not needed ?
+ if (definition.isIsVisited() || !definition.isExtending())
+ return;
+
+ if (log.isDebugEnabled())
+ log.debug("Resolve definition for child name='"
+ + definition.getName()
+ + "' extends='" + definition.getExtends() + "'.");
+
+ // Set as visited to avoid endless recurisvity.
+ definition.setIsVisited(true);
+
+ // Resolve parent before itself.
+ ComponentDefinition parent = getDefinition(definition.getExtends());
+ if (parent == null) { // error
+ String msg = "Error while resolving definition inheritance: child '"
+ + definition.getName()
+ + "' can't find its ancestor '"
+ + definition.getExtends()
+ + "'. Please check your description file.";
+ log.error(msg);
+ // to do : find better exception
+ throw new NoSuchDefinitionException(msg);
+ }
+
+ resolveInheritance(parent);
+
+ overload(parent, definition);
+ }
+
+ /**
+ * Resolve locale-specific inheritance.
+ * First, resolve parent's inheritance, then set path to the parent's path.
+ * Also copy attributes setted in parent, and not set in child
+ * If instance doesn't extend anything, do nothing.
+ * @throws NoSuchDefinitionException If an inheritance can not be solved.
+ */
+ protected void resolveInheritance(ComponentDefinition definition,
+ Locale locale) throws NoSuchDefinitionException {
+ // Already done, or not needed ?
+ if (definition.isIsVisited() || !definition.isExtending())
+ return;
+
+ if (log.isDebugEnabled())
+ log.debug("Resolve definition for child name='"
+ + definition.getName()
+ + "' extends='" + definition.getExtends() + "'.");
+
+ // Set as visited to avoid endless recurisvity.
+ definition.setIsVisited(true);
+
+ // Resolve parent before itself.
+ ComponentDefinition parent = getDefinition(definition.getExtends(),
+ locale);
+ if (parent == null) { // error
+ String msg = "Error while resolving definition inheritance: child '"
+ + definition.getName()
+ + "' can't find its ancestor '"
+ + definition.getExtends()
+ + "'. Please check your description file.";
+ log.error(msg);
+ // to do : find better exception
+ throw new NoSuchDefinitionException(msg);
+ }
+
+ resolveInheritance(definition, locale);
+
+ overload(parent, definition);
+ }
+
+ /**
+ * Overloads a child definition with a given parent.
+ * All attributes present in child are kept. All missing attributes are
+ * copied from the parent.
+ * Special attribute 'path','role' and 'extends' are overloaded in child if
+ * not defined
+ * @param parent The parent definition.
+ * @param child The child that will be overloaded.
+ */
+ protected void overload(ComponentDefinition parent,
+ ComponentDefinition child) {
+ // Iterate on each parent's attribute and add it if not defined in child.
+ Iterator parentAttributes = parent.getAttributes().keySet().iterator();
+ while (parentAttributes.hasNext()) {
+ String name = (String) parentAttributes.next();
+ if (!child.getAttributes().containsKey(name))
+ child.put(name, parent.getAttribute(name));
+ }
+ // Set path and role if not setted
+ if (child.getPath() == null)
+ child.setPath(parent.getPath());
+ if (child.getRole() == null)
+ child.setRole(parent.getRole());
+ if (child.getPreparer() == null) {
+ child.setPreparer(parent.getPreparer());
+ child.setPreparerType(parent.getPreparerType());
+ }
}
}
Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java?view=diff&rev=464448&r1=464447&r2=464448
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java Mon Oct 16 04:33:35 2006
@@ -36,6 +36,8 @@
import org.apache.tiles.DefinitionsFactoryException;
import org.apache.tiles.DefinitionsReader;
import org.apache.tiles.ReloadableDefinitionsFactory;
+import org.apache.tiles.TilesContext;
+import org.apache.tiles.TilesUtilImpl;
import org.apache.tiles.digester.DigesterDefinitionsReader;
/**
@@ -54,15 +56,15 @@
/**
* Contains the URL objects identifying where configuration data is found.
*/
- private List sources;
+ protected List sources;
/**
* Reader used to get definitions from the sources.
*/
- private DefinitionsReader reader;
+ protected DefinitionsReader reader;
/**
* Contains the dates that the URL sources were last modified.
*/
- private Map lastModifiedDates;
+ protected Map lastModifiedDates;
/**
* Contains a list of locales that have been processed.
*/
@@ -127,6 +129,42 @@
}
/**
+ * Returns a ComponentDefinition object that matches the given name and
+ * Tiles context
+ *
+ * @param name The name of the ComponentDefinition to return.
+ * @param tilesContext The Tiles context to use to resolve the definition.
+ * @return the ComponentDefinition matching the given name or null if none
+ * is found.
+ * @throws DefinitionsFactoryException if an error occurs reading definitions.
+ */
+ public ComponentDefinition getDefinition(String name,
+ TilesContext tilesContext) throws DefinitionsFactoryException {
+ ComponentDefinitions definitions = (ComponentDefinitions)
+ tilesContext.getApplicationScope().get(
+ TilesUtilImpl.DEFINITIONS_OBJECT);
+ ComponentDefinition definition = definitions.getDefinition(
+ name, tilesContext.getRequestLocale());
+
+ if (definition == null) {
+ if (!isContextProcessed(tilesContext)) {
+ // FIXME This will modify the factory as well as the definitions
+ // but we are only locking the definitions.
+ //
+ // We'll have to refactor again to remove this issue.
+ synchronized (definitions) {
+ addDefinitions(definitions, tilesContext);
+ }
+ }
+
+ definition = definitions.getDefinition(name,
+ tilesContext.getRequestLocale());
+ }
+
+ return definition;
+ }
+
+ /**
* Adds a source where ComponentDefinition objects are stored.
*
* Implementations should publish what type of source object they expect.
@@ -160,19 +198,20 @@
* the applied sources.
*
* @param definitions The ComponentDefinitions object to append to.
- * @param locale The requested locale.
+ * @param tilesContext The requested locale.
* @throws DefinitionsFactoryException if an error occurs reading definitions.
*/
- public void addDefinitions(ComponentDefinitions definitions, Locale locale)
+ protected void addDefinitions(ComponentDefinitions definitions, TilesContext tilesContext)
throws DefinitionsFactoryException {
+ Locale locale = tilesContext.getRequestLocale();
List postfixes = calculatePostixes(locale);
- if (isLocaleProcessed(locale)) {
- return;
- } else {
- processedLocales.add(locale);
- }
+ if (isContextProcessed(tilesContext)) {
+ return;
+ } else {
+ processedLocales.add(locale);
+ }
for (int i = 0; i < sources.size(); i++) {
URL url = (URL) sources.get(i);
@@ -184,10 +223,11 @@
URL newUrl = new URL(newPath);
URLConnection connection = newUrl.openConnection();
connection.connect();
- lastModifiedDates.put(newUrl.toExternalForm(),
- new Long(connection.getLastModified()));
+ lastModifiedDates.put(newUrl.toExternalForm(),
+ new Long(connection.getLastModified()));
Map defsMap = reader.read(connection.getInputStream());
- definitions.addDefinitions(defsMap, locale);
+ definitions.addDefinitions(defsMap,
+ tilesContext.getRequestLocale());
} catch (FileNotFoundException e) {
// File not found. continue.
} catch (IOException e) {
@@ -215,7 +255,7 @@
URL source = (URL) sources.get(i);
URLConnection connection = source.openConnection();
connection.connect();
- lastModifiedDates.put(source.toExternalForm(),
+ lastModifiedDates.put(source.toExternalForm(),
new Long(connection.getLastModified()));
Map defsMap = reader.read(connection.getInputStream());
definitions.addDefinitions(defsMap);
@@ -234,11 +274,11 @@
* isLoacaleProcessed before synchronizing the object and reading
* locale-specific definitions.
*
- * @param locale The locale to check.
+ * @param tilesContext The Tiles context to check.
* @return true if the given lcoale has been processed and false otherwise.
*/
- public boolean isLocaleProcessed(Locale locale) {
- if (processedLocales.contains(locale)) {
+ protected boolean isContextProcessed(TilesContext tilesContext) {
+ if (processedLocales.contains(tilesContext.getRequestLocale())) {
return true;
} else {
return false;
@@ -253,7 +293,7 @@
* @param postfix Postfix to add.
* @return Concatenated filename.
*/
- private String concatPostfix(String name, String postfix) {
+ protected String concatPostfix(String name, String postfix) {
if (postfix == null) {
return name;
}
@@ -277,7 +317,7 @@
* Method copied from java.util.ResourceBundle
* @param locale the locale
*/
- private static List calculatePostixes(Locale locale) {
+ protected static List calculatePostixes(Locale locale) {
final List result = new ArrayList();
final String language = locale.getLanguage();
final int languageLength = language.length();
Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java?view=diff&rev=464448&r1=464447&r2=464448
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java Mon Oct 16 04:33:35 2006
@@ -27,7 +27,9 @@
import junit.framework.TestSuite;
import org.apache.tiles.definition.UrlDefinitionsFactory;
import org.apache.tiles.mock.MockComponentDefinitions;
+import org.apache.tiles.mock.MockPublicUrlDefinitionsFactory;
import org.apache.tiles.mock.MockDefinitionsReader;
+import org.apache.tiles.mock.MockOnlyLocaleTilesContext;
/**
* Tests the UrlDefinitionsFactory component.
@@ -117,7 +119,7 @@
*/
public void testReadByLocale() {
try {
- DefinitionsFactory factory = new UrlDefinitionsFactory();
+ MockPublicUrlDefinitionsFactory factory = new MockPublicUrlDefinitionsFactory();
// Set up multiple data sources.
URL url1 = this.getClass().getClassLoader().getResource(
@@ -137,8 +139,10 @@
// Parse files.
ComponentDefinitions definitions = factory.readDefinitions();
- factory.addDefinitions(definitions, Locale.US);
- factory.addDefinitions(definitions, Locale.FRENCH);
+ factory.addDefinitions(definitions,
+ new MockOnlyLocaleTilesContext(Locale.US));
+ factory.addDefinitions(definitions,
+ new MockOnlyLocaleTilesContext(Locale.FRENCH));
assertNotNull("test.def1 definition not found.", definitions.getDefinition("test.def1"));
assertNotNull("test.def1 US definition not found.", definitions.getDefinition("test.def1", Locale.US));
@@ -164,7 +168,7 @@
*/
public void testIsLocaleProcessed() {
try {
- DefinitionsFactory factory = new UrlDefinitionsFactory();
+ MockPublicUrlDefinitionsFactory factory = new MockPublicUrlDefinitionsFactory();
// Set up multiple data sources.
URL url1 = this.getClass().getClassLoader().getResource(
@@ -176,12 +180,14 @@
// Parse files.
ComponentDefinitions definitions = factory.readDefinitions();
+ TilesContext tilesContext =
+ new MockOnlyLocaleTilesContext(Locale.US);
assertFalse("Locale should not be processed.",
- factory.isLocaleProcessed(Locale.US));
+ factory.isContextProcessed(tilesContext));
- factory.addDefinitions(definitions, Locale.US);
- assertTrue("Locale should be processed.",
- factory.isLocaleProcessed(Locale.US));
+ factory.addDefinitions(definitions, tilesContext);
+ assertTrue("Locale should be processed.",
+ factory.isContextProcessed(tilesContext));
} catch (Exception e) {
fail("Error running test: " + e);
Added: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockOnlyLocaleTilesContext.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockOnlyLocaleTilesContext.java?view=auto&rev=464448
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockOnlyLocaleTilesContext.java (added)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockOnlyLocaleTilesContext.java Mon Oct 16 04:33:35 2006
@@ -0,0 +1,103 @@
+/*
+ * $Id: MockOnlyLocaleTilesContext.java 350273 2005-12-01 16:50:58Z greddin $
+ *
+ * Copyright 1999-2006 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.
+ */
+
+package org.apache.tiles.mock;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.tiles.TilesContext;
+
+/**
+ * Creates a TilesContext that contains only a Locale
+ *
+ * @version $Rev: 350273 $ $Date: 2005-12-01 17:50:58 +0100 (gio, 01 dic 2005) $
+ */
+public class MockOnlyLocaleTilesContext implements TilesContext {
+
+ /**
+ * The locale object.
+ */
+ private Locale locale;
+
+ /** Creates a new instance of MockOnlyLocaleTilesContext.
+ *
+ * @param locale The locale object to use.
+ */
+ public MockOnlyLocaleTilesContext(Locale locale) {
+ this.locale = locale;
+ }
+
+ /**
+ * Returns the locale specified in the constructor.
+ *
+ * @see org.apache.tiles.TilesContext#getRequestLocale()
+ */
+ public Locale getRequestLocale() {
+ return locale;
+ }
+
+ // The rest of the implemented methods has a "dummy" behaviour, doing
+ // nothing or returning null, because they are not needed at all in tests
+ // that use this class.
+
+ public void dispatch(String path) throws IOException, Exception {
+ }
+
+ public Map getApplicationScope() {
+ return null;
+ }
+
+ public Map getHeader() {
+ return null;
+ }
+
+ public Map getHeaderValues() {
+ return null;
+ }
+
+ public Map getInitParams() {
+ return null;
+ }
+
+ public Map getParam() {
+ return null;
+ }
+
+ public Map getParamValues() {
+ return null;
+ }
+
+ public Map getRequestScope() {
+ return null;
+ }
+
+ public URL getResource(String path) throws MalformedURLException {
+ return null;
+ }
+
+ public Map getSessionScope() {
+ return null;
+ }
+
+ public void include(String path) throws IOException, Exception {
+ }
+}
Added: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java?view=auto&rev=464448
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java (added)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java Mon Oct 16 04:33:35 2006
@@ -0,0 +1,56 @@
+/*
+ * $Id: MockPublicUrlDefinitionsFactory.java 350273 2005-12-01 16:50:58Z greddin $
+ *
+ * Copyright 1999-2006 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.
+ */
+
+package org.apache.tiles.mock;
+
+import org.apache.tiles.ComponentDefinitions;
+import org.apache.tiles.DefinitionsFactoryException;
+import org.apache.tiles.TilesContext;
+import org.apache.tiles.definition.UrlDefinitionsFactory;
+
+/**
+ * Mock implementation of UrlDefinitionsFactory that exposes two of its methods
+ * as public instead of protected.
+ *
+ * @version $Rev: 307013 $ $Date: 2005-10-07 06:49:50 +0200 (ven, 07 ott 2005) $
+ */
+public class MockPublicUrlDefinitionsFactory extends UrlDefinitionsFactory {
+
+ /**
+ * Exposes the <code>addDefinitions</code> method of
+ * <code>UrlDefinitionsFactory</code>
+ *
+ * @see org.apache.tiles.definition.UrlDefinitionsFactory#addDefinitions(org.apache.tiles.ComponentDefinitions,
+ * org.apache.tiles.TilesContext)
+ */
+ public void addDefinitions(ComponentDefinitions definitions,
+ TilesContext tilesContext) throws DefinitionsFactoryException {
+ super.addDefinitions(definitions, tilesContext);
+ }
+
+ /**
+ *
+ * Exposes the <code>isContextProcessed</code> method of
+ * <code>UrlDefinitionsFactory</code>
+ *
+ * @see org.apache.tiles.definition.UrlDefinitionsFactory#isContextProcessed(org.apache.tiles.TilesContext)
+ */
+ public boolean isContextProcessed(TilesContext tilesContext) {
+ return super.isContextProcessed(tilesContext);
+ }
+}