package com.seleniumtests.xmldog;

import java.io.Serializable;

import org.w3c.dom.Node;



/**

 * Convenience Node class containing the Node itself and corresponding XPath

 * expression.

 * <br> This can be used to improve the performance where XPath of all the children

 * needs to be computed, saves time not traversing to the ROOT multiple times.

 *

 */

public class XNode 

	implements Serializable

{

	private Node _node = null;

	private String _xPath = null;

	private String _noIndexXPath = null;

	private int _position = 0;	// Position of the Node under a parent

	private int _depth = 0;		// Depth of the Node in the Document

	

	/**

	 * Default Constructor

	 */

	public XNode()

	{

	}

	

	/**

	 * Constructor

	 * @param node the Node

	 * @param xPath the XPath expression for the Node	

	 */

	public XNode(Node node, String xPath)

	{

		_node = node;

		_xPath = xPath;		

	}

	

	/**

	 * Constructor

	 * @param node the Node

	 * @param xPath the XPath expression for the Node

	 * @param noIndexXPath the XPath expression without the indexes

	 */

	public XNode(Node node, String xPath, String noIndexXPath)

	{

		_node = node;

		_xPath = xPath;

		_noIndexXPath = noIndexXPath;

	}

	

	/**

	 * Gets Node

	 */

	public Node getNode()

	{

		return _node;

	}

	

	/**

	 * Sets Node

	 */

	public void setNode(Node node)

	{

		_node = node;

	}

	

	/**

	 * Gets the position of the Node under the parent

	 */

	public int getPosition()

	{

		return _position;

	}

	

	/**

	 * Sets the position of the Node under the parent

	 */

	public void setPosition(int position)

	{

		_position = position;

	}

	

	/**

	 * Gets the depth of the Node in the Document

	 */

	public int getDepth()

	{

		return _depth;

	}



	/**

	 * Sets the depth of the Node in the Document

	 */	

	public void setDepth(int depth)

	{

		_depth = depth;

	}



	/**

	 * Gets the XPath expression

	 */	

	public String getXPath()

	{

		return _xPath;

	}

	

	/**

	 * Sets XPath expression

	 */

	public void setXPath(String xPath)

	{

		_xPath = xPath;				

	}

	

	/**

	 * Gets XPath expression without the indexes

	 */

	public String getNoIndexXPath()

	{

		String xPath = getXPath();

		

		xPath = XMLUtil.getNoIndexXPath(xPath);

		setNoIndexXPath(xPath);

		

		return xPath;		

	}

		

	

	/**

	 * Sets XPath expression without the indexes

	 */	

	public void setNoIndexXPath(String noIndexXPath)

	{

		_noIndexXPath = noIndexXPath;

	}

	

	/**

	 * Gets Node Value

	 */

	public String getValue()

	{

		if (_node == null)

			return null;

			

		return _node.getNodeValue();

	}

	

	/**

	 * Gets Node Name

	 */

	public String getName()

	{

		if (_node == null)

			return null;

		

		return _node.getNodeName();

	}

	

	/**

	 * Gets String representation of the XNode

	 */

	public String toString()

	{

		String eol = System.getProperty("line.separator");

		StringBuffer sb = new StringBuffer("XNode:[");

		

		sb.append("Node Name:" + getNode().getNodeName());

		sb.append(eol);

		sb.append("Node Value:" + getNode().getNodeValue());

		sb.append(eol);		

		sb.append("Node Type:" + getNode().getNodeType());

		sb.append(eol);		

		sb.append("Node XPath:" + getXPath());

		sb.append(eol);		

		sb.append("]");

		

		return sb.toString();

	}



	/**

	 * Main method for debugging purpose only

	 */	

	public static void main(String[] args)

	{

		XNode x = new XNode();

		

		x.setXPath("/ebay/element[0]/whatsup[3]/element[2]");

		System.out.println("No index str " + x.getNoIndexXPath());

	}

}


@@ -3316,264 +3316,7 @@
 %09%7D%0A%0A
-%0A%0A%09/**%0A%0A%09 * Main method for debugging purpose only%0A%0A%09 */%09%0A%0A%09public static void main(String%5B%5D args)%0A%0A%09%7B%0A%0A%09%09XNode x = new XNode();%0A%0A%09%09%0A%0A%09%09x.setXPath(%22/ebay/element%5B0%5D/whatsup%5B3%5D/element%5B2%5D%22);%0A%0A%09%09System.out.println(%22No index str %22 + x.getNoIndexXPath());%0A%0A%09%7D%0A%0A
 %7D%0A%0A

remove main method