本文整理汇总了Java中org.xml.sax.ErrorHandler类的典型用法代码示例。如果您正苦于以下问题:Java ErrorHandler类的具体用法?Java ErrorHandler怎么用?Java ErrorHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ErrorHandler类属于org.xml.sax包,在下文中一共展示了ErrorHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getErrorHandler
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
/**
* 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;
}
示例2: setDocument
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
/**
* 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);
}
}
示例3: validate
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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;
}
}
示例4: writeTo
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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);
}
示例5: parse
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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 );
}
示例6: parse
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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);
}
示例7: run
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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;
}
示例8: testHandlerLeak
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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);
}
示例9: CompactSyntax
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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);
}
示例10: parse
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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);
}
}
示例11: loadDocument
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
/**
* 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);
}
示例12: createDocumentBuilder
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
/**
* 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;
}
示例13: buildDocument
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
/**
* 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);
}
示例14: writeTo
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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;
}
}
示例15: writeTo
import org.xml.sax.ErrorHandler; //导入依赖的package包/类
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);
}