jkesselm 02/01/31 08:08:25
Modified: java/src/org/apache/xalan/lib NodeInfo.java
java/src/org/apache/xalan/processor
TransformerFactoryImpl.java
java/src/org/apache/xalan/transformer TransformerImpl.java
java/src/org/apache/xalan/xslt Process.java
java/src/org/apache/xml/dtm/ref DTMManagerDefault.java
java/src/org/apache/xml/dtm/ref/sax2dtm SAX2DTM.java
SAX2RTFDTM.java
java/src/org/apache/xml/utils DefaultErrorHandler.java
Log:
Bugzilla 2617: Recreated missing code, changed controls to ensure
that this mode gets set early enough to be useful and can't be broken
by being turned on and off during execution.
NOTE: Current implementation relies on a global static flag in
TransformerFactoryImpl. We need to rearchitect our APIs slightly
so configuration hints of this kind can be passed down from top-level
objects to the back-end code more elegantly. Revisit in future
releases.
Revision Changes Path
1.3 +37 -6 xml-xalan/java/src/org/apache/xalan/lib/NodeInfo.java
Index: NodeInfo.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/NodeInfo.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- NodeInfo.java 30 Jan 2002 14:18:17 -0000 1.2
+++ NodeInfo.java 31 Jan 2002 16:08:21 -0000 1.3
@@ -65,7 +65,7 @@
import org.w3c.dom.NodeList;
/**
- * <code>NodeInfo</code> defines the XSLT extension functions to be
+ * <code>NodeInfo</code> defines a set of XSLT extension functions to be
* used from stylesheets.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
@@ -121,6 +121,8 @@
/**
* <code>publicId</code> returns the public identifier of the current
* context node.
+ *
+ * Xalan does not currently record this value, and will return null.
*
* @param context an <code>ExpressionContext</code> value
* @return a <code>String</code> value
@@ -142,8 +144,9 @@
* <code>publicId</code> returns the public identifier of the node passed as
* argument. If a node set is passed as argument, the public identifier of
* the first node in the set is returned.
+ *
+ * Xalan does not currently record this value, and will return null.
*
- * @param context an <code>ExpressionContext</code> value
* @param nodeList a <code>NodeList</code> value
* @return a <code>String</code> value
*/
@@ -166,9 +169,16 @@
/**
* <code>lineNumber</code> returns the line number of the current
* context node.
+ *
+ * NOTE: Xalan does not normally record location information for each node.
+ * To obtain it, you must set the custom TrAX attribute
+ * "http://xml.apache.org/xalan/features/source_location"
+ * true in the TransformerFactory before generating the Transformer and executing
+ * the stylesheet. Storage cost per node will be noticably increased in this mode.
*
* @param context an <code>ExpressionContext</code> value
- * @return an <code>int</code> value
+ * @return an <code>int</code> value. This may be -1 to indicate that the
+ * line number is not known.
*/
public static int lineNumber(ExpressionContext context)
{
@@ -188,8 +198,15 @@
* passed as argument. If a node set is passed as argument, the line
* number of the first node in the set is returned.
*
+ * NOTE: Xalan does not normally record location information for each node.
+ * To obtain it, you must set the custom TrAX attribute
+ * "http://xml.apache.org/xalan/features/source_location"
+ * true in the TransformerFactory before generating the Transformer and executing
+ * the stylesheet. Storage cost per node will be noticably increased in this mode.
+ *
* @param nodeList a <code>NodeList</code> value
- * @return an <code>int</code> value
+ * @return an <code>int</code> value. This may be -1 to indicate that the
+ * line number is not known.
*/
public static int lineNumber(NodeList nodeList)
{
@@ -211,8 +228,15 @@
* <code>columnNumber</code> returns the column number of the
* current context node.
*
+ * NOTE: Xalan does not normally record location information for each node.
+ * To obtain it, you must set the custom TrAX attribute
+ * "http://xml.apache.org/xalan/features/source_location"
+ * true in the TransformerFactory before generating the Transformer and executing
+ * the stylesheet. Storage cost per node will be noticably increased in this mode.
+ *
* @param context an <code>ExpressionContext</code> value
- * @return an <code>int</code> value
+ * @return an <code>int</code> value. This may be -1 to indicate that the
+ * column number is not known.
*/
public static int columnNumber(ExpressionContext context)
{
@@ -232,8 +256,15 @@
* passed as argument. If a node set is passed as argument, the line
* number of the first node in the set is returned.
*
+ * NOTE: Xalan does not normally record location information for each node.
+ * To obtain it, you must set the custom TrAX attribute
+ * "http://xml.apache.org/xalan/features/source_location"
+ * true in the TransformerFactory before generating the Transformer and executing
+ * the stylesheet. Storage cost per node will be noticably increased in this mode.
+ *
* @param nodeList a <code>NodeList</code> value
- * @return an <code>int</code> value
+ * @return an <code>int</code> value. This may be -1 to indicate that the
+ * column number is not known.
*/
public static int columnNumber(NodeList nodeList)
{
1.41 +49 -0
xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java
Index: TransformerFactoryImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/processor/TransformerFactoryImpl.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- TransformerFactoryImpl.java 19 Sep 2001 17:41:38 -0000 1.40
+++ TransformerFactoryImpl.java 31 Jan 2002 16:08:21 -0000 1.41
@@ -104,6 +104,8 @@
import java.util.Properties;
import java.util.Enumeration;
+import org.apache.xalan.transformer.XalanProperties;
+
/**
* The TransformerFactoryImpl, which implements the TRaX TransformerFactory
* interface, processes XSLT stylesheets into a Templates object
@@ -143,6 +145,8 @@
/** Static string to be used for optimize feature */
public static final String FEATURE_OPTIMIZE =
"http://xml.apache.org/xalan/features/optimize";
+ /** Static string to be used for source_location feature */
+ public static final String FEATURE_SOURCE_LOCATION =
XalanProperties.SOURCE_LOCATION;
/**
* Retrieve a propery bundle from a specified file and load it
@@ -504,6 +508,22 @@
public static boolean m_optimize = true;
+ /** Flag set by FEATURE_SOURCE_LOCATION.
+ * This feature specifies whether the transformation phase should
+ * keep track of line and column numbers for the input source
+ * document. Note that this works only when that
+ * information is available from the source -- in other words, if you
+ * pass in a DOM, there's little we can do for you.
+ *
+ * The default is false. Setting it true may significantly
+ * increase storage cost per node.
+ *
+ * %REVIEW% SAX2DTM is explicitly reaching up to retrieve this global field.
+ * We should instead have an architected pathway for passing hints of this
+ * sort down from TransformerFactory to Transformer to DTMManager to DTM.
+ * */
+ public static boolean m_source_location = false;
+
/**
* Allows the user to set specific attributes on the underlying
* implementation.
@@ -553,6 +573,31 @@
throw new
IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_BAD_VALUE,
new Object[]{name, value})); //name + " bad value " + value);
}
}
+
+ // Custom Xalan feature: annotate DTM with SAX source locator fields.
+ // This gets used during SAX2DTM instantiation.
+ //
+ // %REVIEW% Should the name of this field really be in XalanProperties?
+ // %REVIEW% I hate that it's a global static, but didn't want to change APIs
yet.
+ else if(name.equals(FEATURE_SOURCE_LOCATION))
+ {
+ if(value instanceof Boolean)
+ {
+ // Accept a Boolean object..
+ m_source_location = ((Boolean)value).booleanValue();
+ }
+ else if(value instanceof String)
+ {
+ // .. or a String object
+ m_source_location = (new Boolean((String)value)).booleanValue();
+ }
+ else
+ {
+ // Give a more meaningful error message
+ throw new
IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_BAD_VALUE,
new Object[]{name, value})); //name + " bad value " + value);
+ }
+ }
+
else
{
throw new
IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_NOT_SUPPORTED,
new Object[]{name})); //name + "not supported");
@@ -578,6 +623,10 @@
else if (name.equals(FEATURE_OPTIMIZE))
{
return new Boolean(m_optimize);
+ }
+ else if (name.equals(FEATURE_SOURCE_LOCATION))
+ {
+ return new Boolean(m_source_location);
}
else
throw new
IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_ATTRIB_VALUE_NOT_RECOGNIZED,
new Object[]{name})); //name + " attribute not recognized");
1.122 +4 -18
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
Index: TransformerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -r1.121 -r1.122
--- TransformerImpl.java 30 Jan 2002 19:08:01 -0000 1.121
+++ TransformerImpl.java 31 Jan 2002 16:08:23 -0000 1.122
@@ -356,12 +356,6 @@
public static boolean S_DEBUG = false;
/**
- * This property specifies whether the transformation phase should
- * keep track of line and column numbers for the input source
- * document. By default is false. */
- protected boolean m_useSourceLocationProperty = false;
-
- /**
* The SAX error handler, where errors and warnings are sent.
*/
private ErrorListener m_errorHandler =
@@ -505,32 +499,26 @@
* <code>getProperty</code> returns the current setting of the
* property described by the <code>property</code> argument.
*
+ * %REVIEW% Obsolete now that source_location is handled in the
TransformerFactory?
+ *
* @param property a <code>String</code> value
* @return a <code>boolean</code> value
*/
public boolean getProperty(String property)
{
- if (property.equals(XalanProperties.SOURCE_LOCATION))
- return m_useSourceLocationProperty;
-
return false;
}
/**
* Set a runtime property for this <code>TransformerImpl</code>.
*
+ * %REVIEW% Obsolete now that source_location is handled in the
TransformerFactory?
+ *
* @param property a <code>String</code> value
* @param value an <code>Object</code> value
*/
public void setProperty(String property, Object value)
{
- if (property.equals(XalanProperties.SOURCE_LOCATION)) {
- if (!(value instanceof Boolean))
- throw new
RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_PROPERTY_VALUE_BOOLEAN,
new Object[]{XalanProperties.SOURCE_LOCATION})); //"Value for property "
- //+ XalanProperties.SOURCE_LOCATION
- //+ " should be a Boolean instance");
- m_useSourceLocationProperty = ((Boolean)value).booleanValue();
- }
}
// ========= Transformer Interface Implementation ==========
@@ -635,8 +623,6 @@
setBaseURLOfSource(base);
DTMManager mgr = m_xcontext.getDTMManager();
DTM dtm = mgr.getDTM(source, false, this, true, true);
- dtm.setProperty(XalanProperties.SOURCE_LOCATION,
- new Boolean(m_useSourceLocationProperty));
boolean hardDelete = true; // %REVIEW% I have to think about this. -sb
1.47 +5 -0 xml-xalan/java/src/org/apache/xalan/xslt/Process.java
Index: Process.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xslt/Process.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- Process.java 14 Jan 2002 15:03:12 -0000 1.46
+++ Process.java 31 Jan 2002 16:08:23 -0000 1.47
@@ -640,6 +640,10 @@
}
SAXTransformerFactory stf = (SAXTransformerFactory) tfactory;
+
+ // This is currently controlled via TransformerFactoryImpl.
+ if (useSourceLocation)
+ stf.setAttribute(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);
// Did they pass in a stylesheet, or should we get it from the
// document?
@@ -683,6 +687,7 @@
impl.setQuietConflictWarnings(quietConflictWarnings);
+ // This is currently controlled via TransformerFactoryImpl.
if (useSourceLocation)
impl.setProperty(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);
1.34 +5 -0 xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java
Index: DTMManagerDefault.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- DTMManagerDefault.java 23 Jan 2002 22:53:47 -0000 1.33
+++ DTMManagerDefault.java 31 Jan 2002 16:08:23 -0000 1.34
@@ -327,12 +327,17 @@
// It should actually still work for other uses,
// but may be slightly deoptimized relative to the base
// to allow it to deal with carrying multiple documents.
+ //
+ // %REVIEW% This is a sloppy way to request this mode;
+ // we need to consider architectural improvements.
dtm = new SAX2RTFDTM(this, source, documentID, whiteSpaceFilter,
xstringFactory, doIndexing);
}
else // Create the basic SAX2DTM.
+ {
dtm = new SAX2DTM(this, source, documentID, whiteSpaceFilter,
xstringFactory, doIndexing);
+ }
// Go ahead and add the DTM to the lookup table. This needs to be
// done before any parsing occurs.
1.26 +32 -27 xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java
Index: SAX2DTM.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- SAX2DTM.java 30 Jan 2002 17:54:56 -0000 1.25
+++ SAX2DTM.java 31 Jan 2002 16:08:24 -0000 1.26
@@ -222,12 +222,20 @@
/**
* Describes whether information about document source location
* should be maintained or not.
+ *
+ * Made protected for access by SAX2RTFDTM.
*/
- private boolean m_useSourceLocationProperty = false;
+ protected boolean m_useSourceLocationProperty = false;
- private StringVector m_sourceSystemId;
- private IntVector m_sourceLine;
- private IntVector m_sourceColumn;
+ /** Made protected for access by SAX2RTFDTM.
+ */
+ protected StringVector m_sourceSystemId;
+ /** Made protected for access by SAX2RTFDTM.
+ */
+ protected IntVector m_sourceLine;
+ /** Made protected for access by SAX2RTFDTM.
+ */
+ protected IntVector m_sourceColumn;
/**
* Construct a SAX2DTM object ready to be constructed from SAX2
@@ -259,6 +267,15 @@
m_data.addElement(0); // Need placeholder in case index into here must be <0.
m_dataOrQName = new SuballocatedIntVector(m_initialblocksize);
+
+ // %REVIEW%
+ // A public static is not a good way to retrieve the system-level
+ // FEATURE_SOURCE_LOCATION flag, but we didn't want to deal with
+ // changing APIs at this time. MUST reconsider.
+
m_useSourceLocationProperty=org.apache.xalan.processor.TransformerFactoryImpl.m_source_location;
+ m_sourceSystemId = (m_useSourceLocationProperty) ? new StringVector() : null;
+ m_sourceLine = (m_useSourceLocationProperty) ? new IntVector() : null;
+ m_sourceColumn = (m_useSourceLocationProperty) ? new IntVector() : null;
}
/**
@@ -2299,40 +2316,24 @@
/**
* Set a run time property for this DTM instance.
+ *
+ * %REVIEW% Now that we no longer use this method to support
+ * getSourceLocatorFor, can we remove it?
*
* @param property a <code>String</code> value
* @param value an <code>Object</code> value
*/
public void setProperty(String property, Object value)
{
- if (property.equals(XalanProperties.SOURCE_LOCATION))
- {
- if (!(value instanceof Boolean))
- throw new
RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_PROPERTY_VALUE_BOOLEAN,
new Object[]{XalanProperties.SOURCE_LOCATION})); //"Value for property "
- // + XalanProperties.SOURCE_LOCATION
- // + " should be a Boolean instance");
- // %REVIEW%
- // This MUST NOT be set true after document construction has begun,
- // since that will leave us with incomplete data structures and cause
- // malfunctions. Easier to just say "don't change at all once in progress"
- if(m_size<=0)
- {
- m_useSourceLocationProperty = ((Boolean)value).booleanValue();
- if(m_useSourceLocationProperty)
- {
- m_sourceSystemId = new StringVector();
- m_sourceLine = new IntVector();
- m_sourceColumn = new IntVector();
- }
- }
- }
}
/** Retrieve the SourceLocator associated with a specific node.
* This is only meaningful if the XalanProperties.SOURCE_LOCATION flag was
* set True using setProperty; if it was never set, or was set false, we
- * will return null. (We _could_ return a locator with the document's
- * base URI and bogus line/column information. Should we?)
+ * will return null.
+ *
+ * (We _could_ return a locator with the document's base URI and bogus
+ * line/column information. Trying that; see the else clause.)
* */
public SourceLocator getSourceLocatorFor(int node)
{
@@ -2344,6 +2345,10 @@
m_sourceSystemId.elementAt(node),
m_sourceLine.elementAt(node),
m_sourceColumn.elementAt(node));
+ }
+ else if(m_locator!=null)
+ {
+ return new NodeLocator(null,m_locator.getSystemId(),-1,-1);
}
return null;
}
1.2 +8 -0
xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2RTFDTM.java
Index: SAX2RTFDTM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2RTFDTM.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SAX2RTFDTM.java 23 Jan 2002 22:53:47 -0000 1.1
+++ SAX2RTFDTM.java 31 Jan 2002 16:08:24 -0000 1.2
@@ -142,6 +142,14 @@
{
super(mgr, source, dtmIdentity, whiteSpaceFilter,
xstringfactory, doIndexing);
+
+ // NEVER track source locators for RTFs; they aren't meaningful. I think.
+ // (If we did track them, we'd need to tail-prune these too.)
+ m_useSourceLocationProperty=false;
//org.apache.xalan.processor.TransformerFactoryImpl.m_source_location;
+ m_sourceSystemId = (m_useSourceLocationProperty) ? new StringVector() : null;
+ m_sourceLine = (m_useSourceLocationProperty) ? new IntVector() : null;
+ m_sourceColumn = (m_useSourceLocationProperty) ? new IntVector() : null;
+
}
/**
1.8 +6 -1 xml-xalan/java/src/org/apache/xml/utils/DefaultErrorHandler.java
Index: DefaultErrorHandler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/utils/DefaultErrorHandler.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultErrorHandler.java 10 Aug 2001 16:21:10 -0000 1.7
+++ DefaultErrorHandler.java 31 Jan 2002 16:08:25 -0000 1.8
@@ -142,7 +142,7 @@
*/
public void error(SAXParseException exception) throws SAXException
{
- // printLocation(exception);
+ //printLocation(exception);
// m_pw.println(exception.getMessage());
throw exception;
@@ -290,6 +290,11 @@
}
public static void printLocation(PrintStream pw, TransformerException exception)
+ {
+ printLocation(new PrintWriter(pw), exception);
+ }
+
+ public static void printLocation(java.io.PrintStream pw,
org.xml.sax.SAXParseException exception)
{
printLocation(new PrintWriter(pw), exception);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]