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

1   /*
2    * $Id: TestDbTilesContainerFactory.java 831448 2009-10-30 20:39:52Z 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.test.db;
23  
24  import java.util.List;
25  import java.util.Locale;
26  
27  import javax.sql.DataSource;
28  
29  import org.apache.tiles.TilesApplicationContext;
30  import org.apache.tiles.context.ChainedTilesRequestContextFactory;
31  import org.apache.tiles.context.TilesRequestContextFactory;
32  import org.apache.tiles.definition.LocaleDefinitionsFactory;
33  import org.apache.tiles.definition.dao.DefinitionDAO;
34  import org.apache.tiles.factory.BasicTilesContainerFactory;
35  import org.apache.tiles.freemarker.context.FreeMarkerTilesRequestContextFactory;
36  import org.apache.tiles.locale.LocaleResolver;
37  import org.apache.tiles.velocity.context.VelocityTilesRequestContextFactory;
38  
39  
40  /***
41   * Test alternate Tiles container factory that uses a DB to store definitions.
42   *
43   * @version $Rev: 831448 $ $Date: 2009-10-30 21:39:52 +0100 (ven, 30 ott 2009) $
44   */
45  public class TestDbTilesContainerFactory extends BasicTilesContainerFactory {
46  
47      /*** {@inheritDoc} */
48      @Override
49      protected DefinitionDAO<Locale> createLocaleDefinitionDao(TilesApplicationContext applicationContext,
50              TilesRequestContextFactory contextFactory,
51              LocaleResolver resolver) {
52          LocaleDbDefinitionDAO definitionDao = new LocaleDbDefinitionDAO();
53          definitionDao.setDataSource((DataSource) applicationContext
54                  .getApplicationScope().get("dataSource"));
55          return definitionDao;
56      }
57  
58      /*** {@inheritDoc} */
59      @Override
60      protected LocaleDefinitionsFactory instantiateDefinitionsFactory(
61              TilesApplicationContext applicationContext, TilesRequestContextFactory contextFactory,
62              LocaleResolver resolver) {
63          return new LocaleDefinitionsFactory();
64      }
65  
66      /*** {@inheritDoc} */
67      @Override
68      protected List<TilesRequestContextFactory> getTilesRequestContextFactoriesToBeChained(
69              ChainedTilesRequestContextFactory parent) {
70          List<TilesRequestContextFactory> factories = super.getTilesRequestContextFactoriesToBeChained(parent);
71          registerRequestContextFactory(
72                  FreeMarkerTilesRequestContextFactory.class.getName(),
73                  factories, parent);
74          registerRequestContextFactory(
75                  VelocityTilesRequestContextFactory.class.getName(),
76                  factories, parent);
77          return factories;
78      }
79  }