Java Code Examples for javax.xml.transform.sax.SAXResult#setLexicalHandler()

The following examples show how to use javax.xml.transform.sax.SAXResult#setLexicalHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MarshallingSource.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void parse() throws SAXException {
	SAXResult result = new SAXResult(getContentHandler());
	result.setLexicalHandler(getLexicalHandler());
	try {
		this.marshaller.marshal(this.content, result);
	}
	catch (IOException ex) {
		SAXParseException saxException = new SAXParseException(ex.getMessage(), null, null, -1, -1, ex);
		ErrorHandler errorHandler = getErrorHandler();
		if (errorHandler != null) {
			errorHandler.fatalError(saxException);
		}
		else {
			throw saxException;
		}
	}
}
 
Example 2
Source File: MarshallingSource.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void parse() throws SAXException {
	SAXResult result = new SAXResult(getContentHandler());
	result.setLexicalHandler(getLexicalHandler());
	try {
		this.marshaller.marshal(this.content, result);
	}
	catch (IOException ex) {
		SAXParseException saxException = new SAXParseException(ex.getMessage(), null, null, -1, -1, ex);
		ErrorHandler errorHandler = getErrorHandler();
		if (errorHandler != null) {
			errorHandler.fatalError(saxException);
		}
		else {
			throw saxException;
		}
	}
}
 
Example 3
Source File: MarshallingSource.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void parse() throws SAXException {
	SAXResult result = new SAXResult(getContentHandler());
	result.setLexicalHandler(getLexicalHandler());
	try {
		this.marshaller.marshal(this.content, result);
	}
	catch (IOException ex) {
		SAXParseException saxException = new SAXParseException(ex.getMessage(), null, null, -1, -1, ex);
		ErrorHandler errorHandler = getErrorHandler();
		if (errorHandler != null) {
			errorHandler.fatalError(saxException);
		}
		else {
			throw saxException;
		}
	}
}
 
Example 4
Source File: JibxMarshaller.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, @Nullable 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);
	}
}
 
Example 5
Source File: JibxMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, @Nullable 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);
	}
}
 
Example 6
Source File: JibxMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example 7
Source File: XSLTTransformer.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Override
protected void setSAXConsumer(final SAXConsumer consumer) {
    TransformerHandler transformerHandler;
    try {
        transformerHandler = TRAX_FACTORY.newTransformerHandler(this.templates);
    } catch (Exception e) {
        throw new SetupException("Could not initialize transformer handler.", e);
    }

    if (this.parameters != null) {
        final Transformer transformer = transformerHandler.getTransformer();

        this.parameters.forEach((name, values) -> {
            // is valid XSLT parameter name
            if (XSLT_PARAMETER_NAME_PATTERN.matcher(name).matches()) {
                transformer.setParameter(name, values);
            }
        });
    }

    final SAXResult result = new SAXResult();
    result.setHandler(consumer);
    // According to TrAX specs, all TransformerHandlers are LexicalHandlers
    result.setLexicalHandler(consumer);
    transformerHandler.setResult(result);

    final SAXConsumerAdapter saxConsumerAdapter = new SAXConsumerAdapter();
    saxConsumerAdapter.setContentHandler(transformerHandler);
    super.setSAXConsumer(saxConsumerAdapter);
}
 
Example 8
Source File: TransformerFilter.java    From iaf with Apache License 2.0 5 votes vote down vote up
public TransformerFilter(INamedObject owner, TransformerHandler transformerHandler, ThreadLifeCycleEventListener<Object> threadLifeCycleEventListener, IPipeLineSession session, boolean expectChildThreads, ContentHandler handler) {
	super(transformerHandler);
	if (expectChildThreads) {
		handler = new ThreadConnectingFilter(owner, threadLifeCycleEventListener, session, handler);
	}
	SAXResult transformedStream = new SAXResult();
	transformedStream.setHandler(handler);
	if (handler instanceof LexicalHandler) {
		transformedStream.setLexicalHandler((LexicalHandler)handler);
	}
	this.transformerHandler=transformerHandler;
	transformerHandler.setResult(transformedStream);
}