de.folt.models.documentmodel.document
Class XmlDocument

java.lang.Object
  extended by java.util.Observable
      extended by de.folt.models.documentmodel.document.XmlDocument
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DataSourceConfigurations, TbxDocument, TmxDocument, XliffDocument

public class XmlDocument
extends java.util.Observable
implements java.io.Serializable

This class XmlDocument defines the methods for reading and writing an XML Documents specific for the FOLT/OpenTMS needs.

Author:
klemens
See Also:
Serialized Form

Constructor Summary
XmlDocument()
          Constructor does nothing.
XmlDocument(java.io.File file)
           
XmlDocument(java.lang.String fileName)
           
 
Method Summary
static boolean bIsXmlDocument(java.lang.String fileName)
          bIsXmlDocument check if a document is an xml document - look for
 boolean bIsXmLFile(java.lang.String fileName)
          bIsXmLFile simple check if a file is an xml file - just check if we find at the start "
 org.jdom.Element buildElement(java.lang.String elementString)
          buildElement creates an Element from a string representation of the element.
 boolean createDocument(java.lang.String xmlDocumentName)
          createDocument creates an xml document; must be overridden by subclass
 java.lang.String elementContentToString(org.jdom.Element element)
           
 java.lang.String elementContentToString(org.jdom.Element element, boolean bDoNotKeepElements)
          elementContentToString returns a pure string version of the content of the element.
 java.lang.String elementToString(org.jdom.Element element)
          elementToString creates a pure string version of the element (including the tag name etc.)
 java.lang.String getCatalogueDirectory()
           
 org.jdom.Document getDocument()
           
 org.jdom.Namespace getNamespace()
           
 java.util.List<org.jdom.Namespace> getNamespacelist()
           
 org.jdom.Element getRoot()
          getRoot get the root element of the XmlDocument
 java.lang.String getRootElementName()
          getRootElementName gets the name of the root element of the loaded document
static java.lang.String getRootElementName(java.lang.String fileName)
          getRootElementName gets the name of the root element of an xml file
 org.jdom.Element getsubElementFromElementAttributeNameValue(org.jdom.Element element, java.lang.String subElementName, java.lang.String attributeName, java.lang.String attributeValue)
          getsubElementFromElementAttributeNameValue get the (sub) element with string name subElementName of an element where the subelement has an attribute with name attributeName and an attribute value of attributeValue
Example:
<prop-group name="MULTI-624649fa-7e65-42ee-928d-aa2b10b12f27"><prop prop-value="creationid">1233c020bc55054_klemens</prop><prop prop-value="usagecount">0</prop><prop prop-value="entrynumber">21477</prop><prop prop-value="datatype">125447</prop><prop prop-value="changeid">1233c020bc55054_klemens</prop></prop-group>
getsubElementFromElementAttributeNameValue(prop-group, "prop", "prop-value", "creation-id") will return
<prop prop-value="creationid">1233c020bc55054_klemens</prop>
 org.jdom.Element getsubElementFromElementAttributeNameValueRegExp(org.jdom.Element element, java.lang.String subElementName, java.lang.String attributeName, java.lang.String attributeValue)
          getsubElementFromElementAttributeNameValueRegExp get the (sub) element with string name subElementName of an element where the subelement has an attribute with name attributeName and an attribute value of attributeValue which is a regular expression
Example:
<prop-group name="MULTI-624649fa-7e65-42ee-928d-aa2b10b12f27"><prop prop-value="creationid">1233c020bc55054_klemens</prop><prop prop-value="usagecount">0</prop><prop prop-value="entrynumber">21477</prop><prop prop-value="datatype">125447</prop><prop prop-value="changeid">1233c020bc55054_klemens</prop></prop-group>
getsubElementFromElementAttributeNameValue(prop-group, "prop", "prop-value", "$creation.*") will return
<prop prop-value="creationid">1233c020bc55054_klemens</prop>
 java.lang.String getXmlDocumentName()
           
 org.jdom.output.XMLOutputter getXmlOutputter()
           
 java.net.URL getXmlURL()
           
 boolean isBExpandExternalEntities()
           
 boolean isValidElement(java.lang.String elementString)
           
 org.jdom.Document loadXmlFile(java.io.File newFile)
          loadXmlFile loads an XML file
 org.jdom.Document loadXmlFile(java.lang.String filename)
          loadXmlFile loads an XML file as a document
static void main(java.lang.String[] args)
          main - test xml document just supply a xml document
 java.lang.String quoteXMLString(java.lang.String string)
          quoteXMLString convert character & < and > to their entity equivalent string = string.replaceAll("<", "<"); string = string.replaceAll(">", ">"); string = string.replaceAll("&", "&");
 boolean saveToXmlFile()
          saveToXmlFile saves the currently loaded document back to the original filename
 boolean saveToXmlFile(java.io.File outFile)
          saveToXmlFile
 boolean saveToXmlFile(java.lang.String filename)
          saveToXmlFile writes the document to the given file name
 void setBExpandExternalEntities(boolean bExpandExternalEntities)
           
 void setCatalogueDirectory(java.lang.String catalogueDirectory)
           
 void setDocument(org.jdom.Document document)
           
 void setNamespace(org.jdom.Namespace namespace)
           
 void setNamespacelist(java.util.List<org.jdom.Namespace> namespacelist)
           
 void setXmlDocumentName(java.lang.String xmlDocumentName)
          Method stores the name of the associated XML document; in addition it creates an URL from the file name and stores in xmLURL.
 void setXmlURL(java.net.URL xmlURL)
           
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlDocument

