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

1   /*
2    * $Id: LocaleDefinitionsFactory.java 836180 2009-11-14 14:00:02Z 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.request.Request;
28  
29  /**
30   * {@link DefinitionsFactory DefinitionsFactory} implementation that manages
31   * Definitions configuration data from URLs, but resolving definition
32   * inheritance when a definition is returned.. <p/>
33   * <p>
34   * The Definition objects are read from the
35   * {@link org.apache.tiles.definition.digester.DigesterDefinitionsReader DigesterDefinitionsReader}
36   * class unless another implementation is specified.
37   * </p>
38   *
39   * @version $Rev: 836180 $ $Date: 2009-11-15 01:00:02 +1100 (Sun, 15 Nov 2009) $
40   * @since 2.1.0
41   */
42  public class LocaleDefinitionsFactory extends
43          UnresolvingLocaleDefinitionsFactory {
44  
45      /** {@inheritDoc} */
46      @Override
47      public Definition getDefinition(String name,
48              Request tilesContext) {
49          Definition retValue;
50          Locale locale = null;
51  
52          if (tilesContext != null) {
53              locale = localeResolver.resolveLocale(tilesContext);
54          }
55  
56          retValue = definitionDao.getDefinition(name, locale);
57          if (retValue != null) {
58              retValue = new Definition(retValue);
59              String parentDefinitionName = retValue.getExtends();
60              while (parentDefinitionName != null) {
61                  Definition parent = definitionDao.getDefinition(
62                          parentDefinitionName, locale);
63                  if (parent == null) {
64                      throw new NoSuchDefinitionException("Cannot find definition '"
65                              + parentDefinitionName + "' ancestor of '"
66                              + retValue.getName() + "'");
67                  }
68                  retValue.inherit(parent);
69                  parentDefinitionName = parent.getExtends();
70              }
71          }
72  
73          return retValue;
74      }
75  }