NodeInfo.java revision 286
0N/A/*
0N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
961N/A */
0N/A/*
0N/A * Copyright 1999-2004 The Apache Software Foundation.
0N/A *
0N/A * Licensed under the Apache License, Version 2.0 (the "License");
0N/A * you may not use this file except in compliance with the License.
0N/A * You may obtain a copy of the License at
0N/A *
0N/A * http://www.apache.org/licenses/LICENSE-2.0
0N/A *
0N/A * Unless required by applicable law or agreed to in writing, software
0N/A * distributed under the License is distributed on an "AS IS" BASIS,
0N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A * See the License for the specific language governing permissions and
0N/A * limitations under the License.
0N/A */
0N/A/*
553N/A * $Id: NodeInfo.java,v 1.2.4.1 2005/09/10 18:54:37 jeffsuttor Exp $
553N/A */
553N/A
0N/Apackage com.sun.org.apache.xalan.internal.lib;
0N/A
0N/Aimport javax.xml.transform.SourceLocator;
0N/A
0N/Aimport com.sun.org.apache.xalan.internal.extensions.ExpressionContext;
0N/Aimport com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy;
0N/A
0N/Aimport org.w3c.dom.Node;
0N/Aimport org.w3c.dom.NodeList;
0N/A
0N/A/**
0N/A * <code>NodeInfo</code> defines a set of XSLT extension functions to be
0N/A * used from stylesheets.
0N/A *
0N/A * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
0N/A * @since May 24, 2001
0N/A */
0N/Apublic class NodeInfo
0N/A{
0N/A /**
1147N/A * <code>systemId</code> returns the system id of the current
0N/A * context node.
389N/A *
389N/A * @param context an <code>ExpressionContext</code> value
389N/A * @return a <code>String</code> value
389N/A */
1119N/A public static String systemId(ExpressionContext context)
0N/A {
0N/A Node contextNode = context.getContextNode();
0N/A int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
389N/A SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
0N/A .getSourceLocatorFor(nodeHandler);
0N/A
0N/A if (locator != null)
0N/A return locator.getSystemId();
0N/A else
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * <code>systemId</code> returns the system id of the node passed as
0N/A * argument. If a node set is passed as argument, the system id of
0N/A * the first node in the set is returned.
0N/A *
0N/A * @param nodeList a <code>NodeList</code> value
837N/A * @return a <code>String</code> value
837N/A */
0N/A public static String systemId(NodeList nodeList)
0N/A {
0N/A if (nodeList == null || nodeList.getLength() == 0)
0N/A return null;
0N/A
0N/A Node node = nodeList.item(0);
0N/A int nodeHandler = ((DTMNodeProxy)node).getDTMNodeNumber();
0N/A SourceLocator locator = ((DTMNodeProxy)node).getDTM()
0N/A .getSourceLocatorFor(nodeHandler);
0N/A
0N/A if (locator != null)
0N/A return locator.getSystemId();
0N/A else
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * <code>publicId</code> returns the public identifier of the current
0N/A * context node.
0N/A *
0N/A * Xalan does not currently record this value, and will return null.
0N/A *
0N/A * @param context an <code>ExpressionContext</code> value
0N/A * @return a <code>String</code> value
0N/A */
0N/A public static String publicId(ExpressionContext context)
0N/A {
0N/A Node contextNode = context.getContextNode();
0N/A int nodeHandler = ((DTMNodeProxy)contextNode).getDTMNodeNumber();
0N/A SourceLocator locator = ((DTMNodeProxy)contextNode).getDTM()
0N/A .getSourceLocatorFor(nodeHandler);
0N/A
0N/A if (locator != null)
0N/A return locator.getPublicId();
0N/A else
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * <code>publicId</code> returns the public identifier of the node passed as
0N/A * 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 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.
*
* 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. This may be -1 to indicate that the
* line number is not known.
*/
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.
*
* 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. This may be -1 to indicate that the
* line number is not known.
*/
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.
*
* 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. This may be -1 to indicate that the
* column number is not known.
*/
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.
*
* 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. This may be -1 to indicate that the
* column number is not known.
*/
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;
}
}