org.apache.tiles.Definition类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(230)

本文整理了Java中org.apache.tiles.Definition类的一些代码示例,展示了Definition类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Definition类的具体详情如下:
包路径:org.apache.tiles.Definition
类名称:Definition

Definition介绍

[英]A definition, i.e. a template with (completely or not) filled attributes. Attributes of a template can be defined with the help of this class.
It can be used as a data transfer object used for registering new definitions with the Container.
[中]定义,即具有(完全或不完全)填充属性的模板。模板的属性可以在此类的帮助下定义。
它可以用作数据传输对象,用于向容器注册新定义。

代码示例

代码示例来源:origin: org.apache.tiles/com.springsource.org.apache.tiles.core

  1. /**
  2. * Creates a definition given its representation with wildcards.
  3. *
  4. * @param d The definition to replace.
  5. * @param name The name of the definition to be created.
  6. * @param vars The variables to be substituted.
  7. * @return The definition that can be rendered.
  8. * @since 2.1.0
  9. */
  10. protected Definition replaceDefinition(Definition d, String name,
  11. Map<Integer, String> vars) {
  12. Definition nudef = new Definition();
  13. nudef.setExtends(replace(d.getExtends(), vars));
  14. nudef.setName(name);
  15. nudef.setPreparer(replace(d.getPreparer(), vars));
  16. nudef.setTemplateAttribute(replaceVarsInAttribute(d
  17. .getTemplateAttribute(), vars));
  18. Set<String> localAttributeNames = d.getLocalAttributeNames();
  19. if (localAttributeNames != null && !localAttributeNames.isEmpty()) {
  20. for (String attributeName : localAttributeNames) {
  21. Attribute attr = d.getLocalAttribute(attributeName);
  22. Attribute nuattr = replaceVarsInAttribute(attr, vars);
  23. nudef.putAttribute(replace(attributeName, vars), nuattr);
  24. }
  25. }
  26. return nudef;
  27. }

