Wednesday, April 24, 2013

How to define a property file in spring context and how to retrieve data from the property file

It is always a good practise to use property file to store configuration data kind of things.First we have to define it in the spring context  as below.lets take our property file as test.properties.
 
<bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath : test.properties"/>
</bean>
 
 As we are going to use java.util.Properties we have to define PropertiesFactoryBean as a bean in our context file as below.
 
<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="location" value="classpath : test.properties"/>
 </bean>
 
Also we will use @Autowired annotation when retrieving data.So lets define the below in our context file as well.

 
<context:annotation-config />  Now we have completed the spring context side changes.Lets see how to reach data.  public class Test{

@Autowired
private Properties properties;

private void test(){

String value=properties.getProperty("key");

}




Hope this helps .


 



 

 

 


Thursday, May 19, 2011

How to add a attribute of XML as a html element attribute using XSLT

Once you work with XSLT you may come across a situation where you need to directly apply a value of a XML attribute as the value of a HTML attribute.There are two options to figure the things out.

myXML.xml










Target html










In the above case the value of the attribute boxSize is directly applied as the value of the attribute size of input element in HTML format.This can be achieved as below two methods.

method 1











method 2




As you see method 2 is more easy and it is the simple way to get the job done.Thank you.Hope this helps.

Wednesday, May 11, 2011

How to choose a XML parser

There are many XML parsers out there.So here I am going to give some pros and cons of those.SAX,StAX,DOM,JAXB are the XML parsers that I took into consideration.

Parsing Mechanism

Features

JAXB

High memory usage

DOM

High memory usage

StAX

XML schema can not be validated.
Low memory usage

SAX

XML schema can be validated
Low memory usage

Hope this will give you some hints about what to choose.Thank you.

Wednesday, February 9, 2011

Contributing to a open source project with SVN

SVN

SVN is referred as subversion.Now I am going to tell you how you can use this SVN for your contributions to an open source project in simple ways.I assumed you use unix platform as your working environment.

Checking out a project.

For contributing an open source project you need to have the code base of the project which is available in the relevant organisation's repository and you can find out the url of that repository browsing through their official cite.

  1. Open an terminal
  2. cd Desktop
  3. type svn checkout url
ex: svn checkout https://docbook.svn.sf.net/svnroot/docbook/trunk for checking out the trunk of DocBook project


Then you will get the trunk of that source code in to your Desktop.

Creating a patch

Once you checked out the source you can do necessary editing of the source code and developing your own code for the project.Then you need to inform the community of that project regarding what changes you have made to the source code simply by using the following command in the terminal being in the necessary folder which is the folder where your code is in.

svn diff > a.patch

or

svn diff > a.diff

then the changes will be in your working folder as the file a.patch or a.diff.Then you can send this file to the community.

Come on visitors try SVN for your contribution.

Wednesday, December 29, 2010

Sax Parser...A simple way to access xml documents

Sax parser allow us to access a xml document and we can predefine how the program should behave once certain events are occurred in the xml document when the parser parse the xml document from top to bottom.

A simple java code that helps you to access a xml document through your implementation

package sax;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class SaxHelperSanja {

public static void main(String args[]) {



try {

SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {


public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {
/*this method is called once the parser meets a start element and you should implement here how your code should behave when a start element is found.The name of the start element is the parameter qName and the attributes of that element is under attributes parameter.*/
}

public void endElement(String uri, String localName,
String qName)
throws SAXException {
/*this method is called once the parser meets an end element and you should implement here how your code should behave when an end element is found.The name of the end element is the parameter qName.*/
}

public void characters(char ch[], int start, int length)
throws SAXException {
/* this method is called once the parser encounters text under an element.*/
}
};

// for specifying the xml document
saxParser.parse("/home/sanjaya/Desktop/a.xml", handler);

} catch (Exception e) {
e.printStackTrace();
}
}
}

there are startDocument() and endDocument() methods that are called when the parser begins the parsing of the xml document and ends the parsing of the document.In the above code I have not included them as I think they are not vital as the once I have mentioned above.Anyway feel free to use these two methods if you really need.

Hey that's the simple sax parsing.enjoy....

Tuesday, December 28, 2010

I am back

I was so busy since march as I was fully dealt with completing the gsoc project.And glad to say that I completed it successfully.Soon after I completed the project I wanted to get some vacation and really had a wonderful time in my home having played with my friends until my final year at university begins.Then once again It was and still a tough time as exams are near by.Anyway I think that the time I was away from blogging is too much and thereby I though I must update it.So here I am back again...........

Monday, April 26, 2010

My GSoC proposal has been accepted

I am so happy to mention that my gsoc proposal for apache xerces project has been accepted.I really work hard for last two months in order to gain a better back ground knowledge on the project and to create a proper proposal.Now it begins the harder time and I have to be prepared to face it.By the way I have to arrange a small party for my friends as well.I mean a tea party.Don't take it too serious.
Thank you Ishan sharma for helping me and keep your good habbits going.By the way my mentor is Michael as I have mentioned in my past blog posts and he is a simple man who enjoys the life.I try to gain maximum out of him to make this project a success.And I wish to contact Hiranya ayya as he is more familier about Xerces and I hope he will support me .Until my next blog post here I am going.Bye.