Search in sources :

Example 1 with PrettyPrintFilter

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

the class MessageOutputStream method captureBinaryStream.

@SuppressWarnings("resource")
public void captureBinaryStream(OutputStream outputStream, int maxSize) {
    log.debug("creating capture of " + ClassUtils.nameOf(requestStream));
    closeOnClose(outputStream);
    if (requestStream instanceof OutputStream) {
        requestStream = StreamUtil.captureOutputStream((OutputStream) requestStream, outputStream, maxSize);
        return;
    }
    if (requestStream instanceof ContentHandler) {
        requestStream = new XmlTee((ContentHandler) requestStream, new PrettyPrintFilter(new XmlWriter(StreamUtil.limitSize(outputStream, maxSize))));
        return;
    }
    if (requestStream instanceof JsonEventHandler) {
        requestStream = new JsonTee((JsonEventHandler) requestStream, new JsonWriter(StreamUtil.limitSize(outputStream, maxSize)));
        return;
    }
    if (requestStream instanceof Writer) {
        requestStream = StreamUtil.captureWriter((Writer) requestStream, new OutputStreamWriter(outputStream, StreamUtil.DEFAULT_CHARSET), maxSize);
        return;
    }
    log.warn("captureBinaryStream() called before stream is installed.");
}
Also used : XmlTee(nl.nn.adapterframework.stream.xml.XmlTee) JsonTee(nl.nn.adapterframework.stream.json.JsonTee) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(nl.nn.adapterframework.stream.json.JsonWriter) ContentHandler(org.xml.sax.ContentHandler) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(nl.nn.adapterframework.stream.json.JsonWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter)

Example 2 with PrettyPrintFilter

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

the class MessageOutputStream method captureCharacterStream.

@SuppressWarnings("resource")
public void captureCharacterStream(Writer writer, int maxSize) {
    log.debug("creating capture of " + ClassUtils.nameOf(requestStream));
    closeOnClose(writer);
    if (requestStream instanceof Writer) {
        requestStream = StreamUtil.captureWriter((Writer) requestStream, writer, maxSize);
        return;
    }
    if (requestStream instanceof ContentHandler) {
        requestStream = new XmlTee((ContentHandler) requestStream, new PrettyPrintFilter(new XmlWriter(StreamUtil.limitSize(writer, maxSize))));
        return;
    }
    if (requestStream instanceof JsonEventHandler) {
        requestStream = new JsonTee((JsonEventHandler) requestStream, new JsonWriter(StreamUtil.limitSize(writer, maxSize)));
        return;
    }
    if (requestStream instanceof OutputStream) {
        requestStream = StreamUtil.captureOutputStream((OutputStream) requestStream, new WriterOutputStream(writer, StreamUtil.DEFAULT_CHARSET), maxSize);
        return;
    }
    log.warn("captureCharacterStream() called before stream is installed.");
}
Also used : XmlTee(nl.nn.adapterframework.stream.xml.XmlTee) JsonTee(nl.nn.adapterframework.stream.json.JsonTee) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) WriterOutputStream(org.apache.commons.io.output.WriterOutputStream) JsonWriter(nl.nn.adapterframework.stream.json.JsonWriter) OutputStreamWriter(java.io.OutputStreamWriter) JsonWriter(nl.nn.adapterframework.stream.json.JsonWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) ContentHandler(org.xml.sax.ContentHandler) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter)

Example 3 with PrettyPrintFilter

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

the class XmlBuilder method toXML.

public String toXML(boolean xmlHeader) {
    XmlWriter writer = new XmlWriter();
    PrettyPrintFilter ppf = new PrettyPrintFilter(writer);
    try {
        toXML(ppf);
    } catch (SAXException | IOException e) {
        log.warn("cannot write XML", e);
        return e.getMessage();
    }
    return writer.toString();
}
Also used : IOException(java.io.IOException) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter) SAXException(org.xml.sax.SAXException)

Example 4 with PrettyPrintFilter

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

the class MatchUtils method xmlPretty.

public static String xmlPretty(String xml, boolean removeNamespaces) {
    XmlWriter xmlWriter = new XmlWriter();
    xmlWriter.setIncludeComments(false);
    ContentHandler contentHandler = new PrettyPrintFilter(xmlWriter);
    if (removeNamespaces) {
        contentHandler = new NamespaceRemovingFilter(contentHandler);
    }
    try {
        XmlUtils.parseXml(xml, contentHandler);
        return xmlWriter.toString();
    } catch (IOException | SAXException e) {
        throw new RuntimeException("ERROR: could not prettify [" + xml + "]", e);
    }
}
Also used : IOException(java.io.IOException) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) ContentHandler(org.xml.sax.ContentHandler) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter) NamespaceRemovingFilter(nl.nn.adapterframework.xml.NamespaceRemovingFilter) SAXException(org.xml.sax.SAXException)

Example 5 with PrettyPrintFilter

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

the class ConfigurationDigester method parseAndResolveEntitiesAndProperties.

/**
 * Performs an Identity-transform, which resolves entities with content from files found on the ClassPath.
 * Resolve all non-attribute properties
 */
public void parseAndResolveEntitiesAndProperties(ContentHandler digester, Configuration configuration, Resource resource, Properties appConstants) throws IOException, SAXException, TransformerConfigurationException {
    ContentHandler handler;
    XmlWriter loadedHiddenWriter = new XmlWriter();
    handler = new PrettyPrintFilter(loadedHiddenWriter);
    handler = new AttributePropertyResolver(handler, appConstants, getPropsToHide(appConstants));
    handler = new XmlTee(digester, handler);
    handler = getStub4TesttoolContentHandler(handler, appConstants);
    handler = getConfigurationCanonicalizer(handler);
    handler = new OnlyActiveFilter(handler, appConstants);
    handler = new ElementPropertyResolver(handler, appConstants);
    XmlWriter originalConfigWriter = new XmlWriter();
    handler = new XmlTee(handler, originalConfigWriter);
    XmlUtils.parseXml(resource, handler);
    configuration.setOriginalConfiguration(originalConfigWriter.toString());
    configuration.setLoadedConfiguration(loadedHiddenWriter.toString());
}
Also used : XmlTee(nl.nn.adapterframework.stream.xml.XmlTee) AttributePropertyResolver(nl.nn.adapterframework.xml.AttributePropertyResolver) ElementPropertyResolver(nl.nn.adapterframework.xml.ElementPropertyResolver) OnlyActiveFilter(nl.nn.adapterframework.configuration.filters.OnlyActiveFilter) ContentHandler(org.xml.sax.ContentHandler) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) PrettyPrintFilter(nl.nn.adapterframework.xml.PrettyPrintFilter)

Aggregations

PrettyPrintFilter (nl.nn.adapterframework.xml.PrettyPrintFilter)12 XmlWriter (nl.nn.adapterframework.xml.XmlWriter)11 ContentHandler (org.xml.sax.ContentHandler)8 SAXException (org.xml.sax.SAXException)6 IOException (java.io.IOException)5 XmlTee (nl.nn.adapterframework.stream.xml.XmlTee)4 Writer (java.io.Writer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 StringWriter (java.io.StringWriter)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 SenderException (nl.nn.adapterframework.core.SenderException)2 Message (nl.nn.adapterframework.stream.Message)2 StreamingException (nl.nn.adapterframework.stream.StreamingException)2 JsonTee (nl.nn.adapterframework.stream.json.JsonTee)2 JsonWriter (nl.nn.adapterframework.stream.json.JsonWriter)2 WriterOutputStream (org.apache.commons.io.output.WriterOutputStream)2 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1