/*
* Class XPathHelper
* This class talks directly to the VOTable XML document.
* This class is used for getting all required information
* such as VTable, MetaData, and Data from the XML document.
*
* Used internally.
*/


#ifndef XPATH_HELPER_H
#define XPATH_HELPER_H

// Base header file.  Must be first.
#include "Include/PlatformDefinitions.hpp"

#include <cassert>


//#if defined(XALAN_OLD_STREAM_HEADERS)
//#include <iostream.h>
//#else
//#include <iostream>
//#endif

#include "util/PlatformUtils.hpp"
#include "framework/LocalFileInputSource.hpp"



#include "XalanDOM/XalanDocument.hpp"
#include "XalanDOM/XalanElement.hpp"
#include "XalanDOM/XalanNamedNodeMap.hpp"
#include "XalanDOM/XalanNodeList.hpp"
#include "DOMSupport/DOMServices.hpp"



#include "XPath/XObject.hpp"
#include "XPath/XPathEvaluator.hpp"
#include "XPath/NodeRefListBase.hpp"



#include "XalanSourceTree/XalanSourceTreeDOMSupport.hpp"
#include "XalanSourceTree/XalanSourceTreeInit.hpp"
#include "XalanSourceTree/XalanSourceTreeParserLiaison.hpp"

#include <string.h>
#include "global.h"
#include "VTable.h"
#include "Resource.h"


const int MAX_XPATH_EXPR_LEN = 256;

class XPathHelper {

public:

	XPathHelper(void);
	int getVTableTree(VTable &v, const char * filename, 
		const char * xpath, int *status);
	int getResourceTree(Resource &r, const char * filename, 
		const char * xpath, int *status);
	

private:
	
	int extractResourceInfo(XObjectPtr  xObj, Resource &r, int *status);
	int extractTableInfo(XObjectPtr node, VTable &v, int *status);
	int getTable(const XalanNode* node, VTable &v, int *status);
	int getFieldParam(const XalanNode *siblingNode, FieldParam *f, bool isField, int *status);
	int getLink(const XalanNode *siblingNode, Link &link, int *status);
	char* getDescription(const XalanNode *siblingNode, int *status);
	int getTableAttributes( const XalanNode *node, VTable &v, int *status);
	int getFieldParamAttributes(const XalanNode *node, FieldParam *f, bool isField, int * status);
	int getValuesAttributes(const XalanNode *node, Values &v, int * status);
	char * getCharString(XalanDOMString str);
	unsigned short * XPathHelper::getShortString(XalanDOMString str, int &size);
	int getValues(const XalanNode *node, Values &v, int *status);
	int getOptionAttributes(const XalanNode *node, Option &o, int *status);
	Range * getRange(const XalanNode *node, int *status);
	int getRows(const XalanNode *node, vector<Row> &r, const vector<Field> &fields, int *status);
	int getColumnAttributes(const XalanNode *node, Column &c, int *status);
	Range getRangeAttributes(const XalanNode *node, int *status);
	int getData(const XalanNode *node, TableData &td, const vector<Field> &fields, int *status);
	int getOption(const XalanNode *node, Option &o, int *status);
	int getRow(const XalanNode *node, Row &r, const vector<Field> &fields, int *status);
	int getColumn(const XalanNode *node, Column &c, bool isUnicode, int *status);
	int getResourceAttributes(const XalanNode *node, Resource &r, int *status);
	int getInfoAttributes(const XalanNode *node, Info &i, int *status);
	int getCoosysAttributes(const XalanNode *node, Coosys &c, int *status);
	int getResource(const XalanNode* node, Resource &r, int * status);
	int getInfo(const XalanNode *node, Info &i, int *status);
	int getCoosys(const XalanNode *node, Coosys &c, int *status);
	


};


#endif