/** * Return the current error handler. * * @return The current error handler, or null if none * has been registered. * @see #setErrorHandler */ public ErrorHandler getErrorHandler() { ErrorHandler errorHandler = null; try { XMLErrorHandler xmlErrorHandler = (XMLErrorHandler)fConfiguration.getProperty(ERROR_HANDLER); if (xmlErrorHandler != null && xmlErrorHandler instanceof ErrorHandlerWrapper) { errorHandler = ((ErrorHandlerWrapper)xmlErrorHandler).getErrorHandler(); } } catch (XMLConfigurationException e) { // do nothing } return errorHandler; }
/** * Loads the document used for signing/verification/redaction from the given input stream. * <p> * The document is checked against the given schema and the given error handler is used. * * @param inputStream the input stream * @param schema the schema of the loaded XML document * @param handler the errorhandler * @throws RedactableXMLSignatureException if this RedactableXMLSignature object is not properly initialized */ public final void setDocument(InputStream inputStream, Schema schema, ErrorHandler handler) throws RedactableXMLSignatureException { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setSchema(schema); documentBuilderFactory.setNamespaceAware(true); documentBuilderFactory.setIgnoringElementContentWhitespace(true); try { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); documentBuilder.setErrorHandler(handler); setDocument(documentBuilder.parse(inputStream)); } catch (ParserConfigurationException | SAXException | IOException e) { throw new RedactableXMLSignatureException(e); } }
private void validate(final String xsdFile, final Source src, final Result result) throws Exception { try { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File(ValidatorTest.class.getResource(xsdFile).toURI())); // Get a Validator which can be used to validate instance document // against this grammar. Validator validator = schema.newValidator(); ErrorHandler eh = new ErrorHandlerImpl(); validator.setErrorHandler(eh); // Validate this instance document against the // Instance document supplied validator.validate(src, result); } catch (Exception ex) { throw ex; } }
public void writeTo(ContentHandler h, ErrorHandler errorHandler) throws SAXException { String nsUri = getNamespaceURI(); String ln = getLocalPart(); h.startPrefixMapping("",nsUri); h.startElement(nsUri,ln,ln,EMPTY_ATTS); h.startElement(nsUri,actionLocalName,actionLocalName,EMPTY_ATTS); h.characters(action.toCharArray(),0,action.length()); h.endElement(nsUri,actionLocalName,actionLocalName); if (soapAction != null) { h.startElement(nsUri,soapActionLocalName,soapActionLocalName,EMPTY_ATTS); h.characters(soapAction.toCharArray(),0,soapAction.length()); h.endElement(nsUri,soapActionLocalName,soapActionLocalName); } h.endElement(nsUri,ln,ln); }
public void parse( InputSource source, ContentHandler contentHandler, ErrorHandler errorHandler, EntityResolver entityResolver ) throws SAXException, IOException { String systemId = source.getSystemId(); Document dom = forest.get(systemId); if(dom==null) { // if no DOM tree is built for it, // let the fall back parser parse the original document. // // for example, XSOM parses datatypes.xsd (XML Schema part 2) // but this will never be built into the forest. fallbackParser.parse( source, contentHandler, errorHandler, entityResolver ); return; } scanner.scan( dom, contentHandler ); }
public void parse(InputSource source, ContentHandler handler, ErrorHandler errorHandler, EntityResolver entityResolver) throws SAXException, IOException { String systemId = source.getSystemId(); Document dom = forest.get(systemId); if (dom == null) { // if no DOM tree is built for it, // let the fall back parser parse the original document. // // for example, XSOM parses datatypes.xsd (XML Schema part 2) // but this will never be built into the forest. fallbackParser.parse(source, handler, errorHandler, entityResolver); return; } scanner.scan(dom, handler); }
public boolean run( Outline outline, Options opt, ErrorHandler errorHandler ) { for( ClassOutline ci : outline.getClasses() ) { JDefinedClass impl = ci.implClass; if (ci.getSuperClass() == null) { JVar $loc = impl.field(JMod.PROTECTED, Locator.class, fieldName); $loc.annotate(XmlLocation.class); $loc.annotate(XmlTransient.class); impl._implements(Locatable.class); impl.method(JMod.PUBLIC, Locator.class, "sourceLocation").body()._return($loc); JMethod setter = impl.method(JMod.PUBLIC, Void.TYPE, "setSourceLocation"); JVar $newLoc = setter.param(Locator.class, "newLocator"); setter.body().assign($loc, $newLoc); } } return true; }
public void testHandlerLeak() throws Exception { ErrorHandler handler = new DefaultHandler(); EntityResolver resolver = new DefaultHandler(); Reference<?> handlerRef = new WeakReference<Object>(handler); Reference<?> resolverRef = new WeakReference<Object>(resolver); XMLUtil.parse(new InputSource(new StringReader("<hello/>")), false, false, handler, resolver); handler = null; resolver = null; assertGC("can collect handler", handlerRef); assertGC("can collect resolver", resolverRef); }
public CompactSyntax(CompactParseable parseable, Reader r, String sourceUri, SchemaBuilder sb, ErrorHandler eh, String inheritedNs) { this(r); this.sourceUri = sourceUri; this.parseable = parseable; this.sb = sb; this.ncb = sb.getNameClassBuilder(); this.eh = eh; // this causes the root pattern to have non-null annotations // which is useful because it gives a context to trang this.topLevelComments = sb.makeCommentList(); this.inheritedNs = defaultNamespace = new String(inheritedNs); }
public static Document parse ( InputSource input, boolean validate, boolean namespaceAware, ErrorHandler errorHandler, EntityResolver entityResolver ) throws IOException, SAXException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validate); factory.setNamespaceAware(namespaceAware); DocumentBuilder builder = null; try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException ex) { throw new SAXException(ex); } if (errorHandler != null) { builder.setErrorHandler(errorHandler); } if (entityResolver != null) { builder.setEntityResolver(entityResolver); } assert input != null : "InputSource cannot be null"; try { return builder.parse(input); } catch (SAXException ex) { StringBuilder msg = new StringBuilder(); msg.append("Cannot parse"); msg.append("Thread.cCL: ").append(Thread.currentThread().getContextClassLoader()); throw new SAXException(msg.toString(), ex); } }
/** * Load the {@link Document} at the supplied {@link InputSource} using the standard JAXP-configured * XML parser. */ @Override public Document loadDocument(InputSource inputSource, EntityResolver entityResolver, ErrorHandler errorHandler, int validationMode, boolean namespaceAware) throws Exception { DocumentBuilderFactory factory = createDocumentBuilderFactory(validationMode, namespaceAware); if (logger.isDebugEnabled()) { logger.debug("Using JAXP provider [" + factory.getClass().getName() + "]"); } DocumentBuilder builder = createDocumentBuilder(factory, entityResolver, errorHandler); return builder.parse(inputSource); }
/** * Create a JAXP DocumentBuilder that this bean definition reader * will use for parsing XML documents. Can be overridden in subclasses, * adding further initialization of the builder. * @param factory the JAXP DocumentBuilderFactory that the DocumentBuilder * should be created with * @param entityResolver the SAX EntityResolver to use * @param errorHandler the SAX ErrorHandler to use * @return the JAXP DocumentBuilder * @throws ParserConfigurationException if thrown by JAXP methods */ protected DocumentBuilder createDocumentBuilder( DocumentBuilderFactory factory, EntityResolver entityResolver, ErrorHandler errorHandler) throws ParserConfigurationException { DocumentBuilder docBuilder = factory.newDocumentBuilder(); if (entityResolver != null) { docBuilder.setEntityResolver(entityResolver); } if (errorHandler != null) { docBuilder.setErrorHandler(errorHandler); } return docBuilder; }
/** * Validate the given stream and return a valid DOM document for parsing. */ protected Document buildDocument(ErrorHandler handler, InputStream stream) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder parser = dbf.newDocumentBuilder(); parser.setErrorHandler(handler); return parser.parse(stream); }
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException { try { bridge.marshal(jaxbObject,contentHandler,null); } catch (JAXBException e) { SAXParseException x = new SAXParseException(e.getMessage(),null,null,-1,-1,e); errorHandler.fatalError(x); throw x; } }
public void writeTo(ContentHandler h, ErrorHandler errorHandler) throws SAXException { String nsUri = name.getNamespaceURI(); String ln = name.getLocalPart(); h.startPrefixMapping("",nsUri); if(mustUnderstand) { AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute(soapVersion.nsUri,MUST_UNDERSTAND,"S:"+MUST_UNDERSTAND,"CDATA", getMustUnderstandLiteral(soapVersion)); h.startElement(nsUri,ln,ln,attributes); } else { h.startElement(nsUri,ln,ln,EMPTY_ATTS); } h.characters(value.toCharArray(),0,value.length()); h.endElement(nsUri,ln,ln); }
/** * * @param eh Error handler to receive errors while building the schema. * @param datatypeLibraryFactory This is consulted to locate datatype * libraries. * @param pb Used to build patterns. */ public SchemaBuilderImpl(ErrorHandler eh, DatatypeLibraryFactory datatypeLibraryFactory, SchemaPatternBuilder pb) { this.parent = null; this.eh = eh; this.datatypeLibraryFactory = datatypeLibraryFactory; this.pb = pb; this.inheritNs = ""; this.openIncludes = null; }
/** * * @param eh Error handler to receive errors while building the schema. */ public SchemaBuilderImpl(ErrorHandler eh) { this(eh, new CascadingDatatypeLibraryFactory(new DatatypeLibraryLoader(), new BuiltinDatatypeLibraryFactory(new DatatypeLibraryLoader())), new SchemaPatternBuilder()); }
/** * @see org.xml.sax.ErrorHandler#fatalError(SAXParseException) */ public void fatalError(SAXParseException exc) throws SAXException { super.fatalError(exc); m_needToCallStartDocument = false; if (m_saxHandler instanceof ErrorHandler) { ((ErrorHandler)m_saxHandler).fatalError(exc); } }
/** * Parses an xml config file and returns a Config object. * * @param xmlFile * The xml config file which is passed by the user to annotation processing * @return * A non null Config object */ private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException { XMLReader reader; try { SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing); reader = factory.newSAXParser().getXMLReader(); } catch (ParserConfigurationException e) { // in practice this will never happen throw new Error(e); } NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler); // set up validator ValidatorHandler validator = configSchema.newValidator(); validator.setErrorHandler(errorHandler); // the validator will receive events first, then the parser. reader.setContentHandler(new ForkContentHandler(validator,runtime)); reader.setErrorHandler(errorHandler); Config config = new Config(runtime); runtime.setRootHandler(config); reader.parse(new InputSource(xmlFile.toURL().toExternalForm())); runtime.reset(); return config; }
@Override public void setErrorHandler(ErrorHandler handler) { }
@Override public void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException { streamDelegate.writePayloadTo(contentHandler, errorHandler, fragment); }
public void setErrorHandler(ErrorHandler handler) { this.errorHandler = handler; }
public void setErrorHandler(ErrorHandler errorHandler) { fComponentManager.setErrorHandler(errorHandler); }
/** {@inheritDoc} */ public void setErrorHandler(ErrorHandler eh) { checkValidState(); return; }
public ErrorHandler getErrorHandler() { return this; }
@Override public ErrorHandler getErrorHandler() { return null; }
public void setErrorHandler(ErrorHandler handler) { _errorHandler = handler; }
public ErrorHandler getErrorHandler() { return _errorHandler; }
public final void writeTo(ContentHandler handler, ErrorHandler errorHandler) throws SAXException { writeTo(handler, errorHandler, isFragment()); }
public CheckingSchemaBuilder( SchemaBuilder sb, ErrorHandler eh, DatatypeLibraryFactory dlf ) { super(new SchemaBuilderImpl(eh,dlf,new SchemaPatternBuilder()),sb); }
public void writeTo(ContentHandler contentHandler, ErrorHandler errorHandler) throws SAXException { message.writeTo(contentHandler, errorHandler); }
protected void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException { message.writePayloadTo(contentHandler, errorHandler, fragment); }
public ErrorHandler getErrorHandler() { return fComponentManager.getErrorHandler(); }
public void writePayloadTo(ContentHandler contentHandler, ErrorHandler errorHandler, boolean fragment) throws SAXException { if ( envelopeReader != null ) readEnvelope(this); assert unconsumed(); try { if(payloadLocalName==null) return; // no body if (bodyPrologue != null) { char[] chars = bodyPrologue.toCharArray(); contentHandler.characters(chars, 0, chars.length); } XMLStreamReaderToContentHandler conv = new XMLStreamReaderToContentHandler(reader,contentHandler,true,fragment,getInscopeNamespaces()); while(reader.getEventType() != XMLStreamConstants.END_DOCUMENT){ String name = reader.getLocalName(); String nsUri = reader.getNamespaceURI(); // After previous conv.bridge() call the cursor will be at END_ELEMENT. // Check if its not soapenv:Body then move to next ELEMENT if(reader.getEventType() == XMLStreamConstants.END_ELEMENT){ if (!isBodyElement(name, nsUri)){ // closing payload element: store epilogue for further signing, if applicable // however if there more than one payloads exist - the last one is stored String whiteSpaces = XMLStreamReaderUtil.nextWhiteSpaceContent(reader); if (whiteSpaces != null) { this.bodyEpilogue = whiteSpaces; // write it to the message too char[] chars = whiteSpaces.toCharArray(); contentHandler.characters(chars, 0, chars.length); } } else { // body closed > exit break; } } else { // payload opening element: copy payload to writer conv.bridge(); } } XMLStreamReaderUtil.readRest(reader); XMLStreamReaderUtil.close(reader); XMLStreamReaderFactory.recycle(reader); } catch (XMLStreamException e) { Location loc = e.getLocation(); if(loc==null) loc = DummyLocation.INSTANCE; SAXParseException x = new SAXParseException( e.getMessage(),loc.getPublicId(),loc.getSystemId(),loc.getLineNumber(),loc.getColumnNumber(),e); errorHandler.error(x); } }