Tutorial :Converting an configuration file to HTML


I have a bunch of configuration files which are usually properties files which are opened from application and edited like notepad.Now the requirement is pick each property and find which HTML tag does it fit through and display the whole properties file as HTML page. For eg:

Security.Properties file

//This property checks if the user has already logged or not  //Possible values Y N    order.security.Login=Y  

So the above property has two possible values Y N .The equivalent HTML format can be a radio button with Y N. Similarly if another property takes values 1,2, the HTML is Listbox with these two values.

I know this is little cumbersome but has to done. Development is JAVA JAVASCRIPT VELOCITY My idea is convert all properties files into XML then use XSLT to render as HTML. I would like to hear more ideas including performance issues.


I would define a XML file that lists every properties key, and for each, the way it will displayed in HTML.

<property key="order.security.Login">      <display type="radio" values="Y,N" />  </property>  

then if you want to display a Properties as an HTML file, just parse this XML file with XSLT, using the property key to match the right element and display well its content (with a XSL file that convert a <display type="radio"> into a list of <input type="radio">)

Dunno if it will fit to your app configuration, but that'll be my first idea to fit.


Like you said, XSLT seems like the way to go.


How about a small javadoc/c#doc:

//<desc>This property checks if the user has already logged or not  //Possible values Y N</desc>  //<type>YN</type>  order.security.Login=Y  


If you have 1200 files (wow) then I can't see any other way but to automate it.

If you can work out the possible values from the properties that are filled in then you could use a different solution.

So there can't be many values If the current value is Y then the only possible answer is N same with true or false If the value is a string other then you allow a string input.

You say you use Velocity so you model has access to full Java. Read your properties file into a Properties object from which you can get an Enumeration of all the keys. for all the values in the properties file build up your html using your velocity templates Velocity.

Map<String, YourHolderObject> velocityPropertiesValues =       new HashMap<>(String, YourHolderObject);    Properties properties = new Properties("your properties file")  Enumeration keys = properties .keys();    while (keys.hasMoreElements()) {    String key = (String)keys.nextElement();    String value = (String)p.get(key);  //.......get YourHolderObject which can will have methods like isBoolean,   // if it is then in velocity create radio buttons etc  }      //then in velocity use that enriched object to decide what html to generate   #foreach ($key in $properties.keySet())   #if($refreshed.get($key).isBoolean)     //generate the radio buttons   #elseif($refreshed.get($key).isYesNoList)      //do something else   #  

Next Post »