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