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();
}
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);
}
}
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);
}
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);
}
}
Aggregations