Package org.thymeleaf.dom

Examples of org.thymeleaf.dom.Element


            flushBuffer();

            final NestableNode node = this.elementStack.pop();
           
            if (node instanceof Element) {
                final Element element = (Element) node;
                if (TemplatePreprocessingReader.SYNTHETIC_ROOT_ELEMENT_NAME.equals(element.getOriginalName())) {
                    // If it is the synthetic root element, then we skip the element itself and just add
                    // its children to the results.
                    final List<Node> syntheticRootChildren = element.getChildren();
                    if (this.elementStack.isEmpty()) {
                        this.rootNodes.addAll(syntheticRootChildren);
                    } else {
                        final NestableNode parent = this.elementStack.peek();
                        for (final Node syntheticRootChild : syntheticRootChildren) {
View Full Code Here


   
    public static Element translateElement(final org.w3c.dom.Element domNode, final NestableNode parentNode, final String documentName) {

        final String elementTagName = domNode.getTagName();
       
        final Element element = new Element(elementTagName, documentName);
        element.setParent(parentNode);
       
        final org.w3c.dom.NamedNodeMap attributes = domNode.getAttributes();
        final int attributesLen = attributes.getLength();
        for (int i = 0; i < attributesLen; i++) {
            final org.w3c.dom.Attr attr = (org.w3c.dom.Attr) attributes.item(i);
            element.setAttribute(
                    attr.getName(),
                    false,
                    TemplatePreprocessingReader.removeEntitySubstitutions(attr.getValue()),
                    true);
        }
       
        final org.w3c.dom.NodeList children = domNode.getChildNodes();
        final int childrenLen = children.getLength();
        for (int i = 0; i < childrenLen; i++) {
            final org.w3c.dom.Node child = children.item(i);
            element.addChild(translateNode(child, element, documentName));
        }
       
        return element;
       
    }
View Full Code Here

            return false;
        }

        if (this.elementNameFilter != null) {
            if (attributeHolderNode instanceof Element) {
                final Element element = (Element) attributeHolderNode;
                if (!element.getNormalizedName().equals(this.elementNameFilter)) {
                    return false;
                }
            } else {
                // if node is not an element (because it probably is a group of nodes, it has no
                // "element/tag name", and therefore does not match if this matcher specifies one.
View Full Code Here

    if (contentbody == null) {
      return;
    }

    // If the decorator has no BODY, we can just copy the page BODY
    Element decoratorbody = findElement(decoratorhtml, HTML_ELEMENT_BODY);
    if (decoratorbody == null) {
      decoratorhtml.addChild(contentbody);
      decoratorhtml.addChild(new Text(LINE_SEPARATOR));
      return;
    }
View Full Code Here

   */
  @Override
  public void decorate(Element decoratorhtml, Element contenthead) {

    // If the decorator has no HEAD, then we can just use the content HEAD
    Element decoratorhead = findElement(decoratorhtml, HTML_ELEMENT_HEAD);
    if (decoratorhead == null) {
      if (contenthead != null) {
        decoratorhtml.insertChild(0, new Text(LINE_SEPARATOR));
        decoratorhtml.insertChild(1, contenthead);

        Element contenttitle = findElement(contenthead, HTML_ELEMENT_TITLE);
        if (contenttitle != null) {
          Element resultingtitle = new Element(HTML_ELEMENT_TITLE);
          extractTitle(contenthead, contenttitle, CONTENT_TITLE, resultingtitle);
          contenthead.insertChild(0, new Text(LINE_SEPARATOR));
          contenthead.insertChild(1, resultingtitle);
        }
      }
      return;
    }

    // Merge the content and decorator titles into a single title element
    Element decoratortitle = findElement(decoratorhead, HTML_ELEMENT_TITLE);
    Element contenttitle   = null;
    if (contenthead != null) {
      contenttitle = findElement(contenthead, HTML_ELEMENT_TITLE);
    }
    Element resultingtitle = null;
    if (decoratortitle != null || contenttitle != null) {
      resultingtitle = new Element(HTML_ELEMENT_TITLE);
      if (decoratortitle != null) {
        extractTitle(decoratorhead, decoratortitle, DECORATOR_TITLE, resultingtitle);
      }
      if (contenttitle != null) {
        extractTitle(contenthead, contenttitle, CONTENT_TITLE, resultingtitle);
View Full Code Here

    Template decoratortemplate = arguments.getTemplateRepository().getTemplate(new TemplateProcessingParameters(
        arguments.getConfiguration(), fragment.getTemplateName(), arguments.getContext()));
    element.removeAttribute(attributeName);

    Document decoratordocument = decoratortemplate.getDocument();
    Element decoratorrootelement = decoratordocument.getFirstElementChild();

    // Gather all fragment parts from this page
    Map<String,Object> fragments = findFragments(document.getElementChildren());

    // Decide which kind of decorator to apply, given the decorator page root element
    Decorator decorator = decoratorrootelement != null &&
        decoratorrootelement.getOriginalName().equals(HTML_ELEMENT_HTML) ?
            new HtmlDocumentDecorator() :
            new XmlDocumentDecorator();

    // Perform decoration, apply any new fragments found from the pre-decorated page
    decorator.decorate(decoratorrootelement, document.getFirstElementChild());
    if (!fragments.isEmpty()) {
      Element newrootelement = document.getFirstElementChild();
      Set<String> nodelocalvariables = newrootelement.getNodeLocalVariableNames();
      for (String fragmentname: fragments.keySet()) {
        if (!nodelocalvariables.contains(fragmentname)) {
          newrootelement.setNodeLocalVariable(fragmentname, fragments.get(fragmentname));
        }
      }
    }

    return ProcessorResult.OK;
View Full Code Here

    if (node.getOriginalName().equals(elementname)) {
      return node;
    }
    for (Element child: node.getElementChildren()) {
      Element result = findElement(child, elementname);
      if (result != null) {
        return result;
      }
    }
    return null;
View Full Code Here

  private static void findFragments(HashMap<String,Object> fragments, List<Element> elements) {

    for (Element element: elements) {
      String fragmentname = getAttributeValue(element, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_FRAGMENT);
      if (fragmentname != null) {
        Element fragment = (Element)element.cloneNode(null, true);
        removeAttribute(fragment, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_FRAGMENT);
        fragments.put(FRAGMENT_NAME_PREFIX + fragmentname, fragment);
      } else {
        if (!hasAttribute(element, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_INCLUDE) &&
          !hasAttribute(element, DIALECT_PREFIX_LAYOUT, PROCESSOR_NAME_REPLACE) &&
View Full Code Here

          "your content page, if present.");
    }

    // Locate the page fragment that corresponds to this decorator/include fragment
    String fragmentname = element.getAttributeValue(attributeName);
    Element pagefragment = (Element)arguments.getLocalVariable(FRAGMENT_NAME_PREFIX + fragmentname);
    element.removeAttribute(attributeName);

    // Replace the decorator/include fragment with the page fragment
    if (pagefragment != null) {
      pullAttributes(pagefragment, element);
View Full Code Here

    Map<String,Object> pagefragments = findFragments(element.getElementChildren());

    // Replace the children of this element with those of the include page fragments.
    element.clearChildren();
    if (includefragments != null) {
      Element containerelement = new Element("container");
      for (Node includefragment: includefragments) {
        containerelement.addChild(includefragment);
        containerelement.extractChild(includefragment);
      }
      for (Node extractedchild: containerelement.getChildren()) {
        element.addChild(extractedchild);
      }
    }

    // Scope any fragment parts for the include page to the current element
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.