/** * Renders an attribute. * * @param attr The attribute to render. * @param requestContext The Tiles request context. * @throws IOException If something goes wrong during rendering. */ private void render(Attribute attr, TilesRequestContext requestContext) throws IOException { if (attr == null) { throw new CannotRenderException("Cannot render a null attribute"); } AttributeRenderer renderer = rendererFactory.getRenderer(attr .getRenderer()); if (renderer == null) { throw new CannotRenderException( "Cannot render an attribute with renderer name " + attr.getRenderer()); } renderer.render(attr, requestContext); }
/** * Inherits an attribute, i.e. overwrites null properties with the ones * provided by the attribute. * * @param attribute The attribute to inherit. * @since 2.1.2 */ public void inherit(Attribute attribute) { if (value == null) { value = attribute.getValue(); } if (expression == null) { expression = attribute.getExpression(); } if (roles == null || roles.isEmpty()) { roles = attribute.getRoles(); } if (renderer == null) { renderer = attribute.getRenderer(); } }
/** * Registers a definition in the container. * * @param definition The definition to register. * @param container The container into which the definition will be * registered. * @param composeStack The compose stack, * @param request The request. */ private void registerDefinition(Definition definition, MutableTilesContainer container, Deque<Object> composeStack, Request request) { container.register(definition, request); if (composeStack.isEmpty()) { return; } Object obj = composeStack.peek(); if (obj instanceof Attribute) { Attribute attribute = (Attribute) obj; attribute.setValue(definition.getName()); if (attribute.getRenderer() == null) { attribute.setRenderer("definition"); } } } }
/** * Inherits an attribute, i.e. overwrites null properties with the ones * provided by the attribute. * * @param attribute The attribute to inherit. * @since 2.1.2 */ public void inherit(Attribute attribute) { if (value == null) { value = attribute.getValue(); } Expression targetExpressionObject = attribute.getExpressionObject(); if (targetExpressionObject != null && (expressionObject == null || expressionObject .getExpression() == null)) { expressionObject = new Expression(targetExpressionObject); } if (roles == null || roles.isEmpty()) { roles = attribute.getRoles(); } if (renderer == null) { renderer = attribute.getRenderer(); } }
/** {@inheritDoc} */ public void render(Attribute attr, Request request) throws IOException { if (attr == null) { throw new CannotRenderException("Cannot render a null attribute"); } if (attr.isPermitted(request)) { Renderer renderer = rendererFactory.getRenderer(attr.getRenderer()); Object value = evaluate(attr, request); if (!(value instanceof String)) { throw new CannotRenderException( "Cannot render an attribute that is not a string, toString returns: " + value); } renderer.render((String) value, request); } }
/** * Replaces variables into an attribute. * * @param attr The attribute to be used as a basis, containing placeholders * for variables. * @param vars The variables to replace. * @return A new instance of an attribute, whose properties have been * replaced with variables' values. */ private Attribute replaceVarsInAttribute(Attribute attr, Map<Integer, String> vars) { Attribute nuattr = new Attribute(); nuattr.setRole(replace(attr.getRole(), vars)); nuattr.setRenderer(attr.getRenderer()); nuattr.setExpression(attr.getExpression()); Object value = attr.getValue(); if (value instanceof String) { value = replace((String) value, vars); } nuattr.setValue(value); return nuattr; }
/** * Replaces variables into a simple (not list) attribute. * * @param attr The attribute to be used as a basis, containing placeholders * for variables. * @param vars The variables to replace. * @return A new instance of an attribute, whose properties have been * replaced with variables' values. */ private static Attribute replaceVarsInSimpleAttribute(Attribute attr, Object... vars) { Attribute nuattr; nuattr = new Attribute(); nuattr.setRole(replace(attr.getRole(), vars)); nuattr.setRenderer(attr.getRenderer()); Expression expressionObject = attr.getExpressionObject(); if (expressionObject != null) { Expression newExpressionObject = Expression .createExpression(replace(expressionObject.getExpression(), vars), expressionObject.getLanguage()); nuattr.setExpressionObject(newExpressionObject); } Object value = attr.getValue(); if (value instanceof String) { value = replace((String) value, vars); } nuattr.setValue(value); return nuattr; }