Search in sources :

Example 16 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class XmlUtils method canonicalize.

public static String canonicalize(String input) throws IOException {
    XmlWriter xmlWriter = new XmlWriter();
    xmlWriter.setIncludeComments(false);
    ContentHandler handler = new PrettyPrintFilter(xmlWriter);
    handler = new CanonicalizeFilter(handler);
    try {
        XmlUtils.parseXml(input, handler);
        return xmlWriter.toString();
    } catch (SAXException e) {
        throw new IOException("ERROR: could not canonicalize [" + input + "]", e);
    }
}
Also used : CanonicalizeFilter(nl.nn.adapterframework.xml.CanonicalizeFilter) IOException(java.io.IOException) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) XmlValidatorContentHandler(nl.nn.adapterframework.validation.XmlValidatorContentHandler) ContentHandler(org.xml.sax.ContentHandler) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter) SAXException(org.xml.sax.SAXException)

Example 17 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class OnlyActiveFilterTest method testToWriter.

public void testToWriter(String source, String expected) throws Exception {
    StringWriter target = new StringWriter();
    XmlWriter xmlWriter = new XmlWriter(target);
    OnlyActiveFilter filter = new OnlyActiveFilter(xmlWriter);
    XmlUtils.parseXml(source, filter);
    String actual = new String(target.toString());
    assertEquals(expected, actual);
}
Also used : StringWriter(java.io.StringWriter) OnlyActiveFilter(nl.nn.adapterframework.configuration.filters.OnlyActiveFilter) XmlWriter(nl.nn.adapterframework.xml.XmlWriter)

Example 18 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class ConfigurationDigesterTest method testNewCanonicalizer.

@Test
public void testNewCanonicalizer() throws Exception {
    XmlWriter writer = new XmlWriter();
    ConfigurationDigester digester = new ConfigurationDigester();
    ContentHandler handler = digester.getConfigurationCanonicalizer(writer, FRANK_CONFIG_XSD, new XmlErrorHandler());
    Resource resource = Resource.getResource("/Digester/SimpleConfiguration/Configuration.xml");
    XmlUtils.parseXml(resource, handler);
    String result = writer.toString();
    String expected = TestFileUtils.getTestFile("/Digester/Canonicalized/SimpleConfiguration.xml");
    MatchUtils.assertXmlEquals(expected, result);
}
Also used : Resource(nl.nn.adapterframework.core.Resource) ConfigurationDigester(nl.nn.adapterframework.configuration.ConfigurationDigester) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) ContentHandler(org.xml.sax.ContentHandler) Test(org.junit.Test)

Example 19 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class ConfigurationDigesterTest method testFixedValueAttributeResolverWithFrankConfig.

@Test
public void testFixedValueAttributeResolverWithFrankConfig() throws Exception {
    URL schemaURL = TestFileUtils.getTestFileURL(FRANK_CONFIG_XSD);
    ValidatorHandler validatorHandler = XmlUtils.getValidatorHandler(schemaURL);
    XmlWriter writer = new XmlWriter();
    validatorHandler.setContentHandler(writer);
    validatorHandler.setErrorHandler(new XmlErrorHandler());
    Resource resource = Resource.getResource("/Digester/PreParsedConfiguration.xml");
    assertNotNull(resource);
    XmlUtils.parseXml(resource, validatorHandler);
    String expected = TestFileUtils.getTestFile("/Digester/resolvedPreParsedConfiguration.xml");
    assertEquals(expected, writer.toString().trim());
}
Also used : ValidatorHandler(javax.xml.validation.ValidatorHandler) Resource(nl.nn.adapterframework.core.Resource) URL(java.net.URL) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) Test(org.junit.Test)

Example 20 with XmlWriter

use of nl.nn.adapterframework.xml.XmlWriter in project iaf by ibissource.

the class ConfigurationDigesterTest method testNewConfigurationPreParser.

// Both OLD and NEW configuration parsers should set the same values for 'loadedConfiguration': properties resolved, secrets hidden
// The new configuration parser returns the configuration with all property not yet resolved
@Test
public void testNewConfigurationPreParser() throws Exception {
    ConfigurationDigester digester = new ConfigurationDigester();
    Resource resource = Resource.getResource("/Digester/SimpleConfiguration/Configuration.xml");
    Properties properties = new Properties();
    properties.setProperty("HelloWorld.active", "false");
    properties.setProperty("HelloBeautifulWorld.active", "!false");
    // new style non-escaped property values
    properties.setProperty("digester.property", "[ >\"< ]");
    properties.setProperty("secret", "GEHEIM");
    properties.setProperty("properties.hide", "secret");
    Configuration configuration = new TestConfiguration();
    XmlWriter loadedConfigWriter = new XmlWriter();
    digester.parseAndResolveEntitiesAndProperties(loadedConfigWriter, configuration, resource, properties);
    String result = loadedConfigWriter.toString();
    String expected = TestFileUtils.getTestFile("/Digester/Loaded/SimpleConfigurationUnresolved.xml");
    MatchUtils.assertXmlEquals(expected, result);
    String storedResult = configuration.getLoadedConfiguration();
    String storedExpected = TestFileUtils.getTestFile("/Digester/Loaded/SimpleConfigurationResolvedAndHidden.xml");
    MatchUtils.assertXmlEquals(storedExpected, storedResult);
    loadedConfigWriter = new XmlWriter();
    properties.setProperty(STUB4TESTTOOL_CONFIGURATION_KEY, "true");
    digester.parseAndResolveEntitiesAndProperties(loadedConfigWriter, configuration, resource, properties);
    String stubbedExpected = TestFileUtils.getTestFile("/Digester/Loaded/SimpleConfigurationStubbed.xml");
    MatchUtils.assertXmlEquals(stubbedExpected, loadedConfigWriter.toString());
}
Also used : TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Configuration(nl.nn.adapterframework.configuration.Configuration) Resource(nl.nn.adapterframework.core.Resource) TestConfiguration(nl.nn.adapterframework.testutil.TestConfiguration) Properties(java.util.Properties) ConfigurationDigester(nl.nn.adapterframework.configuration.ConfigurationDigester) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) Test(org.junit.Test)

Aggregations

XmlWriter (nl.nn.adapterframework.xml.XmlWriter)33 Test (org.junit.Test)15 PrettyPrintFilter (nl.nn.adapterframework.xml.PrettyPrintFilter)11 ContentHandler (org.xml.sax.ContentHandler)11 SAXException (org.xml.sax.SAXException)9 Resource (nl.nn.adapterframework.core.Resource)7 IOException (java.io.IOException)6 StringWriter (java.io.StringWriter)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Writer (java.io.Writer)4 XmlTee (nl.nn.adapterframework.stream.xml.XmlTee)4 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 URL (java.net.URL)3 ValidatorHandler (javax.xml.validation.ValidatorHandler)3 ConfigurationDigester (nl.nn.adapterframework.configuration.ConfigurationDigester)3 Message (nl.nn.adapterframework.stream.Message)3 JsonWriter (nl.nn.adapterframework.stream.json.JsonWriter)3 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)3 Properties (java.util.Properties)2