Search in sources :

Example 1 with EncapsulatingReader

use of nl.nn.adapterframework.util.EncapsulatingReader in project iaf by ibissource.

the class FileViewerServlet method showReaderContents.

public static void showReaderContents(Reader reader, String filename, String type, HttpServletResponse response, String title) throws DomBuilderException, TransformerException, IOException {
    PrintWriter out = response.getWriter();
    if (type == null) {
        response.setContentType("text/html");
        out.println("resultType not specified");
        return;
    }
    if (type.equalsIgnoreCase("html")) {
        response.setContentType("text/html");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>" + AppConstants.getInstance().getResolvedProperty("instance.name.lc") + "@" + Misc.getHostname() + " - " + title + "</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + AppConstants.getInstance().getProperty(fvConfigKey + ".css") + "\">");
        out.println("</head>");
        out.println("<body>");
        LineNumberReader lnr = new LineNumberReader(reader);
        String line;
        while ((line = lnr.readLine()) != null) {
            out.println(makeConfiguredReplacements(XmlUtils.encodeChars(line)) + "<br/>");
        }
        out.println("</body>");
        out.println("</html>");
    }
    if (type.equalsIgnoreCase("text")) {
        response.setContentType("text/plain");
        String lastPart;
        try {
            File f = new File(filename);
            lastPart = f.getName();
        } catch (Throwable t) {
            lastPart = filename;
        }
        response.setHeader("Content-Disposition", "attachment; filename=\"" + lastPart + "\"");
        Misc.readerToWriter(reader, out);
    }
    if (type.equalsIgnoreCase("xml")) {
        response.setContentType("application/xml");
        String lastPart;
        try {
            File f = new File(filename);
            lastPart = f.getName();
        } catch (Throwable t) {
            lastPart = filename;
        }
        response.setHeader("Content-Disposition", "inline; filename=\"" + lastPart + "\"");
        LineNumberReader lnr;
        if (filename.indexOf("_xml.log") >= 0) {
            Reader fileReader = new EncapsulatingReader(reader, log4j_prefix, log4j_postfix, true);
            lnr = new LineNumberReader(fileReader);
        } else {
            if (filename.indexOf("-stats_") >= 0) {
                Reader fileReader = new EncapsulatingReader(reader, stats_prefix, stats_postfix, true);
                lnr = new LineNumberReader(fileReader);
            } else {
                lnr = new LineNumberReader(reader);
            }
        }
        String line;
        while ((line = lnr.readLine()) != null) {
            out.println(line + "\n");
        }
    }
    out.close();
}
Also used : EncapsulatingReader(nl.nn.adapterframework.util.EncapsulatingReader) EncapsulatingReader(nl.nn.adapterframework.util.EncapsulatingReader) LineNumberReader(java.io.LineNumberReader) Reader(java.io.Reader) FileReader(java.io.FileReader) File(java.io.File) PrintWriter(java.io.PrintWriter) LineNumberReader(java.io.LineNumberReader)

Example 2 with EncapsulatingReader

use of nl.nn.adapterframework.util.EncapsulatingReader in project iaf by ibissource.

the class FileViewerServlet method transformReader.

public static void transformReader(Reader reader, String filename, Map parameters, HttpServletResponse response, String input_prefix, String input_postfix, String stylesheetUrl, String title) throws DomBuilderException, TransformerException, IOException {
    PrintWriter out = response.getWriter();
    Reader fileReader = new EncapsulatingReader(reader, input_prefix, input_postfix, true);
    URL xsltSource = ClassUtils.getResourceURL(FileViewerServlet.class, stylesheetUrl);
    if (xsltSource != null) {
        Transformer transformer = XmlUtils.createTransformer(xsltSource);
        if (parameters != null) {
            XmlUtils.setTransformerParameters(transformer, parameters);
        }
        XmlUtils.transformXml(transformer, new StreamSource(fileReader), out);
        out.close();
    } else {
        showReaderContents(fileReader, filename, "text", response, title);
    }
}
Also used : EncapsulatingReader(nl.nn.adapterframework.util.EncapsulatingReader) Transformer(javax.xml.transform.Transformer) StreamSource(javax.xml.transform.stream.StreamSource) EncapsulatingReader(nl.nn.adapterframework.util.EncapsulatingReader) LineNumberReader(java.io.LineNumberReader) Reader(java.io.Reader) FileReader(java.io.FileReader) URL(java.net.URL) PrintWriter(java.io.PrintWriter)

