|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectde.bb.util.XmlFile
public class XmlFile
Provides the functionality to use and maintain XML files.
This implementation reads the file and keeps all data in memory.
Each tag corresponds to a section, with the complete path to a tag and the tag's name itself as section name.
<foo> <bar attr="value" /> </foo>corresponds to the sections
getString("/foo/bar", "attr", null);
returns "value"
<foo> <bar attr="value" /> <bar attr="other" /> </foo>Since there seems no way to have access to one of the "/foo/bar" tags, an autonumbering method is used, which adds an unqiue number to all duplicate tags. Better than guessing the assigned numbers, is to use the
getSections() method
which returns a Vector with all valid paths:
getSections("/foo/bar") will return something like
/foo/bar#000000/ /foo/bar#000001/Using that paths enables the direct access again.
<foo> <bar name="joe" attr="value" /> <bar name="carl" attr="other" /> </foo>To access a named tag directly just use a special encoding:
getString("/foo/\\bar\\carl", "attr", null);
returns "other".
| Constructor Summary | |
|---|---|
XmlFile()
construct an XmlFile object without an file. |
|
XmlFile(java.lang.String fileName)
Deprecated. use XmlFile() and readFile() |
|
| Method Summary | |
|---|---|
void |
addComment(java.lang.String section,
java.lang.String comment)
Set the specified content element of the section as String. |
void |
clear()
Remove all content from this instance. |
void |
clearSection(java.lang.String section)
Clear all content and children from this section. |
java.lang.String |
createSection(java.lang.String section)
Creates always a new section and returns its unique path. |
void |
dropSection(java.lang.String section)
Drop the section and remov all content and children from this section. |
void |
flush()
Write all internal data to the file. |
java.util.Map |
getAttributes(java.lang.String section)
Return a map with all attributes: name->value. |
java.lang.String |
getContent(java.lang.String section)
Get the specified content element of the section as String. |
byte[] |
getContentBytes(java.lang.String section)
Get the complete content of the section as byte array. |
java.util.Vector |
getKeys(java.lang.String section)
get all attribute names (keys) for a section in the given XML file. |
java.util.Vector |
getSections(java.lang.String path)
Get all sections for the given XML file, matching the path String. |
java.lang.String |
getString(java.lang.String section,
java.lang.String attribute,
java.lang.String def)
get a value for an attribute in the section for the given XML file. |
void |
read(java.io.InputStream is)
Read and parse the specified intput stream. |
void |
readFile(java.lang.String fileName)
read the specified xml file. |
java.util.Iterator |
sections(java.lang.String sectionName)
Get an Iterator for the child sections. |
void |
setContent(java.lang.String section,
java.lang.String content)
add a comment to the section as String. |
void |
setFile(java.lang.String fileName)
set a new file name. |
void |
setString(java.lang.String section,
java.lang.String attribute,
java.lang.String value)
Set a value for an attribute in the section for the given XML file. |
void |
sort(java.lang.String section,
java.lang.String order)
Sort the entries by the specified order. |
java.lang.String |
toString()
Displays the full XML content. |
void |
write(java.io.OutputStream os)
Write the current XML file to given OutputStream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public XmlFile(java.lang.String fileName)
fileName - name of the used XML filepublic XmlFile()
| Method Detail |
|---|
public void readFile(java.lang.String fileName)
fileName - the file namepublic void setFile(java.lang.String fileName)
fileName - the new file namepublic void clear()
public void read(java.io.InputStream is)
is - n input stream.public void flush()
public void write(java.io.OutputStream os)
throws java.io.IOException
os - the OutputStream
java.io.IOException - on errorpublic java.util.Vector getSections(java.lang.String path)
path - the match String
public java.util.Vector getKeys(java.lang.String section)
section - the name of the section *
public java.util.Map getAttributes(java.lang.String section)
section - the name of the section.
public java.lang.String getString(java.lang.String section,
java.lang.String attribute,
java.lang.String def)
section - the name of the sectionattribute - the name of the attributedef - a default value, if the attribute was not found
setString(java.lang.String, java.lang.String, java.lang.String)
public void setString(java.lang.String section,
java.lang.String attribute,
java.lang.String value)
section - the name of the sectionattribute - the name of the attributevalue - the new key valuegetString(java.lang.String, java.lang.String, java.lang.String)public void clearSection(java.lang.String section)
section - a path to a XML tagpublic void dropSection(java.lang.String section)
section - a path to a XML tagpublic byte[] getContentBytes(java.lang.String section)
section - the name of a section.
public java.lang.String getContent(java.lang.String section)
<sometag attr1="a" ...>CONTENT</sometag>
section - the name of a section.
setContent(java.lang.String, java.lang.String)
public void addComment(java.lang.String section,
java.lang.String comment)
section - the name of a section.comment - the new content.
public void setContent(java.lang.String section,
java.lang.String content)
section - the name of a section.content - the new content.getContent(java.lang.String)public java.lang.String createSection(java.lang.String section)
section - the section to be created
public void sort(java.lang.String section,
java.lang.String order)
section - the name of the section = a path to the xml tag.order - the ordered child tag names which is applied to the existing children.public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()public java.util.Iterator sections(java.lang.String sectionName)
sectionName - the section name is an XML path like "/foo/bar"
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||