kevinoneill 2003/08/08 20:38:55
Modified: java/src/org/apache/xindice/xml/dom ElementImpl.java Log: PR: 22122 expandSource() will now check to see if the src prefix has been used. If it has it will try src + timestamp until it finds one that isn't used. Revision Changes Path 1.13 +41 -12 xml-xindice/java/src/org/apache/xindice/xml/dom/ElementImpl.java Index: ElementImpl.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/xml/dom/ElementImpl.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ElementImpl.java 7 Aug 2003 20:13:25 -0000 1.12 +++ ElementImpl.java 9 Aug 2003 03:38:55 -0000 1.13 @@ -74,6 +74,8 @@ import org.w3c.dom.Node; import java.io.IOException; +import java.util.HashSet; +import java.util.Random; /** * ElementImpl @@ -84,16 +86,14 @@ private static final Log log = LogFactory.getLog(ElementImpl.class); - private static final String SRC_NS = XMLNS_PREFIX + ":src"; - private static final String SRC_COL = "src:" + NodeSource.SOURCE_COL; - private static final String SRC_KEY = "src:" + NodeSource.SOURCE_KEY; + // private static final String SRC_NS = XMLNS_PREFIX + ":src"; + // private static final String SRC_COL = "src:" + NodeSource.SOURCE_COL; + // private static final String SRC_KEY = "src:" + NodeSource.SOURCE_KEY; private NamedNodeMapImpl attributes = new NamedNodeMapImpl(this); private short symbolID = -1; - - public ElementImpl() { - } + public ElementImpl() {} public ElementImpl(NodeImpl parentNode, byte[] data, int pos, int len) { super(parentNode, data, pos, len); @@ -115,7 +115,11 @@ } protected boolean isNodeTypeValid(short type) { - return type == Node.ELEMENT_NODE || type == Node.COMMENT_NODE || type == Node.TEXT_NODE || type == Node.CDATA_SECTION_NODE || type == Node.ENTITY_REFERENCE_NODE; + return type == Node.ELEMENT_NODE + || type == Node.COMMENT_NODE + || type == Node.TEXT_NODE + || type == Node.CDATA_SECTION_NODE + || type == Node.ENTITY_REFERENCE_NODE; } protected void checkLoaded() { @@ -154,12 +158,37 @@ public void expandSource() { NodeSource src = getSource(); if (src != null) { - setAttribute(SRC_NS, NodeSource.SOURCE_NS); - setAttribute(SRC_COL, src.getCollection().getCanonicalName()); + final String prefix = sourcePrefix("src"); + + setAttribute(XMLNS_PREFIX + ":" + prefix, NodeSource.SOURCE_NS); + setAttribute(prefix + ":" + NodeSource.SOURCE_COL, src.getCollection().getCanonicalName()); Key k = src.getKey(); if (k != null) - setAttribute(SRC_KEY, k.toString()); + setAttribute(prefix + ":" + NodeSource.SOURCE_KEY, k.toString()); + } + } + + private String sourcePrefix(final String candidatePrefix) { + Element element = this; + HashSet prefixes = new HashSet(); + while (element != null) { + NamedNodeMap nm = element.getAttributes(); + for (int i = 0; i < nm.getLength(); i++) { + final Attr a = (Attr) nm.item(i); + final String name = a.getNodeName(); + if (name.startsWith("xmlns:")) { + prefixes.add(name.substring(6)); + } + } + element = element.getParentNode().getNodeType() == ELEMENT_NODE ? (Element) element.getParentNode() : null; } + + String result = candidatePrefix; + while (prefixes.contains(result)) { + result = candidatePrefix + System.currentTimeMillis(); + } + + return result; } protected void loadAttributes(SymbolTable st) throws IOException {