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; }
/** * Adds an AnyNode to the current node * @param node the node to append */ public void addAnyNode(AnyNode node) { if (node == null) { throw new IllegalArgumentException("null argument in addAnyNode"); } switch(node.getNodeType()) { case ATTRIBUTE: addAttribute(node); break; case NAMESPACE: addNamespace(node); break; default: addChild(node); break; } }
/** * Returns the concatenation of all the TEXT nodes in the given * AnyNode in document order * * @param node the AnyNode to return the String value of * @param buffer the StringBuffer to append to. */ static final void getStringValue(AnyNode node, StringBuffer buffer) { switch(node.getNodeType()) { case AnyNode.ELEMENT: AnyNode child = node.getFirstChild(); while (child != null) { getStringValue(child, buffer); child = child.getNextSibling(); } break; case AnyNode.TEXT: buffer.append(node.getStringValue()); break; default: break; } } //-- getStringValue
/** * Adds the text value of a TEXT node to another TEXT node. * * @param node1 the AnyNode that receives the text value * @param node2 the AnyNode that needs to be merges with node1. */ private void mergeTextNode(AnyNode node1, AnyNode node2) { if (node1.getNodeType() != node2.getNodeType()) { return; } if (node1.getNodeType() != AnyNode.TEXT) { return; } node1._value = node1.getStringValue() + node2.getStringValue(); node2 = null; }
/** * Returns the first Child node of this node. A 'child' can be either an ELEMENT node, a COMMENT * node, a TEXT node or a PROCESSING INSTRUCTION. * * @return the first child of this node */ public AnyNode getFirstChild() { // an ATTRIBUTE or a NAMESPACE can not // have children if (this.getNodeType() == ATTRIBUTE || this.getNodeType() == NAMESPACE) { return null; } // loop througth the first two (in the worst case) nodes // and then return the firstChild if any AnyNode tempNode = this.getFirstChildNode(); boolean found = false; while (tempNode != null && !found) { short type = tempNode.getNodeType(); if (type == ELEMENT || type == COMMENT || type == TEXT || type == PI) { found = true; } else if (type == ATTRIBUTE || type == NAMESPACE) { tempNode = tempNode.getFirstChildNode(); } } return tempNode; }
if (this.getNodeType() == ELEMENT) { String prefix = getNamespacePrefix(); if (prefix != null) { sb.append(prefix+":"); sb.append(getLocalName()); AnyNode tempNode = this.getFirstAttribute(); while (tempNode != null) { sb.append(" "); sb.append(tempNode.getLocalName()); sb.append("='"+tempNode.getStringValue()+"'"); tempNode = tempNode.getNextSibling(); tempNode = this.getFirstNamespace(); while (tempNode != null) { sb.append(" "); sb.append(XMLNS_PREFIX); prefix = tempNode.getNamespacePrefix(); if (prefix != null && prefix.length() != 0) { sb.append(":"+prefix); sb.append("='"+tempNode.getNamespaceURI()+"'"); tempNode = tempNode.getNextSibling(); tempNode = this.getFirstChild(); if (tempNode != null) { sb.append(">");
AnyNode node = new AnyNode(AnyNode.ELEMENT, name, prefix, namespace, null); _nodes.push(node); namespace = (String) enumeration.nextElement(); prefix = nsDecls.getNamespacePrefix(namespace); node.addNamespace(new AnyNode(AnyNode.NAMESPACE, null, // -- no local name for a ns decl. } else prefix = null; node.addAttribute( new AnyNode(AnyNode.ATTRIBUTE, atts.getName(i), prefix, namespace, atts.getValue(i)));
/** * Adds an attribute to the current node. * @param node the attribute to add. */ public void addAttribute(AnyNode node) { if (node == null) { throw new IllegalArgumentException("null argument in addAttribute"); } if (node.getNodeType() != ATTRIBUTE) { throw new IllegalArgumentException("Only attribute can be added as an attribute"); } if (_firstChildNode == null) { _firstChildNode = node; } else { if (_firstChildNode.getNodeType() == ATTRIBUTE) { //if we reach an attribute then we add the node as its sibling _firstChildNode.appendSibling(node); } else if (_firstChildNode.getNodeType() == NAMESPACE) { //if we reach an namespace the attributre should be added to //the first child of the namespace _firstChildNode.addAttribute(node); } else { //unplug the current firstNode to add a new one node.addChild(_firstChildNode); _firstChildNode = node; } } } //addAttribute
/** * Appends an namespace to the current node. * @param node the attribute to add. */ public void addNamespace(AnyNode node){ if (node == null) { throw new IllegalArgumentException("null argument in addNamespace"); } if (node.getNodeType() != NAMESPACE) { throw new IllegalArgumentException("Only namespace can be added as an namespace"); } if (_firstChildNode == null) { _firstChildNode = node; } else { if (_firstChildNode.getNodeType() == NAMESPACE) { //if we reach an namepace then we add the node as its sibling _firstChildNode.appendSibling(node); } else if (_firstChildNode.getNodeType() == ATTRIBUTE) { //if we reach an attribute the attributre should be added to //the first child of the attribute _firstChildNode.addNamespace(node); } else { //unplug the current firstNode to add a new one node.addChild(_firstChildNode); _firstChildNode = node; } } } //addNamespace
if (_nodes.isEmpty()) { if (node.getNamespaceURI().equals(JDOConstants.JDO_NAMESPACE) && (node.getLocalName().equals(JDOConstants.ANNOTATIONS_TABLE_NAME) || node.getLocalName().equals(JDOConstants.ANNOTATIONS_COLUMN_NAME) || node.getLocalName().equals(JDOConstants.ANNOTATIONS_ONE_TO_ONE_NAME) || node.getLocalName().equals(JDOConstants.ANNOTATIONS_ONE_TO_MANY))) { XMLContext context = new XMLContext(); context.addPackage(JDOConstants.GENERATED_ANNOTATION_CLASSES_PACKAGE); if (node.getNamespaceURI().equals(SOLRJConstants.NAMESPACE) && (node.getLocalName().equals(SOLRJConstants.ANNOTATIONS_FIELD_NAME) || node.getLocalName().equals(SOLRJConstants.ANNOTATIONS_ID_NAME))) { XMLContext context = new XMLContext(); context.addPackage(SOLRJConstants.GENERATED_ANNOTATION_CLASSES_PACKAGE); } else { _nodes.peek().addChild(node);
/** * <p> * Adds a child AnyNode to this node. A 'child' can be either an ELEMENT node, a COMMENT node, a * TEXT node or a PROCESSING INSTRUCTION. If the current node already has a child then the node to * add will be append as a sibling. * <p> * Note: you cannot add a child to a TEXT node. * * @param node the node to add. */ public void addChild(AnyNode node) { if (node == null) { throw new IllegalArgumentException("null argument in appendChild"); } if (node.getNodeType() == ATTRIBUTE || node.getNodeType() == NAMESPACE) { throw new IllegalArgumentException("An Attribute or an Namespace can't be added as a child"); } if (this.getNodeType() == TEXT) { throw new IllegalArgumentException("a TEXT node can't have children."); } if (_firstChildNode == null) { _firstChildNode = node; } else if (_firstChildNode.getNodeType() == ATTRIBUTE || _firstChildNode.getNodeType() == NAMESPACE) { _firstChildNode.addChild(node); } else { _firstChildNode.appendSibling(node); } }
/** * Appends a sibling AnyNode to the current node. The node to append will be added at the end of * the sibling branch. * * @param node the node to add */ protected void appendSibling(AnyNode node) { if (node == null) { throw new IllegalArgumentException(); } if (((node.getNodeType() == ATTRIBUTE) || (node.getNodeType() == NAMESPACE)) && (this.getNodeType() != node.getNodeType())) { String err = "a NAMESPACE or an ATTRIBUTE can only be add as a sibling to a node of the same type"; throw new UnsupportedOperationException(err); } if (_nextSiblingNode == null) { // if we already have a TEXT node -> merge if ((node.getNodeType() == TEXT) && (this.getNodeType() == TEXT)) { mergeTextNode(this, node); } else { _nextSiblingNode = node; } } else { _nextSiblingNode.appendSibling(node); } }
public void endElement(String namespaceURI, String localName, String qName) throws SAXException { _character = false; String name = null; // -- if namespace processing is disabled then the localName might be null, in that case // -- we use the QName if (localName != null && localName.length() > 0) { name = localName; } else { name = getLocalPart(qName); } // --if it is the starting element just returns if (_startingNode.getLocalName().equals(name) && _nodeStack.empty()) return; // --else just add the node we have built to the previous node _node = (AnyNode) _nodeStack.pop(); // -- if the stack is empty, we have a new child for the root node // -- 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; } }
final AnyNode attr = anyNode.getFirstAttribute(); if (!"application".equals(attr.getLocalName()))
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; } _context.addNamespace(prefix, uri); }
/** * Signals to end of the element with the given name. * * @param name the NCName of the element. It is an error if the name is a QName (ie. contains a * prefix). * @param namespace the namespace of the element. **/ public void endElement(String name, String namespace) throws XMLException { AnyNode node = (AnyNode) _nodes.pop(); if (_nodes.isEmpty()) { // -- add to appInfo _documentation.add(node); } else { // -- add to parent AnyNode ((AnyNode) _nodes.peek()).addChild(node); } } // -- endElement
if (this.getNodeType() == ELEMENT) { String prefix = getNamespacePrefix(); if (prefix != null) { sb.append(prefix).append(':'); sb.append(getLocalName()); AnyNode tempNode = this.getFirstAttribute(); while (tempNode != null) { sb.append(' ').append(tempNode.getLocalName()).append("='") .append(tempNode.getStringValue()).append('\''); tempNode = tempNode.getNextSibling(); tempNode = this.getFirstNamespace(); while (tempNode != null) { sb.append(' ').append(XMLNS_PREFIX); prefix = tempNode.getNamespacePrefix(); if (prefix != null && prefix.length() != 0) { sb.append(':').append(prefix); sb.append("='").append(tempNode.getNamespaceURI()).append('\''); tempNode = tempNode.getNextSibling(); tempNode = this.getFirstChild(); if (tempNode != null) { sb.append('>'); while (tempNode != null) { sb.append(tempNode.privateToString());
tempNode = new AnyNode(AnyNode.NAMESPACE, getLocalPart(attrqName), nsPrefix, value, null); _context.addNamespace(nsPrefix, value); _namespaces.push(tempNode); tempNode = new AnyNode(AnyNode.ATTRIBUTE, getLocalPart(attqName), prefix, uri, value); _node.addAttribute(tempNode); _node.addNamespace(tempNode);
/** * Adds an attribute to the current node. * * @param node the attribute to add. */ public void addAttribute(AnyNode node) { if (node == null) { throw new IllegalArgumentException("null argument in addAttribute"); } if (node.getNodeType() != ATTRIBUTE) { throw new IllegalArgumentException("Only attribute can be added as an attribute"); } if (_firstChildNode == null) { _firstChildNode = node; } else { if (_firstChildNode.getNodeType() == ATTRIBUTE) { // if we reach an attribute then we add the node as its sibling _firstChildNode.appendSibling(node); } else if (_firstChildNode.getNodeType() == NAMESPACE) { // if we reach an namespace the attributre should be added to // the first child of the namespace _firstChildNode.addAttribute(node); } else { // unplug the current firstNode to add a new one node.addChild(_firstChildNode); _firstChildNode = node; } } } // addAttribute
/** * Appends an namespace to the current node. * * @param node the attribute to add. */ public void addNamespace(AnyNode node) { if (node == null) { throw new IllegalArgumentException("null argument in addNamespace"); } if (node.getNodeType() != NAMESPACE) { throw new IllegalArgumentException("Only namespace can be added as an namespace"); } if (_firstChildNode == null) { _firstChildNode = node; } else { if (_firstChildNode.getNodeType() == NAMESPACE) { // if we reach an namepace then we add the node as its sibling _firstChildNode.appendSibling(node); } else if (_firstChildNode.getNodeType() == ATTRIBUTE) { // if we reach an attribute the attributre should be added to // the first child of the attribute _firstChildNode.addNamespace(node); } else { // unplug the current firstNode to add a new one node.addChild(_firstChildNode); _firstChildNode = node; } } } // addNamespace