0 Replies Latest reply: Nov 27, 2006 3:45 AM by 548369 RSS

    Time Zone Problem

    548369
      Hi !

      I made Calendar Portlet Program to get Event/Task Information on Specific day
      by using Calendarlet.jar , sample Code

      But Gathering / Displaying data depended on UCT (Coordinated Universal Time)

      Problem is

      User changed timezone( UCT => KST(Korea Standard Time)) in
      Calendar Preference
      and created Meeting on 09:00 ~ 10:00
      then In Calendar Portlet Displayed Meeting Time => 00:00 ~ 01:00

      Can I have API/sample code to select/display data based by
      user setting Time-Zone ?

      thanks

      used code is added
      --------------------------------------------------------------------------
      import java.sql.*;
      import java.util.*;
      import oracle.calendar.soap.client.CalendarUtils;
      import oracle.calendar.soap.client.CreateReply;
      import oracle.calendar.soap.client.Reply;
      import java.util.HashMap;
      import java.text.SimpleDateFormat;
      import java.util.Calendar;
      import java.util.Date;
      import java.io.*;


      public class S35050B615
      {

           private S35050B508 appLog;

      public S35050B615() {}


      public oracle.calendar.soap.client.Reply conn(String sTime, String userID) throws Exception
      {

      oracle.calendar.soap.client.Reply mainReply = null;

      try {

      oracle.calendar.soap.client.Calendarlet cws =
      new oracle.calendar.soap.client.Calendarlet();

      String cal_URL = null;
      String cal_PWD = null;

      Properties props = System.getProperties();
      props.load(new FileInputStream("/WAS/APP/UNIT/OC4J_OCSCLIENT/WEB-INF/classes/common/logenv.properties"));
           cal_URL = (String)props.getProperty("HOME_URL");
           
      cal_URL = cal_URL + "/ocws-bin/ocas.fcgi";

      S35050B600 myInit = new S35050B600();
      myInit.initBasicAuth(
      cws,
      userID,
      "welcome1",
      "http://172.31.64.184:7777/ocws-bin/ocas.fcgi"); // cal_URL);

      S35050B615 S35050B615 = new S35050B615();
      mainReply = S35050B615.run(sTime,cws,userID);

      }catch (Exception e) {
      appLog.log("S35050B615", "outputReply", e);
      }

      return mainReply;

      }

      public oracle.calendar.soap.client.Reply run(String sTime, oracle.calendar.soap.client.Calendarlet cws,String userID) throws Exception
      {

      try {

      // Initialize the event search command and query
      oracle.calendar.soap.client.SearchCommand search =
      new oracle.calendar.soap.client.SearchCommand();

      String cmdID = sTime + userID + "Appointment" ;
      search.setCmdId(cmdID);

      // Create a query to retrieve events
      oracle.calendar.soap.client.query.vQuery query =
      new oracle.calendar.soap.client.query.vQuery();
      query.setFrom
      (oracle.calendar.soap.client.query.vQuery.k_queryFromEvent);

      // Determine the datestamps for a weeks worth of events.
      // Use the CalendarUtils to get a proper timestamp with
      // time zone information set properly

      String strDate = sTime;
      String fmt;
      Date date = null;

      fmt = "yyyy/MM/dd";


      SimpleDateFormat sdf = new SimpleDateFormat(fmt);
      date = new Date(sdf.parse(strDate).getTime());
      Calendar today = Calendar.getInstance();
      today.setTime(date);

      int dayOfWeek = today.get(java.util.Calendar.DAY_OF_WEEK);
      java.util.Calendar beginWeek = (java.util.Calendar)today.clone();
      java.util.Calendar endWeek = (java.util.Calendar)today.clone();
      beginWeek.add(java.util.Calendar.DATE, 0);
      beginWeek.add(java.util.Calendar.HOUR, +9);
      endWeek.add(java.util.Calendar.DATE, +1);
      endWeek.add(java.util.Calendar.HOUR, +9);
      endWeek.add(java.util.Calendar.MINUTE, -1);



      // Use the CalendarUtils to help generate a date range query
      query.setWhere
      (oracle.calendar.soap.client.CalendarUtils.getDateRangeQuery
      (beginWeek, endWeek));

      search.setQuery(query);


      // Make the SOAP call
      oracle.calendar.soap.client.CalendaringResponse response
      = cws.Search(search.getElement());

      // Now display the results
      //System.out.println("SOAP send buffer:");
      //System.out.println(response.getSendBuffer());
      //System.out.println("SOAP receive buffer:");
      //System.out.println(response.getReceiveBuffer());

      Vector bodyEntries = response.getBodyEntries();

      if (CalendarUtils.isSOAPFault(bodyEntries))
      {

      org.apache.soap.Fault soapFault = CalendarUtils.getSOAPFault(bodyEntries);
      System.out.println("soapFault="+soapFault.toString());
      appLog.log("S35050B615", "soapFault="+soapFault.toString());
      oracle.calendar.soap.client.Error calendaringError = oracle.calendar.soap.client.Error.unmarshall(soapFault);
      // System.out.println("calendaringError="+calendaringError.toString());
      String errorCode = calendaringError.getCode();
      // System.out.println("errorCode="+errorCode);
      appLog.log("S35050B615", "errorCode="+errorCode);
      }

      // Get the SOAP reply
      oracle.calendar.soap.client.Reply reply =
      (oracle.calendar.soap.client.Reply) response.getCalendarReply();


      return reply;
      } catch (Exception e)
      {
      appLog.log("S35050B615", "Reply Run="+e);
      // System.out.println("Exception enountered:");
      // System.out.println(e.getMessage());
      // e.printStackTrace();
      }
      return null;
      }


      public HashMap[] outputReply(String sTime, String userID) throws Exception {

      HashMap[] hm2 = null;
      String returnString = "";
      StringTokenizer st;
      String temp0="";
      String temp1="";
      String temp2="";
      String temp3="";
      String temp4="";
      String xid ="";

      // Traverse all the iCalendar objects
      try {  
      Reply replyArg = conn(sTime,userID);
      java.util.Vector someiCalendars = oracle.calendar.soap.iCal.iCalendar.unmarshallVector(replyArg.getEntries());


      int numiCalendars = someiCalendars.size();

      if (numiCalendars == 0)
      {  hm2 = new HashMap[0]; }
      else {
      for (int i = 0; i < numiCalendars; i++)
      {
      oracle.calendar.soap.iCal.iCalendar iCalObj =
      (oracle.calendar.soap.iCal.iCalendar)
      someiCalendars.get(i);

      // Traverse all the vCalendar objects
      java.util.Vector somevCalendars = iCalObj.getvCalendars();

      int numvCalendars = somevCalendars.size();

      hm2 = new HashMap[somevCalendars.size()];
      for (int j = 0; j < numvCalendars; j++)
      {
      oracle.calendar.soap.iCal.vCalendar vCalObj =
      (oracle.calendar.soap.iCal.vCalendar) somevCalendars.get(j);

      // Traverse all the vEvent objects
      java.util.Vector somevEvents = vCalObj.getComponents();
      int numvEvents = somevEvents.size();

      for (int k = 0; k < numvEvents; k++)
      {
      oracle.calendar.soap.iCal.vEvent vEventObj =
      (oracle.calendar.soap.iCal.vEvent)somevEvents.get(i);

      hm2[j] = new HashMap();

      String title = vEventObj.getSummary();
      String dtstart = vEventObj.getDtStart();

      String Time_s = "";
      if (dtstart != "" && dtstart.length() > 15)
      { Time_s  = dtstart.substring(9,11);
      Time_s = Time_s + ":00";
      }

      String Time_e = "" ;
      String dtend = vEventObj.getDtEnd();
      if (dtend != "" && dtend.length() > 15)
      { Time_e  = dtend.substring(9,11);
      Time_e = Time_e + ":00"; }

      String eventType = vEventObj.getXEventType();
      String location = vEventObj.getLocation();
      String duration = vEventObj.getDuration();
      String time16 = vEventObj.getInstanceGuid();

      st = new StringTokenizer(time16,"+");
      temp1 = st.nextToken();
      temp2 = st.nextToken();
      temp3 = st.nextToken();
      temp4 = st.nextToken();

      xid = temp2 +"/"+ temp3 +"/" + temp4;

      hm2[j].put("eventType", eventType);
                               hm2[j].put("startdate", dtstart);
                               hm2[j].put("compldate", dtend);
                               hm2[j].put("Time_s", Time_s);
                               hm2[j].put("Time_e", Time_e);
                               hm2[j].put("title", title);
                               hm2[j].put("location", location);
                               hm2[j].put("duration", duration);
                hm2[j].put("xid", xid);
                
                int jj = 0;
                int result = 0;
                String temp00 = null; String temp01 = null;
                String temp10 = null; String temp11 = null;
                String temp20 = null; String temp21 = null;
                String temp30 = null; String temp31 = null;
                String temp40 = null; String temp41 = null;
                String temp50 = null; String temp51 = null;
                String temp60 = null; String temp61 = null;
                
                do {
                temp00 =(String)hm2[jj].get("eventType");
                temp01 = (String)hm2[j].get("eventType");
                temp10 = (String)hm2[jj].get("startdate");
                temp11= (String)hm2[j].get("startdate");
                temp20 = (String)hm2[jj].get("title");
                temp21 = (String)hm2[j].get("title");
                temp30 = (String)hm2[jj].get("Time_s");
                temp31 = (String)hm2[j].get("Time_s");
                temp40 = (String)hm2[jj].get("Time_e");
                temp41 = (String)hm2[j].get("Time_e");
                temp50 = (String)hm2[jj].get("location");
                temp51 = (String)hm2[j].get("location");
                temp60 = (String)hm2[jj].get("xid");
                temp61 = (String)hm2[j].get("xid");
                
                if( temp00.equals(temp01)) {
      if ( temp11.compareTo(temp10) < 0 ) {

      hm2[jj].put("startdate", temp11);hm2[j].put("startdate", temp10);
      hm2[jj].put("title", temp21);hm2[j].put("title", temp20);
      hm2[jj].put("Time_s", temp31);hm2[j].put("Time_s", temp30);
      hm2[jj].put("Time_e", temp41);hm2[j].put("Time_e", temp40);
      hm2[jj].put("location", temp51);hm2[j].put("location", temp50);
      hm2[jj].put("xid", temp61);hm2[j].put("xid", temp60);
      }
      }
           
           
           if( (temp00.equals("DAILY NOTE") && temp01.equals("APPOINTMENT"))||
                (temp00.equals("DAY EVENT") && temp01.equals("APPOINTMENT"))||
                (temp00.equals("DAILY NOTE") && temp01.equals("DAY EVENT")) )
                {
      hm2[jj].put("eventType", temp01);hm2[j].put("eventType", temp00);
      hm2[jj].put("startdate", temp11);hm2[j].put("startdate", temp10);
      hm2[jj].put("title", temp21);hm2[j].put("title", temp20);
      hm2[jj].put("Time_s", temp31);hm2[j].put("Time_s", temp30);
      hm2[jj].put("Time_e", temp41);hm2[j].put("Time_e", temp40);
      hm2[jj].put("location", temp51);hm2[j].put("location", temp50);
      hm2[jj].put("xid", temp61);hm2[j].put("xid", temp60);
      }

      jj = jj + 1;

      } while( jj < j);


      }
      // Do something interesting with the meeting info
      }

      }
      }
      }catch (Exception e) {
      appLog.log("S35050B615", "outputReply", e);
      }


      return hm2;
      }