Pages

Tuesday, February 21, 2012

A sample Calendar file

Following is a content of a fully functional calendar file


BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//ORG//LN//LS
BEGIN:VEVENT
SUMMARY:My Subject!
DESCRIPTION:My Description content
UID:D70C88D5-E5A1-48EC-84A4-D05DBD5CD8F6-99
DTSTART:20120218T160000
DTEND:20120218T163000
LOCATION:My Location
END:VEVENT
END:VCALENDAR

This is a really nice concept that I liked very much. If you search for info on "ical" files you will get to browse nice sweet pages including the wikepedia which has nice demonstrations/explations on what this does.

I had a scenario where I had to tinker people's outlook calendar from lotus notes. Using ical files were a really nice option. Atleast I did not find another nicer solution. Once these files are sent to users with the necessary values in it, you can have users open them and save them to their calendars.

A nice way like how xml shall mediate between different platforms. ical - I believe this will work with all major calendars. I know it works for Lotus Notes and Outlook. Yet to test on other web-based stuffs like Google Calendars. Let me know if you test them.

:)

Friday, February 17, 2012

Creating simple downloadable text file using lotusscript

Create an agent with the following Lotusscript code in it.

Print "Content-Type:application/octet-stream"

Print "Content-Disposition: Attachment;filename=""sampleDownloadAbleFile.txt"""
Print "this text is from the server"
Print "this has not been saved any where in the server"

Save the agent preview it on the web. You will be able to download a text file



Hope this helps :)

Tuesday, January 3, 2012

Bugs: "Element or Navigator is invalid" error when using NotesRichTextNavigator


-->
Let me dive straight into the point.  Assume that I have few document say five documents with a rich text item in each one of it and all of them are created using same form. So don’t bother about minor variations like missing document items etc… To make things simple let me say that these five documents are design equivalent.

Now let me say that I don’t put any values inside the richtext field in 3 document alone. So on the contrary I have values on all the 4 remaining documents.


Now assume that I have the following sort of code in an agent


On Error Goto errhandler
                …….’some code               
                Set dc=db.UnprocessedDocuments
                Set doc=dc.GetFirstDocument
                Set richStyle = session.CreateRichTextStyle
                richStyle.PassThruHTML = true
                                
                While Not doc Is Nothing
                                itr=itr+1
                               
                                Set richText=doc.GetFirstItem("myRtField")
                                Set rtnav=richText.CreateNavigator
                                                               
                                Call rtnav.FindFirstElement(RTELEM_TYPE_TEXTRUN)
                                Call richText.BeginInsert(rtNav)                   ---------------------à>> when itr=3 this line will error out with error number 4506
                                Call richText.AppendStyle(richStyle)
                                'Call rtnav.GetLastElement(RTELEM_TYPE_TEXTRUN )
                                Call richText.EndInsert
                                Call richText.Update
                                'Call doc.Save(True, False)
                                Set richText=Nothing
                                Set rtnav=Nothing
                                Set doc=dc.GetNextDocument(doc)
                                Print Cstr(itr) & " doc processed"
                Wend
                Exit Sub
errHandler:
                If Err=4506 Then Goto skiploop
                Print Error & " *** occured on line *** " & Cstr(Erl) &"*** with error number *** " & Cstr(Err)
                Exit Sub




As you may understand the since the rich text field in the third document is empty an error with number 4506 will occur.


You can say that one can handle this scenario by using some thing like “IF rtnav Is Nothing Then goto SkipLoop” etc… but it did not work so I managed to loop the control back in my error handler section.


And guess what, the object rtnav becomes unusable. I simply does not set any right values the next time the loop executes and does not accept any values. And so the following error occurs




And alas… the code breaks. Complier does not even make it to the error handler.


So sad L


I think I know a work around for that. So stay tuned

A way to handle "Element or Navigator is invalid" error when using NotesRichTextNavigator


Before attempting to create a rich text navigator, just check if the field is empty or not


                x=doc.GetItemValue("MyTextarea")
                                If isEmpty(x)="" Then
                                                Goto skipLoop2
                                End If


So this is one possible work around for the bug that I was posted earlier


Hope this helps some one J


Friday, December 16, 2011

How to run apache in a different port when its running through eclipse


