Examples of AnyNode


Examples of org.exolab.castor.types.AnyNode

        if (node.getNodeType() == AnyNode.ELEMENT) {
            // -- node local name
            String name = node.getLocalName();

            // -- retrieve the namespaces declaration and handle them
            AnyNode tempNode = node.getFirstNamespace();
            String prefix = null;
            while (tempNode != null) {
                prefix = tempNode.getNamespacePrefix();
                if (prefix == null) {
                    prefix = "";
                }
                String value = tempNode.getNamespaceURI();
                if (value == null) {
                    value = "";
                }
                handler.startPrefixMapping(prefix, value);
                if (value != null && value.length() > 0) {
                    _context.addNamespace(prefix, value);
                }
                tempNode = tempNode.getNextSibling();
            }// namespaceNode

            // -- retrieve the attributes and handle them
            AttributesImpl atts = new AttributesImpl();
            tempNode = node.getFirstAttribute();
            String xmlName = null;
            String value = null;
            String attUri = null;
            String attPrefix = null;
            while (tempNode != null) {
                xmlName = tempNode.getLocalName();
                String localName = xmlName;
                // --retrieve a prefix?
                attUri = tempNode.getNamespaceURI();
                if (attUri != null) {
                    attPrefix = _context.getNamespacePrefix(attUri);
                } else {
                    attUri = "";
                }

                if (attPrefix != null && attPrefix.length() > 0) {
                    xmlName = attPrefix + ':' + xmlName;
                }

                value = tempNode.getStringValue();
                atts.addAttribute(attUri, localName, xmlName, "CDATA", value);
                tempNode = tempNode.getNextSibling();
            }// attributes

            // -- namespace management
//            _context = _context.createNamespaces();
            String nsPrefix = node.getNamespacePrefix();
            String nsURI = node.getNamespaceURI();

            String qName = null;
            // maybe the namespace is already bound to a prefix in the
            // namespace context
            if (nsURI != null && nsURI.length() > 0) {
                String tempPrefix = _context.getNamespacePrefix(nsURI);
                if (tempPrefix != null) {
                    nsPrefix = tempPrefix;
                } else {
                    _context.addNamespace(nsPrefix, nsURI);
                }
            } else {
                nsURI = "";
            }

            if (nsPrefix != null) {
                int len = nsPrefix.length();
                if (len > 0) {
                    StringBuffer sb = new StringBuffer(len + name.length() + 1);
                    sb.append(nsPrefix);
                    sb.append(':');
                    sb.append(name);
                    qName = sb.toString();
                } else {
                    qName = name;
                }
            } else {
                qName = name;
            }

            try {
                // _context.declareAsAttributes(atts,true);
                handler.startElement(nsURI, name, qName, atts);
            } catch (SAXException sx) {
                throw new SAXException(sx);
            }

            // -- handle child&daughter elements
            tempNode = node.getFirstChild();
            while (tempNode != null) {
              _context = _context.createNamespaces();
                processAnyNode(tempNode, handler);
                tempNode = tempNode.getNextSibling();
            }

            // -- finish element
            try {
                handler.endElement(nsURI, name, qName);
                _context = _context.getParent();

                // -- retrieve the namespaces declaration and handle them
                tempNode = node.getFirstNamespace();
                while (tempNode != null) {
                    prefix = tempNode.getNamespacePrefix();
                    if (prefix == null) {
                        prefix = "";
                    }
                    handler.endPrefixMapping(prefix);
                    tempNode = tempNode.getNextSibling();
                } // namespaceNode
            } catch (org.xml.sax.SAXException sx) {
                throw new SAXException(sx);
            }
        } else {
View Full Code Here

Examples of org.exolab.castor.types.AnyNode

    }
    //-------------------------------------------------

    //--Namespace related (SAX2 Events)
    public void startPrefixMapping(String prefix, String uri) throws SAXException {
        AnyNode temp = new AnyNode(AnyNode.NAMESPACE, null, prefix, uri, null);
       _namespaces.push(temp);
       if (_processNamespace) {
           _context = _context.createNamespaces();
           _processNamespace = true;
       }
View Full Code Here

Examples of org.exolab.castor.types.AnyNode

    public void startElement(String name, AttributeList atts)
           throws SAXException {
        _character = false;
        String qName;
        String value;
        AnyNode tempNode = null;

        //Namespace handling code to be moved once we integrate
        //the new event API
        /////////////////NAMESPACE HANDLING/////////////////////
        _context = _context.createNamespaces();
        String prefix = "";
        String namespaceURI = null;
        int idx = name.indexOf(':');
        if (idx >= 0) {
             prefix = name.substring(0,idx);
        }
        namespaceURI = _context.getNamespaceURI(prefix);
        //--Overhead here since we process attributes twice
        for (int i=0; i<atts.getLength(); ++i) {
            qName = atts.getName(i);
            value = atts.getValue(i);
            String nsPrefix = null;

            if (qName.startsWith(XMLNS_PREFIX)) {
                //handles namespace declaration
                // Extract the prefix if any
                nsPrefix = (qName.equals(XMLNS_PREFIX))?null:qName.substring(XMLNS_PREFIX_LENGTH);
                tempNode = new AnyNode(AnyNode.NAMESPACE, getLocalPart(qName), nsPrefix, value, null);
                _context.addNamespace(nsPrefix, value);
                _namespaces.push(tempNode);
                if (prefix.equals(nsPrefix))
                    namespaceURI = value;
            }
        }
        ////////////////////////END OF NAMESPACE HANDLING///////////////

        createNodeElement(namespaceURI, getLocalPart(name), name);
        while (!_namespaces.empty()) {
           tempNode = (AnyNode)_namespaces.pop();
           _node.addNamespace(tempNode);
        }

        //process attributes
        for (int i=0; i<atts.getLength(); ++i) {

            qName = atts.getName(i);
            value = atts.getValue(i);

            //Namespace handling already done
            if (!qName.startsWith(XMLNS_PREFIX)) {
                tempNode = new AnyNode(AnyNode.ATTRIBUTE, getLocalPart(qName), null, null, value);
                _node.addAttribute(tempNode);
            }
        }
        tempNode = null;
    }
View Full Code Here

Examples of org.exolab.castor.types.AnyNode

    /**
     * Implementation of {@link org.xml.sax.ContentHandler#startElement}
     */
    public void startElement(String namespaceURI,  String localName,
                            String qName, Attributes atts) throws SAXException {
        AnyNode tempNode;

        //--SAX2 Parser has not processed the namespaces so we need to do it.
        if (_processNamespace) {
            //Namespace handling code to be moved once we integrate
            //the new event API
            /////////////////NAMESPACE HANDLING/////////////////////
            _context = _context.createNamespaces();
            String prefix = "";
            int idx = qName.indexOf(':');
            if (idx >= 0) {
                 prefix = qName.substring(0,idx);
            }
            namespaceURI = _context.getNamespaceURI(prefix);
            //--Overhead here since we process attributes twice
            for (int i=0; i<atts.getLength(); ++i) {
                String attrqName = atts.getQName(i);
                String value = atts.getValue(i);
                String nsPrefix = null;
                //handles namespace declaration
                if (attrqName.startsWith(XMLNS_PREFIX)) {
                    // Extract the prefix if any
                    nsPrefix = (attrqName.equals(XMLNS_PREFIX))?null:attrqName.substring(XMLNS_PREFIX_LENGTH);
                    tempNode = new AnyNode(AnyNode.NAMESPACE, getLocalPart(attrqName), nsPrefix, value, null);
                    _context.addNamespace(nsPrefix, value);
                    _namespaces.push(tempNode);
                    if (prefix.equals(nsPrefix))
                        namespaceURI = value;
                }
            }
            ////////////////////////END OF NAMESPACE HANDLING///////////////
        }

        //create element
        createNodeElement(namespaceURI, localName, qName);

        //process attributes
        for (int i=0; i<atts.getLength(); ++i) {

            String uri       = atts.getURI(i);
            String attqName  = atts.getQName(i);
            String value     = atts.getValue(i);
            String prefix    = null;

            //-- skip namespace declarations? (handled above)
            if (_processNamespace )
                if(attqName.startsWith(XMLNS_PREFIX))
                    continue;

            //--attribute namespace prefix?
            if ((attqName.length() != 0) && (attqName.indexOf(':') != -1 ))
                prefix = attqName.substring(0,attqName.indexOf(':'));

            //--namespace not yet processed?
            if (_processNamespace ) {
                // attribute namespace
                if(prefix!=null)
                    uri = _context.getNamespaceURI(prefix);
            }
            //--add attribute
            tempNode = new AnyNode(AnyNode.ATTRIBUTE, getLocalPart(attqName), prefix, uri, value);
            _node.addAttribute(tempNode);
        }

        //--empty the namespace stack and add
        //--the namespace nodes to the current node.
View Full Code Here

Examples of org.exolab.castor.types.AnyNode

        //-- or a new sibling for the first child of the root node
        if (_nodeStack.empty()) {
            _startingNode.addChild(_node);
            _node = _startingNode;
        } else {
            AnyNode previousNode = (AnyNode) _nodeStack.peek();
            previousNode.addChild(_node);
            //--the node processing is finished -> come back to the previous node
            _node = previousNode;
         }
    }
View Full Code Here

Examples of org.exolab.castor.types.AnyNode

    public void characters(char[] ch, int start, int length) throws SAXException {
        //create a Text Node
        String temp = new String(ch, start, length);
        //skip whitespaces
        if (isWhitespace(temp) && !_wsPreserve && !_character) return;
        AnyNode tempNode = new AnyNode(AnyNode.TEXT, null, null, null, temp);
        _node.addChild(tempNode);
        _character = true;
    }
View Full Code Here

Examples of org.exolab.castor.types.AnyNode

             name = getLocalPart(qName);

        //creates the starting ELEMENT node
        //or a default ELEMENT node
        if ( (_nodeStack.empty()) && (_startingNode == null)) {
           _startingNode = new AnyNode(AnyNode.ELEMENT, name, prefix, namespaceURI, null);
           _node = _startingNode;
        } else {
          _node = new AnyNode(AnyNode.ELEMENT, name, prefix, namespaceURI, null);
          //push the node in the stack
          _nodeStack.push(_node);
        }
    }
