tiles-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r666834 - in /tiles/framework/trunk: tiles-api/src/main/java/org/apache/tiles/ tiles-core/src/main/java/org/apache/tiles/definition/ tiles-core/src/main/java/org/apache/tiles/definition/dao/ tiles-core/src/main/java/org/apache/tiles/factory...
Date Wed, 11 Jun 2008 20:49:06 GMT
Author: apetrelli
Date: Wed Jun 11 13:49:05 2008
New Revision: 666834

URL: http://svn.apache.org/viewvc?rev=666834&view=rev
Log:
TILES-256
Moved logic that loads URLs to a DAO.

Added:
    tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Initializable.java   (with props)
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/RefreshMonitor.java   (with props)
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/DefinitionDAO.java   (with props)
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAO.java   (with props)
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/URLReader.java   (with props)
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/package.html   (with props)
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/LocaleUtil.java   (with props)
Modified:
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsFactory.java
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ReloadableDefinitionsFactory.java
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/factory/BasicTilesContainerFactory.java
    tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java

Added: tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Initializable.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Initializable.java?rev=666834&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Initializable.java (added)
+++ tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Initializable.java Wed Jun 11 13:49:05 2008
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ *
+ * 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.tiles;
+
+import java.util.Map;
+
+/**
+ * It is an object that can be initialized using a map with parameters.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.1.0
+ */
+public interface Initializable {
+
+    /**
+     * Initializes the object.
+     *
+     * @param params The map of parameters.
+     */
+    void init(Map<String, String> params);
+}

Propchange: tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Initializable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/Initializable.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsFactory.java?rev=666834&r1=666833&r2=666834&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsFactory.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/DefinitionsFactory.java Wed Jun 11 13:49:05 2008
@@ -61,6 +61,14 @@
     String DEFINITIONS_CONFIG = "org.apache.tiles.definition.DefinitionsFactory.DEFINITIONS_CONFIG";
 
     /**
+     * Constant representing the configuration parameter used to define the
+     * definition DAO to use.
+     */
+    String DEFINITION_DAO_INIT_PARAM =
+        "org.apache.tiles.definition.DefinitionsFactory.DefinitionDAO";
+
+
+    /**
      * Initializes the DefinitionsFactory and its subcomponents. <p/>
      * Implementations may support configuration properties to be passed in via
      * the params Map.

Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/RefreshMonitor.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/RefreshMonitor.java?rev=666834&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/RefreshMonitor.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/RefreshMonitor.java Wed Jun 11 13:49:05 2008
@@ -0,0 +1,39 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.definition;
+
+/**
+ * Implementing this interface means that the object monitors the sources it
+ * uses to check when they change.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.1.0
+ */
+public interface RefreshMonitor {
+
+    /**
+     * Indicates whether the sources are out of date and need to be reloaded.
+     *
+     * @return <code>true</code> if the sources need to be refreshed.
+ * @since 2.1.0
+     */
+    boolean refreshRequired();
+}

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/RefreshMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/RefreshMonitor.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ReloadableDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ReloadableDefinitionsFactory.java?rev=666834&r1=666833&r2=666834&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ReloadableDefinitionsFactory.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/ReloadableDefinitionsFactory.java Wed Jun 11 13:49:05 2008
@@ -22,12 +22,13 @@
 
 package org.apache.tiles.definition;
 
+
 /**
  * Indicates support for reloading Tiles configuration when it changes.
  *
  * @version $Rev$ $Date$
  */
-public interface ReloadableDefinitionsFactory {
+public interface ReloadableDefinitionsFactory extends RefreshMonitor {
 
     /**
      * Indicates whether the DefinitionsFactory is out of date and needs to be

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java?rev=666834&r1=666833&r2=666834&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/UrlDefinitionsFactory.java Wed Jun 11 13:49:05 2008
@@ -23,19 +23,20 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.tiles.Definition;
+import org.apache.tiles.Initializable;
 import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.awareness.TilesApplicationContextAware;
 import org.apache.tiles.context.TilesRequestContext;
-import org.apache.tiles.definition.digester.DigesterDefinitionsReader;
+import org.apache.tiles.definition.dao.DefinitionDAO;
+import org.apache.tiles.definition.dao.LocaleUrlDefinitionDAO;
+import org.apache.tiles.definition.dao.URLReader;
 import org.apache.tiles.impl.BasicTilesContainer;
 import org.apache.tiles.locale.LocaleResolver;
 import org.apache.tiles.locale.impl.DefaultLocaleResolver;
 import org.apache.tiles.util.ClassUtil;
+import org.apache.tiles.util.LocaleUtil;
 
-import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -56,7 +57,8 @@
  * @version $Rev$ $Date$
  */
 public class UrlDefinitionsFactory implements DefinitionsFactory,
-        ReloadableDefinitionsFactory, TilesApplicationContextAware {
+        ReloadableDefinitionsFactory, TilesApplicationContextAware,
+        Initializable {
 
     /**
      * Compatibility constant.
@@ -71,11 +73,11 @@
     private static final Log LOG = LogFactory.getLog(UrlDefinitionsFactory.class);
 
     /**
-     * Contains the URL objects identifying where configuration data is found.
+     * The definition DAO that extracts the definitions from the sources.
      *
      * @since 2.1.0
      */
-    protected List<URL> sourceURLs;
+    protected DefinitionDAO<Locale> definitionDao;
 
     /**
      * Contains the URL objects identifying where configuration data is found.
@@ -86,11 +88,15 @@
 
     /**
      * Reader used to get definitions from the sources.
+     *
+     * @deprecated No more used.
      */
     protected DefinitionsReader reader;
 
     /**
      * Contains the dates that the URL sources were last modified.
+     *
+     * @deprecated No more used.
      */
     protected Map<String, Long> lastModifiedDates;
 
@@ -126,8 +132,7 @@
      * Creates a new instance of UrlDefinitionsFactory.
      */
     public UrlDefinitionsFactory() {
-        sourceURLs = new ArrayList<URL>();
-        lastModifiedDates = new HashMap<String, Long>();
+        definitionDao = new LocaleUrlDefinitionDAO();
         processedLocales = new ArrayList<Locale>();
     }
 
@@ -137,32 +142,22 @@
     }
 
     /**
-     * Sets the source URLs to use.
-     *
-     * @param sourceURLs The source URLs.
-     */
-    public void setSourceURLs(List<URL> sourceURLs) {
-        this.sourceURLs = sourceURLs;
-    }
-
-    /**
-     * Sets the definitions reader that will read the URLs.
+     * Sets the locale resolver to use.
      *
-     * @param reader The definitions reader.
+     * @param localeResolver The locale resolver.
      * @since 2.1.0
      */
-    public void setReader(DefinitionsReader reader) {
-        this.reader = reader;
+    public void setLocaleResolver(LocaleResolver localeResolver) {
+        this.localeResolver = localeResolver;
     }
 
     /**
-     * Sets the locale resolver to use.
+     * Sets the definition DAO to use. It must be locale-based.
      *
-     * @param localeResolver The locale resolver.
-     * @since 2.1.0
+     * @param definitionDao The definition DAO.
      */
-    public void setLocaleResolver(LocaleResolver localeResolver) {
-        this.localeResolver = localeResolver;
+    public void setDefinitionDAO(DefinitionDAO<Locale> definitionDao) {
+        this.definitionDao = definitionDao;
     }
 
     /**
@@ -174,17 +169,23 @@
      * @param params The Map of configuration properties.
      * @throws DefinitionsFactoryException if an initialization error occurs.
      */
+    @SuppressWarnings("unchecked")
     public void init(Map<String, String> params) {
-        identifySources(params);
-        String readerClassName =
-            params.get(DefinitionsFactory.READER_IMPL_PROPERTY);
-
-        if (readerClassName != null) {
-            reader = (DefinitionsReader) ClassUtil.instantiate(readerClassName);
+        String definitionDaoClassName = params
+                .get(DefinitionsFactory.DEFINITION_DAO_INIT_PARAM);
+        if (definitionDaoClassName != null) {
+            definitionDao = (DefinitionDAO<Locale>) ClassUtil
+                    .instantiate(definitionDaoClassName);
         } else {
-            reader = new DigesterDefinitionsReader();
+            definitionDao = new LocaleUrlDefinitionDAO();
+        }
+        if (definitionDao instanceof TilesApplicationContextAware) {
+            ((TilesApplicationContextAware) definitionDao)
+                    .setApplicationContext(applicationContext);
+        }
+        if (definitionDao instanceof Initializable) {
+            ((Initializable) definitionDao).init(params);
         }
-        reader.init(params);
 
         String resolverClassName = params
                 .get(DefinitionsFactory.LOCALE_RESOLVER_IMPL_PROPERTY);
@@ -247,8 +248,7 @@
      * @param source The configuration source for definitions.
      * @throws DefinitionsFactoryException if an invalid source is passed in or
      *                                     an error occurs resolving the source to an actual data store.
-     * @deprecated Do not call it, let the Definitions Factory load the sources
-     * by itself.
+     * @deprecated Use {@link URLReader#addSourceURL(URL)}.
      */
     public void addSource(Object source) {
         if (source == null) {
@@ -261,7 +261,9 @@
                 "Source object must be an URL");
         }
 
-        sourceURLs.add((URL) source);
+        if (definitionDao instanceof URLReader) {
+            ((URLReader) definitionDao).addSourceURL((URL) source);
+        }
     }
 
     /**
@@ -302,43 +304,11 @@
         }
 
         processedLocales.add(locale);
-        List<String> postfixes = calculatePostfixes(locale);
-        Map<String, Definition> localeDefsMap = new HashMap<String, Definition>();
-        for (Object postfix : postfixes) {
-            // For each postfix, all the sources must be loaded.
-            for (URL url : sourceURLs) {
-                String path = url.toExternalForm();
-
-                String newPath = concatPostfix(path, (String) postfix);
-                try {
-                    URL newUrl = new URL(newPath);
-                    URLConnection connection = newUrl.openConnection();
-                    connection.connect();
-                    lastModifiedDates.put(newUrl.toExternalForm(),
-                        connection.getLastModified());
-
-                    // Definition must be collected, starting from the base
-                    // source up to the last localized file.
-                    Map<String, Definition> defsMap = reader
-                            .read(connection.getInputStream());
-                    if (defsMap != null) {
-                        localeDefsMap.putAll(defsMap);
-                    }
-                } catch (FileNotFoundException e) {
-                    // File not found. continue.
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("File " + newPath + " not found, continue");
-                    }
-                } catch (IOException e) {
-                    throw new DefinitionsFactoryException(
-                        "I/O error processing configuration.");
-                }
-            }
-        }
 
         // At the end of definitions loading, they can be assigned to
         // Definitions implementation, to allow inheritance resolution.
-        localeSpecificDefinitions.put(locale, localeDefsMap);
+        localeSpecificDefinitions.put(locale, definitionDao
+                .getDefinitions(locale));
         resolveInheritances(locale);
     }
 
@@ -393,23 +363,10 @@
      * @param name    Filename.
      * @param postfix Postfix to add.
      * @return Concatenated filename.
+     * @deprecated Use {@link LocaleUtil#concatPostfix(String,String)} instead
      */
-    protected String concatPostfix(String name, String postfix) {
-        if (postfix == null) {
-            return name;
-        }
-
-        // Search file name extension.
-        // take care of Unix files starting with .
-        int dotIndex = name.lastIndexOf(".");
-        int lastNameStart = name.lastIndexOf(java.io.File.pathSeparator);
-        if (dotIndex < 1 || dotIndex < lastNameStart) {
-            return name + postfix;
-        }
-
-        String ext = name.substring(dotIndex);
-        name = name.substring(0, dotIndex);
-        return name + postfix + ext;
+    protected static String concatPostfix(String name, String postfix) {
+        return LocaleUtil.concatPostfix(name, postfix);
     }
 
     /**
@@ -423,20 +380,7 @@
     protected synchronized void loadDefinitions() {
         reset();
 
-        try {
-            for (URL source : sourceURLs) {
-                URLConnection connection = source.openConnection();
-                connection.connect();
-                lastModifiedDates.put(source.toExternalForm(),
-                    connection.getLastModified());
-                Map<String, Definition> defsMap = reader
-                        .read(connection.getInputStream());
-                baseDefinitions.putAll(defsMap);
-                resolveInheritances();
-            }
-        } catch (IOException e) {
-            throw new DefinitionsFactoryException("I/O error accessing source.", e);
-        }
+        baseDefinitions.putAll(definitionDao.getDefinitions(null));
     }
 
     /**
@@ -446,51 +390,10 @@
      *
      * @param locale the locale
      * @return a list of
+     * @deprecated Use {@link LocaleUtil#calculatePostfixes(Locale)} instead.
      */
     protected static List<String> calculatePostfixes(Locale locale) {
-        final List<String> result = new ArrayList<String>();
-        final String language = locale.getLanguage();
-        final int languageLength = language.length();
-        final String country = locale.getCountry();
-        final int countryLength = country.length();
-        final String variant = locale.getVariant();
-        final int variantLength = variant.length();
-
-        // The default configuration file must be loaded to allow correct
-        // definition inheritance.
-        result.add("");
-        if (languageLength + countryLength + variantLength == 0) {
-            //The locale is "", "", "".
-            return result;
-        }
-
-        final StringBuffer temp = new StringBuffer();
-        temp.append('_');
-        temp.append(language);
-
-        if (languageLength > 0) {
-            result.add(temp.toString());
-        }
-
-        if (countryLength + variantLength == 0) {
-            return result;
-        }
-
-        temp.append('_');
-        temp.append(country);
-
-        if (countryLength > 0) {
-            result.add(temp.toString());
-        }
-
-        if (variantLength == 0) {
-            return result;
-        } else {
-            temp.append('_');
-            temp.append(variant);
-            result.add(temp.toString());
-            return result;
-        }
+        return LocaleUtil.calculatePostfixes(locale);
     }
 
 
@@ -509,60 +412,8 @@
      * @return If the factory needs refresh.
      */
     public boolean refreshRequired() {
-        boolean status = false;
-
-        Set<String> urls = lastModifiedDates.keySet();
-
-        try {
-            for (String urlPath : urls) {
-                Long lastModifiedDate = lastModifiedDates.get(urlPath);
-                URL url = new URL(urlPath);
-                URLConnection connection = url.openConnection();
-                connection.connect();
-                long newModDate = connection.getLastModified();
-                if (newModDate != lastModifiedDate) {
-                    status = true;
-                    break;
-                }
-            }
-        } catch (Exception e) {
-            LOG.warn("Exception while monitoring update times.", e);
-            return true;
-        }
-        return status;
-    }
-
-    /**
-     * Detects the sources to load.
-     *
-     * @param initParameters The initialization parameters.
-     * @since 2.1.0
-     */
-    protected void identifySources(Map<String, String> initParameters) {
-        if (applicationContext == null) {
-            throw new IllegalStateException(
-                    "The TilesApplicationContext cannot be null");
-        }
-
-        String resourceString = getResourceString(initParameters);
-        List<String> resources = getResourceNames(resourceString);
-
-        try {
-            for (String resource : resources) {
-                URL resourceUrl = applicationContext.getResource(resource);
-                if (resourceUrl != null) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug("Adding resource '" + resourceUrl + "' to definitions factory.");
-                    }
-                    sourceURLs.add(resourceUrl);
-                } else {
-                    LOG.warn("Unable to find configured definition '" + resource + "'");
-                }
-            }
-        } catch (IOException e) {
-            throw new DefinitionsFactoryException("Unable to parse definitions from "
-                + resourceString, e);
-        }
+        return (definitionDao instanceof RefreshMonitor)
+                && ((RefreshMonitor) definitionDao).refreshRequired();
     }
 
     /**
@@ -574,8 +425,9 @@
      *
      * @param parms The initialization parameters.
      * @return resource string to be parsed.
+     * @deprecated Deprecated without replacement.
      */
-    @SuppressWarnings("deprecation")
+    @Deprecated
     protected String getResourceString(Map<String, String> parms) {
         String resourceStr = parms.get(DefinitionsFactory.DEFINITIONS_CONFIG);
         if (resourceStr == null) {
@@ -596,7 +448,9 @@
      *
      * @param resourceString comma seperated resources
      * @return parsed resources
+     * @deprecated Deprecated without replacement.
      */
+    @Deprecated
     protected List<String> getResourceNames(String resourceString) {
         StringTokenizer tokenizer = new StringTokenizer(resourceString, ",");
         List<String> filenames = new ArrayList<String>(tokenizer.countTokens());

Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/DefinitionDAO.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/DefinitionDAO.java?rev=666834&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/DefinitionDAO.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/DefinitionDAO.java Wed Jun 11 13:49:05 2008
@@ -0,0 +1,57 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.definition.dao;
+
+import java.util.Map;
+
+import org.apache.tiles.Definition;
+
+/**
+ * It represents an object that provides definitions, depending on a
+ * customization key.
+ *
+ * @param <K> The customization key class.
+ * @version $Rev$ $Date$
+ * @since 2.1.0
+ */
+public interface DefinitionDAO<K> {
+
+    /**
+     * Returns a definition, given its name and the customization key.
+     *
+     * @param name The name of the definition.
+     * @param customizationKey The customization key.
+     * @return The requested definition, if found, otherwise <code>null</code>.
+     * The inheritance of the definition must not be resolved.
+     * @since 2.1.0
+     */
+    Definition getDefinition(String name, K customizationKey);
+
+    /**
+     * Returns all the definitions used of a customization key.
+     *
+     * @param customizationKey The customization key.
+     * @return All the definitions that are connected to the customization key.
+     * The inheritance of the definitions must not be resolved.
+     * @since 2.1.0
+     */
+    Map<String, Definition> getDefinitions(K customizationKey);
+}

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/DefinitionDAO.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/DefinitionDAO.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAO.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAO.java?rev=666834&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAO.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAO.java Wed Jun 11 13:49:05 2008
@@ -0,0 +1,307 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.definition.dao;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tiles.Definition;
+import org.apache.tiles.Initializable;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.awareness.TilesApplicationContextAware;
+import org.apache.tiles.definition.DefinitionsFactory;
+import org.apache.tiles.definition.DefinitionsFactoryException;
+import org.apache.tiles.definition.DefinitionsReader;
+import org.apache.tiles.definition.RefreshMonitor;
+import org.apache.tiles.definition.digester.DigesterDefinitionsReader;
+import org.apache.tiles.impl.BasicTilesContainer;
+import org.apache.tiles.util.ClassUtil;
+import org.apache.tiles.util.LocaleUtil;
+
+/**
+ * A definition DAO that uses {@link Locale} as a customization key and loads
+ * definitions from URLs.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.1.0
+ */
+public class LocaleUrlDefinitionDAO implements DefinitionDAO<Locale>,
+        Initializable, TilesApplicationContextAware, RefreshMonitor, URLReader {
+
+    /**
+     * The logging object.
+     */
+    private static final Log LOG = LogFactory
+            .getLog(LocaleUrlDefinitionDAO.class);
+
+    /**
+     * Compatibility constant.
+     *
+     * @deprecated use {@link DEFINITIONS_CONFIG} to avoid namespace collisions.
+     */
+    private static final String LEGACY_DEFINITIONS_CONFIG = "definitions-config";
+
+    /**
+     * Contains the URL objects identifying where configuration data is found.
+     *
+     * @since 2.1.0
+     */
+    protected List<URL> sourceURLs;
+
+    /**
+     * Contains the dates that the URL sources were last modified.
+     */
+    protected Map<String, Long> lastModifiedDates;
+
+    /**
+     * The application context.
+     *
+     * @since 2.1.0
+     */
+    protected TilesApplicationContext applicationContext;
+
+    /**
+     * Reader used to get definitions from the sources.
+     */
+    protected DefinitionsReader reader;
+
+    /**
+     * Constructor.
+     */
+    public LocaleUrlDefinitionDAO() {
+        sourceURLs = new ArrayList<URL>();
+        lastModifiedDates = new HashMap<String, Long>();
+    }
+
+    /**
+     * <p>
+     * Returns a definition, given its name and the customization key.
+     * </p>
+     * <strong>WARNING!</strong> This method is slow! It loads all the
+     * definitions and then selects the needed one.
+     *
+     * @param name The name of the definition.
+     * @param customizationKey The customization key.
+     * @return The requested definition, if found, otherwise <code>null</code>.
+     * The inheritance of the definition must not be resolved.
+     * @since 2.1.0
+     */
+    public Definition getDefinition(String name, Locale customizationKey) {
+        Map<String, Definition> defsMap = getDefinitions(customizationKey);
+        return defsMap != null ? defsMap.get(name) : null;
+    }
+
+    /** {@inheritDoc} */
+    public Map<String, Definition> getDefinitions(Locale customizationKey) {
+        List<String> postfixes = LocaleUtil.calculatePostfixes(customizationKey);
+        Map<String, Definition> localeDefsMap = new HashMap<String, Definition>();
+        for (Object postfix : postfixes) {
+            // For each postfix, all the sources must be loaded.
+            for (URL url : sourceURLs) {
+                String path = url.toExternalForm();
+
+                String newPath = LocaleUtil.concatPostfix(path,
+                        (String) postfix);
+                try {
+                    URL newUrl = new URL(newPath);
+                    URLConnection connection = newUrl.openConnection();
+                    connection.connect();
+                    lastModifiedDates.put(newUrl.toExternalForm(), connection
+                            .getLastModified());
+
+                    // Definition must be collected, starting from the base
+                    // source up to the last localized file.
+                    Map<String, Definition> defsMap = reader.read(connection
+                            .getInputStream());
+                    if (defsMap != null) {
+                        localeDefsMap.putAll(defsMap);
+                    }
+                } catch (FileNotFoundException e) {
+                    // File not found. continue.
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("File " + newPath + " not found, continue");
+                    }
+                } catch (IOException e) {
+                    throw new DefinitionsFactoryException(
+                            "I/O error processing configuration.", e);
+                }
+            }
+        }
+
+        return localeDefsMap;
+    }
+
+    /**  {@inheritDoc}*/
+    public void setSourceURLs(List<URL> sourceURLs) {
+        this.sourceURLs = sourceURLs;
+    }
+
+    /**  {@inheritDoc}*/
+    public void setReader(DefinitionsReader reader) {
+        this.reader = reader;
+    }
+
+    /**  {@inheritDoc}*/
+    public void addSourceURL(URL sourceURL) {
+        if (sourceURLs == null) {
+            sourceURLs = new ArrayList<URL>();
+        }
+        sourceURLs.add(sourceURL);
+    }
+
+    /** {@inheritDoc} */
+    public void setApplicationContext(TilesApplicationContext applicationContext) {
+        this.applicationContext = applicationContext;
+    }
+
+    /** {@inheritDoc} */
+    public void init(Map<String, String> params) {
+        identifySources(params);
+        String readerClassName = params
+                .get(DefinitionsFactory.READER_IMPL_PROPERTY);
+
+        if (readerClassName != null) {
+            reader = (DefinitionsReader) ClassUtil.instantiate(readerClassName);
+        } else {
+            reader = new DigesterDefinitionsReader();
+        }
+        reader.init(params);
+    }
+
+    /** {@inheritDoc} */
+    public boolean refreshRequired() {
+        boolean status = false;
+
+        Set<String> urls = lastModifiedDates.keySet();
+
+        try {
+            for (String urlPath : urls) {
+                Long lastModifiedDate = lastModifiedDates.get(urlPath);
+                URL url = new URL(urlPath);
+                URLConnection connection = url.openConnection();
+                connection.connect();
+                long newModDate = connection.getLastModified();
+                if (newModDate != lastModifiedDate) {
+                    status = true;
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            LOG.warn("Exception while monitoring update times.", e);
+            return true;
+        }
+        return status;
+    }
+
+    /**
+     * Appends locale-specific {@link Definition} objects to existing
+     * definitions set by reading locale-specific versions of the applied
+     * sources.
+     *
+     * @param locale The requested locale.
+     * @throws DefinitionsFactoryException if an error occurs reading
+     * definitions.
+     * @since 2.1.0
+     */
+    protected synchronized void addDefinitions(Locale locale) {
+    }
+
+    /**
+     * Detects the sources to load.
+     *
+     * @param initParameters The initialization parameters.
+     * @since 2.1.0
+     */
+    protected void identifySources(Map<String, String> initParameters) {
+        if (applicationContext == null) {
+            throw new IllegalStateException(
+                    "The TilesApplicationContext cannot be null");
+        }
+
+        String resourceString = getResourceString(initParameters);
+        String[] resources = getResourceNames(resourceString);
+
+        try {
+            for (int i = 0; i < resources.length; i++) {
+                URL resourceUrl = applicationContext.getResource(resources[i]);
+                if (resourceUrl != null) {
+                    if (LOG.isDebugEnabled()) {
+                        LOG.debug("Adding resource '" + resourceUrl
+                                + "' to definitions factory.");
+                    }
+                    sourceURLs.add(resourceUrl);
+                } else {
+                    LOG.warn("Unable to find configured definition '"
+                            + resources[i] + "'");
+                }
+            }
+        } catch (IOException e) {
+            throw new DefinitionsFactoryException(
+                    "Unable to parse definitions from " + resourceString, e);
+        }
+    }
+
+    /**
+     * Derive the resource string from the initialization parameters. If no
+     * parameter {@link DefinitionsFactory#DEFINITIONS_CONFIG} is available,
+     * attempts to retrieve {@link BasicTilesContainer#DEFINITIONS_CONFIG} and
+     * {@link #LEGACY_DEFINITIONS_CONFIG}. If neither are available, returns
+     * "/WEB-INF/tiles.xml".
+     *
+     * @param parms The initialization parameters.
+     * @return resource string to be parsed.
+     */
+    @SuppressWarnings("deprecation")
+    protected String getResourceString(Map<String, String> parms) {
+        String resourceStr = parms.get(DefinitionsFactory.DEFINITIONS_CONFIG);
+        if (resourceStr == null) {
+            resourceStr = parms.get(BasicTilesContainer.DEFINITIONS_CONFIG);
+        }
+        if (resourceStr == null) {
+            resourceStr = parms.get(LEGACY_DEFINITIONS_CONFIG);
+        }
+        if (resourceStr == null) {
+            resourceStr = "/WEB-INF/tiles.xml";
+        }
+        return resourceStr;
+    }
+
+    /**
+     * Parse the resourceString into a list of resource paths which can be
+     * loaded by the application context.
+     *
+     * @param resourceString comma separated resources
+     * @return parsed resources
+     */
+    protected String[] getResourceNames(String resourceString) {
+        return resourceString.split(",");
+    }
+}

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAO.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/LocaleUrlDefinitionDAO.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/URLReader.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/URLReader.java?rev=666834&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/URLReader.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/URLReader.java Wed Jun 11 13:49:05 2008
@@ -0,0 +1,60 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.definition.dao;
+
+import java.net.URL;
+import java.util.List;
+
+import org.apache.tiles.definition.DefinitionsReader;
+
+/**
+ * It represents an object that reads URLs and is able to read them throw the
+ * use of a {@link DefinitionsReader}.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.1.0
+ */
+public interface URLReader {
+
+    /**
+     * Sets the source URLs to use.
+     *
+     * @param sourceURLs The source URLs.
+     * @since 2.1.0
+     */
+    void setSourceURLs(List<URL> sourceURLs);
+
+    /**
+     * Sets the definitions reader that will read the URLs.
+     *
+     * @param reader The definitions reader.
+     * @since 2.1.0
+     */
+    void setReader(DefinitionsReader reader);
+
+    /**
+     * Adds a single URL to use.
+     *
+     * @param sourceURL The source URL to add.
+     * @since 2.1.0
+     */
+    void addSourceURL(URL sourceURL);
+}

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/URLReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/URLReader.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/package.html
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/package.html?rev=666834&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/package.html (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/package.html Wed Jun 11 13:49:05 2008
@@ -0,0 +1,31 @@
+<!--
+/*
+ * $Id$
+ *
+ * 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.
+ */
+-->
+<html>
+<head>
+    <title>Tiles definition DAO</title>
+</head>
+<body>
+Classes to simply load definitions depending on a customization key.
+The package contains also basic implementations.
+</body>
+</html>
\ No newline at end of file

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/definition/dao/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/factory/BasicTilesContainerFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/factory/BasicTilesContainerFactory.java?rev=666834&r1=666833&r2=666834&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/factory/BasicTilesContainerFactory.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/factory/BasicTilesContainerFactory.java Wed Jun 11 13:49:05 2008
@@ -24,6 +24,7 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -34,6 +35,8 @@
 import org.apache.tiles.definition.DefinitionsFactory;
 import org.apache.tiles.definition.DefinitionsReader;
 import org.apache.tiles.definition.UrlDefinitionsFactory;
+import org.apache.tiles.definition.dao.DefinitionDAO;
+import org.apache.tiles.definition.dao.LocaleUrlDefinitionDAO;
 import org.apache.tiles.definition.digester.DigesterDefinitionsReader;
 import org.apache.tiles.evaluator.AttributeEvaluator;
 import org.apache.tiles.evaluator.impl.DirectAttributeEvaluator;
@@ -161,6 +164,7 @@
      * @param contextFactory The Tiles context factory.
      * @param resolver The locale resolver.
      * @return The definitions factory.
+     * @since 2.1.0
      */
     protected DefinitionsFactory createDefinitionsFactory(Object context,
             TilesApplicationContext applicationContext,
@@ -168,15 +172,33 @@
         UrlDefinitionsFactory factory = new UrlDefinitionsFactory();
         factory.setApplicationContext(applicationContext);
         factory.setLocaleResolver(resolver);
-        factory.setReader(createDefinitionsReader(context, applicationContext,
-                contextFactory));
-        factory.setSourceURLs(getSourceURLs(context, applicationContext,
-                contextFactory));
+        factory.setDefinitionDAO(createLocaleDefinitionDao(context,
+                applicationContext, contextFactory, resolver));
         factory.refresh();
         return factory;
     }
 
     /**
+     * Creates a Locale-based definition DAO.
+     *
+     * @param context The context.
+     * @param applicationContext The Tiles application context.
+     * @param contextFactory The Tiles context factory.
+     * @param resolver The locale resolver.
+     * @return The definition DAO.
+     * @since 2.1.0
+     */
+    protected DefinitionDAO<Locale> createLocaleDefinitionDao(Object context,
+            TilesApplicationContext applicationContext,
+            TilesContextFactory contextFactory, LocaleResolver resolver) {
+        LocaleUrlDefinitionDAO definitionDao = new LocaleUrlDefinitionDAO();
+        definitionDao.setReader(createDefinitionsReader(context, applicationContext,
+                contextFactory));
+        definitionDao.setSourceURLs(getSourceURLs(context, applicationContext,
+                contextFactory));
+        return definitionDao;
+    }
+    /**
      * Creates the locale resolver. By default it creates a
      * {@link DefaultLocaleResolver}.
      *

Added: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/LocaleUtil.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/LocaleUtil.java?rev=666834&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/LocaleUtil.java (added)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/LocaleUtil.java Wed Jun 11 13:49:05 2008
@@ -0,0 +1,128 @@
+/*
+ * $Id$
+ *
+ * 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.tiles.util;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Utilities for locale manipulation.
+ *
+ * @version $Rev$ $Date$
+ * @since 2.1.0
+ */
+public final class LocaleUtil {
+
+    /**
+     * Private constructor to avoid instantiation.
+     */
+    private LocaleUtil() {
+    }
+
+    /**
+     * Calculate the postfixes along the search path from the base bundle to the
+     * bundle specified by baseName and locale. Method copied from
+     * java.util.ResourceBundle
+     *
+     * @param locale The locale.
+     * @return a list of postfixes to add to filenames.
+     * @since 2.1.0
+     */
+    public static List<String> calculatePostfixes(Locale locale) {
+        final List<String> result = new ArrayList<String>();
+        // The default configuration file must be loaded to allow correct
+        // definition inheritance.
+        result.add("");
+
+        if (locale == null) {
+            return result;
+        }
+
+        final String language = locale.getLanguage();
+        final int languageLength = language.length();
+        final String country = locale.getCountry();
+        final int countryLength = country.length();
+        final String variant = locale.getVariant();
+        final int variantLength = variant.length();
+
+        if (languageLength + countryLength + variantLength == 0) {
+            // The locale is "", "", "".
+            return result;
+        }
+
+        final StringBuffer temp = new StringBuffer();
+        temp.append('_');
+        temp.append(language);
+
+        if (languageLength > 0) {
+            result.add(temp.toString());
+        }
+
+        if (countryLength + variantLength == 0) {
+            return result;
+        }
+
+        temp.append('_');
+        temp.append(country);
+
+        if (countryLength > 0) {
+            result.add(temp.toString());
+        }
+
+        if (variantLength == 0) {
+            return result;
+        } else {
+            temp.append('_');
+            temp.append(variant);
+            result.add(temp.toString());
+            return result;
+        }
+    }
+
+    /**
+     * Concat postfix to the name. Take care of existing filename extension.
+     * Transform the given name "name.ext" to have "name" + "postfix" + "ext".
+     * If there is no ext, return "name" + "postfix".
+     *
+     * @param name Filename.
+     * @param postfix Postfix to add.
+     * @return Concatenated filename.
+     * @since 2.1.0
+     */
+    public static String concatPostfix(String name, String postfix) {
+        if (postfix == null) {
+            return name;
+        }
+
+        // Search file name extension.
+        // take care of Unix files starting with .
+        int dotIndex = name.lastIndexOf(".");
+        int lastNameStart = name.lastIndexOf(java.io.File.pathSeparator);
+        if (dotIndex < 1 || dotIndex < lastNameStart) {
+            return name + postfix;
+        }
+
+        String ext = name.substring(dotIndex);
+        name = name.substring(0, dotIndex);
+        return name + postfix + ext;
+    }
+}

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/LocaleUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/util/LocaleUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java?rev=666834&r1=666833&r2=666834&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java (original)
+++ tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java Wed Jun 11 13:49:05 2008
@@ -33,6 +33,7 @@
 
 import org.apache.tiles.TilesApplicationContext;
 import org.apache.tiles.context.TilesRequestContext;
+import org.apache.tiles.util.LocaleUtil;
 import org.easymock.EasyMock;
 
 /**
@@ -373,13 +374,13 @@
     public void testCalculatePostfixes() {
         Locale locale = Locale.US;
 
-        List<String> posts = UrlDefinitionsFactory.calculatePostfixes(locale);
+        List<String> posts = LocaleUtil.calculatePostfixes(locale);
         assertEquals(POSTFIX_COUNT, posts.size());
         assertTrue(posts.contains("_en_US"));
         assertTrue(posts.contains("_en"));
 
         locale = Locale.ENGLISH;
-        posts = UrlDefinitionsFactory.calculatePostfixes(locale);
+        posts = LocaleUtil.calculatePostfixes(locale);
         assertEquals(2, posts.size());
         assertTrue(posts.contains("_en"));
     }
@@ -388,11 +389,10 @@
      * Tests the concatPostfix method.
      */
     public void testConcatPostfix() {
-        UrlDefinitionsFactory factory = new UrlDefinitionsFactory();
         String postfix = "_en_US";
-        assertEquals("a_en_US", factory.concatPostfix("a", postfix));
-        assertEquals("a_en_US.jsp", factory.concatPostfix("a.jsp", postfix));
-        assertEquals("file_en_US.jsp", factory.concatPostfix("file.jsp", postfix));
-        assertEquals("./path/file_en_US.jsp", factory.concatPostfix("./path/file.jsp", postfix));
+        assertEquals("a_en_US", LocaleUtil.concatPostfix("a", postfix));
+        assertEquals("a_en_US.jsp", LocaleUtil.concatPostfix("a.jsp", postfix));
+        assertEquals("file_en_US.jsp", LocaleUtil.concatPostfix("file.jsp", postfix));
+        assertEquals("./path/file_en_US.jsp", LocaleUtil.concatPostfix("./path/file.jsp", postfix));
     }
 }



Mime
View raw message