772 |
} |
} |
773 |
offset += len; |
offset += len; |
774 |
} |
} |
775 |
|
|
776 |
|
/** |
777 |
|
* Creates a copy of the element <code>clonee</code> that has the parent |
778 |
|
* <code>parent</code>. |
779 |
|
* @param parent the parent of the newly created Element |
780 |
|
* @param clonee the Element to clone |
781 |
|
* @return the cloned Element |
782 |
|
*/ |
783 |
|
public Element clone (Element parent, Element clonee) |
784 |
|
{ |
785 |
|
// If the Element we want to clone is a leaf, then simply copy it |
786 |
|
if (clonee.isLeaf()) |
787 |
|
return createLeafElement(parent, clonee.getAttributes(), |
788 |
|
clonee.getStartOffset(), clonee.getEndOffset()); |
789 |
|
|
790 |
|
// Otherwise create a new BranchElement with the desired parent and |
791 |
|
// the clonee's attributes |
792 |
|
BranchElement result = (BranchElement) createBranchElement(parent, clonee.getAttributes()); |
793 |
|
|
794 |
|
// And clone all the of clonee's children |
795 |
|
Element[] children = new Element[clonee.getElementCount()]; |
796 |
|
for (int i = 0; i < children.length; i++) |
797 |
|
children[i] = clone(result, clonee.getElement(i)); |
798 |
|
|
799 |
|
// Make the cloned children the children of the BranchElement |
800 |
|
result.replace(0, 0, children); |
801 |
|
return result; |
802 |
|
} |
803 |
} |
} |
804 |
|
|
805 |
/** |
/** |