Examples of DefinitionsFactory


Examples of org.apache.tiles.definition.DefinitionsFactory

    @Override
    protected DefinitionsFactory createDefinitionsFactory(TilesApplicationContext applicationContext,
        TilesRequestContextFactory contextFactory, LocaleResolver resolver) {
      if (definitionsFactoryClass != null) {
        DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass);
        if (factory instanceof TilesApplicationContextAware) {
          ((TilesApplicationContextAware) factory).setApplicationContext(applicationContext);
        }
        BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(factory);
        if (bw.isWritableProperty("localeResolver")) {
View Full Code Here

Examples of org.apache.tiles.definition.DefinitionsFactory

    @Override
    protected DefinitionsFactory createDefinitionsFactory(ApplicationContext applicationContext,
        LocaleResolver resolver) {

      if (definitionsFactoryClass != null) {
        DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass);
        if (factory instanceof org.apache.tiles.request.ApplicationContextAware) {
          ((org.apache.tiles.request.ApplicationContextAware) factory)
              .setApplicationContext(applicationContext);
        }
        BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(factory);
View Full Code Here

Examples of org.apache.tiles.definition.DefinitionsFactory

    public static void reloadDefinitionsFactory(Object context)
            throws DefinitionsFactoryException {
        TilesContainer container = TilesAccess.getContainer(context);
        if (container instanceof BasicTilesContainer) {
            BasicTilesContainer basic = (BasicTilesContainer) container;
            DefinitionsFactory factory = basic.getDefinitionsFactory();
            if (factory instanceof ReloadableDefinitionsFactory) {
                ReloadableDefinitionsFactory rFactory = (ReloadableDefinitionsFactory) factory;
                if (rFactory.refreshRequired()) {
                    rFactory.refresh();
                }
View Full Code Here

Examples of org.apache.tiles.definition.DefinitionsFactory

    /**
     * Tests reloading definitions impl.
     */
    public void testReloadableDefinitionsFactory() throws Exception {
        DefinitionsFactory factory = new UrlDefinitionsFactory();

        // Set up multiple data sources.
        URL url = this.getClass().getClassLoader().getResource(
                "org/apache/tiles/config/temp-defs.xml");

        URI uri = null;
        String urlPath = null;

        // The following madness is necessary b/c of the way Windows hanndles URLs.
        // We must add a slash to the protocol if Windows does not.  But we cannot
        // add a slash to Unix paths b/c they already have one.
        if (url.getPath().startsWith("/")) {
            urlPath = "file:" + url.getPath();
        } else {
            urlPath = "file:/" + url.getPath();
        }

        // The following second madness is necessary b/c sometimes spaces
        // are encoded as '%20', sometimes they are not. For example in
        // Windows 2000 under Eclipse they are encoded, under the prompt of
        // Windows 2000 they are not.
        // It seems to be in the different behaviour of
        // sun.misc.Launcher$AppClassLoader (called under Eclipse) and
        // java.net.URLClassLoader (under maven).
        // And an URL accepts spaces while URIs need '%20'.
        try {
            uri = new URI(urlPath);
        } catch (URISyntaxException e) {
            uri = new URI(urlPath.replaceAll(" ", "%20"));
        }

        String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" +
                "<!DOCTYPE tiles-definitions PUBLIC " +
                "\"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN\" " +
                "\"http://tiles.apache.org/dtds/tiles-config_2_0.dtd\">\n\n" +
                "<tiles-definitions>" +
                "<definition name=\"rewrite.test\" template=\"/test.jsp\">" +
                "<put-attribute name=\"testparm\" value=\"testval\"/>" +
                "</definition>" +
                "</tiles-definitions>";

        File file = new File(uri);
        FileOutputStream fileOut = new FileOutputStream(file);
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(fileOut));
        writer.write(xml);
        writer.close();

        factory.init(new HashMap());
        factory.addSource(url);

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

        assertNotNull("rewrite.test definition not found.",
                definitions.getDefinition("rewrite.test"));
        assertEquals("Incorrect initial template value", "/test.jsp",
                definitions.getDefinition("rewrite.test").getTemplate());

        ReloadableDefinitionsFactory reloadable = (ReloadableDefinitionsFactory) factory;
        assertEquals("Factory should be fresh.", false,
                reloadable.refreshRequired());

        // Make sure the system actually updates the timestamp.
        Thread.sleep(30000);

        // Set up multiple data sources.
        xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n" +
                "<!DOCTYPE tiles-definitions PUBLIC " +
                "\"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN\" " +
                "\"http://tiles.apache.org/dtds/tiles-config_2_0.dtd\">\n\n" +
                "<tiles-definitions>" +
                "<definition name=\"rewrite.test\" template=\"/newtest.jsp\">" +
                "<put-attribute name=\"testparm\" value=\"testval\"/>" +
                "</definition>" +
                "</tiles-definitions>";

        file = new File(uri);
        fileOut = new FileOutputStream(file);
        writer = new BufferedWriter(new OutputStreamWriter(fileOut));
        writer.write(xml);
        writer.close();


        assertEquals("Factory should be stale.", true,
                reloadable.refreshRequired());
        definitions = factory.readDefinitions();
        assertNotNull("rewrite.test definition not found.",
                definitions.getDefinition("rewrite.test"));
        assertEquals("Incorrect initial template value", "/newtest.jsp",
                definitions.getDefinition("rewrite.test").getTemplate());
    }
View Full Code Here

Examples of org.apache.tiles.definition.DefinitionsFactory

        assertNull(container.getProperDefinitionsFactory("two"));
       
        Map<String, String> initParams = new HashMap<String, String>();
        initParams.put(BasicTilesContainer.DEFINITIONS_CONFIG,
                "/WEB-INF/tiles-one.xml");
        DefinitionsFactory defsFactory = factory.createDefinitionsFactory(context);
        container.setDefinitionsFactory("one", defsFactory, initParams);
        initParams.put(BasicTilesContainer.DEFINITIONS_CONFIG,
                "/WEB-INF/tiles-two.xml");
        defsFactory = factory.createDefinitionsFactory(context);
        container.setDefinitionsFactory("two", defsFactory, initParams);
View Full Code Here

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

Examples of org.apache.tiles.definition.DefinitionsFactory

    /**
     * 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

Examples of org.apache.tiles.definition.DefinitionsFactory

    /**
     * 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

Examples of org.apache.tiles.definition.DefinitionsFactory

        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

Examples of org.apache.tiles.definition.DefinitionsFactory

     * @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
TOP
Copyright © 2018 www.massapi.com. 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.