public XmlDocument()
Constructor does nothing.


XmlDocument

public XmlDocument(java.io.File file)
Parameters:
file - create an xml document and load an xml file stream

XmlDocument

public XmlDocument(java.lang.String fileName)
Parameters:
fileName - create an xml document and load an xml file
Method Detail

bIsXmlDocument

public static boolean bIsXmlDocument(java.lang.String fileName)
bIsXmlDocument check if a document is an xml document - look for

Parameters:
fileName - the file to check
Returns:
true if xml document false otherwise

getRootElementName

public static java.lang.String getRootElementName(java.lang.String fileName)
getRootElementName gets the name of the root element of an xml file

Parameters:
fileName - the xml file to check
Returns:
the name of the root element

main

public static void main(java.lang.String[] args)
main - test xml document just supply a xml document

Parameters:
args - 0: xml document file

bIsXmLFile

public boolean bIsXmLFile(java.lang.String fileName)
bIsXmLFile simple check if a file is an xml file - just check if we find at the start "
Parameters:
fileName - file to check
Returns:
true for an xml file otherwise false

buildElement

public org.jdom.Element buildElement(java.lang.String elementString)
                              throws OpenTMSException
buildElement creates an Element from a string representation of the element. The new element is created by using a StringReader as InputSource for parsing the string. Please note that the method creates from <element>...</element> real elements (Element type); it does not convert <element> to "<element>" to "&lt;element&gt;".

Parameters:
elementString - the string from which an element should be created.
Returns:
the element generated from the string
Throws:
OpenTMSException

createDocument

public boolean createDocument(java.lang.String xmlDocumentName)
createDocument creates an xml document; must be overridden by subclass

Parameters:
xmlDocumentName - the document to create
Returns:
true in case of success, otherwise false

elementContentToString

public java.lang.String elementContentToString(org.jdom.Element element)
Parameters:
element -
Returns:

elementContentToString

public java.lang.String elementContentToString(org.jdom.Element element,
                                               boolean bDoNotKeepElements)
elementContentToString returns a pure string version of the content of the element. Only the first opening and last closing tag of the element is removed! String str = this.elementToString(element); String elementname = element.getName(); str = str.replaceFirst("^<" + elementname + ".*?>", ""); str = str.replaceAll("$", ""); Example:
  TU string a (0) = "<seg><ph><img class="face" src="../img/face/klemens_waldhoer.jpg" alt="</ph>Dr. Klemens Waldhör<ph>" /></ph></seg>"
  TU string b (0) = "<ph><img class="face" src="../img/face/klemens_waldhoer.jpg" alt="</ph>Dr. Klemens Waldhör<ph>" /></ph>"
 

