|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jdom.contrib.beans.JDOMBean
A light wrapper on the JDOM library that you use to load in a file and turn it into a JDOM Document. It also keeps a cache of already-parsed files, and checks to see if they've changed on disk, and reloads if they have. (I know there's some sort of swap-out or weak-reference stuff either in JDOM or coming soon, so this may be a redundant feature.)
JDOMBean jdom = new JDOMBean(); // or new JDOMBean("com.foo.saxparser") jdom.setFileRoot("/path/to/my/xml/documents/"); Document doc = jdom.getDocument("foo.xml"); Element root = jdom.getRootElement("foo.xml");
<jsp:useBean id="jdom" class="JDOMBean" scope="application"> <% jdom.setFileRoot(application.getRealPath("")); %> </jsp:useBean> or <jsp:useBean id="jdom" class="JDOMBean" scope="application"> <jsp:setProperty name="jdom" property="fileRoot" +value='<%=application.getRealPath("")%>' /> </jsp:useBean> then <% Element root = jdom.getRootElement("foo.xml"); %> Bar: <%=root.getChild("bar").getContent()%>
Constructor Summary | |
JDOMBean()
default constructor, uses "org.apache.xerces.parsers.SAXParser" |
|
JDOMBean(java.lang.String parser)
|
Method Summary | |
org.jdom.Document |
getDocument(java.lang.String filename)
Load a file, parse it with JDOM, return a org.jdom.Document. |
java.lang.String |
getFileRoot()
|
java.lang.String |
getParser()
|
org.jdom.Element |
getRootElement(java.lang.String file)
Convenience method, calls getDocument(filename).getRootElement() |
static void |
main(java.lang.String[] args)
|
void |
setFileRoot(java.lang.String root)
All files are fetched relative to this path |
void |
setParser(java.lang.String parser)
This will create an instance of
for use in the rest of this program. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public JDOMBean()
public JDOMBean(java.lang.String parser)
parser
- String
name of driver class to use.Method Detail |
public void setParser(java.lang.String parser)
This will create an instance of
for use in the rest of this program.
SAXBuilder
parser
- String
name of SAX parser class to use.public java.lang.String getParser()
public void setFileRoot(java.lang.String root)
root
- the path (absolute or relative) to the document rootpublic java.lang.String getFileRoot()
public org.jdom.Document getDocument(java.lang.String filename) throws org.jdom.JDOMException, java.io.IOException
Note that this never unloads a document, so is unsuitable for long-term server-side use for a constantly changing set of files. Todo: use weak references or cache timeouts.
Also does not do secure checking on file requested, so if there's no root, and the parameter starts with a "/", this could conceivably access files you don't want accessed. So be careful out there.
filename
- the file to load, relative to file rootpublic org.jdom.Element getRootElement(java.lang.String file) throws org.jdom.JDOMException, java.io.IOException
public static void main(java.lang.String[] args) throws java.io.IOException, org.jdom.JDOMException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |