jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vineet <vchaud...@qasource.com>
Subject org.apache.jackrabbit.rmi.client.ClientNode cannot be cast to net.fortuna.ical4j.model.Component
Date Tue, 03 Jan 2012 11:56:53 GMT
Hi

I am using Ical4j library to read the ics file.But is giving me the 
following error

"org.apache.jackrabbit.rmi.client.ClientNode cannot be cast to 
net.fortuna.ical4j.model.Component"

The code is as following

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.jcr.LoginException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Value;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Component;

import org.apache.jackrabbit.rmi.client.ClientNode;
import org.apache.jackrabbit.rmi.repository.URLRemoteRepository;
import org.apache.jackrabbit.servlet.ServletRepository;


public class Duplicate extends HttpServlet {

     private List<Node> icsFilesList = new ArrayList<Node>();

     SimpleDateFormat f = new SimpleDateFormat("yyyy/MM/dd");

     String todayDate = "";

     String htmlPrefix = "";

     String htmlMid = "";

     String htmlPostfix = "";

     public void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {

         String leadname = req.getParameter("selectedLead");
         System.out.println("selectedLead [" + leadname + "]");
         System.out.println("selected date [" + req.getParameter("theDate")
                 + "]");
         try {
             String htmlString = htmlPrefix + getLeadNamesHtmlString() + 
htmlMid
             + getScheduleForLeads(leadname) + htmlPostfix;
             resp.getWriter().println(htmlString);
         } catch (RepositoryException e) {
             resp.getWriter().println(
                     "Please conatct administrator. Error while 
accessing Calendar repository :\n"
                     + e.getMessage());
         }

     }

     public void init() throws ServletException {
         System.out.println("In the init() Method");
         //todayDate = f.format(Calendar.getInstance().getTime());

         htmlPrefix = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 
Transitional//EN\" "
             + 
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html 
xmlns=\"http://www.w3.org/1999/xhtml\">"
             + "<head><meta http-equiv=\"Content-Type\" 
content=\"text/html; charset=iso-8859-1\" />"
             + "<title>HR - Calendar Viewer</title><link 
href=\"style.css\" rel=\"stylesheet\" type=\"text/css\" />"
             + "<link type=\"text/css\" rel=\"stylesheet\" 
href=\"calendar.css?random=20051112\" media=\"screen\"></LINK>"
             + "<SCRIPT type=\"text/javascript\" 
src=\"calendar.js?random=20060118\"></script>"
             + "</head><body><!--up div start --><div 
id=\"up_div\"><!--header start --><div id=\"header\">"
             + "<!--img src=\"images/best_future.gif\" width=\"153\" 
height=\"91\" alt=\"best for future\"/-->"
             + "<img src=\"images/bebo_technologies_logo.jpg\" 
alt=\"Bebo Technologies\" width=\"150\" height=\"100\" border=\"0\">"
             + "<!--img class=\"logo\" 
src=\"images/bebo_technologies_logo.jpg\" width=\"200\" height=\"38\" 
title=\"bebo\" alt=\"bebo logo\" /-->"
             + "<h1>Be Extension &nbsp;&nbsp;&nbsp;Be Offshore</h1><ul>"
             + "<li><a href=\"#\"> </a></li><li><a href=\"#\">

</a></li><li><a href=\"#\"> </a></li><li><a href=\"#\">
</a></li>"
             + "<li><a href=\"#\"> </a></li><li><a href=\"#\">

</a></li><li><a href=\"#\"> </a></li></ul></div>"
             + "<!--header end --></div><!--up div end --><!--mid div

start --><!--body part start -->"
             + "<div id=\"body_pan\"><h2>Schedule of leads on <br 
/><form align=\"right\"><input type=\"text\" value=\""
             + todayDate
             + "\" style=\"width:70px;\""
             + "readonly name=\"theDate\"><input type=\"button\" 
value=\"Cal\" "
             + 
"onclick=\"displayCalendar(document.forms[0].theDate,'yyyy/mm/dd',this)\"></form></h2><div

id=\"update\"><p class=\"up\">"
             + "</p><div id=\"latest\"><h2>Lead names</h2>";

         htmlMid = "<br class=\"bank\" /></div><p 
class=\"down\"></p></div><!-- services star -->"
             + "<div id=\"ser\"><p class=\"se\"></p><div id=\"services\">";

         htmlPostfix = "<br class=\"bank\" /></div><p 
class=\"se_down\"></p></div><!--services end --><!--body part end
-->"
             + "<br class=\"bank\" /></div></div><div id=\"footer\"><div

id=\"foo\"><ul><li><a href=\"#\">Home</a>|</li>"
             + "<li><a href=\"#\">About Us</a>|</li><li><a

href=\"#\">Company </a>|</li><li><a href=\"#\">Partners</a>|</li>"
             + "<li><a href=\"#\">Blog</a>|</li><li><a 
href=\"#\">Resources </a>|</li><li><a href=\"#\">Contact</a></li></ul>"
             + "<p>Copyright &copy; bebo Technologies Pvt Ltd. All 
rights reserved.</p></div></div><!--mid div end --></body></html>";

         try {
             Repository repository = new URLRemoteRepository(
             "http://192.16.17.60:8080/CalendarViewer/rmi");
             Session session = null;

             session = repository.login(new SimpleCredentials("admin", 
"admin"
                     .toCharArray()));
             Node rootNode = session.getRootNode();
             NodeIterator itr = rootNode.getNodes();
             for (Iterator iterator = rootNode.getNodes(); 
iterator.hasNext();) {
                 Node node = (Node) iterator.next();
                 System.out.println("NodeName = " + node.getName());
                 if (node.getName().endsWith(".ics")) {
                     icsFilesList.add(node);
                     String datacontent = node.getNode("jcr:content")
                     .getProperty("jcr:data").getString();
                     //System.out.println("DataContent : " + datacontent);
                 }
             }
         } catch (LoginException e) {
             throw new ServletException(e);
         } catch (RepositoryException e) {
             throw new ServletException(e);
         } catch (Exception e) {

         }

     }

