coliver 2003/06/29 08:30:21
Modified: src/scratchpad/src/org/apache/cocoon/generation
JXFormsGenerator.java
Log:
Fixed to avoid NPE on null locator when used as transformer, and changed to use
JXPath relative contexts in repeat, group, and itemset so that ../ works
Revision Changes Path
1.18 +25 -10
cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/JXFormsGenerator.java
Index: JXFormsGenerator.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/JXFormsGenerator.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- JXFormsGenerator.java 18 May 2003 16:36:41 -0000 1.17
+++ JXFormsGenerator.java 29 Jun 2003 15:30:21 -0000 1.18
@@ -104,7 +104,9 @@
}
};
- final static String NS =
+ private static final Locator NULL_LOCATOR = new LocatorImpl();
+
+ public final static String NS =
"http://apache.org/cocoon/jxforms/1.0";
// Non XForms elements
@@ -198,6 +200,18 @@
return ptr.getNode();
}
+ Pointer getPointer(JXPathContext root, JXPathContext current) {
+ JXPathContext ctx = current;
+ if (absolute) {
+ ctx = root;
+ }
+ Pointer ptr = jxpath.getPointer(ctx, string);
+ if (ptr == null) {
+ return null;
+ }
+ return ptr;
+ }
+
Iterator iteratePointers(JXPathContext root, JXPathContext current) {
JXPathContext ctx = current;
if (absolute) {
@@ -241,8 +255,9 @@
static class Event {
final Locator location;
Event next;
- Event(Locator location) {
- this.location = new LocatorImpl(location);
+ Event(Locator locator) {
+ this.location =
+ locator == null ? NULL_LOCATOR : new LocatorImpl(locator);
}
public String locationString() {
@@ -1332,11 +1347,11 @@
value = ptr.getNode();
} catch (Exception exc) {
throw new SAXParseException(exc.getMessage(),
- ev.location,
- exc);
+ ev.location,
+ exc);
}
JXPathContext localJXPathContext =
- jxpathContextFactory.newContext(null, value);
+ currentContext.getRelativeContext(ptr);
String path = "";
if (contextPath != null) {
path = contextPath + "/.";
@@ -1362,16 +1377,16 @@
startElement.attributes);
final XPathExpr ref = startGroup.ref;
if (ref != null) {
- Object value;
+ Pointer ptr;
try {
- value = ref.getNode(rootContext, currentContext);
+ ptr = ref.getPointer(rootContext, currentContext);
} catch (Exception exc) {
throw new SAXParseException(exc.getMessage(),
ev.location,
exc);
}
JXPathContext localJXPathContext =
- jxpathContextFactory.newContext(null, value);
+ currentContext.getRelativeContext(ptr);
String path;
if (ref.absolute) {
path = ref.string;
@@ -1427,7 +1442,7 @@
exc);
}
JXPathContext localJXPathContext =
- jxpathContextFactory.newContext(null, value);
+ currentContext.getRelativeContext(ptr);
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute(null, REF, REF, "CDATA",
ptr.asPath());