Pages

Wednesday, July 27, 2011

Regular expression to remove all alphabets in a string

Regular expressions are very handly when it comes to working with patterns. In my case working with patterns in javascript. It saves me pile of code that needs to be written in javascript to do pattern based validations.

Following is a simple line of code that helps me to replace all the non digit characters from a string

var pattern=/\D/g
var myStr="80Alpha5Dog5"
alert(myStr.replace(pattern,""))

The answer would be BOSS :)

Hope that helps :)

Thursday, July 14, 2011

"Automation server can't create object" - Occuring with "ActiveXObject('Word.Application')"

This specific error occurs when your browser does not support ActiveXObjects or it does support ActiveX but the security features configured does not allow it to proceed.

Hence to fix this issue ActiveX controls must be allowed in the browser


Go to Tools -> Internet Options -> Security -> Custom Level and make the following changes under the ActiveX Controls and plug-ins section




1. Enable - Allow prompting for ActiveX controls   (optional/probable)

2. Enable - Download signed ActiveX controls

3. Enable - Initialize and script ActiveX controls not marked as safe for scripting


Hope this helps :)

Try catch doesnot catch ActiveXObject errors

I had been thinking about making a post on this for a very long time. Unfortunately for some reason , I kept forgetting about it from time to time. And at last I have even forgot that I faced such an issue in the past until recently.

As per my understanding errors that occur due to automation object creation failures when attempting to create ActiveX Objects can't be handled by try catch block. Instead, one must check it right up front to give the desired error message to the user.

the following is a simple illustration of what i am speaking about,

try{
...
var obj=new ActiveXObject("Blah blah blah");   // suppose error occurs in this statement
...
} catch (activeXError) {
  // the error that occured due to active x object creation failure does not get captured here and hence any
  //code that you exectute here does not get executed. Rather you can find an abrupt error message in the
  //console
}

So in order to handle it, you must check it upfront,

if (window.ActiveXObject) {
  ... blah blah blah....
} else {
  // report error
}

Hope that helps :)

Thursday, July 7, 2011

Regular Expression to filter HTML Tags

Following is a simple way by which one can filter out the html tags say from ajax responses etc…


normalString=htmlString.replace(/<\/?[^>]+(>
$)/g, "");

inorder to filter out carriage returns one can use

String. replace(/\n/g, "");

AJAX Post Request in Lotus Notes

Following is a short abstract of how you can create AJAX POST request.


One can always find a way to create an XMLHTTPREQUEST and many cross browser solutions are available across the internet. eg w3schools. So if leave the function call in the very first line for you to code.



var mypostrequest=new ajaxRequest()

//handle the response

mypostrequest.onreadystatechange=function(){

if (mypostrequest.readyState==4){

if (mypostrequest.status==200

window.location.href.indexOf("http")==-1){

//handle your response here

}

}

}

//open a post request

