/** * Test to set and get the declaration-handler. * * @param saxparser a SAXParser instance. * @throws SAXException If any parse errors occur. */ @Test(dataProvider = "parser-provider") public void testProperty06(SAXParser saxparser) throws SAXException { MyDeclHandler myDeclHandler = new MyDeclHandler(); saxparser.setProperty(DECL_HANDLER, myDeclHandler); assertTrue(saxparser.getProperty(DECL_HANDLER) instanceof DeclHandler); }
public DocTypeTextLexicalHandler(DeclHandler dh) throws SAXException { // this.dh = dh; xmlReader = XMLReaderFactory.createXMLReader(); // xmlReader.setProperty( // "http://xml.org/sax/properties/lexical-handler", // lh); // DTD xmlReader.setFeature( "http://xml.org/sax/features/resolve-dtd-uris", false); // *skip* resolving entities like DTDs xmlReader.setEntityResolver(new NoEntityResolver()); xmlReader.setProperty( "http://xml.org/sax/properties/declaration-handler", dh); }
protected boolean _setProperty(String name, Object value) throws SAXNotSupportedException{ if(LEXICAL_HANDLER.equals(name) || LEXICAL_HANDLER_ALT.equals(name)){ if(value==null || value instanceof LexicalHandler){ handler.setLexicalHandler((LexicalHandler)value); return true; }else throw new SAXNotSupportedException("value must implement "+LexicalHandler.class); }else if(DECL_HANDLER.equals(name) || DECL_HANDLER_ALT.equals(name)){ if(value==null || value instanceof DeclHandler){ handler.setDeclHandler((DeclHandler)value); return true; }else throw new SAXNotSupportedException("value must implement "+DeclHandler.class); }else return false; }
@Override public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { SAXProperty prop = SAXProperty.findByUri(name); if (prop == SAXProperty.DECLARATION_HANDLER) { mDeclHandler = (DeclHandler) value; return; } else if (prop == SAXProperty.DOCUMENT_XML_VERSION) { ; // read-only } else if (prop == SAXProperty.DOM_NODE) { ; // read-only } else if (prop == SAXProperty.LEXICAL_HANDLER) { mLexicalHandler = (LexicalHandler) value; return; } else if (prop == SAXProperty.XML_STRING) { ; // read-only } else { throw new SAXNotRecognizedException("Property '"+name+"' not recognized"); } // Trying to modify read-only properties? throw new SAXNotSupportedException("Property '"+name+"' is read-only, can not be modified"); }
public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException { if (validatorDeclHandlers.size() > 0) { for (DeclHandler h : this.validatorDeclHandlers) { h.externalEntityDecl(name, publicId, systemId); } } if (context.version == EPUBVersion.VERSION_3) { report.message(MessageId.HTM_003, EPUBLocation.create(path, getLineNumber(), getColumnNumber(), name), name); return; } entities.add(name); }
/** * Set the property of a value on the underlying XMLReader. */ @Override public void setProperty (final String prop, final Object value) throws SAXNotRecognizedException, SAXNotSupportedException { if ((PROP_PREFIX + "lexical-handler").equals (prop)) setLexicalHandler ((LexicalHandler) value); else if ((PROP_PREFIX + "declaration-handler").equals (prop)) setDeclHandler ((DeclHandler) value); else super.setProperty (prop, value); }
public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { if (parser != null) throw new IllegalStateException("parsing in progress"); final String FEATURES = "http://xml.org/sax/features/"; final String PROPERTIES = "http://xml.org/sax/properties/"; final String GNU_FEATURES = "http://gnu.org/sax/features/"; if ((FEATURES + "namespaces").equals(name)) namespaceAware = Boolean.TRUE.equals(value); else if ((FEATURES + "namespace-prefixes").equals(name)) { // NOOP } else if ((FEATURES + "string-interning").equals(name)) stringInterning = Boolean.TRUE.equals(value); else if ((FEATURES + "use-attributes2").equals(name)) { // NOOP } else if ((FEATURES + "validation").equals(name)) validating = Boolean.TRUE.equals(value); else if ((FEATURES + "external-general-entities").equals(name)) externalEntities = Boolean.TRUE.equals(value); else if ((FEATURES + "external-parameter-entities").equals(name)) externalEntities = Boolean.TRUE.equals(value); else if ((PROPERTIES + "declaration-handler").equals(name)) declHandler = (DeclHandler) value; else if ((PROPERTIES + "lexical-handler").equals(name)) lexicalHandler = (LexicalHandler) value; else if ((GNU_FEATURES + "xml-base").equals(name)) baseAware = Boolean.TRUE.equals(value); else if ((GNU_FEATURES + "coalescing").equals(name)) coalescing = Boolean.TRUE.equals(value); else throw new SAXNotSupportedException(name); }
public void setProperty (String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { checkPropertyName (name); String key = name.substring (PROPERTIES_PREFIX.length ()); if ("declaration-handler".equals (key)) { setDeclarationHandler ((DeclHandler) value); } else if ("lexical-handler".equals (key)) { setLexicalHandler ((LexicalHandler) value); } }
/** * <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); }
@Override public void setContentHandler(ContentHandler pHandler) { //Called by XOM during builder construction - grab a reference to the handler so we can pass it to the decoder mContentHandler = pHandler; mDecoder.setLexicalHandler((LexicalHandler) mContentHandler); mDecoder.setDeclHandler((DeclHandler) mContentHandler); }
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 if ("http://xml.org/sax/properties/declaration-handler" .equals(name)) { this.declHandler = (DeclHandler) value; } else { throw new SAXNotRecognizedException(name); } }
/** * Registers given handler with all its implementing interfaces. * This would be handy if you want to register to all interfaces * implemented by given handler object * * @param handler Object implementing one or more sax handler interfaces */ public void setHandler(Object handler){ if(handler instanceof ContentHandler) setContentHandler((ContentHandler)handler); if(handler instanceof EntityResolver) setEntityResolver((EntityResolver)handler); if(handler instanceof ErrorHandler) setErrorHandler((ErrorHandler)handler); if(handler instanceof DTDHandler) setDTDHandler((DTDHandler)handler); if(handler instanceof LexicalHandler) setLexicalHandler((LexicalHandler)handler); if(handler instanceof DeclHandler) setDeclHandler((DeclHandler)handler); }
@Override public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException{ if(LEXICAL_HANDLER.equals(name) || LEXICAL_HANDLER_ALT.equals(name)){ if(value==null || value instanceof LexicalHandler) lexicalHandler = (LexicalHandler)value; else throw new SAXNotSupportedException("value must implement "+LexicalHandler.class); }else if(DECL_HANDLER.equals(name) || DECL_HANDLER_ALT.equals(name)){ if(value==null || value instanceof DeclHandler) declHandler = (DeclHandler)value; else throw new SAXNotSupportedException("value must implement "+DeclHandler.class); }else throw new SAXNotRecognizedException(); }
public void addDeclHandler(DeclHandler handler) { if (handler != null) { validatorDeclHandlers.add(handler); } }
public void attributeDecl(String name, String name2, String type, String mode, String value) throws SAXException { if (validatorDeclHandlers.size() > 0) { for (DeclHandler h : this.validatorDeclHandlers) { h.attributeDecl(name, name2, type, mode, value); } } }
public void elementDecl(String name, String model) throws SAXException { if (validatorDeclHandlers.size() > 0) { for (DeclHandler h : this.validatorDeclHandlers) { h.elementDecl(name, model); } } }
public void internalEntityDecl(String name, String value) throws SAXException { if (validatorDeclHandlers.size() > 0) { for (DeclHandler h : this.validatorDeclHandlers) { h.internalEntityDecl(name, value); } } entities.add(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 if (name.equals(Properties.DTD_DECLARATION_HANDLER_PROPERTY)) { if (value instanceof DeclHandler) { setDeclHandler((DeclHandler)value); } else { throw new SAXNotSupportedException(Properties.LEXICAL_HANDLER_PROPERTY); } } else if (name.equals(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY)) { if (value instanceof Map) { setExternalVocabularies((Map)value); } else { throw new SAXNotSupportedException(FastInfosetReader.EXTERNAL_VOCABULARIES_PROPERTY); } } else if (name.equals(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY)) { if (value instanceof Map) { setRegisteredEncodingAlgorithms((Map)value); } else { throw new SAXNotSupportedException(FastInfosetReader.REGISTERED_ENCODING_ALGORITHMS_PROPERTY); } } else if (name.equals(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY)) { if (value instanceof EncodingAlgorithmContentHandler) { setEncodingAlgorithmContentHandler((EncodingAlgorithmContentHandler)value); } else { throw new SAXNotSupportedException(FastInfosetReader.ENCODING_ALGORITHM_CONTENT_HANDLER_PROPERTY); } } else if (name.equals(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY)) { if (value instanceof PrimitiveTypeContentHandler) { setPrimitiveTypeContentHandler((PrimitiveTypeContentHandler)value); } else { throw new SAXNotSupportedException(FastInfosetReader.PRIMITIVE_TYPE_CONTENT_HANDLER_PROPERTY); } } else if (name.equals(FastInfosetReader.BUFFER_SIZE_PROPERTY)) { if (value instanceof Integer) { setBufferSize(((Integer)value).intValue()); } else { throw new SAXNotSupportedException(FastInfosetReader.BUFFER_SIZE_PROPERTY); } } else { throw new SAXNotRecognizedException(CommonResourceBundle.getInstance(). getString("message.propertyNotRecognized", new Object[]{name})); } }
public void setDeclHandler(DeclHandler handler) { _declHandler = handler; }
public DeclHandler getDeclHandler() { return _declHandler; }