Monday, May 21, 2012

iCal4j example - Set a Meeting using iCalendar

iCalendar is a computer file format which allows Internet users to send meeting requests and tasks to other Internet users, via email, or sharing files with an extension of .ics. Recipients of the iCalendar data file (with supporting software, such as an email client or calendar application) can respond to the sender easily or counter propose another meeting date/time.

iCalendar is used and supported by a large number of products, including Google Calendar, Apple iCal,IBM Lotus Notes,Yahoo Calendar, Microsoft Outlook etc

iCal4j is an API which is used to modifying existing iCalendar data or creating new iCalendar data. To know more about iCal4j, click here.

About the example

This example is straight forward, we will create a calendar (net.fortuna.ical4j.model.Calendar) object and add a Meeting event to it. You can set various properties to the event like subject, location, description etc. Obviously you can customize it according to your requirement. This example will generate a .ics file (TestCalendar.ics). You can send this generated file via email to interested parties. Please see the below self explanatory java program.

For running below example you will need to add below mentioned JAR files in your classpath.
  • ical4j-1.0.3.jar
  • backport-util-concurrent-3.1.jar
  • commons-logging-1.1.1.jar
  • commons-lang-2.6.jar

To download the above JAR file, click here.

Friday, May 18, 2012

Text Extraction with Java


Documents in PDF format, are widely used and accepted within the computer world. And while it is a versatile piece of software, it does have its downsides. The most obvious being the inability to alter the document natively, therefore, text extraction is often sought after to try and make this tedious task less of an uphill struggle.

Extracting all of the useful, interesting, and relevant information from a PDF can be a daunting task, but by utilising text extraction software which is completely written in Java. The process of extraction and conversion has become increasingly crucial for the manipulation and archiving of data. With the use of a Java application, this has become extremely easy in regards to extracting text from a PDF document.


Java simple iCalendar iCal4j example

iCalendar is a computer file format which allows Internet users to send meeting requests and tasks to other Internet users, via email, or sharing files with an extension of .ics. iCal4j is an API which is used to modifying existing iCalendar data or creating new iCalendar data. To know more about iCal4j, click here.

About the example

ICalendarExample.java will create a .ics file lets say mycalendar.ics. It will create a calender event, you can customize it according to your requirement. You can send this generated file via email.

For running below example you will need to add below mentioned JAR files in your classpath.
  • ical4j-1.0.3.jar
  • backport-util-concurrent-3.1.jar
  • commons-logging-1.1.1.jar
  • commons-lang-2.6.jar

To download the above JAR file, click here.

Thursday, May 10, 2012

JSTL forEach loop to iterate List, Map, Map of List, List of Map

Lets see how we can use JSTL to iterate List, Map, Map of List and List of Map. Below are the tested JSP codes, directly you can run below JSPs and see the outputs.

Note : The JSTL tag library needs jstl-1.2.jar in application's classpath. To download jstl-1.2.jar, click here

1. List

Lets see how to iterate List using JSTL forEach loop. Using below code you can iterate ArrayList, Vector or LinkedList.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="java.util.ArrayList"%>
<%
    ArrayList<String> list = new ArrayList<String>();
    list.add("val1");
    list.add("val2");
    list.add("val3");
    
    request.setAttribute("MyList", list);
%>
<html>
<body>
    <c:forEach items="${MyList}" var="listItem">
        ${listItem} <br/>
    </c:forEach>
</body>
</html>

The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application

If you get below mentioned error

org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
 org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:53)
 org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
 org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
 org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:310)
 org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:152)
 org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
 org.apache.jasper.compiler.Parser.parseDirective(Parser.java:475)
 org.apache.jasper.compiler.Parser.parseElements(Parser.java:1425)
 org.apache.jasper.compiler.Parser.parse(Parser.java:138)
 org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239)
 org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
 org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:197)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)
 org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
 org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
 org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1060)
 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:798)
 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Probably the reason could be you have used below mentioned taglib in your JSP file.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

You need to get the right version of JSTL in your application's classpath, they use different URIs. If that one's not working, try downloading JSTL 1.2 (jstl-1.2.jar) from http://download.java.net/maven/1/jstl/jars/jstl-1.2.jar, or pull down the 1.1 JSTL jars.

To know more about JSTL Taglib, Please see below links.
http://docs.oracle.com/javaee/5/tutorial/doc/bnake.html
http://jakarta.apache.org/taglibs/doc/standard-doc/GettingStarted.html