📄 xmldtdprocessor.java
字号:
// the grammar bucket's DTDGrammar will now be the // one we want, whether we're constructing it or not. // if we're not constructing it, then we should not have a reference // to it! if( !fGrammarBucket.getActiveGrammar().isImmutable()) { fDTDGrammar = fGrammarBucket.getActiveGrammar(); } // call handlers if(fDTDGrammar != null ) fDTDGrammar.startDTD(locator, augs); if (fDTDHandler != null) { fDTDHandler.startDTD(locator, augs); } } // startDTD(XMLLocator) /** * Characters within an IGNORE conditional section. * * @param text The ignored text. * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void ignoredCharacters(XMLString text, Augmentations augs) throws XNIException { // ignored characters in DTD if(fDTDGrammar != null ) fDTDGrammar.ignoredCharacters(text, augs); if (fDTDHandler != null) { fDTDHandler.ignoredCharacters(text, augs); } } /** * Notifies of the presence of a TextDecl line in an entity. If present, * this method will be called immediately following the startParameterEntity call. * <p> * <strong>Note:</strong> This method is only called for external * parameter entities referenced in the DTD. * * @param version The XML version, or null if not specified. * @param encoding The IANA encoding name of the entity. * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void textDecl(String version, String encoding, Augmentations augs) throws XNIException { // call handlers if(fDTDGrammar != null ) fDTDGrammar.textDecl(version, encoding, augs); if (fDTDHandler != null) { fDTDHandler.textDecl(version, encoding, augs); } } /** * This method notifies of the start of a parameter entity. The parameter * entity name start with a '%' character. * * @param name The name of the parameter entity. * @param identifier The resource identifier. * @param encoding The auto-detected IANA encoding name of the entity * stream. This value will be null in those situations * where the entity encoding is not auto-detected (e.g. * internal parameter entities). * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void startParameterEntity(String name, XMLResourceIdentifier identifier, String encoding, Augmentations augs) throws XNIException { if (fPerformValidation && fDTDGrammar != null && fGrammarBucket.getStandalone()) { checkStandaloneEntityRef(name, fDTDGrammar, fEntityDecl, fErrorReporter); } // call handlers if(fDTDGrammar != null ) fDTDGrammar.startParameterEntity(name, identifier, encoding, augs); if (fDTDHandler != null) { fDTDHandler.startParameterEntity(name, identifier, encoding, augs); } } /** * This method notifies the end of a parameter entity. Parameter entity * names begin with a '%' character. * * @param name The name of the parameter entity. * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void endParameterEntity(String name, Augmentations augs) throws XNIException { // call handlers if(fDTDGrammar != null ) fDTDGrammar.endParameterEntity(name, augs); if (fDTDHandler != null) { fDTDHandler.endParameterEntity(name, augs); } } /** * An element declaration. * * @param name The name of the element. * @param contentModel The element content model. * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void elementDecl(String name, String contentModel, Augmentations augs) throws XNIException { //check VC: Unique Element Declaration if (fValidation) { if (fDTDElementDecls.contains(name)) { fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "MSG_ELEMENT_ALREADY_DECLARED", new Object[]{ name}, XMLErrorReporter.SEVERITY_ERROR); } else { fDTDElementDecls.addElement(name); } } // call handlers if(fDTDGrammar != null ) fDTDGrammar.elementDecl(name, contentModel, augs); if (fDTDHandler != null) { fDTDHandler.elementDecl(name, contentModel, augs); } } // elementDecl(String,String) /** * The start of an attribute list. * * @param elementName The name of the element that this attribute * list is associated with. * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void startAttlist(String elementName, Augmentations augs) throws XNIException { // call handlers if(fDTDGrammar != null ) fDTDGrammar.startAttlist(elementName, augs); if (fDTDHandler != null) { fDTDHandler.startAttlist(elementName, augs); } } // startAttlist(String) /** * An attribute declaration. * * @param elementName The name of the element that this attribute * is associated with. * @param attributeName The name of the attribute. * @param type The attribute type. This value will be one of * the following: "CDATA", "ENTITY", "ENTITIES", * "ENUMERATION", "ID", "IDREF", "IDREFS", * "NMTOKEN", "NMTOKENS", or "NOTATION". * @param enumeration If the type has the value "ENUMERATION" or * "NOTATION", this array holds the allowed attribute * values; otherwise, this array is null. * @param defaultType The attribute default type. This value will be * one of the following: "#FIXED", "#IMPLIED", * "#REQUIRED", or null. * @param defaultValue The attribute default value, or null if no * default value is specified. * @param nonNormalizedDefaultValue The attribute default value with no normalization * performed, or null if no default value is specified. * @param augs Additional information that may include infoset * augmentations. * * @throws XNIException Thrown by handler to signal an error. */ public void attributeDecl(String elementName, String attributeName, String type, String[] enumeration, String defaultType, XMLString defaultValue, XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException { if (type != XMLSymbols.fCDATASymbol && defaultValue != null) { normalizeDefaultAttrValue(defaultValue); } if (fValidation) { boolean duplicateAttributeDef = false ; //Get Grammar index to grammar array DTDGrammar grammar = (fDTDGrammar != null? fDTDGrammar:fGrammarBucket.getActiveGrammar()); int elementIndex = grammar.getElementDeclIndex( elementName); if (grammar.getAttributeDeclIndex(elementIndex, attributeName) != -1) { //more than one attribute definition is provided for the same attribute of a given element type. duplicateAttributeDef = true ; //this feature works only when validation is true. if(fWarnDuplicateAttdef){ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "MSG_DUPLICATE_ATTRIBUTE_DEFINITION", new Object[]{ elementName, attributeName }, XMLErrorReporter.SEVERITY_WARNING ); } } // // a) VC: One ID per Element Type, If duplicate ID attribute // b) VC: ID attribute Default. if there is a declareared attribute // default for ID it should be of type #IMPLIED or #REQUIRED if (type == XMLSymbols.fIDSymbol) { if (defaultValue != null && defaultValue.length != 0) { if (defaultType == null || !(defaultType == XMLSymbols.fIMPLIEDSymbol || defaultType == XMLSymbols.fREQUIREDSymbol)) { fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "IDDefaultTypeInvalid", new Object[]{ attributeName}, XMLErrorReporter.SEVERITY_ERROR); } } if (!fTableOfIDAttributeNames.containsKey(elementName)) { fTableOfIDAttributeNames.put(elementName, attributeName); } else { //we should not report an error, when there is duplicate attribute definition for given element type //according to XML 1.0 spec, When more than one definition is provided for the same attribute of a given //element type, the first declaration is binding and later declaration are *ignored*. So processor should //ignore the second declarations, however an application would be warned of the duplicate attribute defintion // if http://apache.org/xml/features/validation/warn-on-duplicate-attdef feature is set to true, // one typical case where this could be a problem, when any XML file // provide the ID type information through internal subset so that it is available to the parser which read //only internal subset. Now that attribute declaration(ID Type) can again be part of external parsed entity //referenced. At that time if parser doesn't make this distinction it will throw an error for VC One ID per //Element Type, which (second defintion) actually should be ignored. Application behavior may differ on the //basis of error or warning thrown. - nb. if(!duplicateAttributeDef){ String previousIDAttributeName = (String)fTableOfIDAttributeNames.get( elementName );//rule a) fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "MSG_MORE_THAN_ONE_ID_ATTRIBUTE", new Object[]{ elementName, previousIDAttributeName, attributeName}, XMLErrorReporter.SEVERITY_ERROR); } } } // // VC: One Notation Per Element Type, should check if there is a // duplicate NOTATION attribute if (type == XMLSymbols.fNOTATIONSymbol) { // VC: Notation Attributes: all notation names in the // (attribute) declaration must be declared. for (int i=0; i<enumeration.length; i++) { fNotationEnumVals.put(enumeration[i], attributeName); } if (fTableOfNOTATIONAttributeNames.containsKey( elementName ) == false) { fTableOfNOTATIONAttributeNames.put( elementName, attributeName); } else { //we should not report an error, when there is duplicate attribute definition for given element type //according to XML 1.0 spec, When more than one definition is provided for the same attribute of a given //element type, the first declaration is binding and later declaration are *ignored*. So processor should //ignore the second declarations, however an application would be warned of the duplicate attribute defintion // if http://apache.org/xml/features/validation/warn-on-duplicate-attdef feature is set to true, Application behavior may differ on the basis of error or //warning thrown. - nb. if(!duplicateAttributeDef){ String previousNOTATIONAttributeName = (String) fTableOfNOTATIONAttributeNames.get( elementName ); fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "MSG_MORE_THAN_ONE_NOTATION_ATTRIBUTE", new Object[]{ elementName, previousNOTATIONAttributeName, attributeName}, XMLErrorReporter.SEVERITY_ERROR); } } } // VC: No Duplicate Tokens // XML 1.0 SE Errata - E2 if (type == XMLSymbols.fENUMERATIONSymbol || type == XMLSymbols.fNOTATIONSymbol) { outer: for (int i = 0; i < enumeration.length; ++i) { for (int j = i + 1; j < enumeration.length; ++j) { if (enumeration[i].equals(enumeration[j])) { // Only report the first uniqueness violation. There could be others, // but additional overhead would be incurred tracking unique tokens // that have already been encountered. -- mrglavas fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, type == XMLSymbols.fENUMERATIONSymbol ? "MSG_DISTINCT_TOKENS_IN_ENUMERATION" : "MSG_DISTINCT_NOTATION_IN_ENUMERATION", new Object[]{ elementName, enumeration[i], attributeName }, XMLErrorReporter.SEVERITY_ERROR); break outer; } } } } // VC: Attribute Default Legal boolean ok = true; if (defaultValue != null && (defaultType == null || (defaultType != null && defaultType == XMLSymbols.fFIXEDSymbol))) { String value = defaultValue.toString(); if (type == XMLSymbols.fNMTOKENSSymbol || type == XMLSymbols.fENTITIESSymbol || type == XMLSymbols.fIDREFSSymbol) { StringTokenizer tokenizer = new StringTokenizer(value," "); if (tokenizer.hasMoreTokens()) { while (true) { String nmtoken = tokenizer.nextToken(); if (type == XMLSymbols.fNMTOKENSSymbol) { if (!isValidNmtoken(nmtoken)) { ok = false; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -