xPath support in JDom via Jaxen makes accessing and manipulating XML document trees a breeze. Thus, if you are looking for a low cost solution for manipulating XML documents from a pre-existing template or querying an XML document for extracting xml attribute values, give JDOM a run.org.jdom jdom 1.1.3 maven-plugins maven-cobertura-plugin maven-plugins maven-findbugs-plugin
Wednesday, 21 March 2012
JDom : The Java based solution for XML manipulation
JDom is a Java based open-source XML manipulation tool that is easy to install and use. Whereas technologies like JaXB are focussed on the marshalling and unmarshalling of XML using Java beans, JDom is more of a XML manipulation tool that is an alternative to DOM and SAX even though as the FAQ says, it integrates well with both these technologies.The best way to understand how well JDOM fits into your requirements is to read the very detailed FAQ.
JDom version 1.1.13 is the latest version which is now available from maven-central.
Thursday, 19 January 2012
Setting up a database based authentication realm in Tomcat 7.0.0
Setting up an authentication module is one of the primary tasks that come across a web-developer's canvas when coding a web-application.In this post, I'll detail the basic steps needed to set up a database backed authentication realm and outline the configuration files that need to be updated when using a Tomcat 7.0.0 servlet container. This post is NOT about security or securing the web-app context so please if you do implement these steps, please do some more research on what is required to secure your web-application.It is also important to note that this post pertains to Tomcat version 7.0.0 and some steps may not be required in more recent versions.
Tomcat 7.0.0 implements the Servlet 3.0 specification (JSR 315) which provide login / logout methods to be invoked on the HttpServletRequest.
Step 1: Create the user and user-roles table in your database using the sql scripts described here. Insert a couple of records in each table.Step 2: Set up Tomcat to connect to the database realm
(a) In the context.xml(located in server/conf directory), set up the datasource
(b) In server.xml (located in server/conf directory) add the following snippets in the correct location within the xml file. This will set up the connection between the datasource and the authentication mechanism :
Step 3: Download the jdbc driver based on your database & the tomcat-jdbc jar to set up the JDBC Connection Pool (You do not need to download the tomcat-jdbc jar if you are using Tomcat version 7.0.19 and above)........ ..........
Step 4: Write the logic for passing the login & password from the user form to the backing bean.
public String login() {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context
.getExternalContext().getRequest();
try
{
request.login(username, password);
} catch (ServletException e) {
e.printStackTrace();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Login failed!", null));
return "failed-login";
}
//You can fetch user from database for authenticated principal and do some action
Principal principal = request.getUserPrincipal();
log.info("Authenticated user: " + principal.getName());
if(request.isUserInRole("administrator")) {
setLoginSectionVisible(false);
setUploadSectionVisible(true);
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Login successful!", null));
return "admin-login";
} else {
return "user-login";
}
}
Wednesday, 28 December 2011
Use ColorBrewer for coloring maps rendered with GeoTools
ColorBrewer is an excellent library for creating dynamic color palettes that can be used to apply colors to a map based on the spread of data values. The ColorBrewer web tool allows you to select a color scheme based on the nature of the data (sequential, diverging, qualitative) and the number of data classes present in the data. You can opt to select a color scheme that is color blind safe and works well on a photocopier.
Based on your requirements, the web tool will display the name of the color scheme that works best for the entered combination. For example, in the screenshot below, the color scheme chosen by the tool is BuGn.
Based on your requirements, the web tool will display the name of the color scheme that works best for the entered combination. For example, in the screenshot below, the color scheme chosen by the tool is BuGn.
| ColorBrewer 2.0 |
ColorBrewer comes bundled with GeoTools. To include the correct library,use the following Maven snippet.
org.geotools gt-brewer 2.7.2
To instantiate the required palette within your Java application,
String paletteName = "BuGn";
ColorBrewer brewer = null;
try {
brewer = ColorBrewer.instance(ColorBrewer.DIVERGING);
} catch (IOException e) {
//Log Error
}
// Instantiate the color palette
palette = brewer.getPalette(paletteName);
// Get the number of colors your need. In this case, 3 colors
// which are a variant of Green
palette.getColors(3);
Now, you have an array of colors which you can apply to your GIS features.
Sunday, 25 December 2011
India's upcoming tour of DownUnder 2011
The last time I put together my thoughts before India (the then Twenty20 World Champions) toured Australia, and predicted an exciting time, little did I realise that the tour would become infamous for all the wrong reasons. This time around, both teams have resolved to play cricket in the spirit that it is meant to be played. Michael Clarke will be leading a relatively inexperienced side against the one day World Champions who not so long ago where also the leading Test team. Both sides have a lot to prove. Clarke will be hoping to assert his leadership early in the series while the Indians will be hoping to go 1-up early.
The Boxing Day Test which will be viewed by about 60,000 fans at the MCG including myself will see Tendulkar, Dravid, Laxman and possibly even Ponting play a Boxing Day test for perhaps the last time in their long and illustrious careers.Lets hope that these stalwarts get the best possible opportunity to perform before an adoring legion of fans and we are treated to some superb cricket in the Boxing Day test and through out the series. I guess this series will in all probability see Tendulkar (barring an injury) get his 100th International hundred and it will be a well-deserved milestone that will perhaps stand the test of time, just like the Don's famous average of 99.94 will.
Addendum : The first day of the Boxing Day test was attended by 70,068 fans, a record for an India-Australia test match and the day lived up to its billing. Tough cricket was played out by both sides with neither willing to give an inch and the match looks headed for an exciting finish.Here are some pictures from day one of the test.
Addendum : The first day of the Boxing Day test was attended by 70,068 fans, a record for an India-Australia test match and the day lived up to its billing. Tough cricket was played out by both sides with neither willing to give an inch and the match looks headed for an exciting finish.Here are some pictures from day one of the test.
Subscribe to:
Posts (Atom)