|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjmri.jmrit.XmlFile
public abstract class XmlFile
Handle common aspects of XML files.
JMRI needs to be able to operate offline, so it needs to store DTDs locally. At the same time, we want XML files to be transportable, and to have their DTDs accessible via the web (for browser rendering). Further, our code assumes that default values for attributes will be provided, and it's necessary to read the DTD for that to work.
We implement this using our own EntityResolvor, the
JmriLocalEntityResolver class.
| Field Summary | |
|---|---|
static String |
dtdLocation
Specify a standard prefix for DTDs in new XML documents |
static String |
xsltLocation
Define root part of URL for XSLT style page processing instructions. |
| Constructor Summary | |
|---|---|
XmlFile()
|
|
| Method Summary | |
|---|---|
static void |
addDefaultInfo(org.jdom.Element root)
Add default information to the XML before writing it out. |
String |
backupFileName(String name)
Return the name of a new, unique backup file. |
protected boolean |
checkFile(String name)
Check if a file of the given name exists. |
static void |
dumpElement(org.jdom.Element name)
Diagnostic printout of as much as we can find |
static void |
ensurePrefsPresent(String name)
Ensure that a subdirectory is present; if not, create it. |
protected File |
findFile(String name)
Return a File object for a name. |
protected org.jdom.Element |
getRootViaURI(boolean verify,
InputStream stream)
Find the DTD via a URI and get the root element. |
void |
makeBackupFile(String name)
Move original file to a backup. |
static org.jdom.Document |
newDocument(org.jdom.Element root,
String dtd)
Create the Document object to store a particular root Element. |
static String |
prefsDir()
Define the location of the preferences directory. |
protected void |
reportError1(File file,
Exception e)
|
protected void |
reportError2(File file,
Exception e)
|
void |
revertBackupFile(String name)
Revert to original file from backup. |
org.jdom.Element |
rootFromFile(File file)
Read a File as XML, and return the root object. |
org.jdom.Element |
rootFromName(String name)
Read the contents of an XML file from its filename. |
static JFileChooser |
userFileChooser()
|
static JFileChooser |
userFileChooser(String filter)
|
static JFileChooser |
userFileChooser(String filter,
String suffix1)
|
static JFileChooser |
userFileChooser(String filter,
String suffix1,
String suffix2)
Provide a JFileChooser initialized to the default user location, and with a default filter. |
static String |
userFileLocationDefault()
Provide default initial location for JFileChoosers to user files |
void |
writeXML(File file,
org.jdom.Document doc)
Write a File as XML. |
static String |
xmlDir()
Define the location of XML files within the distribution directory. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String xsltLocation
See the XSLT versioning discussion
public static final String dtdLocation
| Constructor Detail |
|---|
public XmlFile()
| Method Detail |
|---|
public org.jdom.Element rootFromName(String name)
throws org.jdom.JDOMException,
IOException
findFile(java.lang.String)
routine.
name - Filename, as needed by findFile(java.lang.String)
org.jdom.JDOMException
FileNotFoundException
IOException
public org.jdom.Element rootFromFile(File file)
throws org.jdom.JDOMException,
IOException
file - File to be parsed. A FileNotFoundException is thrown if it doesn't exist.
org.jdom.JDOMException - only when all methods have failed
FileNotFoundException
IOException
protected void reportError1(File file,
Exception e)
protected void reportError2(File file,
Exception e)
protected org.jdom.Element getRootViaURI(boolean verify,
InputStream stream)
throws org.jdom.JDOMException,
IOException
org.jdom.JDOMException
IOException
public void writeXML(File file,
org.jdom.Document doc)
throws org.jdom.JDOMException,
IOException,
FileNotFoundException
file - File to be created.doc - Document to be written out. This should never be null.
org.jdom.JDOMException
FileNotFoundException
IOExceptionprotected boolean checkFile(String name)
findFile(java.lang.String)
name - file name, either absolute or relative
protected File findFile(String name)
prefsDir()
xmlDir()
name - Filename perhaps containing
subdirectory information (e.g. "decoders/Mine.xml")
public static void dumpElement(org.jdom.Element name)
name - Element to print, should not be nullpublic void makeBackupFile(String name)
name - Last part of file pathname i.e. subdir/name, without the
pathname for either the xml or preferences directory.public void revertBackupFile(String name)
name - Last part of file pathname i.e. subdir/name, without the
pathname for either the xml or preferences directory.public String backupFileName(String name)
name - Filename without preference path information, e.g.
"decoders/Mine.xml".
public static void ensurePrefsPresent(String name)
name - Complete pathname of directory to be checked/created.
public static org.jdom.Document newDocument(org.jdom.Element root,
String dtd)
root - Root element of the final documentdtd - name of an external DTD
public static void addDefaultInfo(org.jdom.Element root)
Currently, this is identification information as an XML comment. This includes:
It may be necessary to extend this to check whether the info is already present, e.g. if re-writing a file.
root - The root element of the document that will be written.public static String xmlDir()
Because the programs runtime working directory is also the distribution directory, we just use a relative file name.
public static String prefsDir()
public static String userFileLocationDefault()
public static JFileChooser userFileChooser(String filter,
String suffix1,
String suffix2)
filter - Title for the filter, may not be nullsuffix1 - An allowed suffix, or nullsuffix2 - A second allowed suffix, or null. If both arguments are
null, no specific filtering is done.public static JFileChooser userFileChooser()
public static JFileChooser userFileChooser(String filter)
public static JFileChooser userFileChooser(String filter,
String suffix1)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||