One has to change the port numbers in the apache server configuration page in eclipse.
In order to reach the server configuration page, you got to do the following
>On Server tab
>Select Tomcat Server (the one you are trying to start)
>Right Click - Select Open 
This will help you reach the server configuration page.
Refer to following screen shot.

Error Starting Tomcat Server in eclipse : HTTP Status 404 error - "/" not found


 

I was facing this error for some good reason I never understood until I went through the following url.


The issue is that my server wont simply start with the error mentioned in the title.
Now I am glad that I got it to work some how. All that I did was follow the following tips provided in the above mentioned url
>On Server tab 
>Select Tomcat Server (the one you are trying to start) 
> Right Click - Select Open 
> Go to section Server Location 
>Selct Radio button for Use Tomcat Installation 
>Set Server Path to //:the_tomcat_home_location 
>Set Deploy Path to //:the_tomcat_home_location 
All that I did was change the details mentioned in the highlighted section in the following screen shot of the apache server configuration page


Hope this helps some one J

Saturday, November 12, 2011

JDBC Driver URL Format for connection with Oracle


I got the idea of testing my connectivity through JDBC with Oracle, when my attempt to connect through Hibernate in a Struts application failed.
Really I wonder like any one else about what one’s mind can do to one. In my case here it was constructive. Atleast I got to learn something J

jdbc:oracle:thin:[user/password]@[host][:port]:SID
jdbc:oracle:thin:[user/password]@//[host][:port]/SID

  user - The login user name defined in the Oracle server.

  password - The password for the login user.

  host - The host name where Oracle server is running.
         Default is 127.0.0.1 - the IP address of localhost.

  port - The port number where Oracle is listening for connection.
         Default is 1521.

  SID  - System ID of the Oracle server database instance.
         SID is a required value. By default, Oracle Database 10g Express
         Edition creates one database instance called XE.

Here are some example connection URLs:

jdbc:oracle:thin: Herong/TopSecret @localhost:1521:XE
jdbc:oracle:thin:Herong/TopSecret@:1521:XE

jdbc:oracle:thin:Herong/TopSecret@//localhost:1521/XE
jdbc:oracle:thin:Herong/TopSecret@//:1521/XE
jdbc:oracle:thin:Herong/TopSecret@//localhost/XE
jdbc:oracle:thin:Herong/TopSecret@///XE

You can find more details about the same in http://www.herongyang.com/JDBC/Oracle-JDBC-Driver-Connection-URL.html. Seems to be a real nice site

The host, port and SID details can be found in tnsNames.ora file. Following is an illustration of the same


Hence the URL formats for me were like

jdbc:oracle:thin:Karthick/Password@10.106.50.250:1521:AGH
jdbc:oracle:thin: Karthick/Password @//10.106.50.250:1521/AGH


Hope this helps some one seeking for this out there :)

"java.sql.SQLException: Io exception: The Network Adapter could not establish the connection" - A simple way to handle it


Following is a most common exception that one would face if connection to Oracle server is denied for some reason.

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection


All you got to do is ensure that you add classes12.jar to the Java build path of you Java project. You can navigate to this point by right clicking on your project and clicking on properties



Following is a sample class that I used to connect to Oracle

import java.sql.*;

public class OracleConnectionUrl {
       public static void main(String[] args) {
              Connection con = null;

              System.out.println("about to load");
              // Load the Oracle JDBC driver
              try {
                     Class.forName("oracle.jdbc.OracleDriver");
              } catch (ClassNotFoundException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
              }
              System.out.println("Oracle JDBC driver loaded ok.");

              try {
                     con = DriverManager
                                  .getConnection("jdbc:oracle:thin:karthick/password@10.116.51.215:1521:XHF");
                     con.close();
              } catch (SQLException e) {
                     // TODO Auto-generated catch block
                     e.printStackTrace();
              }
}
}

Hope this helps :)

Format Number in Java


Formatting number is something that u might always require in scenarios like, when you are trying to create a sequence number or a unique ticket number, math calculations that would require scientific notations etc. Every technology would have a provision for this. The one found is java is sophisticated.

// The 0 symbol shows a digit or 0 if no digit present
NumberFormat formatter = new DecimalFormat("000000");
String s = formatter.format(-1234.567);  // -001235
// notice that the number was rounded up