代码示例来源:origin: org.springframework.webflow/spring-webflow

  1. if (definition.getLocalAttributeNames() != null) {
  2. attributeNames.addAll(definition.getLocalAttributeNames());
  3. if (definition.getCascadedAttributeNames() != null) {
  4. attributeNames.addAll(definition.getCascadedAttributeNames());
  5. Attribute attribute = definition.getAttribute(attributeName);
  6. if (attribute.getValue() == null || !(attribute.getValue() instanceof String)) {
  7. continue;

代码示例来源:origin: org.apache.tiles/tiles-core

  1. Set<String> alreadyResolvedDefinitions) {
  2. if (!definition.isExtending()
  3. || alreadyResolvedDefinitions.contains(definition.getName())) {
  4. return;
  5. definition.getName(), definition.getExtends());
  6. alreadyResolvedDefinitions.add(definition.getName());
  7. Definition parent = definitions.get(definition.getExtends());
  8. if (parent == null) { // error
  9. String msg = "Error while resolving definition inheritance: child '"
  10. + definition.getName()
  11. + "' can't find its ancestor '"
  12. + definition.getExtends()
  13. + "'. Please check your description file.";
  14. alreadyResolvedDefinitions);
  15. definition.inherit(parent);

代码示例来源:origin: stackoverflow.com

  1. Definition d = new Definition();
  2. d.setCategory(GrammaticalCategory.ADJECTIVE);
  3. d.setDefinition("testdefinition");
  4. JAXB.marshal(d, new File("out.xml"));

代码示例来源:origin: org.apache.tiles/tiles-core

  1. /** {@inheritDoc} */
  2. @Override
  3. public void register(Definition definition, Request request) {
  4. Map<String, Definition> definitions = getOrCreateDefinitions(request);
  5. if (definition.getName() == null) {
  6. definition.setName(getNextUniqueDefinitionName(definitions));
  7. }
  8. if (definition.isExtending()) {
  9. this.resolveInheritance(definition, request);
  10. }
  11. definitions.put(definition.getName(), definition);
  12. }

代码示例来源:origin: org.apache.tiles/tiles-template

  1. /**
  2. * Creates the definition to store.
  3. *
  4. * @param name The name of the definition to create. If not specified, an
  5. * anonymous definition will be created.
  6. * @param template The template of this definition.
  7. * @param role A comma-separated list of roles. If present, the definition
  8. * will be rendered only if the current user belongs to one of the roles.
  9. * @param extendsParam The definition name that this definition extends.
  10. * @param preparer The preparer to use to invoke before the definition is
  11. * rendered.
  12. * @return The created definition.
  13. */
  14. private Definition createDefinition(String name, String template,
  15. String role, String extendsParam, String preparer) {
  16. Definition definition = new Definition();
  17. definition.setName(name);
  18. Attribute templateAttribute = Attribute
  19. .createTemplateAttribute(template);
  20. templateAttribute.setRole(role);
  21. definition.setTemplateAttribute(templateAttribute);
  22. definition.setExtends(extendsParam);
  23. definition.setPreparer(preparer);
  24. return definition;
  25. }

代码示例来源:origin: org.apache.tiles/com.springsource.org.apache.tiles.core

  1. /** {@inheritDoc} */
  2. public Definition getDefinition(String name,
  3. TilesRequestContext tilesContext) {
  4. Definition retValue;
  5. Locale locale = null;
  6. if (tilesContext != null) {
  7. locale = localeResolver.resolveLocale(tilesContext);
  8. }
  9. retValue = definitionDao.getDefinition(name, locale);
  10. if (retValue != null) {
  11. retValue = new Definition(retValue);
  12. String parentDefinitionName = retValue.getExtends();
  13. while (parentDefinitionName != null) {
  14. Definition parent = definitionDao.getDefinition(
  15. parentDefinitionName, locale);
  16. if (parent == null) {
  17. throw new NoSuchDefinitionException("Cannot find definition '"
  18. + parentDefinitionName + "' ancestor of '"
  19. + retValue.getName() + "'");
  20. }
  21. retValue.inherit(parent);
  22. parentDefinitionName = parent.getExtends();
  23. }
  24. }
  25. return retValue;
  26. }

代码示例来源:origin: org.springframework.webflow/spring-js

  1. Map<String, Attribute> resultMap, Definition compositeDefinition, HttpServletRequest request,
  2. HttpServletResponse response) {
  3. Iterator<String> iterator = compositeDefinition.getAttributeNames();
  4. while (iterator.hasNext()) {
  5. String attributeName = iterator.next();
  6. Attribute attribute = compositeDefinition.getAttribute(attributeName);
  7. if (attribute.getValue() == null || !(attribute.getValue() instanceof String)) {
  8. continue;

代码示例来源:origin: org.apache.tiles/com.springsource.org.apache.tiles.core

  1. /**
  2. * Validates a custom definition.
  3. *
  4. * @param definition The definition to validate.
  5. */
  6. private void validate(Definition definition) {
  7. Set<String> names = definition.getLocalAttributeNames();
  8. if (names != null) {
  9. for (String name : names) {
  10. Attribute attribute = definition.getLocalAttribute(name);
  11. if (attribute.getValue() == null) {
  12. throw new IllegalArgumentException(
  13. "Attribute '" + name + "' value not defined");
  14. }
  15. }
  16. }
  17. names = definition.getCascadedAttributeNames();
  18. if (names != null) {
  19. for (String name : names) {
  20. Attribute attribute = definition.getCascadedAttribute(name);
  21. if (attribute.getValue() == null) {
  22. throw new IllegalArgumentException(
  23. "Attribute '" + name + "' value not defined");
  24. }
  25. }
  26. }
  27. }

代码示例来源:origin: org.apache.tiles/com.springsource.org.apache.tiles

  1. /**
  2. * Add an attribute to this definition.
  3. * <p/>
  4. * This method is used by Digester to load definitions.
  5. *
  6. * @param attribute Attribute to add.
  7. * @deprecated Use {@link Definition#putAttribute(String, Attribute)}.
  8. */
  9. @Deprecated
  10. public void addAttribute(Attribute attribute) {
  11. putAttribute(attribute.getName(), attribute);
  12. }

代码示例来源:origin: org.apache.tiles/tiles-core

  1. /** {@inheritDoc} */
  2. @Override
  3. public void begin(String namespace, String name, Attributes attributes) {
  4. Definition definition = (Definition) digester.peek(0);
  5. if (definition.getName() == null) {
  6. definition.setName(getNextUniqueDefinitionName(definitions));
  7. }
  8. Attribute attribute = (Attribute) digester.peek(1);
  9. attribute.setValue(definition.getName());
  10. attribute.setRenderer("definition");
  11. }
  12. }

代码示例来源:origin: org.apache.tiles/tiles-core

  1. /**
  2. * Adds a new <code>Definition</code> to the internal Map or replaces
  3. * an existing one.
  4. *
  5. * @param definition The Definition object to be added.
  6. */
  7. public void addDefinition(Definition definition) {
  8. String name = definition.getName();
  9. if (name == null) {
  10. throw new DigesterDefinitionsReaderException(
  11. "A root definition has been defined with no name");
  12. }
  13. definitions.put(name, definition);
  14. }

代码示例来源:origin: org.apache.tiles/tiles-core

  1. /**
  2. * Copies the definition map to be passed to a higher level of customization
  3. * key.
  4. *
  5. * @param localeDefsMap The map of definition to be copied.
  6. * @return The copy of the definition map. This particular implementation
  7. * deep-copies the <code>localeDefsMap</code> into a {@link LinkedHashMap}.
  8. * @since 2.1.4
  9. */
  10. @Override
  11. protected Map<String, Definition> copyDefinitionMap(
  12. Map<String, Definition> localeDefsMap) {
  13. Map<String, Definition> retValue = new LinkedHashMap<String, Definition>(
  14. localeDefsMap.size());
  15. for (Map.Entry<String, Definition> entry : localeDefsMap.entrySet()) {
  16. Definition definition = new Definition(entry.getValue());
  17. retValue.put(entry.getKey(), definition);
  18. }
  19. return retValue;
  20. }
  21. }

代码示例来源:origin: org.apache.tiles/com.springsource.org.apache.tiles

  1. /**
  2. * Checks whether the <code>key</code> attribute has been set.
  3. *
  4. * @param key The attribute key to check.
  5. * @return <code>true</code> if the attribute has a value.
  6. * @deprecated Check if the {@link AttributeContext#getAttribute(String)}
  7. * returns null.
  8. */
  9. @Deprecated
  10. public boolean hasAttributeValue(String key) {
  11. return getAttribute(key) != null;
  12. }

代码示例来源:origin: spring-projects/spring-webflow

  1. public void testRenderFragment_InheritCascadedAttribute() throws Exception {
  2. ApplicationContext tilesAppContext = new WildcardServletApplicationContext(servletContext);
  3. Request tilesRequest = new ServletRequest(tilesAppContext, request, response);
  4. BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesAppContext);
  5. Definition definition = container.getDefinitionsFactory().getDefinition("search.body", tilesRequest);
  6. definition.setPreparer(AttributeTestingPreparer.class.getName());
  7. setupStaticWebApplicationContext();
  8. request.addHeader("Accept", DefaultAjaxHandler.AJAX_ACCEPT_CONTENT_TYPE);
  9. request.addParameter("fragments", "body");
  10. ajaxTilesView.setUrl("search");
  11. ajaxTilesView.afterPropertiesSet();
  12. ajaxTilesView.renderMergedOutputModel(new HashMap<>(), request, response);
  13. assertTrue(AttributeTestingPreparer.invoked);
  14. }

代码示例来源:origin: org.apache.tiles/com.springsource.org.apache.tiles.core

  1. /** {@inheritDoc} */
  2. @Override
  3. public void begin(String namespace, String name, Attributes attributes)
  4. throws Exception {
  5. Definition definition = (Definition) digester.peek();
  6. definition.setName(attributes.getValue("name"));
  7. definition.setPreparer(attributes.getValue("preparer"));
  8. definition.setExtends(attributes.getValue("extends"));
  9. String template = attributes.getValue("template");
  10. Attribute attribute = Attribute.createTemplateAttribute(template);
  11. attribute.setExpression(attributes.getValue("templateExpression"));
  12. attribute.setRole(attributes.getValue("role"));
  13. String templateType = attributes.getValue("templateType");
  14. if (templateType != null) {
  15. attribute.setRenderer(templateType);
  16. }
  17. definition.setTemplateAttribute(attribute);
  18. }
  19. }

代码示例来源:origin: org.apache.tiles/tiles-core

  1. retValue = new Definition(retValue);
  2. String parentDefinitionName = retValue.getExtends();
  3. while (parentDefinitionName != null) {
  4. Definition parent = definitionDao.getDefinition(
  5. throw new NoSuchDefinitionException("Cannot find definition '"
  6. + parentDefinitionName + "' ancestor of '"
  7. + retValue.getName() + "'");
  8. retValue.inherit(parent);
  9. parentDefinitionName = parent.getExtends();

代码示例来源:origin: org.thymeleaf.extras/thymeleaf-extras-tiles2-spring4

  1. final HttpServletRequest request, final HttpServletResponse response) {
  2. final Iterator<String> iterator = compositeDefinition.getAttributeNames();
  3. final Attribute attribute = compositeDefinition.getAttribute(attributeName);

代码示例来源:origin: org.apache.tiles/com.springsource.org.apache.tiles.core

  1. /**
  2. * Adds a definition to the set of custom ones.
  3. *
  4. * @param definition The definition to add.
  5. * @param request The current request.
  6. * @throws org.apache.tiles.definition.DefinitionsFactoryException If
  7. * something goes wrong during the addition.
  8. */
  9. public void addDefinition(Definition definition,
  10. TilesRequestContext request) {
  11. Map<String, Definition> definitions = getOrCreateDefinitions(request);
  12. if (definition.getName() == null) {
  13. definition.setName(getNextUniqueDefinitionName(definitions));
  14. }
  15. validate(definition);
  16. if (definition.isExtending()) {
  17. this.resolveInheritance(definition, request);
  18. }
  19. definitions.put(definition.getName(), definition);
  20. }

代码示例来源:origin: org.apache.tiles/com.springsource.org.apache.tiles

  1. /**
  2. * Put an attribute in template definition.
  3. * Attribute can be used as content for tag get.
  4. *
  5. * @param name Attribute name
  6. * @param content Attribute value
  7. * @param role Determine if content is used by get tag. If user is in role, content is used.
  8. * @deprecated Use {@link AttributeContext#putAttribute(String, Attribute)}
  9. * or {@link AttributeContext#putAttribute(String, Attribute, boolean)}.
  10. */
  11. @Deprecated
  12. public void put(String name, Object content, String role) {
  13. Attribute attribute = new Attribute(content, null, role, (String) null);
  14. putAttribute(name, attribute);
  15. }

相关文章