Package org.thymeleaf.dom

Examples of org.thymeleaf.dom.Element


        final boolean multiple = element.hasAttribute("multiple");
       
        final NestableNode parent = element.getParent();
       
        final Element inputElement = (Element) element.cloneNode(parent, false);
        inputElement.removeAttribute(attributeName);
       
        inputElement.setAttribute("id", id);
        inputElement.setAttribute("name", name);
        inputElement.setAllNodeLocalVariables(localVariables);

        processOptionChildren(inputElement, attributeName, attributeValue);
       
        parent.insertBefore(element, inputElement);
        parent.removeChild(element);
       

        if (multiple && !isDisabled(inputElement)) {

            final String hiddenName = WebDataBinder.DEFAULT_FIELD_MARKER_PREFIX + name;
            final Element hiddenElement = new Element("input");
            hiddenElement.setAttribute("type", "hidden");
            hiddenElement.setAttribute("name", hiddenName);
            hiddenElement.setAttribute(
                    "value",
                    RequestDataValueProcessorUtils.processFormFieldValue(
                            arguments.getConfiguration(), arguments, hiddenName, "1", "hidden"));

            hiddenElement.setAllNodeLocalVariables(localVariables);
           
            parent.insertAfter(inputElement, hiddenElement);
           
        }
       
View Full Code Here


       
        for (final Node child : children) {
           
            if (child != null && child instanceof Element) {
               
                final Element childTag = (Element) child;
                final String childTagName = childTag.getNormalizedName();

                childTag.setProcessable(true);
               
                if ("option".equals(childTagName)) {
                   
                    if (childTag.hasAttribute(selectAttrName)) { // has attribute
                       
                        final String selectAttrInChildValue = childTag.getAttributeValue(selectAttrName);
                       
                        if (selectAttrInChildValue != null) {
                            if (!selectAttrValue.equals(selectAttrInChildValue)) {
                                throw new TemplateProcessingException(
                                        "If specified (which is not required), attribute " +
                                        "\"" + selectAttrName + "\" in \"option\" tag must have " +
                                        "exactly the same value as in its containing \"select\" " +
                                        "tag");
                            }
                        }
                       
                    } else {
                        childTag.setAttribute(selectAttrName, selectAttrValue);
                        childTag.setRecomputeProcessorsImmediately(true);
                    }
                   
                } else if ("optgroup".equals(childTagName)) {

                    processOptionChildren(childTag, selectAttrName, selectAttrValue);
View Full Code Here

      element.clearChildren();
      element.getParent().insertAfter(element, contents.get(0));
      element.getParent().removeChild(element);
    } else {
      log.debug("Cache not found. Adding add processor element.");
      Element cacheDiv = new Element("div");
      cacheDiv.setAttribute("cache:add", cacheName);
      element.addChild(cacheDiv);
    }
    return ProcessorResult.OK;
  }
View Full Code Here

   
    @Override
    protected final ProcessorResult doProcess(final Arguments arguments, final ProcessorMatchingContext processorMatchingContext, final Node node) {

        // Because of the type of applicability being used, casts to Element here will not fail
        final Element element = (Element) node;
        final String[] attributeNames = this.matcher.getAttributeNames(processorMatchingContext);

        String matchedAttributeName = null;
        for (final String attributeName : attributeNames) {
            if (element.hasNormalizedAttribute(attributeName)) {
                matchedAttributeName = attributeName;
                break;
            }
        }
View Full Code Here

           
            final NestableAttributeHolderNode nestableNode = (NestableAttributeHolderNode) node;

            if (node instanceof Element) {
               
                final Element element = (Element) nestableNode;
               
                final Set<ProcessorAndContext> processorsForElementName =
                        this.mergedSpecificProcessorsByElementName.get(element.getNormalizedName());
                if (processorsForElementName != null) {
                    for (final ProcessorAndContext processorAndContext : processorsForElementName) {
                        if (processorAndContext.matches(node)) {
                            processors.add(processorAndContext);
                        }
View Full Code Here

       
        if (!(node instanceof Element)) {
            return false;
        }
       
        final Element element = (Element) node;
        final String prefix = (this.applyDialectPrefix? context.getDialectPrefix() : null);


        if (!element.hasNormalizedName(prefix, this.elementName)) {
            return false;
        }

        if (this.attributeValuesByNameFilter != null) {

            for (final Map.Entry<String,String> filterAttributeEntry : this.attributeValuesByNameFilter.entrySet()) {

                final String filterAttributeName = filterAttributeEntry.getKey();
                final String filterAttributeValue = filterAttributeEntry.getValue();

                if (!element.hasAttribute(filterAttributeName)) {
                    if (filterAttributeValue != null) {
                        return false;
                    }
                    continue;
                }
                final String elementAttributeValue = element.getAttributeValue(filterAttributeName);
                if (elementAttributeValue == null) {
                    if (filterAttributeValue != null) {
                        return false;
                    }
                } else {
View Full Code Here

        for (final Object obj : list) {
           
            // We choose not to clone processors because the host element
            // has at least one processor that is not valid for the
            // new cloned elements: the iteration processor.
            final Element clonedElement = (Element) element.cloneNode(parentNode, false);
            clonedElement.removeAttribute(attributeName);
           
            /*
             * Prepare local variables that will be available for each iteration item
             */
            clonedElement.setNodeLocalVariable(iterVar, obj);
            final StatusVar status =
                new StatusVar(index, index + 1, size, obj);
            if (statusVar != null) {
                clonedElement.setNodeLocalVariable(statusVar, status);
            } else {
                clonedElement.setNodeLocalVariable(iterVar + DEFAULT_STATUS_VAR_SUFFIX, status);
            }
           
            // Add whitespace to preserve the look in the resulting HTML code
            if (preserveWhitespace && index > 0) {
                parentNode.insertBefore(element, new Text(whitespace));
View Full Code Here

           
            /*
             * First check the element itself
             */
            if (nestableNode instanceof Element) {
                final Element element = (Element) nestableNode;
                if (normalizedElementName == null || normalizedElementName.equals(element.getNormalizedName())) {
                    if (normalizedAttributeName != null) {
                        if (element.hasNormalizedAttribute(normalizedAttributeName)) {
                            final String elementAttrValue = element.getAttributeValue(normalizedAttributeName);
                            if (elementAttrValue != null && elementAttrValue.trim().equals(attributeValue)) {
                                return Collections.singletonList((Node)nestableNode);
                            }
                        }
                    } else {
View Full Code Here

        final int size = list.size();
        int index = 0;
        for (final Object obj : list) {
           
            Element iterElement = null;
           
            if (removeHostIterationElement) {
               
                // We can safely clone the host element because we will remove it below
                iterElement = (Element) element.cloneNode(parentNode, false);
               
            } else {
               
                // We do not clone the iteration element with the same name because that
                // would probably result in an infinite loop as the iteration processor
                // would be applied once and again. Instead, we create iterated elements
                // with a new name (iteratedElementName).
               
                if (iteratedElementName == null) {
                    throw new TemplateProcessingException(
                            "Cannot specify null iterated element name if the host iteration element is not being removed");
                }
               
                iterElement = element.cloneElementNodeWithNewName(parentNode, iteratedElementName, false);
               
            }
            parentNode.insertBefore(element, iterElement);
           
            /*
             * Prepare local variables that will be available for each iteration item
             */
            final Map<String,Object> nodeLocalVariables = new HashMap<String,Object>(4, 1.0f);
            nodeLocalVariables.put(iterVar, obj);
            final StatusVar status =
                new StatusVar(index, index + 1, size, obj);
            if (statusVar != null) {
                nodeLocalVariables.put(statusVar, status);
            } else {
                nodeLocalVariables.put(iterVar + DEFAULT_STATUS_VAR_SUFFIX, status);
            }
           
           
            if (removeHostIterationElement) {
                final List<Node> children = iterElement.getChildren();
                for (final Node child : children) {
                    child.setAllNodeLocalVariables(nodeLocalVariables);
                }
                parentNode.extractChild(iterElement);
            } else {
                iterElement.setAllNodeLocalVariables(nodeLocalVariables);
                processClonedHostIterationElement(arguments, iterElement);
            }
           
            index++;
           
View Full Code Here

            Integer lineNumber = null;
            if (this.locator != null) {
                lineNumber = Integer.valueOf(this.locator.getLineNumber());
            }
           
            final Element element = new Element(qName, this.documentName, lineNumber);
           
            for (int i = 0; i < attributes.getLength(); i++) {
                element.setAttribute(
                        attributes.getQName(i),
                        false,
                        TemplatePreprocessingReader.removeEntitySubstitutions(attributes.getValue(i)),
                        true);
            }
View Full Code Here

TOP

Related Classes of org.thymeleaf.dom.Element

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.