use of org.jdom.input.SAXBuilder in project wildfly-camel by wildfly-extras.
the class StandaloneConfigTest method testUnsupportedNamespaceVersion.
@Test
public void testUnsupportedNamespaceVersion() throws Exception {
URL resurl = StandaloneConfigTest.class.getResource("/standalone.xml");
SAXBuilder jdom = new SAXBuilder();
Document doc = jdom.build(resurl);
doc.getRootElement().getChild("extensions", NS_DOMAIN_60).setNamespace(Namespace.getNamespace("urn:jboss:domain:99.99"));
File modifiedConfig = new File("target/standalone-modified.xml");
outputDocumentContent(doc, new FileOutputStream(modifiedConfig));
jdom = new SAXBuilder();
doc = jdom.build(modifiedConfig);
ConfigContext context = ConfigSupport.createContext(null, modifiedConfig.toPath(), doc);
ConfigPlugin plugin = new WildFlyCamelConfigPlugin();
expectedException.expect(ConfigException.class);
plugin.applyStandaloneConfigChange(context, true);
}
use of org.jdom.input.SAXBuilder in project wildfly-camel by wildfly-extras.
the class StandaloneConfigTest method testRemoveConfig.
@Test
public void testRemoveConfig() throws Exception {
URL resurl = StandaloneConfigTest.class.getResource("/standalone.xml");
SAXBuilder jdom = new SAXBuilder();
Document doc = jdom.build(resurl);
File modifiedConfig = new File("target/standalone-modified.xml");
outputDocumentContent(doc, new FileOutputStream(modifiedConfig));
jdom = new SAXBuilder();
doc = jdom.build(modifiedConfig);
ConfigPlugin plugin = new WildFlyCamelConfigPlugin();
ConfigContext context = ConfigSupport.createContext(null, Paths.get(resurl.toURI()), doc);
plugin.applyStandaloneConfigChange(context, false);
// Verify extension removed
assertElementWithAttributeValueNull(doc.getRootElement(), "extension", "module", "org.wildfly.extension.camel", NS_DOMAINS);
// Verify system-properties removed
Element element = ConfigSupport.findChildElement(doc.getRootElement(), "system-properties", NS_DOMAINS);
Assert.assertNotNull("system-properties not null", element);
assertElementWithAttributeValueNull(element, "property", "name", "hawtio.realm", NS_DOMAINS);
assertElementWithAttributeValueNull(element, "property", "name", "hawtio.offline", NS_DOMAINS);
assertElementWithAttributeValueNull(element, "property", "name", "hawtio.authenticationEnabled", NS_DOMAINS);
assertElementWithAttributeValueNull(element, "property", "name", "ee8.preview.mode", NS_DOMAINS);
List<Element> profiles = ConfigSupport.findProfileElements(doc, NS_DOMAINS);
// Verify camel removed
assertElementNull(profiles.get(0), "subsystem", NS_CAMEL);
// Verify hawtio-domain removed
assertElementWithAttributeValueNull(doc.getRootElement(), "security-domain", "name", "hawtio-domain", NS_SECURITY);
}
use of org.jdom.input.SAXBuilder in project oozie by apache.
the class XmlUtils method parseXml.
/**
* Parse a string assuming it is a valid XML document and return an JDOM Element for it.
*
* @param xmlStr XML string to parse.
* @return JDOM element for the parsed XML string.
* @throws JDOMException thrown if an error happend while XML parsing.
*/
public static Element parseXml(String xmlStr) throws JDOMException {
ParamChecker.notNull(xmlStr, "xmlStr");
try {
SAXBuilder saxBuilder = createSAXBuilder();
Document document = saxBuilder.build(new StringReader(xmlStr));
return document.getRootElement();
} catch (IOException ex) {
throw new RuntimeException("It should not happen, " + ex.getMessage(), ex);
}
}
use of org.jdom.input.SAXBuilder in project oozie by apache.
the class XmlUtils method createSAXBuilder.
private static SAXBuilder createSAXBuilder() {
SAXBuilder saxBuilder = new SAXBuilder();
saxBuilder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
saxBuilder.setFeature("http://xml.org/sax/features/external-general-entities", false);
saxBuilder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
saxBuilder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
return saxBuilder;
}
use of org.jdom.input.SAXBuilder in project com.revolsys.open by revolsys.
the class TestReader method newTestRun.
public TestFile newTestRun(final TestDirectory parent, final File testFile, final int runIndex) throws Throwable {
try {
final SAXBuilder builder = new LineNumberSAXBuilder();
final Document document = builder.build(new FileInputStream(testFile));
final Element runElement = document.getRootElement();
if (!runElement.getName().equalsIgnoreCase("run")) {
throw new TestParseException("Expected <run> but encountered <" + runElement.getName() + ">");
}
return parseTestRun(parent, runElement, testFile, runIndex);
} catch (final IllegalArgumentException e) {
throw e;
} catch (final Exception e) {
throw new IllegalArgumentException("Error parsing " + testFile, e);
}
}
Aggregations