This project has retired. For details please refer to its Attic page.
UnresolvingLocaleDefinitionsFactory xref
View Javadoc

1   /*
2    * $Id: UnresolvingLocaleDefinitionsFactory.java 891884 2009-12-17 20:43:12Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.tiles.definition;
23  
24  import java.util.Locale;
25  
26  import org.apache.tiles.Definition;
27  import org.apache.tiles.definition.dao.DefinitionDAO;
28  import org.apache.tiles.locale.LocaleResolver;
29  import org.apache.tiles.request.Request;
30  
31  /**
32   * {@link DefinitionsFactory DefinitionsFactory} implementation that manages
33   * Definitions configuration data from URLs, without resolving definition
34   * inheritance when a definition is returned.<p/>
35   * <p>
36   * The Definition objects are read from the
37   * {@link org.apache.tiles.definition.digester.DigesterDefinitionsReader DigesterDefinitionsReader}
38   * class unless another implementation is specified.
39   * </p>
40   *
41   * @version $Rev: 891884 $ $Date: 2009-12-18 07:43:12 +1100 (Fri, 18 Dec 2009) $
42   * @since 2.2.1
43   */
44  public class UnresolvingLocaleDefinitionsFactory implements DefinitionsFactory {
45  
46      /**
47       * The definition DAO that extracts the definitions from the sources.
48       *
49       * @since 2.2.1
50       */
51      protected DefinitionDAO<Locale> definitionDao;
52  
53      /**
54       * The locale resolver object.
55       *
56       * @since 2.2.1
57       */
58      protected LocaleResolver localeResolver;
59  
60      /**
61       * Sets the locale resolver to use.
62       *
63       * @param localeResolver The locale resolver.
64       * @since 2.2.1
65       */
66      public void setLocaleResolver(LocaleResolver localeResolver) {
67          this.localeResolver = localeResolver;
68      }
69  
70      /**
71       * Sets the definition DAO to use. It must be locale-based.
72       *
73       * @param definitionDao The definition DAO.
74       * @since 2.2.1
75       */
76      public void setDefinitionDAO(DefinitionDAO<Locale> definitionDao) {
77          this.definitionDao = definitionDao;
78      }
79  
80      /** {@inheritDoc} */
81      public Definition getDefinition(String name,
82              Request tilesContext) {
83          Locale locale = null;
84  
85          if (tilesContext != null) {
86              locale = localeResolver.resolveLocale(tilesContext);
87          }
88  
89          return definitionDao.getDefinition(name, locale);
90      }
91  }