1/*2 * $Id: TestDbTilesContainerFactory.java 831448 2009-10-30 20:39:52Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122package org.apache.tiles.test.db;
2324import java.util.List;
25import java.util.Locale;
2627import javax.sql.DataSource;
2829import org.apache.tiles.TilesApplicationContext;
30import org.apache.tiles.context.ChainedTilesRequestContextFactory;
31import org.apache.tiles.context.TilesRequestContextFactory;
32import org.apache.tiles.definition.LocaleDefinitionsFactory;
33import org.apache.tiles.definition.dao.DefinitionDAO;
34import org.apache.tiles.factory.BasicTilesContainerFactory;
35import org.apache.tiles.freemarker.context.FreeMarkerTilesRequestContextFactory;
36import org.apache.tiles.locale.LocaleResolver;
37import org.apache.tiles.velocity.context.VelocityTilesRequestContextFactory;
383940/***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 */45publicclassTestDbTilesContainerFactoryextends BasicTilesContainerFactory {
4647/*** {@inheritDoc} */48 @Override
49protected DefinitionDAO<Locale> createLocaleDefinitionDao(TilesApplicationContext applicationContext,
50 TilesRequestContextFactory contextFactory,
51 LocaleResolver resolver) {
52LocaleDbDefinitionDAO definitionDao = newLocaleDbDefinitionDAO();
53 definitionDao.setDataSource((DataSource) applicationContext
54 .getApplicationScope().get("dataSource"));
55return definitionDao;
56 }
5758/*** {@inheritDoc} */59 @Override
60protected LocaleDefinitionsFactory instantiateDefinitionsFactory(
61 TilesApplicationContext applicationContext, TilesRequestContextFactory contextFactory,
62 LocaleResolver resolver) {
63returnnew LocaleDefinitionsFactory();
64 }
6566/*** {@inheritDoc} */67 @Override
68protected 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);
77return factories;
78 }
79 }