use of org.dom4j.io.SAXReader in project OpenOLAT by OpenOLAT.
the class XMLParser method parse.
/**
* @param in
* @param validateXML
* @return parsed document
*/
public Document parse(InputStream in, boolean validateXML) {
Document document;
try {
SAXReader reader = new SAXReader();
reader.setEntityResolver(er);
reader.setValidation(validateXML);
document = reader.read(in, "");
document.normalize();
} catch (Exception e) {
throw new OLATRuntimeException(XMLParser.class, "Exception reading XML", e);
}
return document;
}
use of org.dom4j.io.SAXReader in project core by craftercms.
the class XmlUtilsTest method setUpTestDocument.
private void setUpTestDocument() throws SAXException {
SAXReader reader = new SAXReader();
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
try {
document = reader.read(new StringReader(XML));
} catch (DocumentException e) {
}
}
use of org.dom4j.io.SAXReader in project core by craftercms.
the class AttributeAddingProcessorTest method readInputXml.
private Document readInputXml() throws DocumentException, SAXException {
SAXReader reader = new SAXReader();
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
return reader.read(new StringReader(INPUT_XML));
}
use of org.dom4j.io.SAXReader in project maven-archetype by apache.
the class DefaultOldArchetype method addModuleToParentPom.
static boolean addModuleToParentPom(String artifactId, Reader fileReader, Writer fileWriter) throws DocumentException, IOException, ArchetypeTemplateProcessingException {
SAXReader reader = new SAXReader();
Document document = reader.read(fileReader);
Element project = document.getRootElement();
String packaging = null;
Element packagingElement = project.element("packaging");
if (packagingElement != null) {
packaging = packagingElement.getStringValue();
}
if (!"pom".equals(packaging)) {
throw new ArchetypeTemplateProcessingException("Unable to add module to the current project as it is not of packaging type 'pom'");
}
Element modules = project.element("modules");
if (modules == null) {
modules = project.addText(" ").addElement("modules");
modules.setText("\n ");
project.addText("\n");
}
boolean found = false;
for (Iterator<?> i = modules.elementIterator("module"); i.hasNext() && !found; ) {
Element module = (Element) i.next();
if (module.getText().equals(artifactId)) {
found = true;
}
}
if (!found) {
Node lastTextNode = null;
for (Iterator<?> i = modules.nodeIterator(); i.hasNext(); ) {
Node node = (Node) i.next();
if (node.getNodeType() == Node.ELEMENT_NODE) {
lastTextNode = null;
} else if (node.getNodeType() == Node.TEXT_NODE) {
lastTextNode = node;
}
}
if (lastTextNode != null) {
modules.remove(lastTextNode);
}
modules.addText("\n ");
modules.addElement("module").setText(artifactId);
modules.addText("\n ");
XMLWriter writer = new XMLWriter(fileWriter);
writer.write(document);
}
return !found;
}
use of org.dom4j.io.SAXReader in project spring-framework by spring-projects.
the class XsltViewTests method assertHtmlOutput.
@SuppressWarnings("rawtypes")
private void assertHtmlOutput(String output) throws Exception {
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(output));
List nodes = document.getRootElement().selectNodes("/html/body/table/tr");
Element tr1 = (Element) nodes.get(0);
assertRowElement(tr1, "1", "Whatsit", "12.99");
Element tr2 = (Element) nodes.get(1);
assertRowElement(tr2, "2", "Thingy", "13.99");
Element tr3 = (Element) nodes.get(2);
assertRowElement(tr3, "3", "Gizmo", "14.99");
Element tr4 = (Element) nodes.get(3);
assertRowElement(tr4, "4", "Cranktoggle", "11.99");
}
Aggregations