Examples of NestableNode


Examples of org.thymeleaf.dom.NestableNode

           
            checked = SelectedValueComparatorWrapper.isSelected(bindStatus, value);
           
        }
       
        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.setAttribute(
                "value",
                RequestDataValueProcessorUtils.processFormFieldValue(
                        arguments.getConfiguration(), arguments, name, value, "checkbox"));
        if (checked) {
            inputElement.setAttribute("checked", "checked");
        } else {
            inputElement.removeAttribute("checked");
        }
        inputElement.setAllNodeLocalVariables(localVariables);

        parent.insertBefore(element, inputElement);


        if (!isDisabled(inputElement)) {

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

            parent.insertBefore(element, hiddenElement);

        }


        parent.removeChild(element);
       
        return ProcessorResult.OK;        
       
    }
View Full Code Here

Examples of org.thymeleaf.dom.NestableNode

       
        final String id = computeId(arguments, element, name, false);

        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);
           
        }
       
       
        return ProcessorResult.OK;
View Full Code Here

Examples of org.thymeleaf.dom.NestableNode

           
            checked = SelectedValueComparatorWrapper.isSelected(bindStatus, value);
           
        }
       
        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.setAttribute(
                "value",
                RequestDataValueProcessorUtils.processFormFieldValue(
                        arguments.getConfiguration(), arguments, name, value, "checkbox"));
        if (checked) {
            inputElement.setAttribute("checked", "checked");
        } else {
            inputElement.removeAttribute("checked");
        }
        inputElement.setAllNodeLocalVariables(localVariables);

        parent.insertBefore(element, inputElement);


        if (!isDisabled(inputElement)) {

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

            parent.insertBefore(element, hiddenElement);

        }


        parent.removeChild(element);
       
        return ProcessorResult.OK;        
       
    }
View Full Code Here

Examples of org.thymeleaf.dom.NestableNode

       
        final String id = computeId(arguments, element, name, false);

        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);
           
        }
       
       
        return ProcessorResult.OK;
View Full Code Here

Examples of org.thymeleaf.dom.NestableNode

          + "\" is not an AbstractGeneralTemplateWriter");
    }

    StringWriter writer = new StringWriter();
    try {
      NestableNode parent = element.getParent();
      parent.removeChild(element);
      ((AbstractGeneralTemplateWriter) templateWriter).writeNode(arguments, writer, parent);

      Node content = new Macro(writer.toString());
      CacheManager.put(arguments, cacheName, Collections.singletonList(content));
    } catch (IOException e) {
View Full Code Here

Examples of org.thymeleaf.dom.NestableNode

   
    @Override
    public final ProcessorResult processAttribute(final Arguments arguments, final Element element, final String attributeName) {

       
        final NestableNode parentNode = element.getParent();

        // Find out if there's some whitespace to duplicate so as to preserve the
        // 'look' of the HTML code when completed
        Node previousNode = null;
        for (final Node child: parentNode.getChildren()) {
            if (child == element) {
                break;
            }
            previousNode = child;
        }
        boolean preserveWhitespace = false;
        String whitespace = null;
        if (previousNode != null && previousNode instanceof Text) {
            final String content = ((Text)previousNode).getContent();
            if (content.trim().length() == 0) {
                preserveWhitespace = true;
                whitespace = content;
            }
            else {
                int i = content.length();
                while (i > 0 && Character.isWhitespace(content.charAt(i - 1))) {
                    i--;
                }
                if (i < content.length()) {
                    preserveWhitespace = true;
                    whitespace = content.substring(i);
                }
            }
        }

        final IterationSpec iterationSpec =
            getIterationSpec(arguments, element, attributeName);
       
       
        final String iterVar = iterationSpec.getIterVarName();
        final String statusVar = iterationSpec.getStatusVarName();
        final Object iteratedObject = iterationSpec.getIteratedObject();

        final List<?> list = EvaluationUtil.evaluateAsIterable(iteratedObject);

        final int size = list.size();
        int index = 0;
        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));
            }
            parentNode.insertBefore(element, clonedElement);

            processClonedHostIterationElement(arguments, clonedElement, attributeName);
           
            index++;
           
        }
       
        parentNode.removeChild(element);
       
        return ProcessorResult.OK;
       
    }
