📄 xmldtdvalidator.java
字号:
if (fDocumentHandler != null) { fDocumentHandler.startDocument(locator, encoding, namespaceContext, augs); } } // startDocument(XMLLocator,String) /** * Notifies of the presence of an XMLDecl line in the document. If * present, this method will be called immediately following the * startDocument call. * * @param version The XML version. * @param encoding The IANA encoding name of the document, or null if * not specified. * @param standalone The standalone value, or null if not specified. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) throws XNIException { // save standalone state fGrammarBucket.setStandalone(standalone != null && standalone.equals("yes")); // call handlers if (fDocumentHandler != null) { fDocumentHandler.xmlDecl(version, encoding, standalone, augs); } } // xmlDecl(String,String,String) /** * Notifies of the presence of the DOCTYPE line in the document. * * @param rootElement The name of the root element. * @param publicId The public identifier if an external DTD or null * if the external DTD is specified using SYSTEM. * @param systemId The system identifier if an external DTD, null * otherwise. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void doctypeDecl(String rootElement, String publicId, String systemId, Augmentations augs) throws XNIException { // save root element state fSeenDoctypeDecl = true; fRootElement.setValues(null, rootElement, rootElement, null); // find or create grammar: String eid = null; try { eid = XMLEntityManager.expandSystemId(systemId, fDocLocation.getExpandedSystemId(), false); } catch (java.io.IOException e) { } XMLDTDDescription grammarDesc = new XMLDTDDescription(publicId, systemId, fDocLocation.getExpandedSystemId(), eid, rootElement); fDTDGrammar = fGrammarBucket.getGrammar(grammarDesc); if(fDTDGrammar == null) { // give grammar pool a chance... // // Do not bother checking the pool if no public or system identifier was provided. // Since so many different DTDs have roots in common, using only a root name as the // key may cause an unexpected grammar to be retrieved from the grammar pool. This scenario // would occur when an ExternalSubsetResolver has been queried and the // XMLInputSource returned contains an input stream but no external identifier. // This can never happen when the instance document specified a DOCTYPE. -- mrglavas if (fGrammarPool != null && (systemId != null || publicId != null)) { fDTDGrammar = (DTDGrammar)fGrammarPool.retrieveGrammar(grammarDesc); } } if(fDTDGrammar == null) { // we'll have to create it... fDTDGrammar = new DTDGrammar(fSymbolTable, grammarDesc); } else { // we've found a cached one;so let's make sure not to read // any external subset! fValidationManager.setCachedDTD(true); } fGrammarBucket.setActiveGrammar(fDTDGrammar); // call handlers if (fDocumentHandler != null) { fDocumentHandler.doctypeDecl(rootElement, publicId, systemId, augs); } } // doctypeDecl(String,String,String, Augmentations) /** * The start of an element. * * @param element The name of the element. * @param attributes The element attributes. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { handleStartElement(element, attributes, augs); // call handlers if (fDocumentHandler != null) { fDocumentHandler.startElement(element, attributes, augs); } } // startElement(QName,XMLAttributes) /** * An empty element. * * @param element The name of the element. * @param attributes The element attributes. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { boolean removed = handleStartElement(element, attributes, augs); if (fDocumentHandler !=null) { fDocumentHandler.emptyElement(element, attributes, augs); } if (!removed) { handleEndElement(element, augs, true); } } // emptyElement(QName,XMLAttributes) /** * Character content. * * @param text The content. * * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void characters(XMLString text, Augmentations augs) throws XNIException { boolean callNextCharacters = true; // REVISIT: [Q] Is there a more efficient way of doing this? // Perhaps if the scanner told us so we don't have to // look at the characters again. -Ac boolean allWhiteSpace = true; for (int i=text.offset; i< text.offset+text.length; i++) { if (!isSpace(text.ch[i])) { allWhiteSpace = false; break; } } // call the ignoreableWhiteSpace callback // never call ignorableWhitespace if we are in cdata section if (fInElementContent && allWhiteSpace && !fInCDATASection) { if (fDocumentHandler != null) { fDocumentHandler.ignorableWhitespace(text, augs); callNextCharacters = false; } } // validate if (fPerformValidation) { if (fInElementContent) { if (fGrammarBucket.getStandalone() && fDTDGrammar.getElementDeclIsExternal(fCurrentElementIndex)) { if (allWhiteSpace) { fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, "MSG_WHITE_SPACE_IN_ELEMENT_CONTENT_WHEN_STANDALONE", null, XMLErrorReporter.SEVERITY_ERROR); } } if (!allWhiteSpace) { charDataInContent(); } // For E15.2 if (augs != null && augs.getItem(Constants.CHAR_REF_PROBABLE_WS) == Boolean.TRUE) { fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "MSG_CONTENT_INVALID_SPECIFIED", new Object[]{ fCurrentElement.rawname, fDTDGrammar.getContentSpecAsString(fElementDepth), "character reference"}, XMLErrorReporter.SEVERITY_ERROR); } } if (fCurrentContentSpecType == XMLElementDecl.TYPE_EMPTY) { charDataInContent(); } } // call handlers if (callNextCharacters && fDocumentHandler != null) { fDocumentHandler.characters(text, augs); } } // characters(XMLString) /** * Ignorable whitespace. For this method to be called, the document * source must have some way of determining that the text containing * only whitespace characters should be considered ignorable. For * example, the validator can determine if a length of whitespace * characters in the document are ignorable based on the element * content model. * * @param text The ignorable whitespace. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException { // call handlers if (fDocumentHandler != null) { fDocumentHandler.ignorableWhitespace(text, augs); } } // ignorableWhitespace(XMLString) /** * The end of an element. * * @param element The name of the element. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void endElement(QName element, Augmentations augs) throws XNIException { handleEndElement(element, augs, false); } // endElement(QName) /** * The start of a CDATA section. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void startCDATA(Augmentations augs) throws XNIException { if (fPerformValidation && fInElementContent) { charDataInContent(); } fInCDATASection = true; // call handlers if (fDocumentHandler != null) { fDocumentHandler.startCDATA(augs); } } // startCDATA() /** * The end of a CDATA section. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void endCDATA(Augmentations augs) throws XNIException { fInCDATASection = false; // call handlers if (fDocumentHandler != null) { fDocumentHandler.endCDATA(augs); } } // endCDATA() /** * The end of the document. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by handler to signal an error. */ public void endDocument(Augmentations augs) throws XNIException { // call handlers if (fDocumentHandler != null) { fDocumentHandler.endDocument(augs); } } // endDocument() /** * A comment. * * @param text The text in the comment. * @param augs Additional information that may include infoset augmentations * * @throws XNIException Thrown by application to signal an error. */ public void comment(XMLString text, Augmentations augs) throws XNIException { // fixes E15.1 if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) { fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl); if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) { fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "MSG_CONTENT_INVALID_SPECIFIED", new Object[]{ fCurrentElement.rawname, "EMPTY", "comment"}, XMLErrorReporter.SEVERITY_ERROR); } } // call handlers if (fDocumentHandler != null) { fDocumentHandler.comment(text, augs); } } // comment(XMLString) /** * A processing instruction. Processing instructions consist of a * target name and, optionally, text data. The data is only meaningful * to the application. * <p> * Typically, a processing instruction's data will contain a series * of pseudo-attributes. These pseudo-attributes follow the form of
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -