コード例 #1
0
ファイル: TemplatesPool.java プロジェクト: ashish0038/rahasia
  /**
   * Return a new {@link TransformerHandler} based on a given precompiled {@link Templates}. The
   * handler {@link Transformer}'s {@link ErrorListener} is set to {@link TransformerErrorListener}
   * to raise exceptions and give proper warnings.
   */
  public TransformerHandler newTransformerHandler(Templates template)
      throws TransformerConfigurationException {
    final TransformerHandler handler = this.tFactory.newTransformerHandler(template);

    /*
     * We want to raise transformer exceptions on <xml:message terminate="true">, so
     * we add a custom listener. Also, various XSLT processors react in different ways
     * to transformation errors -- some of them report error as recoverable, some of
     * them report error as unrecoverable.
     */
    handler.getTransformer().setErrorListener(new TransformerErrorListener());
    return handler;
  }
コード例 #2
0
  public void write(HttpServletResponse response) {
    StreamResult streamResult;
    SAXTransformerFactory tf;
    TransformerHandler hd;
    Transformer serializer;

    try {
      try {
        streamResult = new StreamResult(response.getWriter());
        tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        hd = tf.newTransformerHandler();
        serializer = hd.getTransformer();

        serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
        serializer.setOutputProperty(
            OutputKeys.DOCTYPE_SYSTEM, "http://labs.omniti.com/resmon/trunk/resources/resmon.dtd");
        serializer.setOutputProperty(OutputKeys.INDENT, "yes");

        hd.setResult(streamResult);
        hd.startDocument();
        AttributesImpl atts = new AttributesImpl();
        hd.startElement("", "", "ResmonResults", atts);
        for (ResmonResult r : s) {
          r.write(hd);
        }
        hd.endElement("", "", "ResmonResults");
        hd.endDocument();
      } catch (TransformerConfigurationException tce) {
        response.getWriter().println(tce.getMessage());
      } catch (SAXException se) {
        response.getWriter().println(se.getMessage());
      }
    } catch (IOException ioe) {
    }
  }