/** * Iterate over dynamically added Tiles attributes (see "Runtime Composition" * in the Tiles documentation) and add them to the output Map passed as input. * * @param container the Tiles container * @param tilesRequest the Tiles request * @param resultMap the output Map where attributes of interest are added to. */ protected void addRuntimeAttributes(BasicTilesContainer container, Request tilesRequest, Map<String, Attribute> resultMap) { AttributeContext attributeContext = container.getAttributeContext(tilesRequest); Set<String> attributeNames = new HashSet<>(); if (attributeContext.getLocalAttributeNames() != null) { attributeNames.addAll(attributeContext.getLocalAttributeNames()); } if (attributeContext.getCascadedAttributeNames() != null) { attributeNames.addAll(attributeContext.getCascadedAttributeNames()); } for (String name : attributeNames) { Attribute attr = attributeContext.getAttribute(name); resultMap.put(name, attr); } } }
@Component public class AViewPreparer implements ViewPreparer { @Autowired private AutowiredBean autowiredBean; @Override public void execute(Request tilesRequest, AttributeContext attributeContext) throws PreparerException { attributeContext.putAttribute("tilesAttributeName", new Attribute("tilesAttributeValue")); } }
+ "' could be found for the current view: " + this); container.startContext(tilesRequest).inheritCascadedAttributes(compositeDefinition); container.render(attributeToRender, tilesRequest); container.endContext(tilesRequest);
/** {@inheritDoc} */ public void inheritCascadedAttributes(AttributeContext context) { if (context instanceof BasicAttributeContext) { copyCascadedAttributes((BasicAttributeContext) context); } else { this.cascadedAttributes = new HashMap<String, Attribute>(); for (String name : context.getCascadedAttributeNames()) { cascadedAttributes.put(name, new Attribute(context .getCascadedAttribute(name))); } } }
/** * Expose the requested property from attribute context. * * @throws TilesJspException On errors processing tag. */ public void execute() throws TilesJspException { if (attributeValue != null) { pageContext.setAttribute(toName != null ? toName : name, attributeValue, scope); } else { importAttributes(attributeContext.getCascadedAttributeNames()); importAttributes(attributeContext.getLocalAttributeNames()); } }
} else { Attribute parentTemplateAttribute = parent.getTemplateAttribute(); inheritParentTemplateAttribute(parentTemplateAttribute); if (preparer == null) { preparer = parent.getPreparer(); Set<String> names = parent.getCascadedAttributeNames(); if (names != null && !names.isEmpty()) { for (String name : names) { Attribute attribute = parent.getCascadedAttribute(name); Attribute destAttribute = getCascadedAttribute(name); if (destAttribute == null) { names = parent.getLocalAttributeNames(); if (names != null && !names.isEmpty()) { for (String name : names) { Attribute attribute = parent.getLocalAttribute(name); Attribute destAttribute = getLocalAttribute(name); if (destAttribute == null) {
public void execute(Request tilesContext, AttributeContext attributeContext) { invoked = true; assertTrue(attributeContext.getAttribute("searchNavigation") != null); }
/** * Copy constructor. * * @param context The constructor to copy. * @since 2.1.0 */ public BasicAttributeContext(AttributeContext context) { if (context instanceof BasicAttributeContext) { copyBasicAttributeContext((BasicAttributeContext) context); } else { Attribute parentTemplateAttribute = context.getTemplateAttribute(); if (parentTemplateAttribute != null) { this.templateAttribute = new Attribute(parentTemplateAttribute); } this.preparer = context.getPreparer(); this.attributes = new HashMap<String, Attribute>(); for (String name : context.getLocalAttributeNames()) { attributes.put(name, new Attribute(context.getLocalAttribute(name))); } inheritCascadedAttributes(context); } }
/** * Renders the specified attribute context. * * @param request The request context. * @param attributeContext The context to render. * @throws InvalidTemplateException If the template is not valid. * @throws CannotRenderException If something goes wrong during rendering. * @since 2.1.3 */ protected void render(TilesRequestContext request, AttributeContext attributeContext) { try { if (attributeContext.getPreparer() != null) { prepare(request, attributeContext.getPreparer(), true); } render(attributeContext.getTemplateAttribute(), request); } catch (IOException e) { throw new CannotRenderException(e.getMessage(), e); } }
} else { Attribute parentTemplateAttribute = parent.getTemplateAttribute(); inheritParentTemplateAttribute(parentTemplateAttribute); if (preparer == null) { preparer = parent.getPreparer(); Set<String> names = parent.getCascadedAttributeNames(); if (names != null && !names.isEmpty()) { for (String name : names) { Attribute attribute = parent.getCascadedAttribute(name); Attribute destAttribute = getCascadedAttribute(name); if (destAttribute == null) { names = parent.getLocalAttributeNames(); if (names != null && !names.isEmpty()) { for (String name : names) { Attribute attribute = parent.getLocalAttribute(name); Attribute destAttribute = getLocalAttribute(name); if (destAttribute == null) {
@Override public void render(final String path, final Request request) throws IOException { Matcher matcher = OPTIONS_PATTERN.matcher((String) path); if (null != matcher && matcher.find()) { boolean done = false; String match = matcher.group(1); ListAttribute fallbacks = (ListAttribute) TilesAccess .getCurrentContainer(request) .getAttributeContext(request) .getAttribute(match); if (null == fallbacks) { throw new IllegalStateException("A matching list-attribute name=\"" + match + "\" must be defined."); } else if (fallbacks.getValue().isEmpty()) { throw new IllegalStateException( "list-attribute name=\"" + match + "\" must have minimum one attribute"); } for (Attribute option : (List<Attribute>) fallbacks.getValue()) { String template = path.replaceFirst(Pattern.quote(matcher.group()), (String) option.getValue()); done = renderAttempt(template, request); if (done) { break; } } if (!done) { throw new IOException("None of the options existed for " + path); } } else { renderer.render(path, request); } }
/** * Copy constructor. * * @param context The constructor to copy. * @since 2.1.0 */ public BasicAttributeContext(AttributeContext context) { if (context instanceof BasicAttributeContext) { copyBasicAttributeContext((BasicAttributeContext) context); } else { Attribute parentTemplateAttribute = context.getTemplateAttribute(); if (parentTemplateAttribute != null) { this.templateAttribute = new Attribute(parentTemplateAttribute); } this.preparer = context.getPreparer(); this.attributes = new HashMap<String, Attribute>(); Set<String> parentAttributeNames = context.getLocalAttributeNames(); if (parentAttributeNames != null) { for (String name : parentAttributeNames) { attributes.put(name, new Attribute(context.getLocalAttribute(name))); } } inheritCascadedAttributes(context); } }
ignore, retValue, request); } else { importAttributes(attributeContext.getCascadedAttributeNames(), container, attributeContext, retValue, ignore, request); importAttributes(attributeContext.getLocalAttributeNames(), container, attributeContext, retValue, ignore, request);
/** {@inheritDoc} */ public void inheritCascadedAttributes(AttributeContext context) { if (context instanceof BasicAttributeContext) { copyCascadedAttributes((BasicAttributeContext) context); } else { this.cascadedAttributes = new HashMap<String, Attribute>(); Set<String> parentAttributeNames = context.getCascadedAttributeNames(); if (parentAttributeNames != null) { for (String name : parentAttributeNames) { cascadedAttributes.put(name, new Attribute(context .getCascadedAttribute(name))); } } } }
/** * Renders the specified attribute context. * * @param request The request context. * @param attributeContext The context to render. * @throws InvalidTemplateException If the template is not valid. * @throws CannotRenderException If something goes wrong during rendering. * @since 2.1.3 */ protected void render(Request request, AttributeContext attributeContext) { try { if (attributeContext.getPreparer() != null) { prepare(request, attributeContext.getPreparer(), true); } render(attributeContext.getTemplateAttribute(), request); } catch (IOException e) { throw new CannotRenderException(e.getMessage(), e); } } }
/** * Iterate over dynamically added Tiles attributes (see "Runtime Composition" * in the Tiles documentation) and add them to the output Map passed as input. * * @param container the Tiles container * @param tilesRequest the Tiles request * @param resultMap the output Map where attributes of interest are added to. */ protected void addRuntimeAttributes(BasicTilesContainer container, Request tilesRequest, Map<String, Attribute> resultMap) { AttributeContext attributeContext = container.getAttributeContext(tilesRequest); Set<String> attributeNames = new HashSet<>(); if (attributeContext.getLocalAttributeNames() != null) { attributeNames.addAll(attributeContext.getLocalAttributeNames()); } if (attributeContext.getCascadedAttributeNames() != null) { attributeNames.addAll(attributeContext.getCascadedAttributeNames()); } for (String name : attributeNames) { Attribute attr = attributeContext.getAttribute(name); resultMap.put(name, attr); } } }
boolean ignore, Map<String, Object> attributes, Request request) { Attribute attr = attributeContext.getAttribute(name); if (attr != null) { try {
builder.append(SUFFIX); attributeContext.putAttribute("body", Attribute.createTemplateAttribute(builder.toString()));
/** {@inheritDoc} */ public AttributeContext startContext(Request request) { AttributeContext context = new BasicAttributeContext(); Deque<AttributeContext> stack = getContextStack(request); if (!stack.isEmpty()) { AttributeContext parent = stack.peek(); context.inheritCascadedAttributes(parent); } stack.push(context); return context; }
/** * Iterate over dynamically added Tiles attributes (see "Runtime Composition" * in the Tiles documentation) and add them to the output Map passed as input. * * @param container the Tiles container * @param tilesRequest the Tiles request * @param resultMap the output Map where attributes of interest are added to. */ protected void addRuntimeAttributes(BasicTilesContainer container, Request tilesRequest, Map<String, Attribute> resultMap) { AttributeContext attributeContext = container.getAttributeContext(tilesRequest); Set<String> attributeNames = new HashSet<String>(); if (attributeContext.getLocalAttributeNames() != null) { attributeNames.addAll(attributeContext.getLocalAttributeNames()); } if (attributeContext.getCascadedAttributeNames() != null) { attributeNames.addAll(attributeContext.getCascadedAttributeNames()); } for (String name : attributeNames) { Attribute attr = attributeContext.getAttribute(name); resultMap.put(name, attr); } } }