org.thymeleaf.templateparser.xmldom.XmlValidatingDOMTemplateParser Maven / Gradle / Ivy
package org.thymeleaf.templateparser.xmldom;
import java.util.List;
import org.thymeleaf.dom.Document;
import org.thymeleaf.dom.NestableNode;
import org.thymeleaf.dom.Node;
/**
*
* Parses XML documents, using a standard non-validating DOM parser.
*
*
*
* This implementation first builds a DOM tree using the
* standard DOM API, and then translates this tree into a
* Thymeleaf-specific one. It also populates tree nodes with
* basic location information (document name only).
*
*
* @since 2.0.0
*
* @author Daniel Fernández
*
*/
public final class XmlValidatingDOMTemplateParser extends AbstractValidatingDOMTemplateParser {
// We simply add enough information for a non-validating parser to consider it alright
// (a document root element declaration).
private static final String FRAGMENT_WRAP_START = "\n";
private static final String FRAGMENT_WRAP_END = " ";
public XmlValidatingDOMTemplateParser(final int poolSize) {
super(poolSize);
}
@Override
protected final String wrapFragment(final String fragment) {
return FRAGMENT_WRAP_START + fragment + FRAGMENT_WRAP_END;
}
@Override
protected final List unwrapFragment(final Document document) {
return ((NestableNode)((NestableNode)((NestableNode)document.getFirstChild()).getFirstChild()).getFirstChild()).getChildren();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy