/** * Replaces variables into a list attribute. * * @param listAttr The attribute to be used as a basis, containing attributes * that may contain 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 replaceVarsInListAttribute(ListAttribute listAttr, Object... vars) { Attribute nuattr; ListAttribute nuListAttr = new ListAttribute(); nuListAttr.setInherit(listAttr.isInherit()); List<Attribute> nuItems = nuListAttr.getValue(); for (Object item : listAttr.getValue()) { Attribute child = (Attribute) item; child = replaceVarsInAttribute(child, vars); nuItems.add(child); } nuattr = nuListAttr; return nuattr; }
/** * Add an element in list. * * @param value Object to add. * @since 2.1.0 */ @SuppressWarnings("unchecked") public void add(Object value) { //list.add( value ); // To correct a bug in digester, we need to check the object type // Digester doesn't call correct method according to object type ;-( if (value instanceof Attribute) { add((Attribute) value); } else { ((List<Object>) this.value).add(value); } }
/** * Constructor. * * @param value List. * @since 2.1.0 */ public ListAttribute(List<Attribute> value) { setValue(value); }
/** {@inheritDoc} */ public void processNestedTag(PutListAttributeTag nestedTag) { ListAttribute attribute = new ListAttribute(nestedTag.getAttributes()); attribute.setRole(nestedTag.getRole()); attribute.setInherit(nestedTag.getInherit()); attributeContext.putAttribute(nestedTag.getName(), attribute, nestedTag .isCascade()); } }
protected Attribute buildPutListAttribute(TilesPutListAttribute putListAttribute) { ListAttribute attribute = new ListAttribute(); attribute.setRole(getValueOrNull(putListAttribute.role())); attribute.setInherit(putListAttribute.inherit()); for (TilesAddAttribute addAttribute : putListAttribute.addAttributes()) { attribute.add(buildAddAttribute(addAttribute)); } for (TilesAddListAttribute addListAttribute : putListAttribute.addListAttributes()) { attribute.add(buildAddListAttribute(addListAttribute)); } return attribute; }
/** * Executes the model. * * @param role The comma-separated list of roles that can use the list attribute. * @param request The request. * @param modelBody The body. * @throws IOException If the body cannot be evaluated. */ public void execute(String role, Request request, ModelBody modelBody) throws IOException { Deque<Object> composeStack = ComposeStackUtil.getComposeStack(request); ListAttribute listAttribute = new ListAttribute(); listAttribute.setRole(role); composeStack.push(listAttribute); modelBody.evaluateWithoutWriting(); listAttribute = (ListAttribute) composeStack.pop(); ListAttribute parent = (ListAttribute) composeStack.peek(); parent.add(listAttribute); } }
/** * Adds missing attributes to the destination map. * * @param source The source attribute map. * @param destination The destination attribute map. * @return The destination attribute map if not null, a new one otherwise. */ private Map<String, Attribute> addMissingAttributes(Map<String, Attribute> source, Map<String, Attribute> destination) { if (source != null && !source.isEmpty()) { if (destination == null) { destination = new HashMap<String, Attribute>(); } for (Map.Entry<String, Attribute> entry : source.entrySet()) { String key = entry.getKey(); Attribute destAttribute = destination.get(key); if (destAttribute == null) { destination.put(key, entry.getValue()); } else if (destAttribute instanceof ListAttribute && entry.getValue() instanceof ListAttribute && ((ListAttribute) destAttribute).isInherit()) { ((ListAttribute) destAttribute) .inherit((ListAttribute) entry.getValue()); } } } return destination; }
/** {@inheritDoc} */ @Override public ListAttribute clone() { return new ListAttribute(this); } }
/** * Copy constructor. * * @param toCopy The list attribute to copy. * @since 2.1.3 */ public ListAttribute(ListAttribute toCopy) { super(toCopy); List<Attribute> attributesToCopy = toCopy.getValue(); if (attributesToCopy != null) { List<Attribute> attributes = new ArrayList<Attribute>(attributesToCopy.size()); for (Attribute attribute : attributesToCopy) { if (attribute != null) { attributes.add(attribute.clone()); } else { attributes.add(null); } } setValue(attributes); } this.inherit = toCopy.inherit; }
/** * Add an element in list. * We use a property to avoid rewriting a new class. * * @param element XmlAttribute to add. * @since 2.1.0 */ public void add(Attribute element) { getValue().add(element); }
/** {@inheritDoc} */ public void processNestedTag(PutListAttributeTag nestedTag) { ListAttribute attribute = new ListAttribute(nestedTag.getAttributes()); attribute.setRole(nestedTag.getRole()); attribute.setInherit(nestedTag.getInherit()); definition.putAttribute(nestedTag.getName(), attribute, nestedTag .isCascade()); }
protected Attribute buildAddListAttribute(TilesAddListAttribute addListAttribute) { ListAttribute attribute = new ListAttribute(); attribute.setRole(getValueOrNull(addListAttribute.role())); for (TilesAddAttribute addAttribute : addListAttribute.addAttributes()) { attribute.add(buildAddAttribute(addAttribute)); } return attribute; }
/** * Adds missing attributes to the destination map. * * @param source The source attribute map. * @param destination The destination attribute map. * @return The destination attribute map if not null, a new one otherwise. */ private Map<String, Attribute> addMissingAttributes(Map<String, Attribute> source, Map<String, Attribute> destination) { if (source != null && !source.isEmpty()) { if (destination == null) { destination = new HashMap<String, Attribute>(); } for (Map.Entry<String, Attribute> entry : source.entrySet()) { String key = entry.getKey(); Attribute destAttribute = destination.get(key); if (destAttribute == null) { destination.put(key, entry.getValue()); } else if (destAttribute instanceof ListAttribute && entry.getValue() instanceof ListAttribute && ((ListAttribute) destAttribute).isInherit()) { ((ListAttribute) destAttribute) .inherit((ListAttribute) entry.getValue()); } } } return destination; }
/** {@inheritDoc} */ @Override public ListAttribute clone() { return new ListAttribute(this); } }
@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); } }
ModelBody modelBody) throws IOException { Deque<Object> composeStack = ComposeStackUtil.getComposeStack(request); ListAttribute listAttribute = new ListAttribute(); listAttribute.setRole(role); listAttribute.setInherit(inherit); composeStack.push(listAttribute); modelBody.evaluateWithoutWriting();
} else if (attribute instanceof ListAttribute && destAttribute instanceof ListAttribute && ((ListAttribute) destAttribute).isInherit()) { ((ListAttribute) destAttribute).inherit((ListAttribute) attribute); } else if (attribute instanceof ListAttribute && destAttribute instanceof ListAttribute && ((ListAttribute) destAttribute).isInherit()) { ((ListAttribute) destAttribute).inherit((ListAttribute) attribute);
/** * Constructor. * * @since 2.1.0 */ public ListAttribute() { setValue(new ArrayList<Object>()); }
attribute.setRenderer(type); listAttribute.add(attribute);
} else if (attribute instanceof ListAttribute && destAttribute instanceof ListAttribute && ((ListAttribute) destAttribute).isInherit()) { ((ListAttribute) destAttribute).inherit((ListAttribute) attribute); } else if (attribute instanceof ListAttribute && destAttribute instanceof ListAttribute && ((ListAttribute) destAttribute).isInherit()) { ((ListAttribute) destAttribute).inherit((ListAttribute) attribute);