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

📄 documentnavigator.java

📁 XML的解析、编译、查询等技术的JAVA源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }    public Iterator getParentAxisIterator(Object contextNode)    {        Object parent = null;        if ( contextNode instanceof Document )        {            return JaxenConstants.EMPTY_ITERATOR;        }        else if ( contextNode instanceof Element )        {            parent = ((Element)contextNode).getParent();            if ( parent == null )            {                if ( ((Element)contextNode).isRootElement() )                {                    parent = ((Element)contextNode).getDocument();                }            }        }        else if ( contextNode instanceof Attribute )        {            parent = ((Attribute)contextNode).getParent();        }        else if ( contextNode instanceof XPathNamespace )        {            parent = ((XPathNamespace)contextNode).getJDOMElement();        }        else if ( contextNode instanceof ProcessingInstruction )        {            parent = ((ProcessingInstruction)contextNode).getParent();        }        else if ( contextNode instanceof Comment )        {            parent = ((Comment)contextNode).getParent();        }        else if ( contextNode instanceof Text )        {            parent = ((Text)contextNode).getParent();        }                if ( parent != null )        {            return new SingleObjectIterator( parent );        }        return JaxenConstants.EMPTY_ITERATOR;    }    public Iterator getAttributeAxisIterator(Object contextNode)    {        if ( ! ( contextNode instanceof Element ) )        {            return JaxenConstants.EMPTY_ITERATOR;        }        Element elem = (Element) contextNode;        return elem.getAttributes().iterator();    }    /**     * Retrieves an <code>Iterator</code> over the attribute elements that     * match the supplied name.     *     * @param contextNode      the origin context node     * @param localName        the local name of the attributes to return, always present     * @param namespacePrefix  the prefix of the namespace of the attributes to return     * @param namespaceURI     the URI of the namespace of the attributes to return     * @return an Iterator     that traverses the named attributes, not null     */    public Iterator getAttributeAxisIterator(            Object contextNode, String localName, String namespacePrefix, String namespaceURI) {        if ( contextNode instanceof Element ) {            Element node = (Element) contextNode;            Namespace namespace = (namespaceURI == null ? Namespace.NO_NAMESPACE :                                     Namespace.getNamespace(namespacePrefix, namespaceURI));            Attribute attr = node.getAttribute(localName, namespace);            if (attr != null) {                return new SingleObjectIterator(attr);            }        }        return JaxenConstants.EMPTY_ITERATOR;    }    /** Returns a parsed form of the given XPath string, which will be suitable     *  for queries on JDOM documents.     */    public XPath parseXPath (String xpath) throws SAXPathException    {        return new JDOMXPath(xpath);    }    public Object getDocumentNode(Object contextNode)    {        if ( contextNode instanceof Document )        {            return contextNode;        }        Element elem = (Element) contextNode;        return elem.getDocument();    }    public String getElementQName(Object obj)    {        Element elem = (Element) obj;        String prefix = elem.getNamespacePrefix();        if ( prefix == null || prefix.length() == 0 )        {            return elem.getName();        }        return prefix + ":" + elem.getName();    }    public String getAttributeQName(Object obj)    {        Attribute attr = (Attribute) obj;        String prefix = attr.getNamespacePrefix();        if ( prefix == null || "".equals( prefix ) )        {            return attr.getName();        }        return prefix + ":" + attr.getName();    }    public String getNamespaceStringValue(Object obj)    {        if (obj instanceof Namespace) {            Namespace ns = (Namespace) obj;            return ns.getURI();        } else {            XPathNamespace ns = (XPathNamespace) obj;            return ns.getJDOMNamespace().getURI();        }            }    public String getNamespacePrefix(Object obj)    {        if (obj instanceof Namespace) {            Namespace ns = (Namespace) obj;            return ns.getPrefix();        } else {            XPathNamespace ns = (XPathNamespace) obj;            return ns.getJDOMNamespace().getPrefix();        }    }    public String getTextStringValue(Object obj)    {        if ( obj instanceof Text )        {            return ((Text)obj).getText();        }        if ( obj instanceof CDATA )        {            return ((CDATA)obj).getText();        }        return "";    }    public String getAttributeStringValue(Object obj)    {        Attribute attr = (Attribute) obj;        return attr.getValue();    }    public String getElementStringValue(Object obj)    {        Element elem = (Element) obj;        StringBuffer buf = new StringBuffer();        List     content     = elem.getContent();        Iterator contentIter = content.iterator();        Object   each        = null;        while ( contentIter.hasNext() )        {            each = contentIter.next();            if ( each instanceof Text )            {                buf.append( ((Text)each).getText() );            }            else if ( each instanceof CDATA )            {                buf.append( ((CDATA)each).getText() );            }            else if ( each instanceof Element )            {                buf.append( getElementStringValue( each ) );            }        }        return buf.toString();    }    public String getProcessingInstructionTarget(Object obj)    {        ProcessingInstruction pi = (ProcessingInstruction) obj;        return pi.getTarget();    }    public String getProcessingInstructionData(Object obj)    {        ProcessingInstruction pi = (ProcessingInstruction) obj;        return pi.getData();    }    public String getCommentStringValue(Object obj)    {        Comment cmt = (Comment) obj;        return cmt.getText();    }    public String translateNamespacePrefixToUri(String prefix, Object context)    {        Element element = null;        if ( context instanceof Element )         {            element = (Element) context;        }        else if ( context instanceof Text )        {            element = (Element)((Text)context).getParent();        }        else if ( context instanceof Attribute )        {            element = ((Attribute)context).getParent();        }        else if ( context instanceof XPathNamespace )        {            element = ((XPathNamespace)context).getJDOMElement();        }        else if ( context instanceof Comment )        {            element = (Element)((Comment)context).getParent();        }        else if ( context instanceof ProcessingInstruction )        {            element = (Element)((ProcessingInstruction)context).getParent();        }        if ( element != null )        {            Namespace namespace = element.getNamespace( prefix );            if ( namespace != null )             {                return namespace.getURI();            }        }        return null;    }    public Object getDocument(String url) throws FunctionCallException    {        try        {            SAXBuilder builder = new SAXBuilder();                        return builder.build( url );        }        catch (Exception e)        {            throw new FunctionCallException( e.getMessage() );        }    }}

⌨️ 快捷键说明

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