Parameters:
element - the element to create a string for the content
Returns:
the string representation of the element content (meaning just the xml element as it is>

elementToString

public java.lang.String elementToString(org.jdom.Element element)
elementToString creates a pure string version of the element (including the tag name etc.) Example:
  "<seg><ph><img class="face" src="../img/face/klemens_waldhoer.jpg" alt="</ph>Dr. Klemens Waldhör<ph>" /></ph></seg>"
 

Parameters:
element - the element to create a string from
Returns:
the string representation of the element (meaning just the xml element as it is>

getCatalogueDirectory

public java.lang.String getCatalogueDirectory()
Returns:
the catalogueDirectors

getDocument

public org.jdom.Document getDocument()
Returns:
the document

getNamespace

public org.jdom.Namespace getNamespace()
Returns:
the namespace

getNamespacelist

public java.util.List<org.jdom.Namespace> getNamespacelist()
Returns:
the namespacelist

getRoot

public org.jdom.Element getRoot()
getRoot get the root element of the XmlDocument

Returns:
the root element

getRootElementName

public java.lang.String getRootElementName()
getRootElementName gets the name of the root element of the loaded document

Returns:
the name of the root element

getsubElementFromElementAttributeNameValue

public org.jdom.Element getsubElementFromElementAttributeNameValue(org.jdom.Element element,
                                                                   java.lang.String subElementName,
                                                                   java.lang.String attributeName,
                                                                   java.lang.String attributeValue)
getsubElementFromElementAttributeNameValue get the (sub) element with string name subElementName of an element where the subelement has an attribute with name attributeName and an attribute value of attributeValue
Example:
 <prop-group name="MULTI-624649fa-7e65-42ee-928d-aa2b10b12f27"><prop prop-value="creationid">1233c020bc55054_klemens</prop><prop prop-value="usagecount">0</prop><prop prop-value="entrynumber">21477</prop><prop prop-value="datatype">125447</prop><prop prop-value="changeid">1233c020bc55054_klemens</prop></prop-group>
getsubElementFromElementAttributeNameValue(prop-group, "prop", "prop-value", "creation-id") will return
<prop prop-value="creationid">1233c020bc55054_klemens</prop>

Parameters:
element - the element which is the super element ("surrounds subElementName")
subElementName - the string name of the sub element
attributeName - the searched attribute name of the sub element
attributeValue - the searched attribute value of the searched attribute name of the sub element
Returns:
null if not found, otherwise the sub element

getsubElementFromElementAttributeNameValueRegExp

public org.jdom.Element getsubElementFromElementAttributeNameValueRegExp(org.jdom.Element element,
                                                                         java.lang.String subElementName,
                                                                         java.lang.String attributeName,
                                                                         java.lang.String attributeValue)
getsubElementFromElementAttributeNameValueRegExp get the (sub) element with string name subElementName of an element where the subelement has an attribute with name attributeName and an attribute value of attributeValue which is a regular expression
Example:
 <prop-group name="MULTI-624649fa-7e65-42ee-928d-aa2b10b12f27"><prop prop-value="creationid">1233c020bc55054_klemens</prop><prop prop-value="usagecount">0</prop><prop prop-value="entrynumber">21477</prop><prop prop-value="datatype">125447</prop><prop prop-value="changeid">1233c020bc55054_klemens</prop></prop-group>
getsubElementFromElementAttributeNameValue(prop-group, "prop", "prop-value", "$creation.*") will return
<prop prop-value="creationid">1233c020bc55054_klemens</prop>

Parameters:
element - the element which is the super element ("surrounds subElementName")
subElementName - the string name of the sub element
attributeName - the searched attribute name of the sub element
attributeValue - the searched attribute value of the searched attribute name of the sub element; the search is based on a regular expression for the attributeValue
Returns:
null if not found, otherwise the sub element

getXmlDocumentName

public java.lang.String getXmlDocumentName()
Returns:
the xmlDocumentName

getXmlOutputter

public org.jdom.output.XMLOutputter getXmlOutputter()
Returns:
the xmlOutputter

getXmlURL

public java.net.URL getXmlURL()
Returns:
the xmlURL

isBExpandExternalEntities

public boolean isBExpandExternalEntities()
Returns:
the bExpandExternalEntities

isValidElement

public boolean isValidElement(java.lang.String elementString)
Parameters:
elementString -
Returns:

loadXmlFile

public org.jdom.Document loadXmlFile(java.io.File newFile)
loadXmlFile loads an XML file

Parameters:
newFile - the File of the XML File
Returns:
the document loaded / null if file does not exist or is not an xml file

loadXmlFile

public org.jdom.Document loadXmlFile(java.lang.String filename)
loadXmlFile loads an XML file as a document

Parameters:
filename - the file name of the XML file
Returns:
the Document loaded

quoteXMLString

public java.lang.String quoteXMLString(java.lang.String string)
quoteXMLString convert character & < and > to their entity equivalent
 string = string.replaceAll("<", "<");
 string = string.replaceAll(">", ">");
 string = string.replaceAll("&", "&");
 

Parameters:
string - the string to quote
Returns:
the quoted string

saveToXmlFile

public boolean saveToXmlFile()
saveToXmlFile saves the currently loaded document back to the original filename

Returns:
true in case of success / false otherwise

saveToXmlFile

public boolean saveToXmlFile(java.io.File outFile)
saveToXmlFile

Parameters:
outFile - the File handle for the xml output
Returns:
true in case of success / false otherwise

saveToXmlFile

public boolean saveToXmlFile(java.lang.String filename)
saveToXmlFile writes the document to the given file name

Parameters:
filename - the file anme for the output xml file
Returns:
true in case of success / false otherwise

setBExpandExternalEntities

public void setBExpandExternalEntities(boolean bExpandExternalEntities)
Parameters:
bExpandExternalEntities - the bExpandExternalEntities to set

setCatalogueDirectory

public void setCatalogueDirectory(java.lang.String catalogueDirectory)
Parameters:
catalogueDirectors - the catalogueDirectors to set

setDocument

public void setDocument(org.jdom.Document document)
Parameters:
document - the document to set

setNamespace

public void setNamespace(org.jdom.Namespace namespace)
Parameters:
namespace - the namespace to set

setNamespacelist

public void setNamespacelist(java.util.List<org.jdom.Namespace> namespacelist)
Parameters:
namespacelist - the namespacelist to set

setXmlDocumentName

public void setXmlDocumentName(java.lang.String xmlDocumentName)
Method stores the name of the associated XML document; in addition it creates an URL from the file name and stores in xmLURL.

Parameters:
xmlDocumentName - the xmlDocumentName to set;

setXmlURL

public void setXmlURL(java.net.URL xmlURL)
Parameters:
xmlURL - the xmlURL to set