/** * 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
/** * <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 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
/** * 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
/** * <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); } }
/** * 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); } }