Example 3 with EncapsulatingReader

use of nl.nn.adapterframework.util.EncapsulatingReader in project iaf by ibissource.

the class Text2XmlPipe method doPipe.

/**
 * @see nl.nn.adapterframework.core.IPipe#doPipe(Object, IPipeLineSession)
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (isSplitLines() && input != null) {
        try {
            Reader reader = new StringReader(input.toString());
            if (replaceNonXmlChars) {
                reader = new EncapsulatingReader(reader, "", "", true);
            }
            BufferedReader br = new BufferedReader(reader);
            String l;
            StringBuffer result = new StringBuffer();
            while ((l = br.readLine()) != null) {
                result.append("<line>" + addCdataSection(l) + "</line>");
            }
            input = result.toString();
            br.close();
        } catch (IOException e) {
            throw new PipeRunException(this, "Unexpected exception during splitting", e);
        }
    } else if (replaceNonXmlChars && input != null) {
        input = addCdataSection(XmlUtils.encodeCdataString(input.toString()));
    } else {
        input = addCdataSection((input == null ? null : input.toString()));
    }
    String resultString = (isIncludeXmlDeclaration() ? "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" : "") + "<" + getXmlTag() + ">" + input + "</" + xmlTag + ">";
    return new PipeRunResult(getForward(), resultString);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) EncapsulatingReader(nl.nn.adapterframework.util.EncapsulatingReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StringReader(java.io.StringReader) EncapsulatingReader(nl.nn.adapterframework.util.EncapsulatingReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) IOException(java.io.IOException)

Example 4 with EncapsulatingReader

use of nl.nn.adapterframework.util.EncapsulatingReader in project iaf by ibissource.

the class StatisticsParser method digestStatistics.

public void digestStatistics(Reader reader, String sysid) throws ConfigurationException {
    Reader fileReader = new EncapsulatingReader(reader, "<" + ROOT_ELEM_NAME + ">", "</" + ROOT_ELEM_NAME + ">", false);
    Digester digester = new Digester();
    digester.setUseContextClassLoader(true);
    // push config on the stack
    digester.push(this);
    try {
        // String prefix="/"+ROOT_ELEM_NAME+"/";
        String prefix = "*/";
        // timestamp info
        digester.addSetProperties(prefix + "statisticsCollection");
        // instance info
        digester.addSetProperties(prefix + "statisticsCollection/statgroup");
        // adapterinfo
        digester.addObjectCreate(prefix + "statisticsCollection/statgroup/statgroup", SummaryRecord.class);
        digester.addSetProperties(prefix + "statisticsCollection/statgroup/statgroup");
        digester.addSetNext(prefix + "statisticsCollection/statgroup/statgroup", "registerRecord");
        // adapterinfo
        digester.addObjectCreate(prefix + "statisticsCollection/statgroup/statgroup/stat/interval/item", Item.class);
        digester.addSetProperties(prefix + "statisticsCollection/statgroup/statgroup/stat/interval/item");
        digester.addSetNext(prefix + "statisticsCollection/statgroup/statgroup/stat/interval/item", "registerItem");
        InputSource is = new InputSource(fileReader);
        digester.parse(is);
    } catch (Exception e) {
        // wrap exception to be sure it gets rendered via the IbisException-renderer
        throw new ConfigurationException("error during parsing of file [" + sysid + "]", e);
    }
}
Also used : EncapsulatingReader(nl.nn.adapterframework.util.EncapsulatingReader) InputSource(org.xml.sax.InputSource) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Digester(org.apache.commons.digester.Digester) Reader(java.io.Reader) EncapsulatingReader(nl.nn.adapterframework.util.EncapsulatingReader) FileReader(java.io.FileReader) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Reader (java.io.Reader)4 EncapsulatingReader (nl.nn.adapterframework.util.EncapsulatingReader)4 FileReader (java.io.FileReader)3 LineNumberReader (java.io.LineNumberReader)2 PrintWriter (java.io.PrintWriter)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 Transformer (javax.xml.transform.Transformer)1 StreamSource (javax.xml.transform.stream.StreamSource)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 Digester (org.apache.commons.digester.Digester)1 InputSource (org.xml.sax.InputSource)1