/** * 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; }
if (definition.getLocalAttributeNames() != null) { attributeNames.addAll(definition.getLocalAttributeNames()); if (definition.getCascadedAttributeNames() != null) { attributeNames.addAll(definition.getCascadedAttributeNames()); Attribute attribute = definition.getAttribute(attributeName); if (attribute.getValue() == null || !(attribute.getValue() instanceof String)) { continue;
Set<String> alreadyResolvedDefinitions) { if (!definition.isExtending() || alreadyResolvedDefinitions.contains(definition.getName())) { return; definition.getName(), definition.getExtends()); alreadyResolvedDefinitions.add(definition.getName()); 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() + "'. Please check your description file."; alreadyResolvedDefinitions); definition.inherit(parent);
Definition d = new Definition(); d.setCategory(GrammaticalCategory.ADJECTIVE); d.setDefinition("testdefinition"); JAXB.marshal(d, new File("out.xml"));
/** {@inheritDoc} */ @Override public void register(Definition definition, Request request) { Map<String, Definition> definitions = getOrCreateDefinitions(request); if (definition.getName() == null) { definition.setName(getNextUniqueDefinitionName(definitions)); } if (definition.isExtending()) { this.resolveInheritance(definition, request); } definitions.put(definition.getName(), definition); }
/** * Creates the definition to store. * * @param name The name of the definition to create. If not specified, an * anonymous definition will be created. * @param template The template of this definition. * @param role A comma-separated list of roles. If present, the definition * will be rendered only if the current user belongs to one of the roles. * @param extendsParam The definition name that this definition extends. * @param preparer The preparer to use to invoke before the definition is * rendered. * @return The created definition. */ private Definition createDefinition(String name, String template, String role, String extendsParam, String preparer) { Definition definition = new Definition(); definition.setName(name); Attribute templateAttribute = Attribute .createTemplateAttribute(template); templateAttribute.setRole(role); definition.setTemplateAttribute(templateAttribute); definition.setExtends(extendsParam); definition.setPreparer(preparer); return definition; }
/** {@inheritDoc} */ public Definition getDefinition(String name, TilesRequestContext tilesContext) { Definition retValue; Locale locale = null; if (tilesContext != null) { locale = localeResolver.resolveLocale(tilesContext); } retValue = definitionDao.getDefinition(name, locale); if (retValue != null) { retValue = new Definition(retValue); String parentDefinitionName = retValue.getExtends(); while (parentDefinitionName != null) { Definition parent = definitionDao.getDefinition( parentDefinitionName, locale); if (parent == null) { throw new NoSuchDefinitionException("Cannot find definition '" + parentDefinitionName + "' ancestor of '" + retValue.getName() + "'"); } retValue.inherit(parent); parentDefinitionName = parent.getExtends(); } } return retValue; }
Map<String, Attribute> resultMap, Definition compositeDefinition, HttpServletRequest request, HttpServletResponse response) { Iterator<String> iterator = compositeDefinition.getAttributeNames(); while (iterator.hasNext()) { String attributeName = iterator.next(); Attribute attribute = compositeDefinition.getAttribute(attributeName); if (attribute.getValue() == null || !(attribute.getValue() instanceof String)) { continue;
/** * Validates a custom definition. * * @param definition The definition to validate. */ private void validate(Definition definition) { Set<String> names = definition.getLocalAttributeNames(); if (names != null) { for (String name : names) { Attribute attribute = definition.getLocalAttribute(name); if (attribute.getValue() == null) { throw new IllegalArgumentException( "Attribute '" + name + "' value not defined"); } } } names = definition.getCascadedAttributeNames(); if (names != null) { for (String name : names) { Attribute attribute = definition.getCascadedAttribute(name); if (attribute.getValue() == null) { throw new IllegalArgumentException( "Attribute '" + name + "' value not defined"); } } } }
/** * Add an attribute to this definition. * <p/> * This method is used by Digester to load definitions. * * @param attribute Attribute to add. * @deprecated Use {@link Definition#putAttribute(String, Attribute)}. */ @Deprecated public void addAttribute(Attribute attribute) { putAttribute(attribute.getName(), attribute); }
/** {@inheritDoc} */ @Override public void begin(String namespace, String name, Attributes attributes) { Definition definition = (Definition) digester.peek(0); if (definition.getName() == null) { definition.setName(getNextUniqueDefinitionName(definitions)); } Attribute attribute = (Attribute) digester.peek(1); attribute.setValue(definition.getName()); attribute.setRenderer("definition"); } }
/** * Adds a new <code>Definition</code> to the internal Map or replaces * an existing one. * * @param definition The Definition object to be added. */ public void addDefinition(Definition definition) { String name = definition.getName(); if (name == null) { throw new DigesterDefinitionsReaderException( "A root definition has been defined with no name"); } definitions.put(name, definition); }
/** * Copies the definition map to be passed to a higher level of customization * key. * * @param localeDefsMap The map of definition to be copied. * @return The copy of the definition map. This particular implementation * deep-copies the <code>localeDefsMap</code> into a {@link LinkedHashMap}. * @since 2.1.4 */ @Override protected Map<String, Definition> copyDefinitionMap( Map<String, Definition> localeDefsMap) { Map<String, Definition> retValue = new LinkedHashMap<String, Definition>( localeDefsMap.size()); for (Map.Entry<String, Definition> entry : localeDefsMap.entrySet()) { Definition definition = new Definition(entry.getValue()); retValue.put(entry.getKey(), definition); } return retValue; } }
/** * Checks whether the <code>key</code> attribute has been set. * * @param key The attribute key to check. * @return <code>true</code> if the attribute has a value. * @deprecated Check if the {@link AttributeContext#getAttribute(String)} * returns null. */ @Deprecated public boolean hasAttributeValue(String key) { return getAttribute(key) != null; }
public void testRenderFragment_InheritCascadedAttribute() throws Exception { ApplicationContext tilesAppContext = new WildcardServletApplicationContext(servletContext); Request tilesRequest = new ServletRequest(tilesAppContext, request, response); BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesAppContext); Definition definition = container.getDefinitionsFactory().getDefinition("search.body", tilesRequest); definition.setPreparer(AttributeTestingPreparer.class.getName()); setupStaticWebApplicationContext(); request.addHeader("Accept", DefaultAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE); request.addParameter("fragments", "body"); ajaxTilesView.setUrl("search"); ajaxTilesView.afterPropertiesSet(); ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response); assertTrue(AttributeTestingPreparer.invoked); }
/** {@inheritDoc} */ @Override public void begin(String namespace, String name, Attributes attributes) throws Exception { Definition definition = (Definition) digester.peek(); definition.setName(attributes.getValue("name")); definition.setPreparer(attributes.getValue("preparer")); definition.setExtends(attributes.getValue("extends")); String template = attributes.getValue("template"); Attribute attribute = Attribute.createTemplateAttribute(template); attribute.setExpression(attributes.getValue("templateExpression")); attribute.setRole(attributes.getValue("role")); String templateType = attributes.getValue("templateType"); if (templateType != null) { attribute.setRenderer(templateType); } definition.setTemplateAttribute(attribute); } }
retValue = new Definition(retValue); String parentDefinitionName = retValue.getExtends(); while (parentDefinitionName != null) { Definition parent = definitionDao.getDefinition( throw new NoSuchDefinitionException("Cannot find definition '" + parentDefinitionName + "' ancestor of '" + retValue.getName() + "'"); retValue.inherit(parent); parentDefinitionName = parent.getExtends();
final HttpServletRequest request, final HttpServletResponse response) { final Iterator<String> iterator = compositeDefinition.getAttributeNames(); final Attribute attribute = compositeDefinition.getAttribute(attributeName);
/** * Adds a definition to the set of custom ones. * * @param definition The definition to add. * @param request The current request. * @throws org.apache.tiles.definition.DefinitionsFactoryException If * something goes wrong during the addition. */ public void addDefinition(Definition definition, TilesRequestContext request) { Map<String, Definition> definitions = getOrCreateDefinitions(request); if (definition.getName() == null) { definition.setName(getNextUniqueDefinitionName(definitions)); } validate(definition); if (definition.isExtending()) { this.resolveInheritance(definition, request); } definitions.put(definition.getName(), definition); }
/** * Put an attribute in template definition. * Attribute can be used as content for tag get. * * @param name Attribute name * @param content Attribute value * @param role Determine if content is used by get tag. If user is in role, content is used. * @deprecated Use {@link AttributeContext#putAttribute(String, Attribute)} * or {@link AttributeContext#putAttribute(String, Attribute, boolean)}. */ @Deprecated public void put(String name, Object content, String role) { Attribute attribute = new Attribute(content, null, role, (String) null); putAttribute(name, attribute); }