当前位置: 首页>>代码示例>>Java>>正文


Java ErrorHandler类代码示例

本文整理汇总了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;

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:DOMParser.java

示例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);
    }
}
 
开发者ID:woefe,项目名称:xmlrss,代码行数:27,代码来源:RedactableXMLSignature.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ValidatorTest.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:ProblemActionHeader.java

示例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 );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:DOMForestParser.java

示例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);

    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:DOMForestParser.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:SourceLocationAddOn.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:XMLUtilTest.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:CompactSyntax.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:XMLUtil.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:DefaultDocumentLoader.java

示例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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:DefaultDocumentLoader.java

示例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);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:PersistenceUnitReader.java

示例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;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:JAXBHeader.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:StringHeader.java


注:本文中的org.xml.sax.ErrorHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。