org.gcube.indexmanagement.common
Class XMLProfileParser

java.lang.Object
  extended by org.gcube.indexmanagement.common.XMLProfileParser

public class XMLProfileParser
extends Object

Provides various XML read only functions for the indexing service.

See Also:
FullTextIndexType

Constructor Summary
XMLProfileParser()
          Creates a parser instance.
 
Method Summary
 int countDescendants(String elementName)
          Counts the number of descendant elements with a specified element name
static String escapeForXML(String text)
          Inserts Entity References in the place of certain illegal characters in order to make an xml file valid
 String getFieldByValue(String elementName)
          Gets the #text element of the specified element in the current field.
 String getFieldText(String fieldname)
          Retreives the #text element of the first instance of fieldname.
 String[] getFieldTextArray(String fieldname)
          Retreives the #text elements of all instances of fieldname.
 String[][] getSubFields()
          Gets the (element name, #text value) pairs for all child nodes in the current field.
 boolean goChildElement(String elementName)
          Sets the current node to the first child (of the current node) element with a specified element name
 boolean goParentElement(String elementName)
          Sets the current node to the first ascendant (of the current node) element with a specified element name
 boolean goSiblingElement(String elementName)
          Sets the current node to the first sibling (of the current node) element with a specified element name
 boolean hasDescendant(String elementName)
          Determines whether the current node has one or more descendant elements with a specified element name
 boolean hasSibling(String elementName)
          Determines whether the current node has one or more sibling elements with a specified element name
 void readDoc(String filename, String schemaLocation)
          Sets the current document to the parsed file.
 void readInputStream(InputStream is, String schemaLocation)
          Sets the current document to the parsed InputStream.
 void readString(String XMLString, String schemaLocation)
          Sets the current document to the parsed XML string.
 boolean setNextField()
          Sets current node to next node.
 int setRootNode(String fieldname)
          Sets the Field Node to the first child of the first instance of the field matching the argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLProfileParser

public XMLProfileParser()
Creates a parser instance.

Method Detail

readString

public void readString(String XMLString,
                       String schemaLocation)
                throws Exception
Sets the current document to the parsed XML string.

Parameters:
XMLString - - the XML document.
schemaLocation - - The loactaion of the schema.
Throws:
IndexException - - in case if failure
Exception

readDoc

public void readDoc(String filename,
                    String schemaLocation)
             throws Exception
Sets the current document to the parsed file.

Parameters:
filename - - the name of the file to parse.
schemaLocation - - the location of the schema
Throws:
Exception - - in case of failure.

readInputStream

public void readInputStream(InputStream is,
                            String schemaLocation)
                     throws Exception
Sets the current document to the parsed InputStream.

Parameters:
is - - the input stream to parse.
schemaLocation - - the location of the schema.
Throws:
Exception - - in case of failure.

getFieldText

public String getFieldText(String fieldname)
                    throws Exception
Retreives the #text element of the first instance of fieldname.

Parameters:
fieldname - name of the element to retreive
Returns:
the #text element
Throws:
Exception - - in case of failure.
See Also:
FullTextIndexType

getFieldTextArray

public String[] getFieldTextArray(String fieldname)
                           throws Exception
Retreives the #text elements of all instances of fieldname.

Parameters:
fieldname - name of the element to retreive
Returns:
the #text element
Throws:
Exception - - in case of failure.
See Also:
FullTextIndexType

setRootNode

public int setRootNode(String fieldname)
                throws Exception
Sets the Field Node to the first child of the first instance of the field matching the argument. Following calls to setNextField() and getFieldByValue(String elementName) will give 2nd layerd text.

Returns:
int nr of child elements, #text elements excluded.
Throws:
Exception - - in case of failure.

countDescendants

public int countDescendants(String elementName)
Counts the number of descendant elements with a specified element name

Parameters:
elementName - String - the name of the elements to count
Returns:
int - the number of descendants with the specified elementName

setNextField

public boolean setNextField()
                     throws Exception
Sets current node to next node.

Returns:
true if the node was present
Throws:
Exception - - in case of failure.
See Also:
setRootNode(String fieldname)

goChildElement

public boolean goChildElement(String elementName)
Sets the current node to the first child (of the current node) element with a specified element name

Parameters:
elementName - String - the name of the element to go to
Returns:
boolean - true if the action was successful

goSiblingElement

public boolean goSiblingElement(String elementName)
Sets the current node to the first sibling (of the current node) element with a specified element name

Parameters:
elementName - String - the name of the element to go to
Returns:
boolean - true if the action was successful

goParentElement

public boolean goParentElement(String elementName)
Sets the current node to the first ascendant (of the current node) element with a specified element name

Parameters:
elementName - String - the name of the element to go to
Returns:
boolean - true if the action was successful

hasDescendant

public boolean hasDescendant(String elementName)
Determines whether the current node has one or more descendant elements with a specified element name

Parameters:
elementName - String - the element name to search for
Returns:
boolean - true if one or more descendants were found

hasSibling

public boolean hasSibling(String elementName)
Determines whether the current node has one or more sibling elements with a specified element name

Parameters:
elementName - String - the element name to search for
Returns:
boolean - true if one or more siblings were found

getFieldByValue

public String getFieldByValue(String elementName)
                       throws Exception
Gets the #text element of the specified element in the current field.

Parameters:
elementName - element identifier
Returns:
the #text element
Throws:
Exception - - in case of failure.
See Also:
setRootNode(String fieldname), setNextField()

getSubFields

public String[][] getSubFields()
                        throws Exception
Gets the (element name, #text value) pairs for all child nodes in the current field.

Returns:
string matrix of the elements of the current field
Throws:
Exception - - in case of failure.
See Also:
setNextField(), setRootNode(String fieldname)

escapeForXML

public static String escapeForXML(String text)
Inserts Entity References in the place of certain illegal characters in order to make an xml file valid

Parameters:
text - String - the xml file insert Entity References into
Returns:
String - a version of the xml file with Entity References in the place of certain illegal characters


Copyright © 2012. All Rights Reserved.