org.ibisph.dao.xml
Class Document

java.lang.Object
  extended by org.ibisph.dao.xml.Document

public class Document
extends java.lang.Object

XML document Helper. Used to load, save, format XML Documents and Elements.

Author:
Garth Braithwaite, STG
See Also:
dom4j API documentation

Field Summary
protected  org.dom4j.io.OutputFormat outputFormat
           
 
Constructor Summary
Document()
           
Document(org.dom4j.io.OutputFormat outputFormat)
           
 
Method Summary
 org.dom4j.Document get(java.io.File xmlFile)
          Creates a new XML document and loads the document with the specified file's contents.
 org.dom4j.Document get(java.lang.String filename)
           
 boolean load(java.io.File xmlFile, org.dom4j.Document document)
          Loads the specified XML file into the document.
 boolean load(java.lang.String filename, org.dom4j.Document document)
          Loads the specified XML file into the document.
 void save(org.dom4j.Document document, java.io.File file)
           
 void save(org.dom4j.Document document, java.io.File file, org.dom4j.io.OutputFormat outputFormat)
           
 void save(org.dom4j.Document document, java.io.OutputStream outputStream, org.dom4j.io.OutputFormat outputFormat)
          Core save method - sends the XML document to the specified output stream.
 void save(org.dom4j.Document document, java.lang.String completePathAndFilename)
           
 void save(org.dom4j.Document document, java.lang.String completePathAndFilename, org.dom4j.io.OutputFormat outputFormat)
           
 void setOutputFormat(org.dom4j.io.OutputFormat outputFormat)
          Sets output format.
 java.lang.String streamToURL(org.dom4j.Document document, java.lang.String urlToSendTo)
          Sends the XML document to the specified URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

outputFormat

protected org.dom4j.io.OutputFormat outputFormat
Constructor Detail

Document

public Document()

Document

public Document(org.dom4j.io.OutputFormat outputFormat)
Method Detail

setOutputFormat

public void setOutputFormat(org.dom4j.io.OutputFormat outputFormat)
Sets output format.

Parameters:
outputFormat - String which contains the output format to be used when saving the document to a text file.
See Also:
dom4j API documentation

get

public org.dom4j.Document get(java.io.File xmlFile)
                       throws org.dom4j.DocumentException
Creates a new XML document and loads the document with the specified file's contents.

Parameters:
xmlFile - Source XML file.
Returns:
XML document or null if file does not exist.
Throws:
org.dom4j.DocumentException - XML parsing/file problems when loading file.

get

public org.dom4j.Document get(java.lang.String filename)
                       throws org.dom4j.DocumentException
Throws:
org.dom4j.DocumentException

load

public boolean load(java.io.File xmlFile,
                    org.dom4j.Document document)
             throws org.dom4j.DocumentException
Loads the specified XML file into the document. Very similar to "get".

Parameters:
xmlFile - Source file to be read and parsed into the document.
document - Destination document
Returns:
true if file was successfully loaded into the document, false if file does not exist.
Throws:
org.dom4j.DocumentException - XML parsing/file problems when loading file.

load

public boolean load(java.lang.String filename,
                    org.dom4j.Document document)
             throws org.dom4j.DocumentException
Loads the specified XML file into the document.

Parameters:
filename - Source filename to be read and parsed into the document.
document - Destination document
Returns:
true if file was successfully loaded into the document, false if file does not exist.
Throws:
org.dom4j.DocumentException - XML parsing/file problems when loading file.

save

public void save(org.dom4j.Document document,
                 java.io.OutputStream outputStream,
                 org.dom4j.io.OutputFormat outputFormat)
          throws java.io.IOException
Core save method - sends the XML document to the specified output stream. If no exceptions were thrown then operation was successful.

Parameters:
document - Source - document to be streamed out.
outputStream - Destination stream where document's contents are to be sent.
outputFormat - Specifies how to format the XML. If null then the pretty printer will be used. If the output format property is specified for this then the encoding specified will be used so that all documents created will use the same encoding.
Throws:
java.io.IOException - Related to file output operations.

save

public void save(org.dom4j.Document document,
                 java.lang.String completePathAndFilename,
                 org.dom4j.io.OutputFormat outputFormat)
          throws java.io.IOException
Throws:
java.io.IOException

save

public void save(org.dom4j.Document document,
                 java.lang.String completePathAndFilename)
          throws java.io.IOException
Throws:
java.io.IOException

save

public void save(org.dom4j.Document document,
                 java.io.File file,
                 org.dom4j.io.OutputFormat outputFormat)
          throws java.io.IOException
Throws:
java.io.IOException

save

public void save(org.dom4j.Document document,
                 java.io.File file)
          throws java.io.IOException
Throws:
java.io.IOException

streamToURL

public java.lang.String streamToURL(org.dom4j.Document document,
                                    java.lang.String urlToSendTo)
                             throws java.io.IOException,
                                    java.net.MalformedURLException
Sends the XML document to the specified URL.

Parameters:
document - Document to be streamed out.
urlToSendTo - Destination URL where the document will be posted.
Returns:
String returned from the HTTP post call.
Throws:
java.io.IOException - Related to stream operations.
java.net.MalformedURLException - URL related issues.