jaxpvalidatorcomponent.java
来自「JAVA 所有包」· Java 代码 · 共 597 行 · 第 1/2 页
JAVA
597 行
return JAXPValidatorComponent.this.getDocumentHandler(); } /** * Converts the {@link XNIException} received from a downstream * component to a {@link SAXException}. */ private SAXException toSAXException( XNIException xe ) { Exception e = xe.getException(); if( e==null ) e = xe; if( e instanceof SAXException ) return (SAXException)e; return new SAXException(e); } /** * Creates a proper {@link QName} object from 3 parts. * <p> * This method does the symbolization. */ private QName toQName( String uri, String localName, String qname ) { String prefix = null; int idx = qname.indexOf(':'); if( idx>0 ) prefix = symbolize(qname.substring(0,idx)); localName = symbolize(localName); qname = symbolize(qname); uri = symbolize(uri); // notify handlers fQName.setValues(prefix, localName, qname, uri); return fQName; } } /** * Converts {@link XNI} events to {@link ContentHandler} events. * * <p> * Deriving from {@link DefaultXMLDocumentHandler} * to reuse its default {@link com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler} * implementation. * * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) */ private final class XNI2SAX extends DefaultXMLDocumentHandler { private ContentHandler fContentHandler; private String fVersion; /** Namespace context */ protected NamespaceContext fNamespaceContext; /** * For efficiency, we reuse one instance. */ private final AttributesProxy fAttributesProxy = new AttributesProxy(null); public void setContentHandler( ContentHandler handler ) { this.fContentHandler = handler; } public ContentHandler getContentHandler() { return fContentHandler; } public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) throws XNIException { this.fVersion = version; } public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException { fNamespaceContext = namespaceContext; fContentHandler.setDocumentLocator(new LocatorProxy(locator)); try { fContentHandler.startDocument(); } catch (SAXException e) { throw new XNIException(e); } } public void endDocument(Augmentations augs) throws XNIException { try { fContentHandler.endDocument(); } catch (SAXException e) { throw new XNIException(e); } } public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException { try { fContentHandler.processingInstruction(target,data.toString()); } catch (SAXException e) { throw new XNIException(e); } } public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { try { // start namespace prefix mappings int count = fNamespaceContext.getDeclaredPrefixCount(); if (count > 0) { String prefix = null; String uri = null; for (int i = 0; i < count; i++) { prefix = fNamespaceContext.getDeclaredPrefixAt(i); uri = fNamespaceContext.getURI(prefix); fContentHandler.startPrefixMapping(prefix, (uri == null)?"":uri); } } String uri = element.uri != null ? element.uri : ""; String localpart = element.localpart; fAttributesProxy.setAttributes(attributes); fContentHandler.startElement(uri, localpart, element.rawname, fAttributesProxy); } catch( SAXException e ) { throw new XNIException(e); } } public void endElement(QName element, Augmentations augs) throws XNIException { try { String uri = element.uri != null ? element.uri : ""; String localpart = element.localpart; fContentHandler.endElement(uri, localpart, element.rawname); // send endPrefixMapping events int count = fNamespaceContext.getDeclaredPrefixCount(); if (count > 0) { for (int i = 0; i < count; i++) { fContentHandler.endPrefixMapping(fNamespaceContext.getDeclaredPrefixAt(i)); } } } catch( SAXException e ) { throw new XNIException(e); } } public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { startElement(element,attributes,augs); endElement(element,augs); } public void characters(XMLString text, Augmentations augs) throws XNIException { try { fContentHandler.characters(text.ch,text.offset,text.length); } catch (SAXException e) { throw new XNIException(e); } } public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException { try { fContentHandler.ignorableWhitespace(text.ch,text.offset,text.length); } catch (SAXException e) { throw new XNIException(e); } } } private static final class DraconianErrorHandler implements ErrorHandler { /** * Singleton instance. */ private static final DraconianErrorHandler ERROR_HANDLER_INSTANCE = new DraconianErrorHandler(); private DraconianErrorHandler() {} /** Returns the one and only instance of this error handler. */ public static DraconianErrorHandler getInstance() { return ERROR_HANDLER_INSTANCE; } /** Warning: Ignore. */ public void warning(SAXParseException e) throws SAXException { // noop } /** Error: Throws back SAXParseException. */ public void error(SAXParseException e) throws SAXException { throw e; } /** Fatal Error: Throws back SAXParseException. */ public void fatalError(SAXParseException e) throws SAXException { throw e; } } // DraconianErrorHandler /** * Compares the given {@link Attributes} with {@link #fCurrentAttributes} * and update the latter accordingly. */ private void updateAttributes( Attributes atts ) { int len = atts.getLength(); for( int i=0; i<len; i++ ) { String aqn = atts.getQName(i); int j = fCurrentAttributes.getIndex(aqn); String av = atts.getValue(i); if(j==-1) { // newly added attribute. add to the current attribute list. String prefix; int idx = aqn.indexOf(':'); if( idx<0 ) { prefix = null; } else { prefix = symbolize(aqn.substring(0,idx)); } j = fCurrentAttributes.addAttribute( new QName( prefix, symbolize(atts.getLocalName(i)), symbolize(aqn), symbolize(atts.getURI(i))), atts.getType(i),av); } else { // the attribute is present. if( !av.equals(fCurrentAttributes.getValue(j)) ) { // but the value was changed. fCurrentAttributes.setValue(j,av); } } /** Augmentations augs = fCurrentAttributes.getAugmentations(j); augs.putItem( Constants.TYPEINFO, typeInfoProvider.getAttributeTypeInfo(i) ); augs.putItem( Constants.ID_ATTRIBUTE, typeInfoProvider.isIdAttribute(i)?Boolean.TRUE:Boolean.FALSE ); **/ } } private String symbolize( String s ) { return fSymbolTable.addSymbol(s); } /** * {@link TypeInfoProvider} that returns no info. */ private static final TypeInfoProvider noInfoProvider = new TypeInfoProvider() { public TypeInfo getElementTypeInfo() { return null; } public TypeInfo getAttributeTypeInfo(int index) { return null; } public TypeInfo getAttributeTypeInfo(String attributeQName) { return null; } public TypeInfo getAttributeTypeInfo(String attributeUri, String attributeLocalName) { return null; } public boolean isIdAttribute(int index) { return false; } public boolean isSpecified(int index) { return false; } }; // // // XMLComponent implementation. // // // no property/feature supported public String[] getRecognizedFeatures() { return null; } public void setFeature(String featureId, boolean state) throws XMLConfigurationException { } public String[] getRecognizedProperties() { return new String[]{ENTITY_MANAGER, ERROR_REPORTER, SYMBOL_TABLE}; } public void setProperty(String propertyId, Object value) throws XMLConfigurationException { } public Boolean getFeatureDefault(String featureId) { return null; } public Object getPropertyDefault(String propertyId) { return null; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?