sboag 01/07/10 21:00:16
Modified: java/src/org/apache/xalan/res XSLTErrorResources.java
java/src/org/apache/xalan/trace PrintTraceListener.java
java/src/org/apache/xalan/transformer TransformerImpl.java
java/src/org/apache/xalan/xslt Process.java
java/src/org/apache/xml/dtm DTM.java
java/src/org/apache/xml/dtm/ref DTMDocumentImpl.java
ExpandedNameTable.java
java/src/org/apache/xml/dtm/ref/dom2dtm DOM2DTM.java
java/src/org/apache/xml/dtm/ref/sax2dtm SAX2DTM.java
Added: java/src/org/apache/xalan/lib NodeInfo.java
java/src/org/apache/xalan/transformer XalanProperties.java
java/src/org/apache/xml/dtm/ref NodeLocator.java
Log:
Application of patch submitted by Ovidiu Predescu <[EMAIL PROTECTED]>
for file, line, column number information for XML source document.
[A made one change: m_sourceSystemId, m_sourceLine, and
m_sourceColumn are not created with the member variable
initializer, since they are initialized in setProperty.]
The following patch is a rework of a previous patch I've submitted on
May 24 against the Stree model, current at that time. This time the
patch is against the DTM model, and makes use of DTM features to
optimize the lookup time and storage requirements. I hope this time
the patch gets incorporated in the CVS repository, before any major
rework happens again ;-).
As with the previous patch, there is no overhead in space or time if
source information is not needed.
From a user perspective, this feature can be turned on by passing the
-L flag to Xalan when invoking it from the command
line. Programmatically you can also enable it by invoking the
setProperty method on the TransformerImpl:
TransformerImpl impl = ((TransformerImpl) transformer);
impl.setProperty(org.apache.xalan.transformer.XalanProperties.SOURCE_LOCATION,
Boolean.TRUE);
A Transformer "property" is different from a "feature": while a
feature is specific to all the transformer instances and usually
refers to an implementation aspect, a property is a runtime capability
that is set per Transformer instance. Currently the only property
added by this patch is the source location in the XML source document.
The patch adds two methods to the DTM interface:
public void setProperty(String property, Object value);
public SourceLocator getSourceLocatorFor(int node);
The second method is used to obtain the source location given a node
handle.
There are two ways you can make use of the source location. The first
one is from within a stylesheet, where you can have something like
this:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:nodeinfo="xalan://org.apache.xalan.lib.NodeInfo"
version="1.0">
<xsl:template match="*">
//node <xsl:value-of select="name()"/>
//file <xsl:value-of select="nodeinfo:systemId()"/>
//line <xsl:value-of select="nodeinfo:lineNumber()"/>
//column <xsl:value-of select="nodeinfo:columnNumber()"/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
If no arguments are passed to the systemId(), lineNumber() or
columnNumber() functions, the corresponding information of the current
context node is returned. A node can be passed as argument to the
above functions, in which case the corresponding information about
that node is returned. If a node set containing multiple nodes is
passed as argument, only the information of the first node in the set
is returned.
The second way of obtaining the source location is
programmatically. Given a Node instance, one can obtain the owner DTM
and the node handle (an integer) that represents the
node. Unfortunately I didn't see any way of hiding this: if you find
one please let me know and I'll fix it.
The following example is extracted from PrintTraceListener and
illustrates the API:
Node sourceNode = ev.m_sourceNode;
int nodeHandler = ((DTMNodeProxy)sourceNode).getDTMNodeNumber();
SourceLocator locator = ((DTMNodeProxy)sourceNode).getDTM()
.getSourceLocatorFor(nodeHandler);
m_pw.println("Selected source node '" + sourceNode.getNodeName()
+ "', at " + locator);
Revision Changes Path
1.1 xml-xalan/java/src/org/apache/xalan/lib/NodeInfo.java
Index: NodeInfo.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by Ovidiu
* Predescu <[EMAIL PROTECTED]> on behalf of the Apache Software
* Foundation and was originally developed at Hewlett Packard Company.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.lib;
import org.apache.xml.dtm.ref.DTMNodeProxy;
import org.apache.xalan.extensions.ExpressionContext;
import javax.xml.transform.SourceLocator;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* <code>NodeInfo</code> defines the XSLT extension functions to be
* used from stylesheets.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
* @since May 24, 2001
*/
public class NodeInfo
{
/**
* <code>systemId</code> returns the system id of the current
* context node.
*
* @param context an <code>ExpressionContext</code> value
* @return a <code>String</code> value
*/
public static String systemId(ExpressionContext context)
{
Node contextNode = context.getContextNode();
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
.getSourceLocatorFor(nodeHandler);
if (locator != null)
return locator.getSystemId();
else
return null;
}
/**
* <code>systemId</code> returns the system id of the node passed as
* argument. If a node set is passed as argument, the system id of
* the first node in the set is returned.
*
* @param context an <code>ExpressionContext</code> value
* @param nodeList a <code>NodeList</code> value
* @return a <code>String</code> value
*/
public static String systemId(NodeList nodeList)
{
if (nodeList == null || nodeList.getLength() == 0)
return null;
Node node = nodeList.item(0);
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
.getSourceLocatorFor(nodeHandler);
if (locator != null)
return locator.getSystemId();
else
return null;
}
/**
* <code>publicId</code> returns the system id of the current
* context node.
*
* @param context an <code>ExpressionContext</code> value
* @return a <code>String</code> value
*/
public static String publicId(ExpressionContext context)
{
Node contextNode = context.getContextNode();
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
.getSourceLocatorFor(nodeHandler);
if (locator != null)
return locator.getPublicId();
else
return null;
}
/**
* <code>publicId</code> returns the system id of the node passed as
* argument. If a node set is passed as argument, the system id of
* the first node in the set is returned.
*
* @param context an <code>ExpressionContext</code> value
* @param nodeList a <code>NodeList</code> value
* @return a <code>String</code> value
*/
public static String publicId(NodeList nodeList)
{
if (nodeList == null || nodeList.getLength() == 0)
return null;
Node node = nodeList.item(0);
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
.getSourceLocatorFor(nodeHandler);
if (locator != null)
return locator.getPublicId();
else
return null;
}
/**
* <code>lineNumber</code> returns the line number of the current
* context node.
*
* @param context an <code>ExpressionContext</code> value
* @return an <code>int</code> value
*/
public static int lineNumber(ExpressionContext context)
{
Node contextNode = context.getContextNode();
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
.getSourceLocatorFor(nodeHandler);
if (locator != null)
return locator.getLineNumber();
else
return -1;
}
/**
* <code>lineNumber</code> returns the line number of the node
* passed as argument. If a node set is passed as argument, the line
* number of the first node in the set is returned.
*
* @param nodeList a <code>NodeList</code> value
* @return an <code>int</code> value
*/
public static int lineNumber(NodeList nodeList)
{
if (nodeList == null || nodeList.getLength() == 0)
return -1;
Node node = nodeList.item(0);
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
.getSourceLocatorFor(nodeHandler);
if (locator != null)
return locator.getLineNumber();
else
return -1;
}
/**
* <code>columnNumber</code> returns the column number of the
* current context node.
*
* @param context an <code>ExpressionContext</code> value
* @return an <code>int</code> value
*/
public static int columnNumber(ExpressionContext context)
{
Node contextNode = context.getContextNode();
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
.getSourceLocatorFor(nodeHandler);
if (locator != null)
return locator.getColumnNumber();
else
return -1;
}
/**
* <code>columnNumber</code> returns the column number of the node
* passed as argument. If a node set is passed as argument, the line
* number of the first node in the set is returned.
*
* @param nodeList a <code>NodeList</code> value
* @return an <code>int</code> value
*/
public static int columnNumber(NodeList nodeList)
{
if (nodeList == null || nodeList.getLength() == 0)
return -1;
Node node = nodeList.item(0);
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
.getSourceLocatorFor(nodeHandler);
if (locator != null)
return locator.getColumnNumber();
else
return -1;
}
}
1.19 +3 -1
xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java
Index: XSLTErrorResources.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/res/XSLTErrorResources.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- XSLTErrorResources.java 2001/04/10 18:49:36 1.18
+++ XSLTErrorResources.java 2001/07/11 04:00:09 1.19
@@ -92,7 +92,7 @@
public static final int MAX_WARNING = 26;
/** Maximum misc strings. */
- public static final int MAX_OTHERS = 44;
+ public static final int MAX_OTHERS = 45;
/** Maximum total warnings and error messages. */
public static final int MAX_MESSAGES = MAX_CODE + MAX_WARNING + 1;
@@ -1452,6 +1452,8 @@
contents[MAX_MESSAGES + 43][1] = " [-ENTITYRESOLVER full class name
(EntityResolver to be used to resolve entities)]";
contents[MAX_MESSAGES + 44][0] = "optionCONTENTHANDLER";
contents[MAX_MESSAGES + 44][1] = " [-CONTENTHANDLER full class name
(ContentHandler to be used to serialize output)]";
+ contents[MAX_MESSAGES + 45][0] = "optionLINENUMBERS";
+ contents[MAX_MESSAGES + 45][1] = " [-L use line numbers for source
document]";
}
1.11 +10 -0
xml-xalan/java/src/org/apache/xalan/trace/PrintTraceListener.java
Index: PrintTraceListener.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/trace/PrintTraceListener.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- PrintTraceListener.java 2001/06/27 03:54:50 1.10
+++ PrintTraceListener.java 2001/07/11 04:00:10 1.11
@@ -67,7 +67,9 @@
import org.apache.xalan.templates.Constants;
import org.apache.xpath.axes.ContextNodeList;
+import javax.xml.transform.SourceLocator;
import org.apache.xml.dtm.DTM;
+import org.apache.xml.dtm.ref.DTMNodeProxy;
/**
* <meta name="usage" content="advanced"/>
@@ -181,6 +183,14 @@
if (m_traceSelection)
{
ElemTemplateElement ete = (ElemTemplateElement) ev.m_styleNode;
+ Node sourceNode = ev.m_sourceNode;
+ int nodeHandler = ((DTMNodeProxy)sourceNode).getDTMNodeNumber();
+
+ SourceLocator locator = ((DTMNodeProxy)sourceNode).getDTM()
+ .getSourceLocatorFor(nodeHandler);
+
+ m_pw.println("Selected source node '" + sourceNode.getNodeName()
+ + "', at " + locator);
if (ev.m_styleNode.getLineNumber() == 0)
{
1.106 +42 -0
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.105
retrieving revision 1.106
diff -u -r1.105 -r1.106
--- TransformerImpl.java 2001/07/09 15:17:15 1.105
+++ TransformerImpl.java 2001/07/11 04:00:11 1.106
@@ -91,6 +91,7 @@
import org.apache.xalan.templates.XUnresolvedVariable;
import org.apache.xalan.templates.OutputProperties;
import org.apache.xalan.trace.TraceManager;
+import org.apache.xalan.transformer.XalanProperties;
import org.apache.xml.utils.DOMBuilder;
import org.apache.xml.utils.NodeVector;
import org.apache.xml.utils.BoolStack;
@@ -355,6 +356,12 @@
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 =
@@ -490,6 +497,38 @@
// m_reportInPostExceptionFromThread = false;
}
+ /**
+ * <code>getProperty</code> returns the current setting of the
+ * property described by the <code>property</code> argument.
+ *
+ * @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>.
+ *
+ * @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("Value for property "
+ + XalanProperties.SOURCE_LOCATION
+ + " should be a Boolean instance");
+ m_useSourceLocationProperty = ((Boolean)value).booleanValue();
+ }
+ }
+
// ========= Transformer Interface Implementation ==========
/**
@@ -583,6 +622,9 @@
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
try
1.1
xml-xalan/java/src/org/apache/xalan/transformer/XalanProperties.java
Index: XalanProperties.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by Ovidiu
* Predescu <[EMAIL PROTECTED]> on behalf of the Apache Software
* Foundation and was originally developed at Hewlett Packard Company.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xalan.transformer;
/**
* <code>XalanProperties</code> defines the features understood by
* Xalan.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
@ @since May 23, 2001
*/
public class XalanProperties
{
public final static String SOURCE_LOCATION
= "http://xml.apache.org/xalan/properties/source-location";
}
1.38 +10 -2 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.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- Process.java 2001/06/23 17:37:23 1.37
+++ Process.java 2001/07/11 04:00:12 1.38
@@ -86,6 +86,7 @@
import org.apache.xalan.templates.ElemTemplateElement;
import org.apache.xalan.templates.StylesheetRoot;
import org.apache.xalan.transformer.TransformerImpl;
+import org.apache.xalan.transformer.XalanProperties;
import org.apache.xalan.processor.TransformerFactoryImpl;
import org.apache.xalan.trace.PrintTraceListener;
import org.apache.xalan.trace.TraceListener;
@@ -159,7 +160,8 @@
System.out.println(resbundle.getString("optionTEXT")); //" [-TEXT
(Use simple Text formatter.)]");
System.out.println(resbundle.getString("optionHTML")); //" [-HTML
(Use HTML formatter.)]");
System.out.println(resbundle.getString("optionPARAM")); //" [-PARAM
name expression (Set a stylesheet parameter)]");
-
+ System.out.println(resbundle.getString("optionLINENUMBERS")); //" [-L
use line numbers]"
+
// sc 28-Feb-01 these below should really be added as resources
System.out.println(
" [-MEDIA mediaType (use media attribute to find stylesheet
associated with a document.)]");
@@ -189,7 +191,7 @@
*/
public static void main(String argv[])
{
-
+
// Runtime.getRuntime().traceMethodCalls(false); // turns Java tracing
off
boolean doStackDumpOnError = false;
boolean setQuietMode = false;
@@ -233,6 +235,7 @@
}
boolean formatOutput = false;
+ boolean useSourceLocation = false;
String inFileName = null;
String outFileName = null;
String dumpFileName = null;
@@ -532,6 +535,8 @@
doExit(-1);
}
}
+ else if ("-L".equalsIgnoreCase(argv[i]))
+ useSourceLocation = true;
else
System.err.println(
XSLMessages.createMessage(
@@ -634,6 +639,9 @@
tm.addTraceListener(tracer);
impl.setQuietConflictWarnings(quietConflictWarnings);
+
+ if (useSourceLocation)
+ impl.setProperty(XalanProperties.SOURCE_LOCATION,
Boolean.TRUE);
// sc 28-Feb-01 if we re-implement this, please uncomment
helpmsg in printArgOptions
// impl.setDiagnosticsOutput( setQuietMode ? null :
diagnosticsWriter );
1.3 +19 -0 xml-xalan/java/src/org/apache/xml/dtm/DTM.java
Index: DTM.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/DTM.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DTM.java 2001/06/12 19:15:36 1.2
+++ DTM.java 2001/07/11 04:00:13 1.3
@@ -58,6 +58,8 @@
import org.apache.xml.utils.XMLString;
+import javax.xml.transform.SourceLocator;
+
/**
* <code>DTM</code> is an XML document model expressed as a table
* rather than an object tree. It attempts to provide an interface to
@@ -186,6 +188,14 @@
*/
public void setFeature(String featureId, boolean state);
+ /**
+ * Set a run time property for this DTM instance.
+ *
+ * @param property a <code>String</code> value
+ * @param value an <code>Object</code> value
+ */
+ public void setProperty(String property, Object value);
+
// ========= Document Navigation Functions =========
/**
@@ -928,4 +938,13 @@
* @param str Non-null reference to a string.
*/
public void appendTextChild(String str);
+
+ /**
+ * Get the location of a node in the source document.
+ *
+ * @param node an <code>int</code> value
+ * @return a <code>SourceLocator</code> value or null if no location
+ * is available
+ */
+ public SourceLocator getSourceLocatorFor(int node);
}
1.3 +24 -0
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDocumentImpl.java
Index: DTMDocumentImpl.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDocumentImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DTMDocumentImpl.java 2001/06/12 19:15:46 1.2
+++ DTMDocumentImpl.java 2001/07/11 04:00:13 1.3
@@ -61,6 +61,8 @@
//import java.util.Stack;
import java.util.Vector;
+import javax.xml.transform.SourceLocator;
+
import org.apache.xml.dtm.ref.ChunkedIntArray;
import org.apache.xml.utils.FastStringBuffer;
@@ -2405,4 +2407,26 @@
// residual data from provious use of this DTM
}
+ /**
+ * For the moment all the run time properties are ignored by this
+ * class.
+ *
+ * @param property a <code>String</code> value
+ * @param value an <code>Object</code> value
+ */
+ public void setProperty(String property, Object value)
+ {
+ }
+
+ /**
+ * Source information is not handled yet, so return
+ * <code>null</code> here.
+ *
+ * @param node an <code>int</code> value
+ * @return null
+ */
+ public SourceLocator getSourceLocatorFor(int node)
+ {
+ return null;
+ }
}
1.3 +2 -1
xml-xalan/java/src/org/apache/xml/dtm/ref/ExpandedNameTable.java
Index: ExpandedNameTable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/ExpandedNameTable.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ExpandedNameTable.java 2001/06/12 19:15:49 1.2
+++ ExpandedNameTable.java 2001/07/11 04:00:13 1.3
@@ -87,7 +87,8 @@
public static int MASK_LOCALNAME = 0x0000FFFF;
public static int MASK_NAMESPACE = 0x03FF0000;
public static int MASK_NODETYPE = 0xFC000000;
-
+ public static int MASK_NODEHANDLE = 0x000FFFFF;
+
public static final int ROTAMOUNT_TYPE =
(BITS_PER_NAMESPACE+BITS_PER_LOCALNAME);
// These are all the types prerotated, for caller convenience.
1.1
xml-xalan/java/src/org/apache/xml/dtm/ref/NodeLocator.java
Index: NodeLocator.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by Ovidiu
* Predescu <[EMAIL PROTECTED]> on behalf of the Apache Software
* Foundation and was originally developed at Hewlett Packard Company.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.xml.dtm.ref;
import javax.xml.transform.SourceLocator;
/**
* <code>NodeLocator</code> maintains information on an XML source
* node.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
* @since May 23, 2001
*/
public class NodeLocator implements SourceLocator
{
protected String m_publicId;
protected String m_systemId;
protected int m_lineNumber;
protected int m_columnNumber;
/**
* Creates a new <code>NodeLocator</code> instance.
*
* @param publicId a <code>String</code> value
* @param systemId a <code>String</code> value
* @param lineNumber an <code>int</code> value
* @param columnNumber an <code>int</code> value
*/
public NodeLocator(String publicId, String systemId,
int lineNumber, int columnNumber)
{
this.m_publicId = publicId;
this.m_systemId = systemId;
this.m_lineNumber = lineNumber;
this.m_columnNumber = columnNumber;
}
/**
* <code>getPublicId</code> returns the public ID of the node.
*
* @return a <code>String</code> value
*/
public String getPublicId()
{
return m_publicId;
}
/**
* <code>getSystemId</code> returns the system ID of the node.
*
* @return a <code>String</code> value
*/
public String getSystemId()
{
return m_systemId;
}
/**
* <code>getLineNumber</code> returns the line number of the node.
*
* @return an <code>int</code> value
*/
public int getLineNumber()
{
return m_lineNumber;
}
/**
* <code>getColumnNumber</code> returns the column number of the
* node.
*
* @return an <code>int</code> value
*/
public int getColumnNumber()
{
return m_columnNumber;
}
/**
* <code>toString</code> returns a string representation of this
* NodeLocator instance.
*
* @return a <code>String</code> value
*/
public String toString()
{
return "file '" + m_systemId
+ "', line #" + m_lineNumber
+ ", column #" + m_columnNumber;
}
}
1.10 +23 -0
xml-xalan/java/src/org/apache/xml/dtm/ref/dom2dtm/DOM2DTM.java
Index: DOM2DTM.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/dom2dtm/DOM2DTM.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DOM2DTM.java 2001/07/10 22:23:50 1.9
+++ DOM2DTM.java 2001/07/11 04:00:14 1.10
@@ -72,6 +72,7 @@
import java.util.Vector;
import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.SourceLocator;
import org.xml.sax.ContentHandler;
import org.apache.xml.utils.NodeVector;
@@ -1630,4 +1631,26 @@
throws org.xml.sax.SAXException;
}
+ /**
+ * For the moment all the run time properties are ignored by this
+ * class.
+ *
+ * @param property a <code>String</code> value
+ * @param value an <code>Object</code> value
+ */
+ public void setProperty(String property, Object value)
+ {
+ }
+
+ /**
+ * No source information is available for DOM2DTM, so return
+ * <code>null</code> here.
+ *
+ * @param node an <code>int</code> value
+ * @return null
+ */
+ public SourceLocator getSourceLocatorFor(int node)
+ {
+ return null;
+ }
}
1.9 +74 -21
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SAX2DTM.java 2001/07/02 19:39:41 1.8
+++ SAX2DTM.java 2001/07/11 04:00:15 1.9
@@ -56,24 +56,25 @@
*/
package org.apache.xml.dtm.ref.sax2dtm;
-import org.apache.xml.dtm.ref.*;
-import org.apache.xml.dtm.*;
import java.util.Hashtable;
import java.util.Vector;
-
-import org.xml.sax.*;
-import org.xml.sax.ext.*;
-
import javax.xml.transform.Source;
-
+import javax.xml.transform.SourceLocator;
+import org.apache.xalan.transformer.XalanProperties;
+import org.apache.xml.dtm.*;
+import org.apache.xml.dtm.ref.*;
+import org.apache.xml.utils.StringVector;
+import org.apache.xml.utils.IntVector;
import org.apache.xml.utils.FastStringBuffer;
-import org.apache.xml.utils.SuballocatedIntVector;
import org.apache.xml.utils.IntStack;
-import org.apache.xml.utils.XMLCharacterRecognizer;
+import org.apache.xml.utils.SuballocatedIntVector;
import org.apache.xml.utils.SystemIDResolver;
+import org.apache.xml.utils.WrappedRuntimeException;
+import org.apache.xml.utils.XMLCharacterRecognizer;
import org.apache.xml.utils.XMLString;
import org.apache.xml.utils.XMLStringFactory;
-import org.apache.xml.utils.WrappedRuntimeException;
+import org.xml.sax.*;
+import org.xml.sax.ext.*;
/**
* This class implements a DTM that tends to be optimized more for speed than
@@ -208,6 +209,16 @@
* or -1 if there is no text node in progress
*/
private int m_textPendingStart = -1;
+
+ /**
+ * Describes whether information about document source location
+ * should be maintained or not.
+ */
+ private boolean m_useSourceLocationProperty = false;
+
+ private StringVector m_sourceSystemId;
+ private IntVector m_sourceLine;
+ private IntVector m_sourceColumn;
/**
* Construct a SAX2DTM object ready to be constructed from SAX2
@@ -234,16 +245,6 @@
m_data = new SuballocatedIntVector(doIndexing ? (1024*2) : 512, 1024);
m_dataOrQName = new SuballocatedIntVector(m_initialblocksize);
-
- int doc = addNode(DTM.DOCUMENT_NODE,
-
m_expandedNameTable.getExpandedTypeID(DTM.DOCUMENT_NODE),
- m_levelAmount, DTM.NULL, DTM.NULL, 0, true);
-
- m_levelAmount++;
-
- m_parents.push(doc);
-
- m_previous = DTM.NULL;
}
/**
@@ -836,6 +837,19 @@
ensureSize(nodeIndex);
+ if (m_useSourceLocationProperty && m_locator != null) {
+ m_sourceSystemId.addElement(m_locator.getSystemId());
+ m_sourceLine.addElement(m_locator.getLineNumber());
+ m_sourceColumn.addElement(m_locator.getColumnNumber());
+
+ if (m_sourceSystemId.size() != m_size) {
+ System.out.println("size array " + m_size
+ + " is different from size of array "
+ + m_sourceSystemId.size());
+ System.exit(1);
+ }
+ }
+
// Do the hard casts here, so we localize changes that may have to be
made.
m_level.addElement((byte)level); // %REVIEW%
setElementAt(level,nodeIndex)?
m_firstch.setElementAt(canHaveFirstChild ? NOTPROCESSED :
DTM.NULL,nodeIndex);
@@ -1480,6 +1494,16 @@
*/
public void startDocument() throws SAXException
{
+ int doc = addNode(DTM.DOCUMENT_NODE,
+
m_expandedNameTable.getExpandedTypeID(DTM.DOCUMENT_NODE),
+ m_levelAmount, DTM.NULL, DTM.NULL, 0, true);
+
+ m_levelAmount++;
+
+ m_parents.push(doc);
+
+ m_previous = DTM.NULL;
+
m_contextIndexes.push(m_prefixMappings.size()); // for the next element.
}
@@ -1497,7 +1521,6 @@
*/
public void endDocument() throws SAXException
{
-
charactersFlush();
m_nextsib.setElementAt(NULL,0);
@@ -2192,5 +2215,35 @@
m_previous = addNode(DTM.COMMENT_NODE, exName, m_levelAmount,
m_parents.peek(), m_previous, dataIndex, false);
+ }
+
+ /**
+ * Set a run time property for this DTM instance.
+ *
+ * @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("Value for property "
+ + XalanProperties.SOURCE_LOCATION
+ + " should be a Boolean instance");
+ m_useSourceLocationProperty = ((Boolean)value).booleanValue();
+ m_sourceSystemId = new StringVector();
+ m_sourceLine = new IntVector();
+ m_sourceColumn = new IntVector();
+ }
+ }
+
+ public SourceLocator getSourceLocatorFor(int node)
+ {
+ node = node & ExpandedNameTable.MASK_NODEHANDLE;
+
+ return new NodeLocator(null,
+ m_sourceSystemId.elementAt(node),
+ m_sourceLine.elementAt(node),
+ m_sourceColumn.elementAt(node));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]