mypostrequest.open("POST", “your agent url", true);

mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

//sample parameter

Var parameters = “label=value&process=post”

//send in the parameters to be processed in the lotus script agent

mypostrequest.send(parameters);

Friday, July 1, 2011

Eclipse Plugin for Tomcat Server with Hello World

The following site seems to be a good source for downloading and installing a Tomcat Server plugin for Eclipse.
All you got to do is download this plugin and proceed with the following procedure to install them
  • This plugin does not contain Tomcat.
    (Download and install Tomcat before using this plugin).
    This is a design choice not to include Tomcat in the plugin distribution, this way the same plugin version can works with any Tomcat version.
  • Download tomcatPluginVxxx.zip
  • Unzip it in :
    - Eclipse_Home/dropins for Eclipse 3.4, 3.5 and 3.6
    - Eclipse_Home/plugins for Eclipse 2.1, 3.0, 3.1, 3.2 and 3.3
  • Plugin activation for Eclipse 3.x :
    - launch eclipse once using this option :
     -clean
    - if Tomcat icons are not shown in toolbar : select menu 'Window>Customize Perspective...>Commands', and check 'Tomcat' in 'Available command groups'
  • Set Tomcat version and Tomcat home : Workbench -> Preferences, select Tomcat and set Tomcat version and Tomcat home (Tomcat version and Tomcat home are the only required fields, other settings are there for advanced configuration).
  • This plugin launches Tomcat using the default JRE checked in Eclipe preferences window.
    To set a JDK as default JRE for Eclipse open the preference window : Window -> Preferences -> Java -> Installed JREs.
    This JRE must be a JDK (This is a Tomcat prerequisite).
The plugin sets itself Tomcat classpath and bootclasspath. Use Preferences -> Tomcat ->JVM Settings, only if you need specific settings.

 
The following site contains an awesome example/illustration that will help you get started with the plugin on eclipse
Once you have installed the plugin, the following are the things that you need to have a closer look at.
You would be able to see 3 icons added to the eclipse tool bar which is as illustrated in the following image . And these are  self explanatory

Go to Windows->Preferences. This will bring up the Preferences dialog box, that will contain a whole new section as highlighted in the navigation section.  And on the right side you have to choose your Tomcat version and provide its installation path as Tomcat home

Specifying the tomcat home helps the plugin assume the path of the server.xml file which in my case is as follows

Well you may not do much with this one for the time being, but its always good to know right J
Once that’s done, Navigate to the Tomcat Manager App option available in the left menu of the preferences window as illustrated by the following image

Now when you provide a ManagerApp username and ManagerApp password, and click on “Add user to tomcat-users.xml”, this will update the corresponding xml file as illustrated by the following image


As you can see, the username and password are abruptly visible and hence exercise caution in handling these files to avoid security breaches
Once the above stuffs are complete now create a new project by right clicking the navigator as illustrated in the following images
 
So create a new tomcat project as mentioned above and now name them as per your requirement and in this case it is “HelloWorld” and create your servelet classes as illustrated in the following image. Mind the folder structure :)
 

Now create your web.xml file in the same WEB_INF folder and not in the src folder that is highlighted above with servelet mappings to class file and url, in my case the web.xml file contains
DOCTYPE web-app PUBLIC
  '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
  'http://java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
  <servlet>
    <servlet-name>helloservlet-name>
    <servlet-class>HelloServletservlet-class>
  servlet>

  <servlet-mapping>
    <servlet-name>helloservlet-name>
    <url-pattern>/hellourl-pattern>
  servlet-mapping>
web-app>
Now save all your work. Start your tomcat server and check out the following url,
In my case the pages looks like the following


The materials contained here are more exhaustive than the one posted here.

Hope this helps :)

 
 
 

Thursday, June 30, 2011

Illustration of Wiring Concept in Composite Applications – Lotus Notes 8.5.2

Let images talk :)
1.
 
2.
3.

4. 
5.

6.
7.
8.
 
9.
 
10.
 
11.
 
12.
 
13.
 
14.
 
15.
16
 
17.
 
18.
 
19.

20.

21.

Hope this helps :)

Using Notes Outline for navigation in composite application

1.    Create a new composite application
2.    Create a new outline with the specifications as illustrated by the image
 
3.    Now embed the out line into a page and name it as the “Main Page” as illustrated in the following image

4.    Now Open up the Composite Application Editor (CAE). And open up the Page Navigator properties as illustrated in the following image
5.    Now ensure that the properties highlighted in the following screen shots are set accordingly. U may have to manually add them if you don’t find them
 
6.    The useNavigator setting tells the CA subsystem that we want a navigation system and the navigationModel setting equalling "custom" tells it that we will provide our own page switcher

7.    Now add 3 pages to the CAE as illustrated in the following images
 
8.    You would see a screen as follows in the Left margin in CAE
9.    Now select eacha and every page in the left section of the CAE and add a “Managed Browser” section to each of them as illustrated in the following image
10.    Now edit the component properties of all these managed browsers and give them a target url as illustrated in the following images

11.    Once that is done, save and close your CAE and preview your application on the Notes Client as illustrated in the following figure
12.    And you would be viewing something similar to the following

