View Javadoc

1   /*
2    * $Id: TestAlternateTilesContainerFactory.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.alt;
23  
24  import java.io.IOException;
25  import java.net.URL;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  import org.apache.tiles.TilesApplicationContext;
30  import org.apache.tiles.context.TilesRequestContextFactory;
31  import org.apache.tiles.definition.DefinitionsFactoryException;
32  import org.apache.tiles.definition.dao.BaseLocaleUrlDefinitionDAO;
33  import org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO;
34  import org.apache.tiles.locale.LocaleResolver;
35  import org.apache.tiles.test.factory.TestTilesContainerFactory;
36  
37  /***
38   * Test alternate Tiles container factory to customize Tiles behaviour.
39   *
40   * @version $Rev: 831448 $ $Date: 2009-10-30 21:39:52 +0100 (ven, 30 ott 2009) $
41   */
42  public class TestAlternateTilesContainerFactory extends TestTilesContainerFactory {
43  
44      /***
45       * The number of URLs to load..
46       */
47      private static final int URL_COUNT = 3;
48  
49      /*** {@inheritDoc} */
50      @Override
51      protected List<URL> getSourceURLs(TilesApplicationContext applicationContext,
52              TilesRequestContextFactory contextFactory) {
53          List<URL> urls = new ArrayList<URL>(URL_COUNT);
54          try {
55              urls.add(applicationContext.getResource("classpath:/org/apache/tiles/test/alt/defs/tiles-alt-defs.xml"));
56              urls.add(applicationContext.getResource("classpath:/org/apache/tiles/test/alt/defs/tiles-alt-freemarker-defs.xml"));
57              urls.add(applicationContext.getResource("classpath:/org/apache/tiles/test/alt/defs/tiles-alt-velocity-defs.xml"));
58          } catch (IOException e) {
59              throw new DefinitionsFactoryException(
60                      "Cannot load definition URLs", e);
61          }
62          return urls;
63      }
64  
65      /*** {@inheritDoc} */
66      @Override
67      protected BaseLocaleUrlDefinitionDAO instantiateLocaleDefinitionDao(
68              TilesApplicationContext applicationContext,
69              TilesRequestContextFactory contextFactory, LocaleResolver resolver) {
70          return new CachingLocaleUrlDefinitionDAO();
71      }
72  }