// The # symbol shows a digit or nothing if no digit present
formatter = new DecimalFormat("##");
s = formatter.format(-1234.567);         // -1235
s = formatter.format(0);                 // 0
formatter = new DecimalFormat("##00");
s = formatter.format(0);                 // 00


// The . symbol indicates the decimal point
formatter = new DecimalFormat(".00");
s = formatter.format(-.567);             // -.57
formatter = new DecimalFormat("0.00");
s = formatter.format(-.567);             // -0.57
formatter = new DecimalFormat("#.#");
s = formatter.format(-1234.567);         // -1234.6
formatter = new DecimalFormat("#.######");
s = formatter.format(-1234.567);         // -1234.567
formatter = new DecimalFormat(".######");
s = formatter.format(-1234.567);         // -1234.567
formatter = new DecimalFormat("#.000000");
s = formatter.format(-1234.567);         // -1234.567000


// The , symbol is used to group numbers
formatter = new DecimalFormat("#,###,###");
s = formatter.format(-1234.567);         // -1,235
s = formatter.format(-1234567.890);      // -1,234,568

// The ; symbol is used to specify an alternate pattern for negative values
formatter = new DecimalFormat("#;(#)");
s = formatter.format(-1234.567);         // (1235)

// The ' symbol is used to quote literal symbols
formatter = new DecimalFormat("'#'#");
s = formatter.format(-1234.567);         // -#1235
formatter = new DecimalFormat("'abc'#");
s = formatter.format(-1234.567);         // -abc1235

String pre=”xx”;
String post=”yy”;
formatter = new DecimalFormat(pre+"'abc'000000"+post);
s=formatter.format(12.3);           // xxabc000012yy

In addition to this you can also print formatted output ot the console by using System.out.format command
System.out.format("%5s", Integer.toString(n));  //     n  (- including 5 white spaces)

Hope this helps J

Wednesday, November 9, 2011

Interceptors with Struts 2


Well another mile stone to me and learning all by yourself is such a pain. Now I understand the interceptors better. After all I was having a lot of issues with them

An interceptor as the name signifies gets triggered when an action is invoked provided the action is associated with the interceptor

 First of all following is my action class

import com.opensymphony.xwork2.ActionSupport;

public class TestLoggerAction extends ActionSupport{

       public String execute()    {
      
              System.out.println("new Inside Action");
              return SUCCESS;
             
       }
}


Following is a my interceptor class. I have imported Action support class here as well in order to overrule the return value of the action. You would understand the same when you uncomment a specific code indicated in the following block of code

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class MyLoggingInterceptor extends ActionSupport implements Interceptor  {

       private static final long serialVersionUID = 1L;


       public String intercept(ActionInvocation invocation) throws Exception {
      
             
              System.out.println("Finishing execution stack for action //TestLogger");

                     //----------  Un comment this line and you will see the result of the prevention of action
                     //----------  from being executed

                     //if(true) return ERROR;  


                     //----------------------------------------------------------------------------------

              String result = invocation.invoke();
              // Post processing
      
              System.out.println("Finishing execution stack for action //TestLogger");
              return result;
       }

          //called during interceptor destruction
              public void destroy() {
                     System.out.println("CustomInterceptor2 destroy() is called...");
              }
        
              //called during interceptor initialization
              public void init() {
                     System.out.println("CustomInterceptor2 init() is called...");
              }

}

Finally my struts file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
       <package name="default" extends="struts-default">

              <interceptors>
                     <interceptor name="logger"
                           class="MyLoggingInterceptor">
                     </interceptor>

                     <interceptor-stack name="loggingStack">
                           <interceptor-ref name="logger" />
                           <interceptor-ref name="defaultStack" />
                     </interceptor-stack>

              </interceptors>

              <action name="TestLogger" class=" TestLoggerAction">
                     <interceptor-ref name="loggingStack" />
                     <result name="error">/InterceptorFailure.jsp</result>
                     <result name="success">/InterceptorSuccess.jsp</result>
              </action>

       </package>
</struts>
             
Be very very precise with the characters you type in. Case sensitivity is hell lot of issue for me. L

You will get the following page if you un comment the block of code I have indicated in the interceptor class



And the following line page if you proceed as such



And your console would contain the following info


Hope this helps  :)