⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtdgrammar.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    // return the XMLDTDDescription object with which this is associated    public XMLGrammarDescription getGrammarDescription() {        return fGrammarDescription;    } // getGrammarDescription():  XMLGrammarDescription    //    // Public methods    //    /**     * Returns true if the specified element declaration is external.     *     * @param elementDeclIndex The element declaration index.     */    public boolean getElementDeclIsExternal(int elementDeclIndex) {        if (elementDeclIndex < 0) {            return false;        }        int chunk = elementDeclIndex >> CHUNK_SHIFT;        int index = elementDeclIndex & CHUNK_MASK;        return (fElementDeclIsExternal[chunk][index] != 0);    } // getElementDeclIsExternal(int):boolean    /**     * Returns true if the specified attribute declaration is external.     *     * @param attributeDeclIndex Attribute declaration index.     */    public boolean getAttributeDeclIsExternal(int attributeDeclIndex) {        if (attributeDeclIndex < 0) {            return false;        }        int chunk = attributeDeclIndex >> CHUNK_SHIFT;        int index = attributeDeclIndex & CHUNK_MASK;        return (fAttributeDeclIsExternal[chunk][index] != 0);    }    public int getAttributeDeclIndex(int elementDeclIndex, String attributeDeclName) {        if (elementDeclIndex == -1) {            return -1;        }        int attDefIndex = getFirstAttributeDeclIndex(elementDeclIndex);        while (attDefIndex != -1) {            getAttributeDecl(attDefIndex, fAttributeDecl);            if (fAttributeDecl.name.rawname == attributeDeclName                || attributeDeclName.equals(fAttributeDecl.name.rawname) ) {                return attDefIndex;            }            attDefIndex = getNextAttributeDeclIndex(attDefIndex);        }        return -1;    } // getAttributeDeclIndex (int,QName)    //    // XMLDTDHandler methods    //    /**     * The start of the DTD.     *     * @param locator  The document locator, or null if the document     *                 location cannot be reported during the parsing of     *                 the document DTD. However, it is <em>strongly</em>     *                 recommended that a locator be supplied that can     *                 at least report the base system identifier of the     *                 DTD.     *     * @param augs Additional information that may include infoset     *                      augmentations.     * @throws XNIException Thrown by handler to signal an error.     */    public void startDTD(XMLLocator locator, Augmentations augs) throws XNIException {        //Initialize stack        fOpStack = null;        fNodeIndexStack = null;        fPrevNodeIndexStack = null;    } // startDTD(XMLLocator)    /**     * This method notifies of the start of an entity. The DTD has the     * pseudo-name of "[dtd]" and parameter entity names start with '%'.     * <p>     * <strong>Note:</strong> Since the DTD is an entity, the handler     * will be notified of the start of the DTD entity by calling the     * startParameterEntity method with the entity name "[dtd]" <em>before</em> calling     * the startDTD method.     *     * @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 {        // keep track of this entity before fEntityDepth is increased        if (fPEDepth == fPEntityStack.length) {            boolean[] entityarray = new boolean[fPEntityStack.length * 2];            System.arraycopy(fPEntityStack, 0, entityarray, 0, fPEntityStack.length);            fPEntityStack = entityarray;        }        fPEntityStack[fPEDepth] = fReadingExternalDTD;        fPEDepth++;    } // startParameterEntity(String,XMLResourceIdentifier,String,Augmentations)    /**     * The start of the DTD external subset.     *     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startExternalSubset(XMLResourceIdentifier identifier,                                    Augmentations augs) throws XNIException {        fReadingExternalDTD = true;    } // startExternalSubset(Augmentations)    /**     * This method notifies the end of an entity. The DTD has the pseudo-name     * of "[dtd]" and parameter entity names start with '%'.     * <p>     * <strong>Note:</strong> Since the DTD is an entity, the handler     * will be notified of the end of the DTD entity by calling the     * endEntity method with the entity name "[dtd]" <em>after</em> calling     * the endDTD method.     *     * @param name The name of the 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 {        fPEDepth--;        fReadingExternalDTD = fPEntityStack[fPEDepth];    } // endParameterEntity(String,Augmentations)    /**     * The end of the DTD external subset.     *     * @param augs Additional information that may include infoset     *                      augmentations.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endExternalSubset(Augmentations augs) throws XNIException {        fReadingExternalDTD = false;    } // endExternalSubset(Augmentations)    /**     * 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 {        XMLElementDecl tmpElementDecl = (XMLElementDecl) fElementDeclTab.get(name) ;        // check if it is already defined        if ( tmpElementDecl != null ) {            if (tmpElementDecl.type == -1) {                fCurrentElementIndex = getElementDeclIndex(name);            }            else {                // duplicate element, ignored.                return;            }        }        else {            fCurrentElementIndex = createElementDecl();//create element decl        }        XMLElementDecl elementDecl       = new XMLElementDecl();                fQName.setValues(null, name, name, null);               elementDecl.name.setValues(fQName);        elementDecl.contentModelValidator = null;        elementDecl.scope= -1;        if (contentModel.equals("EMPTY")) {            elementDecl.type = XMLElementDecl.TYPE_EMPTY;        }        else if (contentModel.equals("ANY")) {            elementDecl.type = XMLElementDecl.TYPE_ANY;        }        else if (contentModel.startsWith("(") ) {            if (contentModel.indexOf("#PCDATA") > 0 ) {                elementDecl.type = XMLElementDecl.TYPE_MIXED;            }            else {                elementDecl.type = XMLElementDecl.TYPE_CHILDREN;            }        }        //add(or set) this elementDecl to the local cache        this.fElementDeclTab.put(name, elementDecl );        fElementDecl         = elementDecl;        if ((fDepth == 0 ||            (fDepth == 1 && elementDecl.type == XMLElementDecl.TYPE_MIXED)) &&            fNodeIndexStack != null) {            if (elementDecl.type == XMLElementDecl.TYPE_MIXED) {                int pcdata = addUniqueLeafNode(null);                if (fNodeIndexStack[0] == -1) {                    fNodeIndexStack[0] = pcdata;                }                else {                    fNodeIndexStack[0] = addContentSpecNode(XMLContentSpec.CONTENTSPECNODE_CHOICE,                                                            pcdata, fNodeIndexStack[0]);                }            }            setContentSpecIndex(fCurrentElementIndex, fNodeIndexStack[fDepth]);        }        if ( DEBUG ) {            System.out.println(  "name = " + fElementDecl.name.localpart );            System.out.println(  "Type = " + fElementDecl.type );        }        setElementDecl(fCurrentElementIndex, fElementDecl );//set internal structure        int chunk = fCurrentElementIndex >> CHUNK_SHIFT;        int index = fCurrentElementIndex & CHUNK_MASK;        ensureElementDeclCapacity(chunk);        fElementDeclIsExternal[chunk][index] = fReadingExternalDTD? 1 : 0;    } // elementDecl(String,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", 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 ( this.fElementDeclTab.containsKey( (String) elementName) ) {            //if ElementDecl has already being created in the Grammar then remove from table,            //this.fElementDeclTab.remove( (String) elementName );        }        // then it is forward reference to a element decl, create the elementDecl first.        else {            fCurrentElementIndex = createElementDecl();//create element decl            XMLElementDecl elementDecl       = new XMLElementDecl();            elementDecl.name.setValues(null, elementName, elementName, null);            elementDecl.scope= -1;            //add(or set) this elementDecl to the local cache            this.fElementDeclTab.put(elementName, elementDecl );            //set internal structure            setElementDecl(fCurrentElementIndex, elementDecl );        }        //Get Grammar index to grammar array        int elementIndex       = getElementDeclIndex(elementName);                //return, when more than one definition is provided for the same attribute of given element type        //only the first declaration is binding and later declarations are ignored        if (getAttributeDeclIndex(elementIndex, attributeName) != -1) {            return;        }        fCurrentAttributeIndex = createAttributeDecl();// Create current Attribute Decl        fSimpleType.clear();        if ( defaultType != null ) {            if ( defaultType.equals( "#FIXED") ) {                fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_FIXED;            } else if ( defaultType.equals( "#IMPLIED") ) {                fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_IMPLIED;            } else if ( defaultType.equals( "#REQUIRED") ) {                fSimpleType.defaultType = XMLSimpleType.DEFAULT_TYPE_REQUIRED;            }        }        if ( DEBUG ) {            System.out.println("defaultvalue = " + defaultValue.toString() );        }        fSimpleType.defaultValue      = defaultValue!=null ?  defaultValue.toString() : null;        fSimpleType.nonNormalizedDefaultValue      = nonNormalizedDefaultValue!=null ?  nonNormalizedDefaultValue.toString() : null;        fSimpleType.enumeration       = enumeration;        if (type.equals("CDATA")) {            fSimpleType.type = XMLSimpleType.TYPE_CDATA;        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -