Search in sources :

Example 31 with SAXBuilder

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);
}
Also used : ConfigPlugin(org.wildfly.extras.config.ConfigPlugin) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) SAXBuilder(org.jdom.input.SAXBuilder) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) FileOutputStream(java.io.FileOutputStream) Document(org.jdom.Document) File(java.io.File) URL(java.net.URL) ConfigContext(org.wildfly.extras.config.ConfigContext) Test(org.junit.Test)

Example 32 with SAXBuilder

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);
}
Also used : ConfigPlugin(org.wildfly.extras.config.ConfigPlugin) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) SAXBuilder(org.jdom.input.SAXBuilder) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) FileOutputStream(java.io.FileOutputStream) Element(org.jdom.Element) Document(org.jdom.Document) File(java.io.File) URL(java.net.URL) ConfigContext(org.wildfly.extras.config.ConfigContext) Test(org.junit.Test)

Example 33 with SAXBuilder

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);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) StringReader(java.io.StringReader) IOException(java.io.IOException) Document(org.jdom.Document)

Example 34 with SAXBuilder

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;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder)

Example 35 with 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);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) LineNumberSAXBuilder(com.revolsys.geometry.test.util.LineNumberSAXBuilder) LineNumberElement(com.revolsys.geometry.test.util.LineNumberElement) Element(org.jdom.Element) Document(org.jdom.Document) LineNumberSAXBuilder(com.revolsys.geometry.test.util.LineNumberSAXBuilder) FileInputStream(java.io.FileInputStream) DataConversionException(org.jdom.DataConversionException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)145 Document (org.jdom.Document)109 Element (org.jdom.Element)84 IOException (java.io.IOException)60 JDOMException (org.jdom.JDOMException)50 StringReader (java.io.StringReader)35 InputStream (java.io.InputStream)29 File (java.io.File)18 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 ArrayList (java.util.ArrayList)12 XPath (org.jdom.xpath.XPath)11 HttpMethod (org.apache.commons.httpclient.HttpMethod)10 XMLOutputter (org.jdom.output.XMLOutputter)10 URL (java.net.URL)9 List (java.util.List)8 GoraException (org.apache.gora.util.GoraException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 Namespace (org.jdom.Namespace)6 StringWriter (java.io.StringWriter)5