use of org.apache.cocoon.sax.component.XMLGenerator in project syncope by apache.
the class WADLServlet method doGet.
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
Matcher schemaMatcher = SCHEMA_PATTERN.matcher(request.getServletPath());
WadlGenerator wadlGenerator = ApplicationContextProvider.getApplicationContext().getBean(WadlGenerator.class);
String wadl = wadlGenerator.getWadl();
Pipeline<SAXPipelineComponent> pipeline = new CachingPipeline<>();
pipeline.addComponent(new XMLGenerator(wadl));
if ("/index.html".equals(request.getServletPath())) {
XSLTTransformer xslt = new XSLTTransformer(getClass().getResource("/wadl2html/index.xsl"));
Map<String, Object> parameters = new HashMap<>();
parameters.put("contextPath", request.getContextPath());
xslt.setParameters(parameters);
pipeline.addComponent(xslt);
finish(pipeline, response);
} else if (schemaMatcher.matches()) {
XSLTTransformer xslt = new XSLTTransformer(getClass().getResource("/wadl2html/schema.xsl"));
Map<String, Object> parameters = new HashMap<>();
parameters.put("contextPath", request.getContextPath());
parameters.put("schema-position", schemaMatcher.group(1));
parameters.put("schema-prefix", schemaMatcher.group(2));
xslt.setParameters(parameters);
pipeline.addComponent(xslt);
finish(pipeline, response);
} else if ("/syncope.wadl".equals(request.getServletPath())) {
response.setContentType(MediaType.APPLICATION_XML);
try (InputStream in = new ByteArrayInputStream(wadl.getBytes());
OutputStream out = response.getOutputStream()) {
IOUtils.copy(in, out);
}
} else {
throw new ServerException("URL not supported: " + request.getRequestURI());
}
}
use of org.apache.cocoon.sax.component.XMLGenerator in project syncope by apache.
the class ReportLogic method exportExecutionResult.
@PreAuthorize("hasRole('" + StandardEntitlement.REPORT_READ + "')")
public void exportExecutionResult(final OutputStream os, final ReportExec reportExec, final ReportExecExportFormat format) {
// streaming SAX handler from a compressed byte array stream
try (ByteArrayInputStream bais = new ByteArrayInputStream(reportExec.getExecResult());
ZipInputStream zis = new ZipInputStream(bais)) {
// a single ZipEntry in the ZipInputStream (see ReportJob)
zis.getNextEntry();
Pipeline<SAXPipelineComponent> pipeline = new NonCachingPipeline<>();
pipeline.addComponent(new XMLGenerator(zis));
Map<String, Object> parameters = new HashMap<>();
parameters.put("status", reportExec.getStatus());
parameters.put("message", reportExec.getMessage());
parameters.put("start", reportExec.getStart());
parameters.put("end", reportExec.getEnd());
switch(format) {
case HTML:
XSLTTransformer xsl2html = new XSLTTransformer(new StreamSource(IOUtils.toInputStream(reportExec.getReport().getTemplate().getHTMLTemplate(), StandardCharsets.UTF_8)));
xsl2html.setParameters(parameters);
pipeline.addComponent(xsl2html);
pipeline.addComponent(XMLSerializer.createXHTMLSerializer());
break;
case PDF:
XSLTTransformer xsl2pdf = new XSLTTransformer(new StreamSource(IOUtils.toInputStream(reportExec.getReport().getTemplate().getFOTemplate(), StandardCharsets.UTF_8)));
xsl2pdf.setParameters(parameters);
pipeline.addComponent(xsl2pdf);
pipeline.addComponent(new FopSerializer(MimeConstants.MIME_PDF));
break;
case RTF:
XSLTTransformer xsl2rtf = new XSLTTransformer(new StreamSource(IOUtils.toInputStream(reportExec.getReport().getTemplate().getFOTemplate(), StandardCharsets.UTF_8)));
xsl2rtf.setParameters(parameters);
pipeline.addComponent(xsl2rtf);
pipeline.addComponent(new FopSerializer(MimeConstants.MIME_RTF));
break;
case CSV:
XSLTTransformer xsl2csv = new XSLTTransformer(new StreamSource(IOUtils.toInputStream(reportExec.getReport().getTemplate().getCSVTemplate(), StandardCharsets.UTF_8)));
xsl2csv.setParameters(parameters);
pipeline.addComponent(xsl2csv);
pipeline.addComponent(new TextSerializer());
break;
case XML:
default:
pipeline.addComponent(XMLSerializer.createXMLSerializer());
}
pipeline.setup(os);
pipeline.execute();
LOG.debug("Result of {} successfully exported as {}", reportExec, format);
} catch (Exception e) {
LOG.error("While exporting content", e);
}
}
Aggregations