Package org.apache.tiles

Examples of org.apache.tiles.Definition


        EasyMock.expect(context.getSessionScope()).andReturn(
                new HashMap<String, Object>()).anyTimes();
        EasyMock.expect(context.getRequestLocale()).andReturn(null).anyTimes();
        EasyMock.replay(context);

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

        RefreshMonitor reloadable = (RefreshMonitor) definitionDao;
        assertEquals("Factory should be fresh.", false, reloadable
                .refreshRequired());
View Full Code Here


        EasyMock.expect(context.getSessionScope()).andReturn(
                new HashMap<String, Object>()).anyTimes();
        EasyMock.expect(context.getRequestLocale()).andReturn(null).anyTimes();
        EasyMock.replay(context);

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

        RefreshMonitor reloadable = (RefreshMonitor) definitionDao;
        assertEquals("Factory should be fresh.", false, reloadable
                .refreshRequired());
View Full Code Here

        EasyMock.replay(applicationContext);
        ((TilesApplicationContextAware) definitionDao)
                .setApplicationContext(applicationContext);
        definitionDao.setReader(new DigesterDefinitionsReader());

        Definition definition = definitionDao.getDefinition("test.defName.subLayered", Locale.ITALY);
        assertEquals("The template is not correct", "/testName.jsp", definition.getTemplate());
        assertEquals("The header attribute is not correct",
                "/common/headerLayered.jsp", definition.getAttribute("header")
                        .getValue());
        definition = definitionDao.getDefinition("test.defName.subLayered", Locale.ITALIAN);
        assertEquals("The template is not correct", "/testName.jsp", definition.getTemplate());
        assertEquals("The header attribute is not correct",
                "/common/headerLayered.jsp", definition.getAttribute("header")
                        .getValue());
        definition = definitionDao.getDefinition("test.defName.subLayered", null);
        assertEquals("The template is not correct", "/testName.jsp", definition.getTemplate());
        assertEquals("The header attribute is not correct",
                "/common/headerLayered.jsp", definition.getAttribute("header")
                        .getValue());
        definition = definitionDao.getDefinition("test.def3", null);
        assertNotNull("The simple definition is null", definition);
    }
View Full Code Here

        checkRefresh = "true".equals(param);
    }

    /** {@inheritDoc} */
    public Definition getDefinition(String name, Locale customizationKey) {
        Definition retValue = null;
        if (customizationKey == null) {
            customizationKey = LocaleUtil.NULL_LOCALE;
        }
        Map<String, Definition> definitions = getDefinitions(customizationKey);
        if (definitions != null) {
View Full Code Here

     * @since 2.1.0
     */
    protected Definition resolveWildcardDefinition(
            List<WildcardMapping> paths, String name) {
        Map<Integer, String> vars = new HashMap<Integer, String>();
        Definition d = null;

        for (WildcardMapping wm : paths) {
            if (wildcardHelper.match(vars, name, wm.getPattern())) {
                d = replaceDefinition(wm.getDefinition(), name, vars);
                break;
View Full Code Here

     * @return The definition that can be rendered.
     * @since 2.1.0
     */
    protected Definition replaceDefinition(Definition d, String name,
            Map<Integer, String> vars) {
        Definition nudef = new Definition();

        nudef.setExtends(replace(d.getExtends(), vars));
        nudef.setName(name);
        nudef.setPreparer(replace(d.getPreparer(), vars));
        nudef.setRole(replace(d.getRole(), vars));
        nudef.setTemplate(replace(d.getTemplate(), vars));

        for (String attributeName : d.getLocalAttributeNames()) {
            Attribute attr = d.getLocalAttribute(attributeName);
            Attribute nuattr = new Attribute();

            nuattr.setRole(replace(attr.getRole(), vars));
            nuattr.setRenderer(attr.getRenderer());

            Object value = attr.getValue();
            if (value instanceof String) {
                value = replace((String) value, vars);
            }
            nuattr.setValue(value);

            nudef.putAttribute(replace(attributeName, vars), nuattr);
        }

        return nudef;
    }
View Full Code Here

        // Set as visited to avoid endless recurisvity.
        alreadyResolvedDefinitions.add(definition.getName());

        // Resolve parent before itself.
        Definition parent = definitions.get(definition.getExtends());
        if (parent == null) { // error
            String msg = "Error while resolving definition inheritance: child '"
                + definition.getName()
                + "' can't find its ancestor '"
                + definition.getExtends()
View Full Code Here

     * @throws DefinitionsFactoryException If the definitions factory throws an
     * exception.
     */
    protected Definition getDefinition(String definitionName,
            TilesRequestContext request) {
        Definition definition =
            definitionsFactory.getDefinition(definitionName, request);
        return definition;
    }
View Full Code Here

        if (LOG.isDebugEnabled()) {
            LOG.debug("Render request recieved for definition '" + definitionName + "'");
        }

        Definition definition = getDefinition(definitionName, request);

        if (definition == null) {
            if (LOG.isWarnEnabled()) {
                String message = "Unable to find the definition '" + definitionName + "'";
                LOG.warn(message);
            }
            throw new NoSuchDefinitionException(definitionName);
        }

        AttributeContext originalContext = getAttributeContext(request);
        BasicAttributeContext subContext = new BasicAttributeContext(originalContext);
        subContext.inherit(definition);

        if (!isPermitted(request, subContext.getRoles())) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Access to definition '" + definitionName
                        + "' denied.  User not in role '"
                        + definition.getRoles());
            }
            return;
        }

        pushContext(subContext, request);
View Full Code Here

     * @return <code>true</code> if <code>definitionName</code> is a valid
     * definition name.
     */
    private boolean isValidDefinition(TilesRequestContext context, String definitionName) {
        try {
            Definition definition = getDefinition(definitionName, context);
            return definition != null;
        } catch (NoSuchDefinitionException nsde) {
            return false;
        } catch (DefinitionsFactoryException e) {
            // TODO, is this the right thing to do?
View Full Code Here

TOP

Related Classes of org.apache.tiles.Definition

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.