xpointerelementhandler.java

来自「JAVA 所有包」· Java 代码 · 共 760 行 · 第 1/2 页

JAVA
760
字号
        }    }    ///////// END OF IMPLEMENTATION  OF XMLComponents methods. //////////                //////// START OF  IMPLEMENTATION OF XMLDOCUMENTSOURCE INTERFACE /////////        public void setDocumentHandler(XMLDocumentHandler handler) {        fDocumentHandler = handler;    }        public XMLDocumentHandler getDocumentHandler() {        return fDocumentHandler;    }        ///////   END OF IMPLENTATION OF XMLDOCUMENTSOURCE INTERFACE ///////////                    /////////////// Implementation of XPointerSchema Methods //////////////////////        String fSchemaName;    String fSchemaPointer;    boolean fSubResourceIdentified;    /**     * set the Schema Name  eg element , xpointer     */    public void setXPointerSchemaName(String schemaName){        fSchemaName = schemaName;    }        /**     * Return  Schema Name  eg element , xpointer     *     */    public String getXpointerSchemaName(){        return fSchemaName;    }        /**     * Parent Contenhandler for the this contenthandler.     * // not sure about the parameter type. It can be Contenthandler instead of Object type.     */    public void setParent(Object parent){        fParentXIncludeHandler = (XIncludeHandler)parent;    }            /**     * return the Parent Contenthandler     */    public Object getParent(){        return fParentXIncludeHandler;    }        /**     * Content of the XPointer Schema. Xpath to be resolved.     */    public void setXPointerSchemaPointer(String content){        fSchemaPointer = content;    }        /**     * Return the XPointer Schema.     */    public String getXPointerSchemaPointer(){        return fSchemaPointer;    }        public boolean isSubResourceIndentified(){        return fSubResourceIdentified;    }        ///////////End Implementation of XPointerSchema Methods //////////////////////                //////////// Tokens Playground ///////////////////        Stack fPointerToken = new Stack();    int  fCurrentTokenint=0;    String fCurrentTokenString=null;    int fCurrentTokenType=0 ;// 0 Notype; 1 for integer; 2 for string.        public void getTokens(){        fSchemaPointer = fSchemaPointer.substring(fSchemaPointer.indexOf("(")+1, fSchemaPointer.length());        StringTokenizer st = new StringTokenizer(fSchemaPointer, "/");        String tempToken;        Integer integerToken =null;        Stack tempPointerToken = new Stack();        if(fPointerToken == null){            fPointerToken = new Stack();        }        while(st.hasMoreTokens()){            tempToken=st.nextToken();            try {                integerToken = Integer.valueOf(tempToken);                tempPointerToken.push(integerToken);            }catch(NumberFormatException e){                tempPointerToken.push(tempToken);            }        }        while(!tempPointerToken.empty()){            fPointerToken.push(tempPointerToken.pop());        }    }//getTokens            public boolean hasMoreToken(){        if(fPointerToken.isEmpty())            return false;        else            return true;    }        public boolean getNextToken(){        Object currentToken;        if (!fPointerToken.isEmpty()){            currentToken = fPointerToken.pop();            if(currentToken instanceof Integer){                fCurrentTokenint = ((Integer)currentToken).intValue();                fCurrentTokenType = 1;            }            else{                fCurrentTokenString = ((String)currentToken).toString();                fCurrentTokenType = 2;            }            return true;        }        else {            return false;        }    }        private boolean isIdAttribute(XMLAttributes attributes,Augmentations augs, int index) {        Object o = augs.getItem(Constants.ID_ATTRIBUTE);        if( o instanceof Boolean )            return ((Boolean)o).booleanValue();        return "ID".equals(attributes.getType(index));    }        public boolean checkStringToken(QName element, XMLAttributes attributes){        QName cacheQName = null;        String id =null;        String rawname =null;        QName attrName = new QName();        String attrType = null;        String attrValue = null;        int attrCount = attributes.getLength();        for (int i = 0; i < attrCount; i++) {            Augmentations aaugs = attributes.getAugmentations(i);            attributes.getName(i,attrName);            attrType = attributes.getType(i);            attrValue = attributes.getValue(i);            if(attrType != null && attrValue!= null && isIdAttribute(attributes,aaugs,i) && attrValue.equals(fCurrentTokenString)){                if(hasMoreToken()){                    fCurrentTokenType = 0;                    fCurrentTokenString = null;                    return true;                }                else{                    foundElement = element;                    includeElement = true;                    fCurrentTokenType = 0;                    fCurrentTokenString = null;                    fSubResourceIdentified = true;                    return true;                }            }        }        return false;    }        public boolean checkIntegerToken(QName element){        if(!skip){            fElementCount++;            if(fCurrentTokenint == fElementCount){                if(hasMoreToken()){                    fElementCount=0;                    fCurrentTokenType = 0;                    return true;                }                else{                    foundElement = element;                    includeElement = true;                    fCurrentTokenType = 0;                    fElementCount=0;                    fSubResourceIdentified =true;                    return true;                }            }else{                addQName(element);                skip = true;                return false;            }        }        return false;    }        public void addQName(QName element){        QName cacheQName = new QName(element);        ftempCurrentElement.push(cacheQName);    }        ///////////  END TOKEN PLAYGROUND ///////////////            /////   START OF IMPLEMTATION OF XMLDocumentHandler methods //////////            public void startDocument(XMLLocator locator, String encoding,    NamespaceContext namespaceContext, Augmentations augs)    throws XNIException {                getTokens();    }        public void doctypeDecl(String rootElement, String publicId, String systemId,    Augmentations augs)throws XNIException {    }        public void xmlDecl(String version, String encoding, String standalone,    Augmentations augs) throws XNIException {    }            public void comment(XMLString text, Augmentations augs)    throws XNIException {        if (fDocumentHandler != null && includeElement) {            fDocumentHandler.comment(text, augs);        }    }        public void processingInstruction(String target, XMLString data,    Augmentations augs) throws XNIException {        if (fDocumentHandler != null && includeElement) {            fDocumentHandler.processingInstruction(target, data, augs);                    }    }        Stack  ftempCurrentElement = new Stack();    int fElementCount =0;    int fCurrentToken ;    boolean includeElement;            public void startElement(QName element, XMLAttributes attributes,    Augmentations augs)throws XNIException {                boolean requiredToken=false;        if(fCurrentTokenType == 0)            getNextToken();        if(fCurrentTokenType ==1)            requiredToken = checkIntegerToken(element);        else if (fCurrentTokenType ==2)            requiredToken = checkStringToken(element, attributes);        if(requiredToken && hasMoreToken())            getNextToken();        if(fDocumentHandler != null && includeElement){            elemCount++;            fDocumentHandler.startElement(element, attributes, augs);        }            }            public void endElement(QName element, Augmentations augs)    throws XNIException {        if(includeElement && foundElement != null ){            if(elemCount >0 )elemCount --;            fDocumentHandler.endElement(element, augs);            if(elemCount == 0)includeElement = false;                    }else if(!ftempCurrentElement.empty()){            QName name = (QName)ftempCurrentElement.peek();            if(name.equals(element)){                ftempCurrentElement.pop();                skip = false;            }        }    }        public void emptyElement(QName element, XMLAttributes attributes,    Augmentations augs)throws XNIException {        if(fDocumentHandler != null && includeElement){            fDocumentHandler.emptyElement(element, attributes, augs);        }    }        public void startGeneralEntity(String name, XMLResourceIdentifier resId,    String encoding,    Augmentations augs)    throws XNIException {        if (fDocumentHandler != null && includeElement) {            fDocumentHandler.startGeneralEntity(name, resId, encoding, augs);        }    }        public void textDecl(String version, String encoding, Augmentations augs)    throws XNIException {        if (fDocumentHandler != null && includeElement) {            fDocumentHandler.textDecl(version, encoding, augs);        }    }        public void endGeneralEntity(String name, Augmentations augs)    throws XNIException {        if (fDocumentHandler != null) {            fDocumentHandler.endGeneralEntity(name, augs);        }    }        public void characters(XMLString text, Augmentations augs)    throws XNIException {        if (fDocumentHandler != null  && includeElement) {            fDocumentHandler.characters(text, augs);        }    }        public void ignorableWhitespace(XMLString text, Augmentations augs)    throws XNIException {        if (fDocumentHandler != null && includeElement) {            fDocumentHandler.ignorableWhitespace(text, augs);        }    }        public void startCDATA(Augmentations augs) throws XNIException {        if (fDocumentHandler != null && includeElement) {            fDocumentHandler.startCDATA(augs);        }    }        public void endCDATA(Augmentations augs) throws XNIException {        if (fDocumentHandler != null && includeElement) {            fDocumentHandler.endCDATA(augs);        }    }        public void endDocument(Augmentations augs) throws XNIException {    }        public void setDocumentSource(XMLDocumentSource source) {        fDocumentSource = source;    }        public XMLDocumentSource getDocumentSource() {        return fDocumentSource;    }            protected void reportFatalError(String key) {        this.reportFatalError(key, null);    }        protected void reportFatalError(String key, Object[] args) {        if (fErrorReporter != null) {            fErrorReporter.reportError(            fDocLocation,            XIncludeMessageFormatter.XINCLUDE_DOMAIN,            key,            args,            XMLErrorReporter.SEVERITY_FATAL_ERROR);        }        // we won't worry about when error reporter is null, since there should always be        // at least the default error reporter    }                // used to know whether to pass declarations to the document handler    protected boolean isRootDocument() {        return this.fParentXIncludeHandler == null;    }        } // class XPointerElementhandler

⌨️ 快捷键说明

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