Posts Tagged ‘Java’

Secure JSP Taglibs

February 4th, 2007

I’ve just created the project Secure JSP Taglibs at Google Code Project Hosting with the ambition to fill some gaps in the security of the presentation layer in a Java web application.

For now it doesn’t do too much, more features will be added in the future.
This Taglib allows you to evaluate the nested body content of the tag to test if the user has the specified roles.
This is equivalent to the isUserInRole() method, but you can evaluate multiple roles (comma separated) at the same time.

Examples:

<secure:one roles="role1toevaluate, role2toevaluate">
    Show this content if the user has one of the specified roles.
</secure:one>
<secure:all roles="role1toevaluate, role2toevaluate">
    Show this content if the user has all the specified roles.
</secure:all>
<secure:none roles="role1toevaluate, role2toevaluate">
    Show this content if the user has none of the specified roles.
</secure:none>

Feel free to use it, it’s licensed under Apache License 2.0 and can be found at http://code.google.com/p/secure-taglib/.

Comparison between Stripes and JSF

January 8th, 2007

Reading the TheServerSide.COM news I’ve found a comparison’s article between Stripes and JSF frameworks.

I can’t agree more with the author Gregg Bolinger when he says Since I stumbled on Stripes, I’ve found it to be the best all around framework for my purposes.

Read it at “Stripes and JSF: A Brief Comparison“.

Java and UTF-8 encoding

December 31st, 2006

If the J2SE platform has come a long way in internationalization, entering non-ASCII text in the J2EE world isn’t nearly as easy.

To achieve the same result you have to make some changes in your code and in your web server settings.

Firstly, to make sure that the right value in the Content-Type header precedes the text/html content so your browser correctly auto-detects the right encoding, place the following declaration at the beginning of the JSP:

<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8" %>

Next you have to create a filter that implements the ‘javax.servlet.Filter’ interface so you can have the request parameters encoded with UTF-8:

package com.samaxes.filters;

import javax.servlet.*;
import java.io.IOException;

/**
 * Filter called before every action.
 *
 * @author : samaxes
 */
public class UTF8Filter implements Filter {

    public void init(FilterConfig filterConfig) {
    }

    public void destroy() {
    }

    public void doFilter(ServletRequest servletRequest,
                         ServletResponse servletResponse,
                         FilterChain filterChain)
            throws IOException, ServletException {
        servletRequest.setCharacterEncoding("UTF-8");
        filterChain.doFilter(servletRequest, servletResponse);
    }
}

Now, your server reads the URL POST parameters correctly…

But there still is an issue – during a GET operation.

The trouble is that none of the charset information gets sent back to the web server during a GET or POST operation. The server has no way of knowing how to interpret the url-encoded GET parameters, so it assumes ISO-8859-1.

Fortunately the solution to address this is pretty simple, just specify URIEncoding="UTF-8" in your Tomcat’s connector settings within the server.xml file.

Your application shall now handle UTF-8 just fine.

Java 6 Final Release Available for Download

December 11th, 2006

The news article from InfoQ:

This morning Sun officially released Java 6 for download after over two years of development. The Java 6 development cycle has been the most open of any Java release with weekly builds available to the public and extensive collaboration between Sun and over 330 external developers. Sun has worked with over 160 companies to ensure backwards compatibility, stability and optimum performance of applications running on the JVM. Java 6 included a number of focus areas. From the press release:

Web 2.0

The Java SE 6 software helps accelerate developer innovation for web-based, dynamic and online collaboration applications by including a new framework and developer APIs to allow mixing of Java technology with dynamically typed languages, such as PHP, Python, Ruby and JavaScript(TM) technology. Sun has also created a collection of scripting engines at: http://scripting.dev.java.net and pre-configured the Rhino JavaScript engine in the Java SE 6 platform. In addition, the Java SE 6 software includes a full web services client stack and supports the latest web services specifications, such as JAX-WS 2.0, JAXB 2.0, STAX and JAXP.

Diagnostics, Monitoring, and Management

The Java SE 6 platform provides expanded tools for diagnosing, managing and monitoring applications and also includes support for the new NetBeans Profiler 5.5 and for Solaris(TM) DTrace, a comprehensive dynamic tracing framework for the Solaris 10 Operating System (OS). In addition, the Java SE 6 software further increases ease of development with tool interface updates for the Java Virtual Machine (JVM (TM)) and the Java Platform Debugger Architecture (JPDA).

Enterprise Desktop

The Java SE 6 release delivers significant improvements to the desktop, which enable Java applications to integrate even more seamlessly into the end-user experience. For rapid visual development of interactive applications, the Java SE 6 platform includes a new layout manager component, based on the NetBeans GUI Builder (formerly code named Matisse). The Java SE 6 software also provides enhanced support for the upcoming version of Windows Vista.

InfoQ discussed the Java 6 release with Bill Curci, Product Marketing Manager for Java Platform Standard Edition and Danny Coward, Java SE Platform Lead. Among the items they highlighted:

A good summary of the main features included in Java 6 can be found in InfoQ’s previous coverage “Top 10 New Things You Need to Know About Java 6“.

Sun open sources Java under GPLv2

November 14th, 2006

It’s finally here as you can see in Free and Open Source Java.

The key behind moving to the GPL is to drive more volume and more adoption for the platform. The GPL helps get Java into some markets that it hasn’t served as fully as it should – such as educational markets, governments in the developing world, and some commercial customers – as well as, obviously, some distributions of Linux which insist not on Linux-friendly licenses but on actual GPL licensing.

GPLv2 was chosen over GPLv3 for fairly obvious reasons: GPLv3 isn’t finished yet! Sun is, they said, working with the FSF on defining GPLv3.

Read the complete news.

Gantt Charts with JFreeChart

November 4th, 2006

If you have ever tried to draw gantt charts with JFreeChart you have already noticed that it’s a very simplistic implementation – it doesn’t have the facility to display dependency lines or milestones.

Orginal Gantt Chart
Gantt chart demo from JFreeChart samples

In a recent project I needed some additional features like:

  1. Summary tasks
  2. Milestones/deliverables
  3. Dependencies between task and milestones/deliverables

So I modified BarRenderer.java, GanttRenderer.java, GanttCategoryDataset.java, Task.java, and TaskSeriesCollection.java appropriately and also created my own class called LineAndShapeGanttRenderer.java.

Modified Gantt Chart
Gantt chart with JFreeChart after files modification

The base version of JFreeChart was 1.0.2, and the modified files were:

Apache Struts 2 development build

October 20th, 2006

The first development build (2.0.1) of Apache Struts 2 project has been released.

Struts 2 was originally known as WebWork 2. After working independently for several years, the WebWork and Struts communities joined forces to create Struts 2. This new version of Struts is designed to be simpler to use and closer to how Struts was always meant to be. Some key changes are:

  • Smarter!
    • Improved Design – All Struts 2 classes are based on interfaces. Core interfaces are HTTP independent.
    • Intelligent Defaults – Most configuration elements have a default value that we can set and forget.
    • Enhanced Results – Unlike ActionForwards, Struts 2 Results can actually help prepare the response.
    • Enhanced Tags – Struts 2 tags don’t just output data, but provide stylesheet-driven markup, so that we can create consistent pages with less code.
    • First-class AJAX support – The AJAX theme gives interactive applications a significant boost.
    • Stateful Checkboxes – Struts 2 checkboxes do not require special handling for false values.
    • QuickStart – Many changes can be made on the fly without restarting a web container.
  • Easier!
    • Easy-to-test Actions – Struts 2 Actions are HTTP independent and can be tested without resorting to mock objects.
    • Easy-to-customize controller – Struts 1 lets us customize the request processor per module, Struts 2 lets us customize the request handling per action, if desired.
    • Easy-to-tweak tags – Struts 2 tag markup can be altered by changing an underlying stylesheet. Individual tag markup can be changed by editing a FreeMarker template. No need to grok the taglib API! Both JSP and FreeMarker tags are fully supported.
    • Easy cancel handling – The Struts 2 Cancel button can go directly to a different action.
    • Easy Spring integration – Struts 2 Actions are Spring-aware. Just add Spring beans!
    • Easy plugins – Struts 2 extensions can be added by dropping in a JAR. No manual configuration required!
  • POJO-ier!
    • POJO forms – No more ActionForms! We can use any JavaBean we like or put properties directly on our Action classes. No need to use all String properties!
    • POJO Actions – Any class can be used as an Action class. We don’t even have to implement an interface!