View Full Code Here

Examples of org.thymeleaf.dom.NestableNode

    private static List<Node> extractFragmentFromNode(
            final Node node, final String normalizedElementName, final String normalizedAttributeName, final String attributeValue) {
       
        if (node instanceof NestableNode) {

            final NestableNode nestableNode = (NestableNode) node;
           
            /*
             * 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 {
                        return Collections.singletonList((Node)nestableNode);
                    }
               }
            } else if (nestableNode instanceof NestableAttributeHolderNode) {
                final NestableAttributeHolderNode attributeHolderNode = (NestableAttributeHolderNode) nestableNode;
                // If not null, an element without name can never be selectable
                if (normalizedElementName == null) {
                    if (normalizedAttributeName != null) {
                        if (attributeHolderNode.hasNormalizedAttribute(normalizedAttributeName)) {
                            final String elementAttrValue = attributeHolderNode.getAttributeValue(normalizedAttributeName);
                            if (elementAttrValue != null && elementAttrValue.trim().equals(attributeValue)) {
                                return Collections.singletonList((Node)nestableNode);
                            }
                        }
                    } else {
                        return Collections.singletonList((Node)nestableNode);
                    }
                }
            }
           
            /*
             * If element does not match itself, try children
             */
            final List<Node> extraction = new ArrayList<Node>(5);
            final List<Node> children = nestableNode.getChildren();
            for (final Node child : children) {
                final List<Node> childResult =
                        extractFragmentFromNode(
                                child, normalizedElementName, normalizedAttributeName, attributeValue);
                if (childResult != null) {
View Full Code Here

Examples of org.thymeleaf.dom.NestableNode

    @Override
    public final ProcessorResult processElement(final Arguments arguments, final Element element) {

        final List<Node> substitutes = getMarkupSubstitutes(arguments, element);
       
        final NestableNode parent = element.getParent();
       
        for (final Node node : substitutes) {
            parent.insertBefore(element, node);
        }
        parent.removeChild(element);
       
        return ProcessorResult.OK;
       
    }
View Full Code Here

Examples of org.thymeleaf.dom.NestableNode

    public final ProcessorResult processElement(final Arguments arguments, final Element element) {

        final boolean removeHostElementIfChildNotRemoved =
                removeHostElementIfChildNotRemoved(arguments, element);

        final NestableNode parent = element.getParent();
       
        if (getRemoveElementAndChildren(arguments, element)) {
            parent.removeChild(element);
            return ProcessorResult.OK;
        }
       
        if (removeHostElementIfChildNotRemoved) {
            parent.extractChild(element);
        }
       
        return ProcessorResult.OK;
       
    }
View Full Code Here

Examples of org.thymeleaf.dom.NestableNode

   
    @Override
    public final ProcessorResult processElement(final Arguments arguments, final Element element) {

       
        final NestableNode parentNode = element.getParent();
       
        final IterationSpec iterationSpec =
            getIterationSpec(arguments, element);

        final boolean removeHostIterationElement =
                removeHostIterationElement(arguments, element);
       
        final String iteratedElementName =
                getIteratedElementName(arguments, element);
       
        final String iterVar = iterationSpec.getIterVarName();
        final String statusVar = iterationSpec.getStatusVarName();
        final Object iteratedObject = iterationSpec.getIteratedObject();

        final List<?> list = EvaluationUtil.evaluateAsIterable(iteratedObject);

        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++;
           
        }
       
        parentNode.removeChild(element);
       
        return ProcessorResult.OK;
       
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.