hi,
this is a simple patch that adds to Xerces2 XNI ability to track absolute
positioning in parsed entities (besides column and row numbers). i have
added new method public int getCurrentEntityAbsoluteOffset(); to
XMLLocator and enhanced XMLEntityManager load(...) to keep track of
consumed data so absolute offset can be calculated.
this patch will have no impact on existing user code and absolutely
minimal performance impact.
i hope that it will be added.
thanks,
alek
Index: src/org/apache/xerces/impl/XMLEntityManager.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityMa
nager.java,v
retrieving revision 1.8
diff -w -c -r1.8 XMLEntityManager.java
*** src/org/apache/xerces/impl/XMLEntityManager.java 2001/10/19
03:20:40
1.8
--- src/org/apache/xerces/impl/XMLEntityManager.java 2001/10/22
19:43:48
***************
*** 1632,1637 ****
--- 1632,1640 ----
/** Count of characters in buffer. */
public int count;
+ /** Absolute offset since origin of buffer */
+ public int offsetZero;
+
//
// Constructors
//
***************
*** 3005,3010 ****
--- 3008,3043 ----
return -1;
} // getColumnNumber():int
+ /**
+ * Return the position of parser in current entity since its
beginning.
+ * This position is in number of UTF16 characters since
beginning of
+ * reading that entity.
+ *
+ * @return The position in UTF16 characters or -1 if none is
available.
+ */
+ public int getCurrentEntityAbsoluteOffset() {
+ //return fCurrentEntity != null ?
fCurrentEntity.columnNumber : -1;
+ if (fCurrentEntity != null) {
+ if (fCurrentEntity.systemId != null ) {
+ return fCurrentEntity.position +
fCurrentEntity.offsetZero;
+ }
+ else {
+ // search for the first external entity on the stack
+ int size = fEntityStack.size();
+ for (int i=size-1; i>0 ; i--) {
+ ScannedEntity firstExternalEntity =
(ScannedEntity)fEntityStack.elementAt(i);
+
+ if (firstExternalEntity.systemId != null) {
+ return fCurrentEntity.position +
firstExternalEntity.offsetZero;
+ }
+ }
+ }
+ }
+
+ return -1;
+ } // getCurrentEntityAbsoluteOffset():int
+
+
//
// Private methods
//
***************
*** 3030,3035 ****
--- 3063,3070 ----
print();
System.out.println();
}
+ // update absolute offset for this entity
+ fCurrentEntity.offsetZero += fCurrentEntity.position -
offset;
// read characters
int length = fCurrentEntity.ch.length - offset;
Index: src/org/apache/xerces/util/ErrorHandlerWrapper.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/util/ErrorHandle
rWrapper.java,v
retrieving revision 1.2
diff -w -c -r1.2 ErrorHandlerWrapper.java
*** src/org/apache/xerces/util/ErrorHandlerWrapper.java 2001/08/23
00:35:32
1.2
--- src/org/apache/xerces/util/ErrorHandlerWrapper.java 2001/10/22
19:43:51
***************
*** 240,245 ****
--- 240,246 ----
public String getBaseSystemId() { return null; }
public int getColumnNumber() { return fColumnNumber; }
public int getLineNumber() { return fLineNumber; }
+ public int getCurrentEntityAbsoluteOffset() { return -1; }
};
return new XMLParseException(location, exception.getMessage(),
exception.getException());
Index: src/org/apache/xerces/xni/XMLLocator.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xerces/xni/XMLLocator.j
ava,v
retrieving revision 1.2
diff -w -c -r1.2 XMLLocator.java
*** src/org/apache/xerces/xni/XMLLocator.java 2001/08/23 00:35:36
1.2
--- src/org/apache/xerces/xni/XMLLocator.java 2001/10/22 19:43:51
***************
*** 85,88 ****
--- 85,91 ----
/** Returns the column number. */
public int getColumnNumber();
+ /** Returns the parser position counting sizne beginning of entity
input.
*/
+ public int getCurrentEntityAbsoluteOffset();
+
} // interface XMLLocator
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]