6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 1999-2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
/*
|
|
21 |
* $Id: NodeInfo.java,v 1.2.4.1 2005/09/10 18:54:37 jeffsuttor Exp $
|
|
22 |
*/
|
|
23 |
|
|
24 |
package com.sun.org.apache.xalan.internal.lib;
|
|
25 |
|
|
26 |
import javax.xml.transform.SourceLocator;
|
|
27 |
|
|
28 |
import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
|
|
29 |
import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
|
|
30 |
|
|
31 |
import org.w3c.dom.Node;
|
|
32 |
import org.w3c.dom.NodeList;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* <code>NodeInfo</code> defines a set of XSLT extension functions to be
|
|
36 |
* used from stylesheets.
|
|
37 |
*
|
|
38 |
* @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
|
|
39 |
* @since May 24, 2001
|
|
40 |
*/
|
|
41 |
public class NodeInfo
|
|
42 |
{
|
|
43 |
/**
|
|
44 |
* <code>systemId</code> returns the system id of the current
|
|
45 |
* context node.
|
|
46 |
*
|
|
47 |
* @param context an <code>ExpressionContext</code> value
|
|
48 |
* @return a <code>String</code> value
|
|
49 |
*/
|
|
50 |
public static String systemId(ExpressionContext context)
|
|
51 |
{
|
|
52 |
Node contextNode = context.getContextNode();
|
|
53 |
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
|
|
54 |
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
|
|
55 |
.getSourceLocatorFor(nodeHandler);
|
|
56 |
|
|
57 |
if (locator != null)
|
|
58 |
return locator.getSystemId();
|
|
59 |
else
|
|
60 |
return null;
|
|
61 |
}
|
|
62 |
|
|
63 |
/**
|
|
64 |
* <code>systemId</code> returns the system id of the node passed as
|
|
65 |
* argument. If a node set is passed as argument, the system id of
|
|
66 |
* the first node in the set is returned.
|
|
67 |
*
|
|
68 |
* @param nodeList a <code>NodeList</code> value
|
|
69 |
* @return a <code>String</code> value
|
|
70 |
*/
|
|
71 |
public static String systemId(NodeList nodeList)
|
|
72 |
{
|
|
73 |
if (nodeList == null || nodeList.getLength() == 0)
|
|
74 |
return null;
|
|
75 |
|
|
76 |
Node node = nodeList.item(0);
|
|
77 |
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
|
|
78 |
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
|
|
79 |
.getSourceLocatorFor(nodeHandler);
|
|
80 |
|
|
81 |
if (locator != null)
|
|
82 |
return locator.getSystemId();
|
|
83 |
else
|
|
84 |
return null;
|
|
85 |
}
|
|
86 |
|
|
87 |
/**
|
|
88 |
* <code>publicId</code> returns the public identifier of the current
|
|
89 |
* context node.
|
|
90 |
*
|
|
91 |
* Xalan does not currently record this value, and will return null.
|
|
92 |
*
|
|
93 |
* @param context an <code>ExpressionContext</code> value
|
|
94 |
* @return a <code>String</code> value
|
|
95 |
*/
|
|
96 |
public static String publicId(ExpressionContext context)
|
|
97 |
{
|
|
98 |
Node contextNode = context.getContextNode();
|
|
99 |
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
|
|
100 |
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
|
|
101 |
.getSourceLocatorFor(nodeHandler);
|
|
102 |
|
|
103 |
if (locator != null)
|
|
104 |
return locator.getPublicId();
|
|
105 |
else
|
|
106 |
return null;
|
|
107 |
}
|
|
108 |
|
|
109 |
/**
|
|
110 |
* <code>publicId</code> returns the public identifier of the node passed as
|
|
111 |
* argument. If a node set is passed as argument, the public identifier of
|
|
112 |
* the first node in the set is returned.
|
|
113 |
*
|
|
114 |
* Xalan does not currently record this value, and will return null.
|
|
115 |
*
|
|
116 |
* @param nodeList a <code>NodeList</code> value
|
|
117 |
* @return a <code>String</code> value
|
|
118 |
*/
|
|
119 |
public static String publicId(NodeList nodeList)
|
|
120 |
{
|
|
121 |
if (nodeList == null || nodeList.getLength() == 0)
|
|
122 |
return null;
|
|
123 |
|
|
124 |
Node node = nodeList.item(0);
|
|
125 |
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
|
|
126 |
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
|
|
127 |
.getSourceLocatorFor(nodeHandler);
|
|
128 |
|
|
129 |
if (locator != null)
|
|
130 |
return locator.getPublicId();
|
|
131 |
else
|
|
132 |
return null;
|
|
133 |
}
|
|
134 |
|
|
135 |
/**
|
|
136 |
* <code>lineNumber</code> returns the line number of the current
|
|
137 |
* context node.
|
|
138 |
*
|
|
139 |
* NOTE: Xalan does not normally record location information for each node.
|
|
140 |
* To obtain it, you must set the custom TrAX attribute
|
|
141 |
* "http://xml.apache.org/xalan/features/source_location"
|
|
142 |
* true in the TransformerFactory before generating the Transformer and executing
|
|
143 |
* the stylesheet. Storage cost per node will be noticably increased in this mode.
|
|
144 |
*
|
|
145 |
* @param context an <code>ExpressionContext</code> value
|
|
146 |
* @return an <code>int</code> value. This may be -1 to indicate that the
|
|
147 |
* line number is not known.
|
|
148 |
*/
|
|
149 |
public static int lineNumber(ExpressionContext context)
|
|
150 |
{
|
|
151 |
Node contextNode = context.getContextNode();
|
|
152 |
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
|
|
153 |
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
|
|
154 |
.getSourceLocatorFor(nodeHandler);
|
|
155 |
|
|
156 |
if (locator != null)
|
|
157 |
return locator.getLineNumber();
|
|
158 |
else
|
|
159 |
return -1;
|
|
160 |
}
|
|
161 |
|
|
162 |
/**
|
|
163 |
* <code>lineNumber</code> returns the line number of the node
|
|
164 |
* passed as argument. If a node set is passed as argument, the line
|
|
165 |
* number of the first node in the set is returned.
|
|
166 |
*
|
|
167 |
* NOTE: Xalan does not normally record location information for each node.
|
|
168 |
* To obtain it, you must set the custom TrAX attribute
|
|
169 |
* "http://xml.apache.org/xalan/features/source_location"
|
|
170 |
* true in the TransformerFactory before generating the Transformer and executing
|
|
171 |
* the stylesheet. Storage cost per node will be noticably increased in this mode.
|
|
172 |
*
|
|
173 |
* @param nodeList a <code>NodeList</code> value
|
|
174 |
* @return an <code>int</code> value. This may be -1 to indicate that the
|
|
175 |
* line number is not known.
|
|
176 |
*/
|
|
177 |
public static int lineNumber(NodeList nodeList)
|
|
178 |
{
|
|
179 |
if (nodeList == null || nodeList.getLength() == 0)
|
|
180 |
return -1;
|
|
181 |
|
|
182 |
Node node = nodeList.item(0);
|
|
183 |
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
|
|
184 |
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
|
|
185 |
.getSourceLocatorFor(nodeHandler);
|
|
186 |
|
|
187 |
if (locator != null)
|
|
188 |
return locator.getLineNumber();
|
|
189 |
else
|
|
190 |
return -1;
|
|
191 |
}
|
|
192 |
|
|
193 |
/**
|
|
194 |
* <code>columnNumber</code> returns the column number of the
|
|
195 |
* current context node.
|
|
196 |
*
|
|
197 |
* NOTE: Xalan does not normally record location information for each node.
|
|
198 |
* To obtain it, you must set the custom TrAX attribute
|
|
199 |
* "http://xml.apache.org/xalan/features/source_location"
|
|
200 |
* true in the TransformerFactory before generating the Transformer and executing
|
|
201 |
* the stylesheet. Storage cost per node will be noticably increased in this mode.
|
|
202 |
*
|
|
203 |
* @param context an <code>ExpressionContext</code> value
|
|
204 |
* @return an <code>int</code> value. This may be -1 to indicate that the
|
|
205 |
* column number is not known.
|
|
206 |
*/
|
|
207 |
public static int columnNumber(ExpressionContext context)
|
|
208 |
{
|
|
209 |
Node contextNode = context.getContextNode();
|
|
210 |
int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
|
|
211 |
SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
|
|
212 |
.getSourceLocatorFor(nodeHandler);
|
|
213 |
|
|
214 |
if (locator != null)
|
|
215 |
return locator.getColumnNumber();
|
|
216 |
else
|
|
217 |
return -1;
|
|
218 |
}
|
|
219 |
|
|
220 |
/**
|
|
221 |
* <code>columnNumber</code> returns the column number of the node
|
|
222 |
* passed as argument. If a node set is passed as argument, the line
|
|
223 |
* number of the first node in the set is returned.
|
|
224 |
*
|
|
225 |
* NOTE: Xalan does not normally record location information for each node.
|
|
226 |
* To obtain it, you must set the custom TrAX attribute
|
|
227 |
* "http://xml.apache.org/xalan/features/source_location"
|
|
228 |
* true in the TransformerFactory before generating the Transformer and executing
|
|
229 |
* the stylesheet. Storage cost per node will be noticably increased in this mode.
|
|
230 |
*
|
|
231 |
* @param nodeList a <code>NodeList</code> value
|
|
232 |
* @return an <code>int</code> value. This may be -1 to indicate that the
|
|
233 |
* column number is not known.
|
|
234 |
*/
|
|
235 |
public static int columnNumber(NodeList nodeList)
|
|
236 |
{
|
|
237 |
if (nodeList == null || nodeList.getLength() == 0)
|
|
238 |
return -1;
|
|
239 |
|
|
240 |
Node node = nodeList.item(0);
|
|
241 |
int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
|
|
242 |
SourceLocator locator = ((DTMNodeProxy)node).getDTM()
|
|
243 |
.getSourceLocatorFor(nodeHandler);
|
|
244 |
|
|
245 |
if (locator != null)
|
|
246 |
return locator.getColumnNumber();
|
|
247 |
else
|
|
248 |
return -1;
|
|
249 |
}
|
|
250 |
}
|