X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Futil%2FXML.java;h=d0775c79e84bca5c8dd662d674419ad2df50f193;hp=db55a66987b322f360ef09a14d45b9a22d409744;hb=01732f3955ae92c0520283b44f52d1ec69f9f9f2;hpb=3591b88b94a6bb378af3d4abe6eb5233ce583104 diff --git a/src/org/ibex/util/XML.java b/src/org/ibex/util/XML.java index db55a66..d0775c7 100644 --- a/src/org/ibex/util/XML.java +++ b/src/org/ibex/util/XML.java @@ -70,6 +70,7 @@ public abstract class XML private Reader in; private char[] buf; private int off; + private int base; // base+off == distance into the stream private int len; private Element current; @@ -87,13 +88,15 @@ public abstract class XML if (current == null) current = new Element(); } - /** Returns the line number at the beginning of the last process call. */ public int getLine() { return line; } /** Returns the column number at the beginning of the last process call. */ public int getCol() { return col; } + /** Returns the global file offset at the beginning of the last process call. */ + public int getGlobalOffset() { return base + off; } + /** * Parse given input and call the abstract event functions. * @@ -691,12 +694,14 @@ public abstract class XML } else if (off >= min) { // moving offset data to start will leave enough free space on the end System.arraycopy(buf, off, buf, 0, len); + base += off; off = 0; } else { // buffer size will have to be increased char[] newbuf = new char[buf.length * 2]; System.arraycopy(buf, off, newbuf, 0, len); buf = newbuf; + base += off; off = 0; } @@ -774,7 +779,6 @@ public abstract class XML protected Exn[] errors = new Exn[] {}; - /** Parent of current element. */ public Element getParent() { return parent; } @@ -787,7 +791,19 @@ public abstract class XML /** Prefix of current element. Substring of qName. XML Namespace Spec 14-Jan-1999 [7] */ public String getPrefix() { return prefix; } - public Hash getUriMap() { return urimap; } // HACK + // HACK + public Hash getUriMap() { + Hash map = new Hash(); + for (Element e = this; e != null; e = e.getParent()) { + java.util.Enumeration en = e.urimap.keys(); + while(en.hasMoreElements()) { + String key = (String)en.nextElement(); + String val = getUri(key); + map.put(key, val); + } + } + return map; + } /** URI of current tag. XML Namespace Spec 14-Jan-1999 section 1 */ public String getUri() { return getUri(prefix); } @@ -813,14 +829,27 @@ public abstract class XML /** Current number of attributes in the element. */ public int getAttrLen() { return len; } + /** Poor performance, but easier to use when speed is not a concern */ + public Hash getAttrHash() { + Hash ret = new Hash(getAttrLen() * 2, 3); + for(int i=0; i