Struts 2 key features

  • A flexible, plain old Java object (POJO)-based architecture to structure your code and pages, yet stay out of your way.
  • A theme-enabled tag library supporting JSP, Velocity, and Freemarker.
  • Built in support for complex Javascript and Ajax widgets.
  • A simple plugin framework to integrate with third-party libraries like JavaServer Faces, JasperReports, and JFreeChart.
  • Built-in debugging tools supporting profiling, problem reports, and interactive object model queries.
  • Automatic portlet support allowing portal and servlet deployments with no code changes
  • Quick start development tools like Maven archetypes, automatic reloading configuration files, and bootstrap tutorials.

Other Resources

Eclipse RCP to Cellphones

October 18th, 2006

Great news for embedded devices developers.
Eclipse has recently released the embedded Rich Client Platform (eRCP) 1.0.

eRCP is for J2ME what RCP is for the desktop, and includes among other things

  • Eclipse Core which provides OSGI and Extension Point Framework support
  • a version of SWT called embedded Standard Widget Toolkit (eSWT)
  • eJFace a set of classes which enable eRCP applications to integrate with an eRCP workbench, and provide more complex widgets like MVC oriented viewers
  • eUpdate for dynamically updating device software
  • and microXML a smaller, faster XML parser supporting SAX and DOM API

eRCP currently support Windows Mobile 2003/5.0, Symbian S60/S80, and QT embedded devices.

Deploying BIRT Report Engine API with Jakarta Struts

August 15th, 2006

After reading the great article Deploying BIRT from Jason Weathersby I decide to create a little example on how to use BIRT RE API with Jakarta Struts framework.

To do so I’ve followed Jason steps:

  1. Create a WebReport/WEB-INF/lib directory underneath the Tomcat webapps directory.
  2. Copy all the jars in the birt-runtime-2_1_0/ReportEngine/lib directory from the Report Engine download into your WebReport/WEB-INF/lib directory.
  3. Next, create a directory named platform in your WEB-INF folder.
  4. Copy the birt-runtime-2_1_0/Report Engine/plugins and birt-runtime-2_1_0/ReportEngine/configuration directories to the platform directory you just created. In this example the context is WebReport, so the folder structure is /webapps/WebReport/platform/plugins and webapps/WebReport/platform/configuration.
  5. Additionally, create directories below WebReport for image location and report location.

and used the same directory structure:

WebReport directory structure

The example allows you to generate reports in HTML, PDF, and XLS formats. For the last one I’ve used Tribix XLS Emitter.

To get more information about how to use XLS emitter with BIRT Report Engine API please read the README file that comes with in the binary distribution.

» Read more: Deploying BIRT Report Engine API with Jakarta Struts

Tribix – Extended Emitters for BIRT

July 13th, 2006

Tribix 2.1.0 final – Extended emitters for BIRT (Business Intelligence and Reporting Tools) provides a set of extended emitters for BIRT 2.1.0 final or above.

It comes along with a PPT (MS PowerPoint) emitter preview release. You can now export all your reports made with the BIRT Reporting System to Excel, or even preview them in PowerPoint.

This version does support fixed-column-width sheet output and image export to Excel which are great news since my last post about Reporting Tools.

Here’s a screenshoot:
Tribix - Screenshot Preview as XLS