/** * Creates a definition given its representation with wildcards. * * @param d The definition to replace. * @param name The name of the definition to be created. * @param vars The variables to be substituted. * @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.setTemplateAttribute(replaceVarsInAttribute(d .getTemplateAttribute(), vars)); Set<String> localAttributeNames = d.getLocalAttributeNames(); if (localAttributeNames != null && !localAttributeNames.isEmpty()) { for (String attributeName : localAttributeNames) { Attribute attr = d.getLocalAttribute(attributeName); Attribute nuattr = replaceVarsInAttribute(attr, vars); nudef.putAttribute(replace(attributeName, vars), nuattr); } } return nudef; }
/** * 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; }