Package org.apache.tiles.definition

Examples of org.apache.tiles.definition.DefinitionsFactory


    /**
     * Tests the readDefinitions method under normal conditions.
     */
    public void testReadDefinitions() throws Exception {
        DefinitionsFactory factory = new UrlDefinitionsFactory();

        // Set up multiple data sources.
        URL url1 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs1.xml");
        assertNotNull("Could not load defs1 file.", url1);
        URL url2 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs2.xml");
        assertNotNull("Could not load defs2 file.", url2);
        URL url3 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs3.xml");
        assertNotNull("Could not load defs3 file.", url3);

        factory.init(Collections.EMPTY_MAP);
        factory.addSource(url1);
        factory.addSource(url2);
        factory.addSource(url3);

        // Parse files.
        ComponentDefinitions definitions = factory.readDefinitions();

        assertNotNull("test.def1 definition not found.", definitions.getDefinition("test.def1"));
        assertNotNull("test.def2 definition not found.", definitions.getDefinition("test.def2"));
        assertNotNull("test.def3 definition not found.", definitions.getDefinition("test.def3"));
    }
View Full Code Here


    /**
     * Tests the getDefinition method.
     */
    public void testGetDefinition() throws Exception {
        DefinitionsFactory factory = new UrlDefinitionsFactory();

        // Set up multiple data sources.
        URL url1 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs1.xml");
        assertNotNull("Could not load defs1 file.", url1);
        URL url2 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs2.xml");
        assertNotNull("Could not load defs2 file.", url2);
        URL url3 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs3.xml");
        assertNotNull("Could not load defs3 file.", url3);

        factory.init(Collections.EMPTY_MAP);
        factory.addSource(url1);
        factory.addSource(url2);
        factory.addSource(url3);

        // Parse files.
        factory.readDefinitions();
       
        TilesRequestContext emptyContext = new MockOnlyLocaleTilesContext(null);
        TilesRequestContext usContext = new MockOnlyLocaleTilesContext(Locale.US);
        TilesRequestContext frenchContext = new MockOnlyLocaleTilesContext(Locale.FRENCH);
        TilesRequestContext chinaContext = new MockOnlyLocaleTilesContext(Locale.CHINA);
        TilesRequestContext canadaFrenchContext = new MockOnlyLocaleTilesContext(Locale.CANADA_FRENCH);

        assertNotNull("test.def1 definition not found.", factory.getDefinition("test.def1", emptyContext));
        assertNotNull("test.def2 definition not found.", factory.getDefinition("test.def2", emptyContext));
        assertNotNull("test.def3 definition not found.", factory.getDefinition("test.def3", emptyContext));
        assertNotNull("test.common definition not found.", factory.getDefinition("test.common", emptyContext));
        assertNotNull("test.common definition in US locale not found.", factory.getDefinition("test.common", usContext));
        assertNotNull("test.common definition in FRENCH locale not found.", factory.getDefinition("test.common", frenchContext));
        assertNotNull("test.common definition in CHINA locale not found.", factory.getDefinition("test.common", chinaContext));
        assertNotNull("test.common.french definition in FRENCH locale not found.", factory.getDefinition("test.common.french", frenchContext));
        assertNotNull("test.common.french definition in CANADA_FRENCH locale not found.", factory.getDefinition("test.common.french", canadaFrenchContext));
        assertNotNull("test.def.toextend definition not found.", factory.getDefinition("test.def.toextend", emptyContext));
        assertNotNull("test.def.overridden definition not found.", factory.getDefinition("test.def.overridden", emptyContext));
        assertNotNull("test.def.overridden definition in FRENCH locale not found.", factory.getDefinition("test.def.overridden", frenchContext));

        assertEquals("Incorrect default country value", "default",
                factory.getDefinition("test.def1", emptyContext).getAttribute("country"));
        assertEquals("Incorrect US country value", "US",
                factory.getDefinition("test.def1", usContext).getAttribute("country"));
        assertEquals("Incorrect France country value", "France",
                factory.getDefinition("test.def1", frenchContext).getAttribute("country"));
        assertEquals("Incorrect Chinese country value (should be default)", "default",
                factory.getDefinition("test.def1", chinaContext).getAttribute("country"));
        assertEquals("Incorrect default country value", "default",
                factory.getDefinition("test.def.overridden", emptyContext).getAttribute("country"));
        assertEquals("Incorrect default title value", "Definition to be overridden",
                factory.getDefinition("test.def.overridden", emptyContext).getAttribute("title"));
        assertEquals("Incorrect France country value", "France",
                factory.getDefinition("test.def.overridden", frenchContext).getAttribute("country"));
        assertEquals("Incorrect France title value", "Definition to be extended",
                factory.getDefinition("test.def.overridden", frenchContext).getAttribute("title"));
    }
