suki2.jpg

« Doing Scheduled agents When not on a Domino server | Main| Back to fencing comps - 55 days to go »

Oi, where's me config docs?, Oh bugger i don't have a nsf

QuickImage Category Java notes equivalent

Here we go with another example of what to do when cruelly ripped from the bosom of the notes server

This time its config docs, these as we all know are a happy doddle in notes, we just store them in what ever db (usually the current one) is suitable and pull then back with a view (personally i don't like profile documents as they are a swine to copy around in comparison to normal docs), when faced this same basic need in Java, and not wanting to use a relation database (feels like a bit of an over kill for some things) i went searching and found more wonderful people who have already done the job, this time at
http://commons.apache.org/configuration/

They have a nice little lib that lets you store stuff in xml docs (as well as many other things), here is an example (lets call it config.xml)


<?xml version="1.0" encoding="ISO-8859-1" ?>

<project-definition>
        <example1>
                <textexample>im a example</textexample>
        </example1>

        <example2>
                <intexample>15</intexample>
                <list1>
                        <name>item1,item2,item</name>
                </list1>
        </example2>
</project-definition>


Im going to save this in the root of my Java project, and now on to the code


import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;

public class EasyConfigDocs{
       public static void main(String[] args) {

          try {
                  XMLConfiguration config = new XMLConfiguration("Config.xml");
 
                   String textconfig = config.getString("example1.textexample");
               //Note: to get an indented value you separate with a "."  
                   
                  int numberconfig = config.getInt("example2.intexample");
                  List buttons = config.getList("example2.list1.name");
               //Note: on multivalue items the default separator is a "," if you want to use a "," in a text string you need to either do "\," or change the default delimiter (easy to do, its on the site)
                   
          } catch(ConfigurationException cex)        {
                    System.out.println("config file not found");
          }
       }
}

Nearly as simple as Notes (not that i did any work), it also does all the Edit and Add stuff, but you can get that off the examples at http://commons.apache.org/configuration/ if you need it, i just want to save you the pain on the initial search, Oh!, on that note keep a look out at http://www.benpoole.com hes on the same track as me and has some good blog tutorials for notes developers fighting with pure Java coming up.
Bookmark and Share

Comments

Gravatar Image1 - this time your blod was like the emergency help for me! have never had troubles with config docs, so was unprepared to what has happenned to me. with your help the problem is easily and painlessly (almost) solved:)

Gravatar Image2 - There is some really neat stuff lurking in the apache libraries... You never know when you will find that gem of info that saves you hours of work in Notes or even Java.

Gravatar Image3 - Amen to that, and long may little gems live out there to save us all

Gravatar Image4 - I don't really like the way that they have write that code

Gravatar Image5 - @john really?, i find it a pleasant and easy going way of doing configs, what way do you prefer?

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Avalable for on site contract in

 

Hire Me

Directly:

Curriculum Vitae

As a member of:
ldc_badge.gif

Contact My Grubby Hide

Skype Linkin Main Me Twitter

Paid Advert

o2 ad

Get LDC Tshirts

All profits go to the Children’s Cancer Association (CCA) in the US.