Package org.thymeleaf.dom

Examples of org.thymeleaf.dom.Document




    public final List<Node> parseFragment(final Configuration configuration, final String fragment) {
        final String wrappedFragment = wrapFragment(fragment);
        final Document document =
                parseTemplate(
                        configuration,
                        null, // documentName
                        new StringReader(wrappedFragment));
        return unwrapFragment(document);
View Full Code Here


       
        final Template template = this.templateRepository.getTemplate(templateProcessingParameters);
        final TemplateResolution templateResolution = template.getTemplateResolution();
        final String templateMode = templateResolution.getTemplateMode();

        Document document = template.getDocument();

        if (fragmentSpec != null) {

            // Apply the fragment specification and filter the parsed template.
            final List<Node> processingRootNodes =
                    fragmentSpec.extractFragment(this.configuration, Collections.singletonList((Node)document));
           
            if (processingRootNodes == null || processingRootNodes.size() == 0) {
                // If the result is null, there will be no processing to do
                document = null;
            } else {
                final Node firstProcessingRootNode = processingRootNodes.get(0);
                if (processingRootNodes.size() == 1 &&
                        firstProcessingRootNode != null &&
                        firstProcessingRootNode instanceof Document) {
                    // If it is a document, just process it as it is output from the filter
                    document = (Document) firstProcessingRootNode;
                } else {
                    // Fragment exists and it is not a Document. We will therefore lose DOCTYPE
                    final String documentName = document.getDocumentName();
                    document = new Document(documentName);
                    for (final Node processingRootNode : processingRootNodes) {
                        if (processingRootNode != null) {
                            final Node clonedProcessingRootNode =
                                    processingRootNode.cloneNode(document, false);
                            document.addChild(clonedProcessingRootNode);
                        }
                    }
                    document.precompute(this.configuration);
                }
            }
           
        }
       
        final Arguments arguments =
                new Arguments(this,
                        templateProcessingParameters, templateResolution,
                        this.templateRepository, document);
      
       
        if (logger.isDebugEnabled()) {
            logger.debug("[THYMELEAF][{}] Starting process on template \"{}\" using mode \"{}\"",
                    new Object[] { TemplateEngine.threadIndex(), templateName, templateMode });
        }

        if (document != null) {
            document.process(arguments);
        }
       
        if (logger.isDebugEnabled()) {
            logger.debug("[THYMELEAF][{}] Finished process on template \"{}\" using mode \"{}\"",
                    new Object[] { TemplateEngine.threadIndex(), templateName, templateMode });
View Full Code Here

        templateEngine.initialize();
       
        final TemplateRepository templateRepository = templateEngine.getTemplateRepository();
       
        final Document document = new Document(templateName);
        document.addChild(node);
       
       
        final Arguments arguments =
                new Arguments(new TemplateEngine(),
                        templateProcessingParameters, templateResolution,
View Full Code Here



    public final List<Node> parseFragment(final Configuration configuration, final String fragment) {
        final String wrappedFragment = wrapFragment(fragment);
        final Document document =
                parseTemplate(
                        configuration,
                        null, // documentName
                        new StringReader(wrappedFragment));
        return unwrapFragment(document);
View Full Code Here

        try {
           
            /*
             * Parse the document
             */
            final Document document =
                    doParse(configuration, documentName, templateReader, saxParser);
           
            if (this.canResetParsers) {
                try {
                    /*
 
View Full Code Here

       
        final String xmlVersion = handler.getXmlVersion();
        final String xmlEncoding = handler.getXmlEncoding();
        final boolean xmlStandalone = handler.isXmlStandalone();
       
        final Document document = new Document(documentName, docType);

        if (xmlVersion != null) {
            document.setNodeProperty(Node.NODE_PROPERTY_XML_VERSION, xmlVersion);
        }
       
        if (xmlEncoding != null) {
            document.setNodeProperty(Node.NODE_PROPERTY_XML_ENCODING, xmlEncoding);
        }
       
        if (xmlStandalone) {
            document.setNodeProperty(Node.NODE_PROPERTY_XML_STANDALONE, Boolean.TRUE);
        }
       
        document.setChildren(rootNodes);
       
        return document;
       
    }
View Full Code Here

   

    public final List<Node> parseFragment(final Configuration configuration, final String fragment) {
        final String wrappedFragment = wrapFragment(fragment);
        final Document document =
                parseTemplateUsingPool(
                        configuration,
                        null, // documentName
                        new StringReader(wrappedFragment),
                        getNonValidatingPool());
View Full Code Here

    public static Document translateDocument(final org.w3c.dom.Document domDocument, final String documentName,
            final String originalDocTypeClause) {
       
        final org.w3c.dom.DocumentType domDocumentType = domDocument.getDoctype();
        final org.w3c.dom.NodeList children = domDocument.getChildNodes();
        final Document document = new Document(documentName, translateDocumentType(domDocumentType, originalDocTypeClause));
       
        final String xmlVersion = domDocument.getXmlVersion();
        if (xmlVersion != null) {
            document.setNodeProperty(Node.NODE_PROPERTY_XML_VERSION, xmlVersion);
        }
       
        final String xmlEncoding = domDocument.getXmlEncoding();
        if (xmlEncoding != null) {
            document.setNodeProperty(Node.NODE_PROPERTY_XML_ENCODING, xmlEncoding);
        }
       
        final boolean xmlStandalone = domDocument.getXmlStandalone();
        if (xmlStandalone) {
            document.setNodeProperty(Node.NODE_PROPERTY_XML_STANDALONE, Boolean.TRUE);
        }
       
        final int childrenLen = children.getLength();
        for (int i = 0; i < childrenLen; i++) {
            final org.w3c.dom.Node child = children.item(i);
            if (!(child instanceof org.w3c.dom.DocumentType)) {
                if (child instanceof org.w3c.dom.Element) {
                    final List<Node> childNodes =
                            translateRootElement((org.w3c.dom.Element)child, document, documentName);
                    for (final Node childNode : childNodes) {
                        document.addChild(childNode);
                    }
                } else {
                    document.addChild(translateNode(child, document, documentName));
                }
            }
        }
        return document;
       
View Full Code Here

            }
        } else {
            reader = new InputStreamReader(templateInputStream);
        }
       
        final Document document =
                templateParser.parseTemplate(configuration, templateName, reader);
       
        if (logger.isTraceEnabled()) {
            logger.trace("[THYMELEAF][{}] Finished parsing of template \"{}\"", TemplateEngine.threadIndex(), templateName);
        }

        document.precompute(configuration);
       
        final Template template =
            new Template(templateName, templateResolution, document);

        if (this.templateCache != null) {
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  public void decorate(Element decorator, Element content) {

    Document decoratordocument = (Document)decorator.getParent();
    Document contentdocument   = (Document)content.getParent();

    // Copy text outside of the root element, keeping whitespace copied to a minimum
    boolean beforehtml = true;
    boolean allownext = false;
    Node lastnode = content;
    for (Node externalnode: decoratordocument.getChildren()) {
      if (externalnode.equals(decorator)) {
        beforehtml = false;
        allownext = true;
        continue;
      }
      if (externalnode instanceof Comment || allownext) {
        if (beforehtml) {
          contentdocument.insertBefore(content, externalnode);
        }
        else {
          contentdocument.insertAfter(lastnode, externalnode);
          lastnode = externalnode;
        }
        allownext = externalnode instanceof Comment;
      }
    }
View Full Code Here

TOP

Related Classes of org.thymeleaf.dom.Document

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.