Parser parser = ParserFactory.getParser(); if (parser == null) { // now what? // this would be an example of where null isn't (or shouldn't be) a valid response } Action action = parser.findAction(someInput); if (action == null) { // do nothing } else { action.doSomething(); }
@Override public String getSystemId() { return this.locator.getSystemId(); } }
@Override public boolean getFeature(String name) throws SAXNotRecognizedException { throw new SAXNotRecognizedException(name); }
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(); } });
/** * Throws a SAXException if this tried to resolve any entity. */ @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { throw new SAXException("Refusing to resolve entity with publicId(" + publicId + ") and systemId (" + systemId + ")"); } }
/** * Return the line number in the XML resource that failed. * @return the line number if available (in case of a SAXParseException); -1 else * @see org.xml.sax.SAXParseException#getLineNumber() */ public int getLineNumber() { Throwable cause = getCause(); if (cause instanceof SAXParseException) { return ((SAXParseException) cause).getLineNumber(); } return -1; }
private void handleEndDocument() throws SAXException { if (getContentHandler() != null) { getContentHandler().endDocument(); } }
@Override public int getLineNumber() { return this.locator.getLineNumber(); }
@Override public int getColumnNumber() { return this.locator.getColumnNumber(); }
/** * This implementation throws a {@code SAXNotRecognizedException} exception * for any feature outside of the "http://xml.org/sax/features/" namespace * and accepts a {@code false} value for any feature within. */ @Override public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { if (name.startsWith("http://xml.org/sax/features/")) { if (value) { throw new SAXNotSupportedException(name); } } else { throw new SAXNotRecognizedException(name); } }
@Override public String getAsText() { InputSource value = (InputSource) getValue(); return (value != null ? value.getSystemId() : ""); }
@Override public String getPublicId() { return this.locator.getPublicId(); }
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(); } });
private void handleEndDocument() throws SAXException { if (getContentHandler() != null) { getContentHandler().endDocument(); } }
@Override public void setFeature(String name, boolean value) throws SAXNotRecognizedException { throw new SAXNotRecognizedException(name); }
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(); } });
@Override public void setProperty(String name, Object value) throws SAXNotRecognizedException { if ("http://xml.org/sax/properties/lexical-handler".equals(name)) { this.lexicalHandler = (LexicalHandler) value; } else { throw new SAXNotRecognizedException(name); } }
/** * Construct a new instance of the {@code StaxSource} with the specified {@code XMLEventReader}. * The supplied event reader must be in {@code XMLStreamConstants.START_DOCUMENT} or * {@code XMLStreamConstants.START_ELEMENT} state. * @param eventReader the {@code XMLEventReader} to read from * @throws IllegalStateException if the reader is not at the start of a document or element */ StaxSource(XMLEventReader eventReader) { super(new StaxEventXMLReader(eventReader), new InputSource()); this.eventReader = eventReader; }
/** * 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); } }
/** * Construct a new instance of the {@code StaxSource} with the specified {@code XMLStreamReader}. * The supplied stream reader must be in {@code XMLStreamConstants.START_DOCUMENT} or * {@code XMLStreamConstants.START_ELEMENT} state. * @param streamReader the {@code XMLStreamReader} to read from * @throws IllegalStateException if the reader is not at the start of a document or element */ StaxSource(XMLStreamReader streamReader) { super(new StaxStreamXMLReader(streamReader), new InputSource()); this.streamReader = streamReader; }