📄 dtdgrammar.java
字号:
public boolean getAttributeDecl(int attributeDeclIndex, XMLAttributeDecl attributeDecl) { if (attributeDeclIndex < 0 || attributeDeclIndex >= fAttributeDeclCount) { return false; } int chunk = attributeDeclIndex >> CHUNK_SHIFT; int index = attributeDeclIndex & CHUNK_MASK; attributeDecl.name.setValues(fAttributeDeclName[chunk][index]); short attributeType; boolean isList; if (fAttributeDeclType[chunk][index] == -1) { attributeType = -1; isList = false; } else { attributeType = (short) (fAttributeDeclType[chunk][index] & LIST_MASK); isList = (fAttributeDeclType[chunk][index] & LIST_FLAG) != 0; } attributeDecl.simpleType.setValues(attributeType,fAttributeDeclName[chunk][index].localpart, fAttributeDeclEnumeration[chunk][index], isList, fAttributeDeclDefaultType[chunk][index], fAttributeDeclDefaultValue[chunk][index], fAttributeDeclNonNormalizedDefaultValue[chunk][index], fAttributeDeclDatatypeValidator[chunk][index]); return true; } // getAttributeDecl /** * Returns whether the given attribute is of type CDATA or not * * @param elName The element name. * @param atName The attribute name. * * @return true if the attribute is of type CDATA */ public boolean isCDATAAttribute(QName elName, QName atName) { int elDeclIdx = getElementDeclIndex(elName); int atDeclIdx = getAttributeDeclIndex(elDeclIdx, atName.rawname); if (getAttributeDecl(elDeclIdx, fAttributeDecl) && fAttributeDecl.simpleType.type != XMLSimpleType.TYPE_CDATA){ return false; } return true; } /** * getEntityDeclIndex * * @param entityDeclName * * @return the index of the EntityDecl */ public int getEntityDeclIndex(String entityDeclName) { if (entityDeclName == null) { return -1; } return fEntityIndexMap.get(entityDeclName); } // getEntityDeclIndex /** * getEntityDecl * * @param entityDeclIndex * @param entityDecl * * @return true if getEntityDecl was able to fill entityDecl with the contents of the entity * with index entityDeclIndex */ public boolean getEntityDecl(int entityDeclIndex, XMLEntityDecl entityDecl) { if (entityDeclIndex < 0 || entityDeclIndex >= fEntityCount) { return false; } int chunk = entityDeclIndex >> CHUNK_SHIFT; int index = entityDeclIndex & CHUNK_MASK; entityDecl.setValues(fEntityName[chunk][index], fEntityPublicId[chunk][index], fEntitySystemId[chunk][index], fEntityBaseSystemId[chunk][index], fEntityNotation[chunk][index], fEntityValue[chunk][index], fEntityIsPE[chunk][index] == 0 ? false : true , fEntityInExternal[chunk][index] == 0 ? false : true ); return true; } // getEntityDecl /** * getNotationDeclIndex * * @param notationDeclName * * @return the index if found a notation with the name, otherwise -1. */ public int getNotationDeclIndex(String notationDeclName) { if (notationDeclName == null) { return -1; } return fNotationIndexMap.get(notationDeclName); } // getNotationDeclIndex /** * getNotationDecl * * @param notationDeclIndex * @param notationDecl * * @return return true of getNotationDecl can fill notationDecl with information about * the notation at notationDeclIndex. */ public boolean getNotationDecl(int notationDeclIndex, XMLNotationDecl notationDecl) { if (notationDeclIndex < 0 || notationDeclIndex >= fNotationCount) { return false; } int chunk = notationDeclIndex >> CHUNK_SHIFT; int index = notationDeclIndex & CHUNK_MASK; notationDecl.setValues(fNotationName[chunk][index], fNotationPublicId[chunk][index], fNotationSystemId[chunk][index], fNotationBaseSystemId[chunk][index]); return true; } // getNotationDecl /** * getContentSpec * * @param contentSpecIndex * @param contentSpec * * @return true if find the requested contentSpec node, false otherwise */ public boolean getContentSpec(int contentSpecIndex, XMLContentSpec contentSpec) { if (contentSpecIndex < 0 || contentSpecIndex >= fContentSpecCount ) return false; int chunk = contentSpecIndex >> CHUNK_SHIFT; int index = contentSpecIndex & CHUNK_MASK; contentSpec.type = fContentSpecType[chunk][index]; contentSpec.value = fContentSpecValue[chunk][index]; contentSpec.otherValue = fContentSpecOtherValue[chunk][index]; return true; } /** * getContentSpecAsString * * @param elementDeclIndex * * @return String */ public String getContentSpecAsString(int elementDeclIndex){ if (elementDeclIndex < 0 || elementDeclIndex >= fElementDeclCount) { return null; } int chunk = elementDeclIndex >> CHUNK_SHIFT; int index = elementDeclIndex & CHUNK_MASK; int contentSpecIndex = fElementDeclContentSpecIndex[chunk][index]; // lookup content spec node XMLContentSpec contentSpec = new XMLContentSpec(); if (getContentSpec(contentSpecIndex, contentSpec)) { // build string StringBuffer str = new StringBuffer(); int parentContentSpecType = contentSpec.type & 0x0f; int nextContentSpec; switch (parentContentSpecType) { case XMLContentSpec.CONTENTSPECNODE_LEAF: { str.append('('); if (contentSpec.value == null && contentSpec.otherValue == null) { str.append("#PCDATA"); } else { str.append(contentSpec.value); } str.append(')'); break; } case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE: { getContentSpec(((int[])contentSpec.value)[0], contentSpec); nextContentSpec = contentSpec.type; if (nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) { str.append('('); str.append(contentSpec.value); str.append(')'); } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { str.append('(' ); appendContentSpec(contentSpec, str, true, parentContentSpecType ); str.append(')'); } else { appendContentSpec(contentSpec, str, true, parentContentSpecType ); } str.append('?'); break; } case XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE: { getContentSpec(((int[])contentSpec.value)[0], contentSpec); nextContentSpec = contentSpec.type; if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) { str.append('('); if (contentSpec.value == null && contentSpec.otherValue == null) { str.append("#PCDATA"); } else if (contentSpec.otherValue != null) { str.append("##any:uri="+contentSpec.otherValue); } else if (contentSpec.value == null) { str.append("##any"); } else { appendContentSpec(contentSpec, str, true, parentContentSpecType ); } str.append(')'); } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { str.append('(' ); appendContentSpec(contentSpec, str, true, parentContentSpecType ); str.append(')'); } else { appendContentSpec(contentSpec, str, true, parentContentSpecType ); } str.append('*'); break; } case XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE: { getContentSpec(((int[])contentSpec.value)[0], contentSpec); nextContentSpec = contentSpec.type; if ( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_LEAF) { str.append('('); if (contentSpec.value == null && contentSpec.otherValue == null) { str.append("#PCDATA"); } else if (contentSpec.otherValue != null) { str.append("##any:uri="+contentSpec.otherValue); } else if (contentSpec.value == null) { str.append("##any"); } else { str.append(contentSpec.value); } str.append(')'); } else if( nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ONE_OR_MORE || nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_MORE || nextContentSpec == XMLContentSpec.CONTENTSPECNODE_ZERO_OR_ONE ) { str.append('(' ); appendContentSpec(contentSpec, str, true, parentContentSpecType ); str.append(')'); } else { appendContentSpec(contentSpec, str, true, parentContentSpecType); } str.append('+'); break; } case XMLContentSpec.CONTENTSPECNODE_CHOICE: case XMLContentSpec.CONTENTSPECNODE_SEQ: { appendContentSpec(contentSpec, str, true, parentContentSpecType ); break; } case XMLContentSpec.CONTENTSPECNODE_ANY: { str.append("##any"); if (contentSpec.otherValue != null) { str.append(":uri="); str.append(contentSpec.otherValue); } break; } case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER: { str.append("##other:uri="); str.append(contentSpec.otherValue); break; } case XMLContentSpec.CONTENTSPECNODE_ANY_LOCAL: { str.append("##local"); break; } default: { str.append("???"); } } // switch type // return string return str.toString(); } // not found return null; } // getContentSpecAsString(int):String // debugging public void printElements( ) { int elementDeclIndex = 0; XMLElementDecl elementDecl = new XMLElementDecl(); while (getElementDecl(elementDeclIndex++, elementDecl)) { System.out.println("element decl: "+elementDecl.name+ ", "+ elementDecl.name.rawname ); // ", "+ elementDecl.contentModelValidator.toString());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -