1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.definition;
23
24 import java.util.Locale;
25 import java.util.Map;
26
27 import org.apache.tiles.Definition;
28 import org.apache.tiles.TilesApplicationContext;
29 import org.apache.tiles.awareness.TilesApplicationContextAware;
30 import org.apache.tiles.context.TilesRequestContext;
31 import org.apache.tiles.definition.dao.DefinitionDAO;
32 import org.apache.tiles.locale.LocaleResolver;
33
34 /***
35 * {@link DefinitionsFactory DefinitionsFactory} implementation that manages
36 * Definitions configuration data from URLs, without resolving definition
37 * inheritance when a definition is returned.<p/>
38 * <p>
39 * The Definition objects are read from the
40 * {@link org.apache.tiles.definition.digester.DigesterDefinitionsReader DigesterDefinitionsReader}
41 * class unless another implementation is specified.
42 * </p>
43 *
44 * @version $Rev: 822631 $ $Date: 2009-10-07 11:21:12 +0200 (mer, 07 ott 2009) $
45 * @since 2.2.1
46 */
47 public class UnresolvingLocaleDefinitionsFactory implements DefinitionsFactory,
48 TilesApplicationContextAware {
49
50 /***
51 * The definition DAO that extracts the definitions from the sources.
52 *
53 * @since 2.2.1
54 */
55 protected DefinitionDAO<Locale> definitionDao;
56
57 /***
58 * The application context.
59 *
60 * @since 2.2.1
61 */
62 protected TilesApplicationContext applicationContext;
63
64 /***
65 * The locale resolver object.
66 *
67 * @since 2.2.1
68 */
69 protected LocaleResolver localeResolver;
70
71 /*** {@inheritDoc} */
72 public void setApplicationContext(TilesApplicationContext applicationContext) {
73 this.applicationContext = applicationContext;
74 }
75
76 /***
77 * Sets the locale resolver to use.
78 *
79 * @param localeResolver The locale resolver.
80 * @since 2.2.1
81 */
82 public void setLocaleResolver(LocaleResolver localeResolver) {
83 this.localeResolver = localeResolver;
84 }
85
86 /***
87 * Sets the definition DAO to use. It must be locale-based.
88 *
89 * @param definitionDao The definition DAO.
90 * @since 2.2.1
91 */
92 public void setDefinitionDAO(DefinitionDAO<Locale> definitionDao) {
93 this.definitionDao = definitionDao;
94 }
95
96 /*** {@inheritDoc} */
97 public Definition getDefinition(String name,
98 TilesRequestContext tilesContext) {
99 Locale locale = null;
100
101 if (tilesContext != null) {
102 locale = localeResolver.resolveLocale(tilesContext);
103 }
104
105 return definitionDao.getDefinition(name, locale);
106 }
107
108 /*** {@inheritDoc} */
109 @Deprecated
110 public void addSource(Object source) {
111 throw new UnsupportedOperationException(
112 "The addSource method is not supported");
113 }
114
115 /*** {@inheritDoc} */
116 @Deprecated
117 public Definitions readDefinitions() {
118 throw new UnsupportedOperationException(
119 "The readDefinitions method is not supported");
120 }
121
122 /*** {@inheritDoc} */
123 @Deprecated
124 public void init(Map<String, String> params) {
125
126 }
127 }