     /**
      * <ul>
      * <li><a href="#">Lead 1 </a></li>
      * <li><a href="#">Lead 2</a></li>
      * <li><a href="#">Lead 3</a></li>
      * <li><a href="#">Lead 4</a></li>
      * </ul>
      *
      * @return
      * @throws RepositoryException
      */
     private String getLeadNamesHtmlString() throws RepositoryException {

         StringBuffer htmlStr = new StringBuffer("<ul>");

         String contextPath = getServletContext().getContextPath();

         System.out.println("contextPath : " + contextPath);

         contextPath = contextPath + "/viewer?selectedLead=";
         htmlStr.append("<li><a href=\"" + contextPath + "\">All</a>");
         for (Iterator iterator = icsFilesList.iterator(); 
iterator.hasNext();) {
             Node node = (Node) iterator.next();
             String filename = node.getName();
             String lead = filename.substring(0, filename.indexOf(".ics"));

             htmlStr.append("<li><a href=\"" + contextPath + lead + "\">");

             htmlStr.append(lead);
             htmlStr.append("</a></li>");

         }

         htmlStr.append("</ul>");

         return htmlStr.toString();
     }

     private String getScheduleForLeads(String leadname)
     throws RepositoryException {
         System.out.println("In the getScheduleForLeads() Method with 
arg = "
                 + leadname);
         StringBuffer htmlStr = new StringBuffer("");

         for (Iterator iterator = icsFilesList.iterator(); 
iterator.hasNext();) {
             Node node = (Node) iterator.next();
             String filename = node.getName();
             String lead = filename.substring(0, filename.indexOf(".ics"));

             if (leadname != null && !leadname.equals("")
&& lead.equals(leadname)) {
                 System.out.println("adding cal for : " + leadname);
                 htmlStr.append("<h2>");
                 htmlStr.append(lead);
                 htmlStr.append("</h2>");
                 /*
                  * htmlStr .append("<table border=\"0\">" + "<tr><td>10:00
                  * to 12:00 </td><td><font size=\"4\">Interview with 
yyyyyy on
                  * ttttttt using mmmmmmm</font></td></tr>" + "<tr><td>1:00
                  * to 2:00 </td><td><font size=\"3\">Interview with 
xxxxxx on
                  * dddjdjd using dkdkdkd</font></td></tr>" + "</table>");
                  */

                 try {
                     FileInputStream fin = new FileInputStream(filename);

                     CalendarBuilder builder = new CalendarBuilder();

                     System.out.println("PATH --->" + node.getPath());
                     net.fortuna.ical4j.model.Calendar calendar = builder
                     .build(node.getNode("jcr:content").getProperty(
                     "jcr:data").getStream());


                     List list = calendar.getComponents("VEVENT");
                     System.out.println(list.size());

                     for (Iterator iterator2 = list.iterator(); iterator
                     .hasNext();) {
                         String eventName = null;
                         String eventStartDate = null;
                         String eventEndDate = null;
                         String eventRepeatPattern = null;




                         Component component = (Component) iterator.next();

                         eventName = 
component.getProperty("SUMMARY").getValue();
                         eventStartDate = component.getProperty("DTSTART")
                         .getValue();
                         eventEndDate = component.getProperty("DTEND")
                         .getValue();
                         if (component.getProperty("RRULE") != null) {
                             eventRepeatPattern = 
component.getProperty("RRULE")
                             .getValue();
                         }

                         System.out.println(eventName);
                         System.out.println(eventStartDate);
                         System.out.println(eventEndDate);
                         if (eventRepeatPattern != null) {

                             System.out.println(eventRepeatPattern);
                         }

                         System.out.println();

                         htmlStr.append("<table border=\"0\">" + "<tr><td>"
                                 + eventName + "</td><td><font size=\"4\">"
                                 + eventStartDate + "</font></td>"
                                 + "<td><font size=\"4\">" + eventEndDate
                                 + "</font></td></tr>" + "</table>");
                     }

                 } catch (Exception e) {
                     System.out.println("Execption ---> " + e.getMessage());
                 }

                 String datacontent = 
node.getNode("jcr:content").getProperty(
                 "jcr:data").getString();
                 break;
             } else if (leadname == null || leadname.equals("")) {
                 System.out.println("adding cal for ================== " 
+ leadname);
                 htmlStr.append("<h2>");
                 htmlStr.append(lead);
                 htmlStr.append("</h2>");

                 String datacontent = 
node.getNode("jcr:content").getProperty("jcr:data").getString();

                 //htmlStr.append(datacontent);

                 byte datacontentInBytes[] = datacontent.getBytes();
                 try {

                     CalendarBuilder builder = new CalendarBuilder();

                     FileOutputStream fos = new 
FileOutputStream("\\\\192.16.17.52//shared//vin.ics");
                     fos.write(datacontentInBytes);
                     fos.flush();
                     fos.close();

                     //ByteArrayInputStream bis = new 
ByteArrayInputStream(datacontentInBytes);
                     //FileInputStream fis = 
node.getNode("jcr:content").getProperty("jcr:data").getStream();



                     Calendar calendar = 
builder.build(node.getNode("jcr:content").getProperty("jcr:data").getStream());


                     List list1 = calendar.getComponents("VEVENT");


                     System.out.println("list size = "+list1.size());


                     for (Iterator iterator2 = list1.iterator(); 
iterator.hasNext();) {

                         String eventName = null;
                         String eventStartDate = null;
                         String eventEndDate = null;
                         String eventRepeatPattern =    null;

                         Component component = (Component) iterator.next();
                         System.out.println("component = "+ component);
                         //htmlStr.append(datacontent);

                         /*component.
                         //eventNamev = component.getProperty("SUMMARY");
                         //eventName = eventNamev.getString();
                         eventStartDate = 
component.getProperty("DTSTART").getValue();
                         eventEndDate = 
component.getProperty("DTEND").getValue();

                         if (component.getProperty("RRULE") != null) {

                             eventRepeatPattern = 
component.getProperty("RRULE")    .getValue();

                         }

                         System.out.println(eventName);
                         System.out.println(eventStartDate);
                         System.out.println(eventEndDate);

                         if(eventRepeatPattern != null){

                             System.out.println(eventRepeatPattern);
                         }

                         System.out.println();
                         //htmlStr.append(eventName);


                         htmlStr.append("<table border=\"0\">" + 
"<tr><td>" +
                                 eventName + "</td><td><font 
size=\"4\">" + eventStartDate + "</font></td>" +
                                 "<td><fontsize=\"4\">" + eventEndDate + 
"</font></td></tr>" + "</table>"); */

                         System.out.println(" ================== " );
                         }
                 } catch (Exception e) {
                     System.out.println("Execption ---> " +e.getMessage());
                 }

             }

         }

         return htmlStr.toString();
     }
}

Can anyone help me with this...

Thanks
Vineet


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message