Пример #1
0
  /** Transform a SAX Source to a TinyTree. */
  public static DocumentInfo readTinyTree(
      Configuration configuration, Source source, boolean handleXInclude) {
    final TinyBuilder treeBuilder = new TinyBuilder();
    try {
      if (handleXInclude) {
        // Insert XIncludeContentHandler
        final TransformerXMLReceiver identityHandler = getIdentityTransformerHandler(configuration);
        identityHandler.setResult(treeBuilder);
        final XMLReceiver receiver =
            new XIncludeProcessor.XIncludeXMLReceiver(
                null,
                identityHandler,
                null,
                new TransformerURIResolver(XMLUtils.ParserConfiguration.PLAIN));
        TransformerUtils.sourceToSAX(source, receiver);
      } else {
        final Transformer identity = getIdentityTransformer(configuration);
        identity.transform(source, treeBuilder);
      }

    } catch (TransformerException e) {
      throw new OXFException(e);
    }
    return (DocumentInfo) treeBuilder.getCurrentRoot();
  }
Пример #2
0
  /**
   * Transform a SAXStore into a DOM document
   *
   * @param saxStore input SAXStore
   * @return DOM document
   */
  public static org.w3c.dom.Document saxStoreToDomDocument(SAXStore saxStore) {
    try {
      // Convert to dom4j and then to DOM
      return TransformerUtils.dom4jToDomDocument(saxStoreToDom4jDocument(saxStore));
    } catch (TransformerException e) {
      throw new OXFException(e);
    }

    // NOTE: The more straight and efficient implementation below doesn't seem to work
    //        final TransformerHandler identity = getIdentityTransformerHandler();
    //        final DOMResult domResult = new DOMResult();
    //        identity.setResult(domResult);
    //        try {
    //            saxStore.replay(identity);
    //        } catch (SAXException e) {
    //            throw new OXFException(e);
    //        }
    //        return domResult.getNode().getOwnerDocument();
  }