Ejemplo n.º 1
0
  /** Public default constructor. */
  public JDOMResult() {
    // Allocate custom builder object...
    DocumentBuilder builder = new DocumentBuilder();

    // And use it as ContentHandler and LexicalHandler.
    super.setHandler(builder);
    super.setLexicalHandler(builder);
  }
Ejemplo n.º 2
0
 /** Transform a SAX source to SAX events. */
 public static void sourceToSAX(Source source, XMLReceiver xmlReceiver) {
   try {
     final Transformer identity = getIdentityTransformer();
     final SAXResult saxResult = new SAXResult(xmlReceiver);
     saxResult.setLexicalHandler(xmlReceiver);
     identity.transform(source, saxResult);
   } catch (TransformerException e) {
     throw new OXFException(e);
   }
 }
 @Override
 protected void marshalSaxHandlers(
     Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
     throws XmlMappingException {
   try {
     // JiBX does not support SAX natively, so we write to a buffer first, and transform that to
     // the handlers
     SAXResult saxResult = new SAXResult(contentHandler);
     saxResult.setLexicalHandler(lexicalHandler);
     transformAndMarshal(graph, saxResult);
   } catch (IOException ex) {
     throw new MarshallingFailureException("JiBX marshalling exception", ex);
   }
 }
 /* (non-Javadoc)
  * @see org.exist.collections.Trigger#prepare(java.lang.String, org.w3c.dom.Document)
  */
 public void prepare(
     int event,
     DBBroker broker,
     Txn transaction,
     XmldbURI documentName,
     DocumentImpl existingDocument)
     throws TriggerException {
   SAXResult result = new SAXResult();
   result.setHandler(getOutputHandler());
   result.setLexicalHandler(getLexicalOutputHandler());
   handler.setResult(result);
   setOutputHandler(handler);
   setLexicalOutputHandler(handler);
 }
Ejemplo n.º 5
0
  @Override
  protected void setSAXConsumer(SAXConsumer consumer) {
    TransformerHandler handler = createTransformerHandler();

    if (consumer instanceof SaxonSerializer) {
      // serializer will finish setup of handler result
      SaxonSerializer serializer = (SaxonSerializer) consumer;
      serializer.setTransformerHandler(handler);
    } else {
      SAXResult result = new SAXResult();
      result.setHandler(consumer);
      // According to TrAX specification, all TransformerHandlers are LexicalHandlers
      result.setLexicalHandler(consumer);
      handler.setResult(result);
    }

    SAXConsumerAdapter saxConsumerAdapter = new SAXConsumerAdapter();
    saxConsumerAdapter.setContentHandler(handler);

    super.setSAXConsumer(saxConsumerAdapter);
  }
Ejemplo n.º 6
0
  /** Set the <code>XMLConsumer</code> that will receive XML data. */
  public void setConsumer(XMLConsumer consumer) {

    if (this.transformerHandler == null) {
      try {
        this.transformerHandler = this.xsltProcessor.getTransformerHandler(this.inputSource);
      } catch (XSLTProcessorException se) {
        // the exception will be thrown during startDocument()
        this.exceptionDuringSetConsumer =
            new SAXException(
                "Unable to get transformer handler for " + this.inputSource.getURI(), se);
        return;
      }
    }
    final Map map = getLogicSheetParameters();
    if (map != null) {
      final javax.xml.transform.Transformer transformer = this.transformerHandler.getTransformer();
      final Iterator iterator = map.entrySet().iterator();
      while (iterator.hasNext()) {
        final Map.Entry entry = (Entry) iterator.next();
        transformer.setParameter((String) entry.getKey(), entry.getValue());
      }
    }

    super.setContentHandler(this.transformerHandler);
    super.setLexicalHandler(this.transformerHandler);

    if (this.transformerHandler instanceof LogEnabled) {
      ((LogEnabled) this.transformerHandler).enableLogging(getLogger());
    }
    // According to TrAX specs, all TransformerHandlers are LexicalHandlers
    final SAXResult result = new SAXResult(consumer);
    result.setLexicalHandler(consumer);
    this.transformerHandler.setResult(result);

    this.errorListener = new TraxErrorListener(getLogger(), this.inputSource.getURI());
    this.transformerHandler.getTransformer().setErrorListener(this.errorListener);
  }