View Full Code Here

    /**
     * Tests addSource with a bad source object type.
     */
    public void testBadSourceType() throws Exception {
        try {
            DefinitionsFactory factory = new UrlDefinitionsFactory();

            factory.init(Collections.EMPTY_MAP);
            factory.addSource("Bad object.");

            fail("Should've thrown exception.");
        } catch (DefinitionsFactoryException e) {
            // success.
        }
View Full Code Here

        params.put(DefinitionsFactory.READER_IMPL_PROPERTY,
                "org.apache.tiles.definition.MockDefinitionsReader");

        int instanceCount = MockDefinitionsReader.getInstanceCount();

        DefinitionsFactory factory = new UrlDefinitionsFactory();

        // Set up multiple data sources.
        URL url1 = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/defs1.xml");
        assertNotNull("Could not load defs1 file.", url1);

        factory.init(params);
        factory.addSource(url1);

        assertEquals("MockDefinitionsReader not used.",
                instanceCount + 1,
                MockDefinitionsReader.getInstanceCount());
    }
View Full Code Here

     * @return The newly created definitions factory.
     * @throws TilesException If something goes wrong.
     */
    public DefinitionsFactory createDefinitionsFactory(Object context)
            throws TilesException {
        DefinitionsFactory retValue;
        Map<String, String> config = new HashMap<String, String>(defaultConfiguration);
        config.putAll(getInitParameterMap(context));
        retValue = (DefinitionsFactory) createFactory(config,
                    DEFINITIONS_FACTORY_INIT_PARAM);

View Full Code Here

                if (param != null) {
                    initParams.put(BasicTilesContainer.DEFINITIONS_CONFIG,
                            param);
                }

                DefinitionsFactory defsFactory =
                    (DefinitionsFactory) createFactory(config,
                            DEFINITIONS_FACTORY_INIT_PARAM);
                ((KeyedDefinitionsFactoryTilesContainer) container)
                        .setDefinitionsFactory(keys[i], defsFactory,
                                initParams);
View Full Code Here

                                              BasicTilesContainer container) throws TilesException {
        TilesContextFactory contextFactory =
            (TilesContextFactory) createFactory(configuration,
                CONTEXT_FACTORY_INIT_PARAM);

        DefinitionsFactory defsFactory =
            (DefinitionsFactory) createFactory(configuration,
                DEFINITIONS_FACTORY_INIT_PARAM);

        PreparerFactory prepFactory =
            (PreparerFactory) createFactory(configuration,
View Full Code Here

     * @return the definitions factory used by this container. If the key is not
     * valid, the default factory will be returned.
     * @param key The key of the needed definitions factory.
     */
    public DefinitionsFactory getDefinitionsFactory(String key) {
      DefinitionsFactory retValue = null;
     
      if (key != null) {
        retValue = key2definitionsFactory.get(key);
      }
      if (retValue == null) {
View Full Code Here

     * @return the definitions factory used by this container. If the key is not
     * valid, <code>null</code> will be returned.
     * @param key The key of the needed definitions factory.
     */
    public DefinitionsFactory getProperDefinitionsFactory(String key) {
        DefinitionsFactory retValue = null;
       
        if (key != null) {
            retValue = key2definitionsFactory.get(key);
        }
       
View Full Code Here

    protected ComponentDefinition getDefinition(String definitionName,
            TilesRequestContext request) throws DefinitionsFactoryException {
        ComponentDefinition retValue = null;
        String key = getDefinitionsFactoryKey(request);
        if (key != null) {
            DefinitionsFactory definitionsFactory =
                key2definitionsFactory.get(key);
            if (definitionsFactory != null) {
                retValue = definitionsFactory.getDefinition(definitionName,
                        request);
            }
        }
        if (retValue == null) {
            retValue = super.getDefinition(definitionName, request);
View Full Code Here

TOP

Related Classes of org.apache.tiles.definition.DefinitionsFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.