KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > 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.6 2004/02/11 17:56:36 minchau Exp $
18  */

19
20 package org.apache.xalan.lib;
21
22 import javax.xml.transform.SourceLocator JavaDoc;
23
24 import org.apache.xalan.extensions.ExpressionContext;
25 import org.apache.xml.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 context an <code>ExpressionContext</code> value
65    * @param nodeList a <code>NodeList</code> value
66    * @return a <code>String</code> value
67    */

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

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

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

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

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

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

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