|
||||||||||
| 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(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. |
String |
createFileNameWithDate(String name)
|
static void |
dumpElement(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. |
static SAXBuilder |
getBuilder(boolean verify)
|
protected Element |
getRootViaURI(boolean verify,
InputStream stream)
Find the DTD via a URI and get the root element. |
static boolean |
getVerify()
|
void |
makeBackupFile(String name)
Move original file to a backup. |
boolean |
makeBackupFile(String directory,
File file)
Move original file to backup directory. |
static Document |
newDocument(Element root)
Create the Document object to store a particular root Element, without a DocType DTD (e.g. for using a schema) |
static Document |
newDocument(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(String name,
Exception e)
|
protected void |
reportError2(String name,
Exception e)
|
static String |
resourcesDir()
|
void |
revertBackupFile(String name)
Revert to original file from backup. |
Element |
rootFromFile(File file)
Read a File as XML, and return the root object. |
Element |
rootFromName(String name)
Read the contents of an XML file from its filename. |
Element |
rootFromURL(URL url)
Read a URL as XML, and return the root object. |
static String |
scriptsDir()
|
static void |
setScriptsFileLocationDefault(String scriptDir)
Provide default initial location for JFileChoosers to user files |
static void |
setUserFileLocationDefault(String userDir)
|
static void |
setVerify(boolean v)
|
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,
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.
Things that have been tried here:
public static final String dtdLocation
| Constructor Detail |
|---|
public XmlFile()
| Method Detail |
|---|
public Element rootFromName(String name)
throws JDOMException,
IOException
findFile(java.lang.String)
routine.
name - Filename, as needed by findFile(java.lang.String)
JDOMException
FileNotFoundException
IOException
public Element rootFromFile(File file)
throws JDOMException,
IOException
file - File to be parsed. A FileNotFoundException is thrown if it doesn't exist.
JDOMException - only when all methods have failed
FileNotFoundException
IOException
public Element rootFromURL(URL url)
throws JDOMException,
IOException
url - URL locating the data file
JDOMException - only when all methods have failed
FileNotFoundException
IOException
protected void reportError1(String name,
Exception e)
protected void reportError2(String name,
Exception e)
protected Element getRootViaURI(boolean verify,
InputStream stream)
throws JDOMException,
IOException
JDOMException
IOException
public void writeXML(File file,
Document doc)
throws IOException,
FileNotFoundException
file - File to be created.doc - Document to be written out. This should never be null.
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(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 boolean makeBackupFile(String directory,
File file)
directory - the backup directory to use.file - the file to be backed up. The file name will have
the current date embedded in the backup name.
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 String createFileNameWithDate(String name)
public static void ensurePrefsPresent(String name)
name - Complete pathname of directory to be checked/created.
public static Document newDocument(Element root,
String dtd)
root - Root element of the final documentdtd - name of an external DTD
public static Document newDocument(Element root)
root - Root element of the final document
public static void addDefaultInfo(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 void setUserFileLocationDefault(String userDir)
public static String prefsDir()
public static String resourcesDir()
public static boolean getVerify()
public static void setVerify(boolean v)
public static String userFileLocationDefault()
public static String scriptsDir()
public static void setScriptsFileLocationDefault(String scriptDir)
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)
public static SAXBuilder getBuilder(boolean verify)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||