Tutorials to .com

Tutorials to .com » Jsp » Xml » Advanced article master: Jive in the use of analytical Jdom

Advanced article master: Jive in the use of analytical Jdom

Print View , by: iSee ,Total views: 8 ,Word Count: 1008 ,Date: Mon, 20 Apr 2009 Time: 1:35 AM

Well-known Open Source Forum Jive has a lot of things worthy of our analysis and study, by analyzing the use of its Jdom mechanism, we can easily facilitate the reading and writing xml configuration files in order to achieve the following functions:

Settings in the configuration file system attributes languages, different language versions, the system not the same as the text interface, you can define your own country's language, such as the English version of Simplified Chinese version. In this way, the will can be easily extended to a system in various languages, do not directly modify the program, as long as the modified xml configuration file can be.

Settings in the configuration file e-mail the contents of a system usually have a variety of automatic e-mail distribution, such as user registration is successful, there will be an Email sent to his mailbox, the system is installed in different occasions, customers, Email the content of course not the same as , such as A customer using the system, of course, wish to Email in the Name of A customers, which do not have to modify the program to be completed.

The system of optional attributes, a system installed in different occasions, customers, customers have some different requirements, some features are optional, then of course these must be set in the xml configuration file.

XML tree structure used record store is most convenient, especially for those classification system directory, such as Yahoo, in a small classification category, or directly from relational database elements we know are not good at tree data stored in relational databases typical approach is to take two tables: one table for each recorded cell; a table indicating the relationship between before and after; but once we start from the two tree structure table to be in space and time repeatedly balance.

If you are using XML as a data source, it is convenient to solve this problem, if the line with the XML data source by a very convenient, maintenance, and other functions, then we will of course choose to XML, in fact, Jdom readily available on the tool. Jdom DOM SAX is similar to XML, such as analytical methods are only suitable for java language, Jdom is characterized by easy and convenient.

So let us take a look at how Jive is it to achieve the above functions, it is to write all these attributes in a document called jive_config.xml. The XML documents and use of the arrangement is like this:

XML content of the document format:

<! - Root element, all properties must be under this element ->
<fromName> Jive_Administrator </ fromName>
<fromEmail> webmaster@example.com </ fromEmail>
<subject> Your thread was updated! </ subject>
<body> Hello (name)! The thread (threadName) was updated! </ body>
</ email>

Of which:

<jive> </ jive>

Is the root element, all attributes must be in one. Also relatively simple to use, the use of punctuation "." To intervals. For example, we want webmaster@example.com the value of the above, then you can use email.fromEmail. In Jive, the specific statement is JiveGlobals.getJiveProperty ( "email.fromEmail"); this value is very simple to obtain and understand, no matter how deep the XML tree structure, we can easily access.

The key here is a Jdom to resolve the use of XML document type: XMLProperties, which has several major methods of operation:

access (query): getProperty (name);

Add to amend: properties.setProperty (name, value);

Delete: properties.deleteProperty (name);

Several ways this is very similar to the method Hasntable? Hashtable data is stored in memory, and the XML is stored in the file system, no doubt we can use hashtable as easy as the use of XML.

We can XMLProperties intact copy of our system. The only preparation to do is similar to Jive's JiveGlobals, In fact, this is also very simple, in two steps: first remove the XML file load; then provide getProperty (name) and so on. Such as the public class JiveGlobals (
private static final String JIVE_CONFIG_FILENAME = "jive_config.xml";

public static String getJiveProperty (String name) (
loadProperties ();
return properties.getProperty (name);

private synchronized static void loadProperties () (
if (properties == null) (
/ / Create a manager with the full path to the xml config file.
properties = new XMLProperties (jiveHome + File.separator +

Of course, the premise of all these is to http://www.jdom.org Download Jdom package, and added to the Tomcat's common / lib, or in the Add Classpath.

Other supporting documents: DataFormatFilter.java DataUnformatFilter.java XMLFilterBase.java. If you are a Jdom specifically how to use each and can be carefully studied XMLProperties, easy to understand.

Java and XML Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.