示例#1
0
  public static org.dom4j.Document createDocument(DebugXML debugXML) {
    final TransformerXMLReceiver identity = TransformerUtils.getIdentityTransformerHandler();
    final LocationDocumentResult result = new LocationDocumentResult();
    identity.setResult(result);

    final ContentHandlerHelper helper =
        new ContentHandlerHelper(
            new ForwardingXMLReceiver(identity) {
              @Override
              public void startDocument() {}

              @Override
              public void endDocument() {}
            });

    try {
      identity.startDocument();
      debugXML.toXML(helper);
      identity.endDocument();
    } catch (SAXException e) {
      throw new OXFException(e);
    }

    return result.getDocument();
  }
示例#2
0
  public static String domToString(Node node) {
    try {
      Transformer transformer = TransformerUtils.getXMLIdentityTransformer();
      DOMSource source = new DOMSource(node);

      StringBuilderWriter writer = new StringBuilderWriter();
      transformer.transform(source, new StreamResult(writer));
      return writer.toString();
    } catch (TransformerException e) {
      throw new OXFException(e);
    }
  }
    private XMLReceiver getDebugReceiver(final IndentedLogger indentedLogger) {
      final TransformerXMLReceiver identity = TransformerUtils.getIdentityTransformerHandler();
      final StringBuilderWriter writer = new StringBuilderWriter();
      identity.setResult(new StreamResult(writer));

      return new ForwardingXMLReceiver(identity) {
        @Override
        public void endDocument() throws SAXException {
          super.endDocument();
          // Log out at end of document
          indentedLogger.logDebug("", "static state input", "input", writer.toString());
        }
      };
    }
示例#4
0
 /** Compute a digest for a SAX source. */
 public static byte[] getDigest(Source source) {
   final DigestContentHandler digester = new DigestContentHandler();
   TransformerUtils.sourceToSAX(source, digester);
   return digester.getResult();
 }
    public StaticStateBits(
        PipelineContext pipelineContext,
        ExternalContext externalContext,
        IndentedLogger indentedLogger,
        String existingStaticStateDigest) {

      final boolean computeDigest = isLogStaticStateInput || existingStaticStateDigest == null;

      indentedLogger.startHandleOperation(
          "", "reading input", "existing digest", existingStaticStateDigest);

      final TransformerXMLReceiver documentReceiver =
          TransformerUtils.getIdentityTransformerHandler();
      final LocationDocumentResult documentResult = new LocationDocumentResult();
      documentReceiver.setResult(documentResult);

      final XMLUtils.DigestContentHandler digestReceiver =
          computeDigest ? new XMLUtils.DigestContentHandler("MD5") : null;
      final XMLReceiver extractorOutput;
      if (isLogStaticStateInput) {
        extractorOutput =
            computeDigest
                ? new TeeXMLReceiver(
                    documentReceiver, digestReceiver, getDebugReceiver(indentedLogger))
                : new TeeXMLReceiver(documentReceiver, getDebugReceiver(indentedLogger));
      } else {
        extractorOutput =
            computeDigest ? new TeeXMLReceiver(documentReceiver, digestReceiver) : documentReceiver;
      }

      // Read the input through the annotator and gather namespace mappings
      //
      // Output of annotator is:
      //
      // o annotated page template (TODO: this should not include model elements)
      // o extractor
      //
      // Output of extractor is:
      //
      // o static state document
      // o optionally: digest
      // o optionally: debug output
      //
      readInputAsSAX(
          pipelineContext,
          INPUT_ANNOTATED_DOCUMENT,
          new XFormsAnnotatorContentHandler(
              annotatedTemplate,
              new XFormsExtractorContentHandler(extractorOutput, metadata),
              metadata));

      this.staticStateDocument = documentResult.getDocument();
      this.staticStateDigest =
          computeDigest ? NumberUtils.toHexString(digestReceiver.getResult()) : null;

      assert !isLogStaticStateInput
          || existingStaticStateDigest == null
          || this.staticStateDigest.equals(existingStaticStateDigest);

      indentedLogger.endHandleOperation("computed digest", this.staticStateDigest);
    }