View Full Code Here

Examples of org.exolab.castor.types.AnyNode

    if (!_elements.add(node)) return;

        if (node.getNodeType() == AnyNode.ELEMENT)
    {
            //the first sibling node of the current one
            AnyNode siblingNode = node.getNextSibling();

            String name = node.getLocalName();

            //-- retrieve the attributes and handle them
            AttributesImpl atts = new AttributesImpl();
            AnyNode tempNode = node.getFirstAttribute();
            String xmlName = null;
            String value = null;
            String attUri = null;
            String attPrefix = null;
           
            while (tempNode != null) {               
                xmlName = tempNode.getLocalName();
                String localName = xmlName;
                //--retrieve a prefix?
                attUri = tempNode.getNamespaceURI();
                if (attUri != null)
                    attPrefix = _context.getNamespacePrefix(attUri);
                else
                    attUri = "";
               
                if (attPrefix != null && attPrefix.length() > 0)
                    xmlName = attPrefix + ':' + xmlName;
               
                value = tempNode.getStringValue();
                atts.addAttribute(attUri, localName, xmlName, "CDATA", value);
                tempNode = tempNode.getNextSibling();
            }//attributes

            //-- namespace management
            _context = _context.createNamespaces();
            String nsPrefix = node.getNamespacePrefix();
            String nsURI = node.getNamespaceURI();

             //-- retrieve the namespaces declaration and handle them
            tempNode = node.getFirstNamespace();
            String prefix = null;
            while (tempNode != null) {
                prefix = tempNode.getNamespacePrefix();
                if (prefix == null) prefix = "";
                value = tempNode.getNamespaceURI();
                if (value == null) value = "";
               
                handler.startPrefixMapping(prefix, value);
               
                if (value != null && value.length() >0)
                    _context.addNamespace(prefix, value);
                tempNode = tempNode.getNextSibling();
             }//namespaceNode


            String qName = null;
            //maybe the namespace is already bound to a prefix in the
            //namespace context
            if (nsURI != null && nsURI.length() > 0) {
                String tempPrefix = _context.getNamespacePrefix(nsURI);
                if (tempPrefix != null)
                    nsPrefix = tempPrefix;
                else {
                    _context.addNamespace(nsPrefix, nsURI);
                }
            }
            else nsURI = "";


            if (nsPrefix != null) {
                int len = nsPrefix.length();
                if (len > 0) {
                    StringBuffer sb = new StringBuffer(len+name.length()+1);
                    sb.append(nsPrefix);
                    sb.append(':');
                    sb.append(name);
                    qName = sb.toString();
                } else qName = name;
            } else {
                qName = name;
            }

             try {
                 //_context.declareAsAttributes(atts,true);
                 handler.startElement(nsURI, name, qName, atts);
             } catch (SAXException sx) {
                  throw new SAXException(sx);
             }

             //-- handle child&daughter elements
             tempNode = node.getFirstChild();
             while (tempNode != null) {
                 processAnyNode(tempNode, handler);
                 tempNode = tempNode.getNextSibling();
             }

             //-- finish element
             try {
               handler.endElement(nsURI, name, qName);
               _context = _context.getParent();
              
               //-- retrieve the namespaces declaration and handle them
               tempNode = node.getFirstNamespace();
               while (tempNode != null) {
                   prefix = tempNode.getNamespacePrefix();
                   if (prefix == null) prefix = "";
                   handler.endPrefixMapping(prefix);
                   tempNode = tempNode.getNextSibling();
                }//namespaceNode
              
              
             } catch(org.xml.sax.SAXException sx) {
                  throw new SAXException(sx);
View Full Code Here

Examples of org.exolab.castor.types.AnyNode

    if (!_elements.add(node)) return;

        if (node.getNodeType() == AnyNode.ELEMENT)
    {
            //the first sibling node of the current one
            AnyNode siblingNode = node.getNextSibling();

            String name = node.getLocalName();

            //-- retrieve the attributes and handle them
            AttributeListImpl atts = new AttributeListImpl();
            AnyNode tempNode = node.getFirstAttribute();
            String xmlName = null;
            String value = null;
            String attUri = null;
            String attPrefix = null;
           
            while (tempNode != null) {
                xmlName = tempNode.getLocalName();
                //--retrieve a prefix?
                attUri = tempNode.getNamespaceURI();
                if (attUri != null)
                    attPrefix = _context.getNamespacePrefix(attUri);
                if (attPrefix != null && attPrefix.length() > 0)
                    xmlName = attPrefix + ':' + xmlName;
                value = tempNode.getStringValue();
                atts.addAttribute(xmlName, "CDATA", value);
                tempNode = tempNode.getNextSibling();
            }//attributes

            //-- namespace management
            _context = _context.createNamespaces();
            String nsPrefix = node.getNamespacePrefix();
            String nsURI = node.getNamespaceURI();

             //-- retrieve the namespaces declaration and handle them
            tempNode = node.getFirstNamespace();
            String prefix = null;
            while (tempNode != null) {
                prefix = tempNode.getNamespacePrefix();
                value = tempNode.getNamespaceURI();
                if (value != null && value.length() >0)
                    _context.addNamespace(prefix, value);
                tempNode = tempNode.getNextSibling();
             }//namespaceNode


            String qName = null;
            //maybe the namespace is already bound to a prefix in the
            //namespace context
            if (nsURI != null && nsURI.length() > 0) {
                String tempPrefix = _context.getNamespacePrefix(nsURI);
                if (tempPrefix != null)
                    nsPrefix = tempPrefix;
                else {
                    _context.addNamespace(nsPrefix, nsURI);
                }
            }


            if (nsPrefix != null) {
                int len = nsPrefix.length();
                if (len > 0) {
                    StringBuffer sb = new StringBuffer(len+name.length()+1);
                    sb.append(nsPrefix);
                    sb.append(':');
                    sb.append(name);
                    qName = sb.toString();
                } else qName = name;
            } else {
                qName = name;
            }

             try {
                 _context.declareAsAttributes(atts,true);
                 handler.startElement(qName, atts);
             } catch (SAXException sx) {
                  throw new SAXException(sx);
             }

             //-- handle child&daughter elements
             tempNode = node.getFirstChild();
             while (tempNode != null) {
                 processAnyNode(tempNode, handler);
                 tempNode = tempNode.getNextSibling();
             }

             //-- finish element
             try {
               handler.endElement(qName);
View Full Code Here

Examples of org.exolab.castor.types.AnyNode

            //-- find prefix (elements use default namespace if null)
            if (namespace == null) namespace = "";
            prefix = nsDecls.getNamespacePrefix(namespace);
        }
       
        AnyNode node = new AnyNode(AnyNode.ELEMENT, name, prefix, namespace, null);
        _nodes.push(node);
       
        //-- process namespace nodes
        if (nsDecls != null) {
            Enumeration enumeration = nsDecls.getLocalNamespaces();
            while (enumeration.hasMoreElements()) {
                namespace = (String)enumeration.nextElement();
                prefix = nsDecls.getNamespacePrefix(namespace);
                node.addNamespace ( new AnyNode(AnyNode.NAMESPACE,
                                                null,  //-- no local name for a ns decl.
                                                prefix,
                                                namespace,
                                                null)); //-- no value
            }
        }
        //-- process attributes
        if (atts != null) {
            for (int i = 0; i < atts.getSize(); i++) {
                namespace = atts.getNamespace(i);
                if ((nsDecls != null) && (namespace != null)) {
                    prefix = nsDecls.getNamespacePrefix(namespace);
                }
                else prefix = null;
                node.addAttribute( new AnyNode(AnyNode.ATTRIBUTE,
                                           atts.getName(i),
                                           prefix, namespace,
                                           atts.getValue(i)) );
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.