org.jtheque.core.utils.file
Class XMLReader

java.lang.Object
  extended by org.jtheque.core.utils.file.XMLReader
All Implemented Interfaces:
java.io.Closeable

public final class XMLReader
extends java.lang.Object
implements java.io.Closeable

A reader for XML files.

Author:
Baptiste Wicht

Constructor Summary
XMLReader()
           
 
Method Summary
 void close()
           
 org.jdom.Element getNode(java.lang.String path, java.lang.Object node)
          Return the unique node corresponding to the XPath request on the specified node.
 java.util.List<org.jdom.Element> getNodes(java.lang.String path, java.lang.Object node)
          Return all the nodes corresponding to the XPath request on the specified node.
 org.jdom.Element getRootElement()
          Return the root element of the reader.
 void openFile(java.io.File file)
          Open the file.
 void openFile(java.lang.String strFile)
          Open the file.
 void openURL(java.lang.String strUrl)
          Open the file a the URL.
 void openURL(java.net.URL url)
          Open the file a the URL.
 boolean readBoolean(java.lang.String path, java.lang.Object node)
          Read a boolean value from the node.
 double readDouble(java.lang.String path, java.lang.Object node)
          Read a double value from the node.
 int readInt(java.lang.String path, java.lang.Object node)
          Read a int value from the node.
 long readLong(java.lang.String path, java.lang.Object node)
          Read a long value from the node.
 java.lang.String readString(java.lang.String path, java.lang.Object node)
          Read a String value from the node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLReader

public XMLReader()
Method Detail

openURL

public void openURL(java.lang.String strUrl)
             throws XMLException
Open the file a the URL.

Parameters:
strUrl - The URL of the XML file.
Throws:
XMLException - If an error occurs during the open process.

openURL

public void openURL(java.net.URL url)
             throws XMLException
Open the file a the URL.

Parameters:
url - The URL of the XML file.
Throws:
XMLException - If an error occurs during the open process.

openFile

public void openFile(java.lang.String strFile)
              throws XMLException
Open the file.

Parameters:
strFile - The path to the file to open.
Throws:
XMLException - If an error occurs during the open process.

openFile

public void openFile(java.io.File file)
              throws XMLException
Open the file.

Parameters:
file - The file to open.
Throws:
XMLException - If an error occurs during the open process.

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException

getRootElement

public org.jdom.Element getRootElement()
Return the root element of the reader.

Returns:
the root element else null if the reader is not open.

getNodes

public java.util.List<org.jdom.Element> getNodes(java.lang.String path,
                                                 java.lang.Object node)
                                          throws XMLException
Return all the nodes corresponding to the XPath request on the specified node.

Parameters:
path - The XPath request.
node - The node to request in.
Returns:
A List containing all elements corresponding to the request.
Throws:
XMLException - If an errors occurs during the reading process.

getNode

public org.jdom.Element getNode(java.lang.String path,
                                java.lang.Object node)
                         throws XMLException
Return the unique node corresponding to the XPath request on the specified node.

Parameters:
path - The XPath request.
node - The node to request in.
Returns:
The unique node corresponding to the request else null if there is no node coresponding to the request.
Throws:
XMLException - If an errors occurs during the reading process.

readString

public java.lang.String readString(java.lang.String path,
                                   java.lang.Object node)
                            throws XMLException
Read a String value from the node.

Parameters:
path - The XPath request.
node - The node.
Returns:
The string value of the request.
Throws:
XMLException - If an errors occurs during the reading process.

readInt

public int readInt(java.lang.String path,
                   java.lang.Object node)
            throws XMLException
Read a int value from the node.

Parameters:
path - The XPath request.
node - The node.
Returns:
The int value of the request.
Throws:
XMLException - If an errors occurs during the reading process.

readDouble

public double readDouble(java.lang.String path,
                         java.lang.Object node)
                  throws XMLException
Read a double value from the node.

Parameters:
path - The XPath request.
node - The node.
Returns:
The double value of the request.
Throws:
XMLException - If an errors occurs during the reading process.

readBoolean

public boolean readBoolean(java.lang.String path,
                           java.lang.Object node)
                    throws XMLException
Read a boolean value from the node.

Parameters:
path - The XPath request.
node - The node.
Returns:
The boolean value of the request.
Throws:
XMLException - If an errors occurs during the reading process.

readLong

public long readLong(java.lang.String path,
                     java.lang.Object node)
              throws XMLException
Read a long value from the node.

Parameters:
path - The XPath request.
node - The node.
Returns:
The double value of the request.
Throws:
XMLException - If an errors occurs during the reading process.


Copyright © 2009 JTheque. All Rights Reserved.