private Reader in;
private char[] buf;
private int off;
+ private int base; // base+off == distance into the stream
private int len;
private Element current;
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.
*
} 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;
}
protected Exn[] errors = new Exn[] {};
-
/** Parent of current element. */
public Element getParent() { return parent; }
/** 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); }
/** 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<len; i++)
+ ret.put(getAttrKey(i), getAttrVal(i));
+ return ret;
+ }
+
+ /** Poor performance, but easier to use */
+ public String getAttrVal(String key) {
+ for(int i=0; i<len; i++) if (keys[i].equals(key)) return vals[i];
+ return null;
+ }
+
/** An array of non-fatal errors related to this element. */
public Exn[] getErrors() { return errors; }
-
protected Element() { }
/** Add (replace if exists in current element) a Namespace prefix/uri map. */
- protected void addUri(String name, String value) {
+ public void addUri(String name, String value) {
urimap.put(name, value);
}