KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xalan > internal > lib > NodeInfo


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: NodeInfo.java,v 1.2.4.1 2005/09/10 18:54:37 jeffsuttor Exp $
18  */

19
20 package com.sun.org.apache.xalan.internal.lib;
21
22 import javax.xml.transform.SourceLocator JavaDoc;
23
24 import com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
25 import com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
26
27 import org.w3c.dom.Node JavaDoc;
28 import org.w3c.dom.NodeList JavaDoc;
29
30 /**
31  * <code>NodeInfo</code> defines a set of XSLT extension functions to be
32  * used from stylesheets.
33  *
34  * @author <a HREF="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
35  * @since May 24, 2001
36  */

37 public class NodeInfo
38 {
39   /**
40    * <code>systemId</code> returns the system id of the current
41    * context node.
42    *
43    * @param context an <code>ExpressionContext</code> value
44    * @return a <code>String</code> value
45    */

46   public static String JavaDoc systemId(ExpressionContext context)
47   {
48     Node JavaDoc contextNode = context.getContextNode();
49     int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
50     SourceLocator JavaDoc locator = ((DTMNodeProxy)contextNode).getDTM()
51       .getSourceLocatorFor(nodeHandler);
52
53     if (locator != null)
54       return locator.getSystemId();
55     else
56       return null;
57   }
58
59   /**
60    * <code>systemId</code> returns the system id of the node passed as
61    * argument. If a node set is passed as argument, the system id of
62    * the first node in the set is returned.
63    *
64    * @param nodeList a <code>NodeList</code> value
65    * @return a <code>String</code> value
66    */

67   public static String JavaDoc systemId(NodeList JavaDoc nodeList)
68   {
69     if (nodeList == null || nodeList.getLength() == 0)
70       return null;
71     
72     Node JavaDoc node = nodeList.item(0);
73     int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
74     SourceLocator JavaDoc locator = ((DTMNodeProxy)node).getDTM()
75       .getSourceLocatorFor(nodeHandler);
76
77     if (locator != null)
78       return locator.getSystemId();
79     else
80       return null;
81   }
82
83   /**
84    * <code>publicId</code> returns the public identifier of the current
85    * context node.
86    *
87    * Xalan does not currently record this value, and will return null.
88    *
89    * @param context an <code>ExpressionContext</code> value
90    * @return a <code>String</code> value
91    */

92   public static String JavaDoc publicId(ExpressionContext context)
93   {
94     Node JavaDoc contextNode = context.getContextNode();
95     int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
96     SourceLocator JavaDoc locator = ((DTMNodeProxy)contextNode).getDTM()
97       .getSourceLocatorFor(nodeHandler);
98
99     if (locator != null)
100       return locator.getPublicId();
101     else
102       return null;
103   }
104
105   /**
106    * <code>publicId</code> returns the public identifier of the node passed as
107    * argument. If a node set is passed as argument, the public identifier of
108    * the first node in the set is returned.
109    *
110    * Xalan does not currently record this value, and will return null.
111    *
112    * @param nodeList a <code>NodeList</code> value
113    * @return a <code>String</code> value
114    */

115   public static String JavaDoc publicId(NodeList JavaDoc nodeList)
116   {
117     if (nodeList == null || nodeList.getLength() == 0)
118       return null;
119     
120     Node JavaDoc node = nodeList.item(0);
121     int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
122     SourceLocator JavaDoc locator = ((DTMNodeProxy)node).getDTM()
123       .getSourceLocatorFor(nodeHandler);
124
125     if (locator != null)
126       return locator.getPublicId();
127     else
128       return null;
129   }
130
131   /**
132    * <code>lineNumber</code> returns the line number of the current
133    * context node.
134    *
135    * NOTE: Xalan does not normally record location information for each node.
136    * To obtain it, you must set the custom TrAX attribute
137    * "http://xml.apache.org/xalan/features/source_location"
138    * true in the TransformerFactory before generating the Transformer and executing
139    * the stylesheet. Storage cost per node will be noticably increased in this mode.
140    *
141    * @param context an <code>ExpressionContext</code> value
142    * @return an <code>int</code> value. This may be -1 to indicate that the
143    * line number is not known.
144    */

145   public static int lineNumber(ExpressionContext context)
146   {
147     Node JavaDoc contextNode = context.getContextNode();
148     int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
149     SourceLocator JavaDoc locator = ((DTMNodeProxy)contextNode).getDTM()
150       .getSourceLocatorFor(nodeHandler);
151
152     if (locator != null)
153       return locator.getLineNumber();
154     else
155       return -1;
156   }
157
158   /**
159    * <code>lineNumber</code> returns the line number of the node
160    * passed as argument. If a node set is passed as argument, the line
161    * number of the first node in the set is returned.
162    *
163    * NOTE: Xalan does not normally record location information for each node.
164    * To obtain it, you must set the custom TrAX attribute
165    * "http://xml.apache.org/xalan/features/source_location"
166    * true in the TransformerFactory before generating the Transformer and executing
167    * the stylesheet. Storage cost per node will be noticably increased in this mode.
168    *
169    * @param nodeList a <code>NodeList</code> value
170    * @return an <code>int</code> value. This may be -1 to indicate that the
171    * line number is not known.
172    */

173   public static int lineNumber(NodeList JavaDoc nodeList)
174   {
175     if (nodeList == null || nodeList.getLength() == 0)
176       return -1;
177     
178     Node JavaDoc node = nodeList.item(0);
179     int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
180     SourceLocator JavaDoc locator = ((DTMNodeProxy)node).getDTM()
181       .getSourceLocatorFor(nodeHandler);
182
183     if (locator != null)
184       return locator.getLineNumber();
185     else
186       return -1;
187   }
188
189   /**
190    * <code>columnNumber</code> returns the column number of the
191    * current context node.
192    *
193    * NOTE: Xalan does not normally record location information for each node.
194    * To obtain it, you must set the custom TrAX attribute
195    * "http://xml.apache.org/xalan/features/source_location"
196    * true in the TransformerFactory before generating the Transformer and executing
197    * the stylesheet. Storage cost per node will be noticably increased in this mode.
198    *
199    * @param context an <code>ExpressionContext</code> value
200    * @return an <code>int</code> value. This may be -1 to indicate that the
201    * column number is not known.
202    */

203   public static int columnNumber(ExpressionContext context)
204   {
205     Node JavaDoc contextNode = context.getContextNode();
206     int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
207     SourceLocator JavaDoc locator = ((DTMNodeProxy)contextNode).getDTM()
208       .getSourceLocatorFor(nodeHandler);
209
210     if (locator != null)
211       return locator.getColumnNumber();
212     else
213       return -1;
214   }
215
216   /**
217    * <code>columnNumber</code> returns the column number of the node
218    * passed as argument. If a node set is passed as argument, the line
219    * number of the first node in the set is returned.
220    *
221    * NOTE: Xalan does not normally record location information for each node.
222    * To obtain it, you must set the custom TrAX attribute
223    * "http://xml.apache.org/xalan/features/source_location"
224    * true in the TransformerFactory before generating the Transformer and executing
225    * the stylesheet. Storage cost per node will be noticably increased in this mode.
226    *
227    * @param nodeList a <code>NodeList</code> value
228    * @return an <code>int</code> value. This may be -1 to indicate that the
229    * column number is not known.
230    */

231   public static int columnNumber(NodeList JavaDoc nodeList)
232   {
233     if (nodeList == null || nodeList.getLength() == 0)
234       return -1;
235     
236     Node JavaDoc node = nodeList.item(0);
237     int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
238     SourceLocator JavaDoc locator = ((DTMNodeProxy)node).getDTM()
239       .getSourceLocatorFor(nodeHandler);
240
241     if (locator != null)
242       return locator.getColumnNumber();
243     else
244       return -1;
245   }
246 }
247
Popular Tags