下面列出了怎么用org.xml.sax.ext.LexicalHandler的API类实例代码及写法,或者点击链接到github查看源代码。
@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);
}
}
public static void output(Object e, ContentHandler ch) throws SAXException {
if (ch instanceof LexicalHandler) {
output(e, ch, (LexicalHandler) ch);
} else {
output(e, ch, null);
}
}
/**
* A constructor.
* @param handler the wrapped SAX content handler
* @param lex the wrapped lexical handler
* @param encoding the encoding of the output HTML document
*/
public ToHTMLSAXHandler(
ContentHandler handler,
LexicalHandler lex,
String encoding)
{
super(handler,lex,encoding);
}
public void setContentHandler(ContentHandler handler) throws
NullPointerException
{
_sax = handler;
if (handler instanceof LexicalHandler) {
_lex = (LexicalHandler) handler;
}
if (handler instanceof SAXImpl) {
_saxImpl = (SAXImpl)handler;
}
}
public void setContentHandler(ContentHandler handler) throws
NullPointerException
{
_sax = handler;
if (handler instanceof LexicalHandler) {
_lex = (LexicalHandler) handler;
}
if (handler instanceof SAXImpl) {
_saxImpl = (SAXImpl)handler;
}
}
public static void output(Object e, ContentHandler ch) throws SAXException {
if (ch instanceof LexicalHandler) {
output(e, ch, (LexicalHandler) ch);
} else {
output(e, ch, null);
}
}
public void setContentHandler(ContentHandler handler) throws
NullPointerException
{
_sax = handler;
if (handler instanceof LexicalHandler) {
_lex = (LexicalHandler) handler;
}
if (handler instanceof SAXImpl) {
_saxImpl = (SAXImpl)handler;
}
}
public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
if (value instanceof LexicalHandler) {
setLexicalHandler((LexicalHandler)value);
} else {
throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY);
}
} else {
throw new SAXNotRecognizedException("Property not recognized: " + name);
}
}
public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
if (value instanceof LexicalHandler) {
setLexicalHandler((LexicalHandler)value);
} else {
throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY);
}
} else {
throw new SAXNotRecognizedException("Property not recognized: " + name);
}
}
public void setContentHandler(ContentHandler handler) throws
NullPointerException
{
_sax = handler;
if (handler instanceof LexicalHandler) {
_lex = (LexicalHandler) handler;
}
if (handler instanceof SAXImpl) {
_saxImpl = (SAXImpl)handler;
}
}
@Override
public void setProperty(String name, Object value) throws SAXNotRecognizedException {
if( "http://xml.org/sax/properties/lexical-handler".equals(name) ) {
this.lexicalHandler = (LexicalHandler)value;
return;
}
throw new SAXNotRecognizedException(name);
}
@Override
public void setProperty(String name, Object value) throws SAXNotRecognizedException {
if( "http://xml.org/sax/properties/lexical-handler".equals(name) ) {
this.lexicalHandler = (LexicalHandler)value;
return;
}
throw new SAXNotRecognizedException(name);
}
public void setContentHandler(ContentHandler handler) throws
NullPointerException
{
_sax = handler;
if (handler instanceof LexicalHandler) {
_lex = (LexicalHandler) handler;
}
if (handler instanceof SAXImpl) {
_saxImpl = (SAXImpl)handler;
}
}
public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
if (value instanceof LexicalHandler) {
setLexicalHandler((LexicalHandler)value);
} else {
throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY);
}
} else {
throw new SAXNotRecognizedException("Property not recognized: " + name);
}
}
public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (name.equals(Properties.LEXICAL_HANDLER_PROPERTY)) {
if (value instanceof LexicalHandler) {
setLexicalHandler((LexicalHandler)value);
} else {
throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY);
}
} else {
throw new SAXNotRecognizedException("Property not recognized: " + name);
}
}
public void setProperty(String name, Object value) throws SAXNotRecognizedException {
if( "http://xml.org/sax/properties/lexical-handler".equals(name) ) {
this.lexicalHandler = (LexicalHandler)value;
return;
}
throw new SAXNotRecognizedException(name);
}
@Override
public void setProperty(String name, Object value) throws SAXNotRecognizedException {
if( "http://xml.org/sax/properties/lexical-handler".equals(name) ) {
this.lexicalHandler = (LexicalHandler)value;
return;
}
throw new SAXNotRecognizedException(name);
}
@Override
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
throws XmlMappingException {
SaxWriter saxWriter = new SaxWriter(this.nameCoder);
saxWriter.setContentHandler(contentHandler);
doMarshal(graph, saxWriter, null);
}
public ToXMLSAXHandler(
ContentHandler handler,
LexicalHandler lex,
String encoding)
{
super(handler, lex, encoding);
initCDATA();
// initNamespaces();
m_prefixMap = new NamespaceMappings();
}
@Override
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, LexicalHandler lexicalHandler)
throws XmlMappingException {
Marshaller marshaller = xmlContext.createMarshaller();
marshaller.setContentHandler(contentHandler);
doMarshal(graph, marshaller);
}
public ToSAXHandler(
ContentHandler hdlr,
LexicalHandler lex,
String encoding)
{
setContentHandler(hdlr);
setLexHandler(lex);
setEncoding(encoding);
}
public void setContentHandler(ContentHandler handler) throws
NullPointerException
{
_sax = handler;
if (handler instanceof LexicalHandler) {
_lex = (LexicalHandler) handler;
}
if (handler instanceof SAXImpl) {
_saxImpl = (SAXImpl)handler;
}
}
@Override
protected void marshalSaxHandlers(Object graph, ContentHandler contentHandler, @Nullable LexicalHandler lexicalHandler)
throws XmlMappingException {
Assert.state(this.xmlContext != null, "CastorMarshaller not initialized");
Marshaller marshaller = this.xmlContext.createMarshaller();
marshaller.setContentHandler(contentHandler);
doMarshal(graph, marshaller);
}
public void setProperty(String name, Object value)
throws SAXNotRecognizedException, SAXNotSupportedException {
if (LEXICAL_HANDLER_PROP.equals(name)) {
lexicalHandler = (LexicalHandler) value;
} else {
super.setProperty(name, value);
}
}
/**
* Test to set and get the lexical-handler.
*
* @param saxparser a SAXParser instance.
* @throws SAXException If any parse errors occur.
*/
@Test(dataProvider = "parser-provider")
public void testProperty05(SAXParser saxparser) throws SAXException {
MyLexicalHandler myLexicalHandler = new MyLexicalHandler();
saxparser.setProperty(LEXICAL_HANDLER, myLexicalHandler);
assertTrue(saxparser.getProperty(LEXICAL_HANDLER) instanceof LexicalHandler);
}
/**
* A constructor.
* @param handler the wrapped SAX content handler
* @param lex the wrapped lexical handler
* @param encoding the encoding of the output HTML document
*/
public ToHTMLSAXHandler(
ContentHandler handler,
LexicalHandler lex,
String encoding)
{
super(handler,lex,encoding);
}
public ToSAXHandler(
ContentHandler hdlr,
LexicalHandler lex,
String encoding)
{
setContentHandler(hdlr);
setLexHandler(lex);
setEncoding(encoding);
}
public ToSAXHandler(
ContentHandler hdlr,
LexicalHandler lex,
String encoding)
{
setContentHandler(hdlr);
setLexHandler(lex);
setEncoding(encoding);
}
/**
* Throws a {@code SAXNotRecognizedException} exception when the given property does not signify a lexical
* handler. The property name for a lexical handler is {@code http://xml.org/sax/properties/lexical-handler}.
*/
@Override
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
if ("http://xml.org/sax/properties/lexical-handler".equals(name)) {
this.lexicalHandler = (LexicalHandler) value;
}
else {
throw new SAXNotRecognizedException(name);
}
}
/**
* Throws an {@code UnsupportedOperationException}.
* @throws UnsupportedOperationException always
*/
@Override
public void setLexicalHandler(LexicalHandler handler) {
throw new UnsupportedOperationException("setLexicalHandler is not supported");
}