Wednesday, June 29, 2011

Understanding the CAI URL

CAI stands for “Computer Assisted (or-Aided) Instruction”.
CAI URLs are special URLs that are used in Composite applications to launch an application or to switch between a pages with in or across composite applications.
The CAI URL is broken into several parts, most of which are optional in many cases.


SYNTAX


 cai://[GUID]/[Page Id]?[pagealias][hint]
Where,
[GUID] - the optional GUID for the application. This parameter is actually not needed at all as long as the [Page Id], [pagealias], or the [hint] is specified.

[Page Id] - this is essentially the Eclipse perspective Id. Also an optional parameter if the [pagealias] or [hint] is specified.

[pagealias] - this corresponds to the com.ibm.rcp.alias parameter in the pages for a composite application. By including this parameter with a blank [GUID] and blank [Page Id] the composite application framework will attempt to open the page with the matching pagealias in the current application.Lotus Notes 8.5.2 and Lotus Expdeitor 6.2.2 and above.

[hint] - the url hint is used to tell the composite framework where to get the file for this cai url. The hint can be any kind of addressable URL: file, http, nrpc. The hint is the actual .ca file



Sample URLs and their behaviors



cai://?hint=http://acme.com/mycompapp.ca
- This will open the application stored at the http site and show its first visible page
- This will process the .CA file and install any features referenced by the .CA
- If any features are installed this will require a restart of the product

cai://DB1F567B0E6F6784084D923134028D4C_8525764000063159
- This will open an already installed application with the following GUID
- If the application is not installed it will error out.
- The first visible page will be opened
- If the hint URL is specified then this will process the .CA file and install any features referenced by the .CA. If any features are installed this will require a restart of the product

cai://DB1F567B0E6F6784084D923134028D4C_8525764000063159/BD973A4E8C0FCDED54C69CB23940B5FC_6_3KE527R200VQ502MGJOIMC20H7
- This will open an already installed application with the following GUID
- If the application is not installed it will error out.
- The page with the [Page Id] will be displayed.
- If the hint URL is specified then this will process the .CA file and install any features referenced by the .CA. If any features are installed this will require a restart of the product

cai://?hint=nrpc:/__8525729D0030946C/composite.xml?file=MyCompApp.nsf&name=CompAppMain
- This will install and launch the composite application from a Lotus Notes database using the nrpc URL.

cai://?pagealias=First Page
- This launches the page in the currently opened composite application with the com.ibm.rcp.alias set to "First Page"
- If the pagealias is not found in the current application the user will see an error dialog.

cai://?pagealias=First Page?hint=http://acme.com/mycompapp.ca?ColorScheme=Blue&Font=Arial
- This launches the page in the currently opened composite application with the com.ibm.rcp.alias set to "First Page"
- The application at the hint will be checked for an update prior to opening the page
- If the pagealias is not found in the current application the user will see an error dialog.
- The ColorScheme and Font parameters will be available as preferences for all components on the page.


Computing a cai URL in formula language



The following can be used to simply show a page in the same composite NSF from formula language as a URL:

"cai://?pagealias=Page 1"


The following snippet of code can be used in a Notes outline to show a specific page (using the [pagealias] parameter) and optionally install or update the composite using the [hint] parameter.

rep_id := @Left(@ReplicaID; 8) + @Right(@ReplicaID; 8);

"cai://?pagealias=Page 1&hint=nrpc:/__" + rep_id + "/composite.xml?file=PlayWithNavigator.nsf&name=CompAppMain"

Note :
1.    nrpc stands for  Notes Remote Procedure Calls
2.    The next section titled “Using Notes Outline for navigation in composite application” shows  CAI URL in action

GUID of a Composite application

GUID stands for Global Unique Identifier. Hope the title makes sense now. This section will simply help you understand how you can get the GUID of a composite application.

In the following screen shot of a composite application, I have an action button which upon clicking gets me the GUID if the application.


This is possible when you code the button with a formula as follows  


So the trick is – hmmm its simple - @GetGUID
And the lotus script equivalent is as follows