@Override public void setResult(Result result) throws IllegalArgumentException { SAXResult saxResult = toSAXResult(result); ContentHandler handler = saxResult.getHandler(); this.nextContentHandler = handler; if (handler instanceof LexicalHandler) { this.nextLexicalHandler = (LexicalHandler) handler; } if (handler instanceof DTDHandler) { this.nextDtdHandler = (DTDHandler) handler; } }
@Test public void lexicalHandler() throws Exception { Resource testLexicalHandlerXml = new ClassPathResource("testLexicalHandler.xml", getClass()); LexicalHandler expectedLexicalHandler = mockLexicalHandler(); standardReader.setContentHandler(null); standardReader.setProperty("http://xml.org/sax/properties/lexical-handler", expectedLexicalHandler); standardReader.parse(new InputSource(testLexicalHandlerXml.getInputStream())); inputFactory.setProperty("javax.xml.stream.isCoalescing", Boolean.FALSE); inputFactory.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", Boolean.TRUE); inputFactory.setProperty("javax.xml.stream.isReplacingEntityReferences", Boolean.FALSE); inputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE); LexicalHandler actualLexicalHandler = mockLexicalHandler(); willAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return invocation.getArguments()[0] = "element"; } }).given(actualLexicalHandler).startDTD(anyString(), anyString(), anyString()); AbstractStaxXMLReader staxXmlReader = createStaxXmlReader(testLexicalHandlerXml.getInputStream()); staxXmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", actualLexicalHandler); staxXmlReader.parse(new InputSource()); verifyIdenticalInvocations(expectedLexicalHandler, actualLexicalHandler); }
/** * <b>SAX2</b>: Assigns the specified property. Like SAX1 handlers, these may * be changed at any time. */ public void setProperty (final String propertyId, final Object property) throws SAXNotRecognizedException, SAXNotSupportedException { if (propertyId.equals ("http://xml.org/sax/properties/lexical-handler")) { if (property instanceof LexicalHandler) { lexicalHandler = (LexicalHandler) property; } else { throw new SAXNotSupportedException ("Lexical Handler must be instance of org.xml.sax.ext.LexicalHandler"); } } else { throw new SAXNotRecognizedException (propertyId); } }
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); }
public SaxSerializer(ContentHandler handler,LexicalHandler lex, boolean indenting) { if(!indenting) { writer = handler; lexical = lex; } else { IndentingXMLFilter indenter = new IndentingXMLFilter(handler, lex); writer = indenter; lexical = indenter; } }
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { if (LEXICAL_HANDLER_PROP.equals(name)) { lexicalHandler = (LexicalHandler) value; } else { super.setProperty(name, value); } }
public void setContentHandler(ContentHandler handler) throws NullPointerException { _sax = handler; if (handler instanceof LexicalHandler) { _lex = (LexicalHandler) handler; } if (handler instanceof SAXImpl) { _saxImpl = (SAXImpl)handler; } }
public ToXMLSAXHandler( ContentHandler handler, LexicalHandler lex, String encoding) { super(handler, lex, encoding); initCDATA(); // initNamespaces(); m_prefixMap = new NamespaceMappings(); }
/** * 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 static void output(Object e, ContentHandler ch) throws SAXException { if (ch instanceof LexicalHandler) { output(e, ch, (LexicalHandler) ch); } else { output(e, ch, null); } }
@Override public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { if (LEXICAL_HANDLER_PROP.equals(name)) { lexicalHandler = (LexicalHandler) value; } else { super.setProperty(name, value); } }
public void setContentHandler(ContentHandler handler) throws NullPointerException { _sax = handler; if (handler instanceof LexicalHandler) { _lex = (LexicalHandler)handler; } if (handler instanceof SAXImpl) { _saxImpl = (SAXImpl)handler; } }
/** * 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); }
/** * <b>SAX2</b>: Assigns the specified property. At this time only * declaration and lexical handlers, and the initial DOM document, are * supported. These must not be changed to values of the wrong type. * Like SAX1 handlers, these handlers may be changed at any time. * Like SAX1 input source or document URI, the initial DOM document * may not be changed during a parse. */ public void setProperty (String name, Object state) throws SAXNotRecognizedException, SAXNotSupportedException { if ((HANDLERS + "declaration-handler").equals (name)) { if (!(state instanceof DeclHandler || state == null)) throw new SAXNotSupportedException (name); declHandler = (DeclHandler) state; return; } if ((HANDLERS + "lexical-handler").equals (name)) { if (!(state instanceof LexicalHandler || state == null)) throw new SAXNotSupportedException (name); lexicalHandler = (LexicalHandler) state; return; } if ((HANDLERS + "dom-node").equals (name)) { if (state == null || state instanceof Node) { if (current != null) throw new SAXNotSupportedException ( "property is readonly during parse: " + name); setStart ((Node) state); return; } throw new SAXNotSupportedException ("not a DOM Node"); } // unknown properties throw new SAXNotRecognizedException (name); }