Documentation

I was given a task to list down all controls and theirs labels along with some other attributes like style, style class, parent id, etc and prepare an Excel sheet. It was so boring and tedious task for me. This is a repetitive task in which I need to copy attributes value and paste it to the Excel sheet. I decided to automate this task and wrote this piece of code which simplifies my task drastically.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var Doc = {
    generate : function (xpage, parent) { //fpfPr(xpage.getId())
        var itr = xpage.getChildren().iterator();
        while(itr.hasNext()) {
            var c:com.ibm.xsp.component.xp.XspScriptCollector = itr.next();
            if(!parent) parent = xpage;
            var p = xpage;
            if(p && p.getId() && !p.getId().match(/^_id/i) && !p.getId().match(/^event/i) && !p.getId().match(/^selectItem/i) && !p.getId().match(/^dateTimeHelper/i) && !p.getId().match(/^br/i)) {
                parent = xpage;
            }
            if(c.getId() && !c.getId().match(/^_id/i) && !c.getId().match(/^event/i) && !c.getId().match(/^selectItem/i) && !c.getId().match(/^dateTimeHelper/i) && !c.getId().match(/^br/i) && !c.getId().match(/^typeAhead/i) && !c.getRendererType().equalsIgnoreCase('com.ibm.xsp.PassThroughTagRenderer')) {
                var d:NotesDocument = database.createDocument();
                d.replaceItemValue("Form", "fDoc");
                d.replaceItemValue("control", c.getId());
                if(parent) d.replaceItemValue("parent", parent.getId());
                d.replaceItemValue("type", this.getType(c.getRendererType()));
                
                if(!d.getItemValueString("type").equalsIgnoreCase("Output Script")) {
                    if(this.getType(c.getRendererType()).equalsIgnoreCase('View Panel')) {
                        d.replaceItemValue("style", c.getViewStyle());
                        if(c.getViewStyleClass()) {
                            d.replaceItemValue("styleClass", c.getViewStyleClass().match(/^xsp/i) ? "" : c.getViewStyleClass());
                        }
                    } else {
                        try {
                            d.replaceItemValue("style", c.getStyle());
                        } catch(e) {
                            if(e.getClass().getName().equals('com.ibm.xsp.exception.EvaluationExceptionEx')) {
                                d.replaceItemValue("style", '<computed>');
                            } else {
                                d.replaceItemValue("style", c.getStyle());
                            }
                        }
                        
                        try {
                            if(c.getStyleClass()) {
                                d.replaceItemValue("styleClass", c.getStyleClass().match(/^xsp/i) ? "" : c.getStyleClass());
                            }
                        } catch(e) {
                            d.replaceItemValue("styleClass", "</computed><computed>");
                        }
                    }
                }
                
                if(this.getType(c.getRendererType()).equalsIgnoreCase("Editbox")) {
                    if(c.getId().equalsIgnoreCase('xc_AppPath')) {
                        d.replaceItemValue("defaultValue", "Application path defined in global parameters");
                    } else if(c.getId().equalsIgnoreCase("xc_AuditLogKey")) {
                        var lsAType:java.lang.String = c.getDefaultValue().split('_');
                        d.replaceItemValue("defaultValue", lsAType[0] + '_@Unique()');
                    } else if(c.getId().equalsIgnoreCase("xc_ServerName")) {
                        d.replaceItemValue("defaultValue", 'Application server name');
                    } else {
                        try {
                            d.replaceItemValue("defaultValue", c.getDefaultValue());
                        } catch(e) {
                            d.replaceItemValue("defaultValue", "</computed><computed>");
                        }
                    }
                }
                if(this.getType(c.getRendererType()).equalsIgnoreCase("Button")) {
                    try {
                        d.replaceItemValue("label", c.getValue());
                    } catch(e) {
                        if(e.getClass().getName().equals('com.ibm.xsp.exception.EvaluationExceptionEx')) {
                            d.replaceItemValue("label", '</computed><computed>');
                        } else {
                            d.replaceItemValue("label", c.getValue());
                        }
                    }
                } else {
                    var l = c.getId().replace(/xc_/i, '').replace('_', ' ');
                    d.replaceItemValue("label", l);
                }
                d.save(true);
            }
            
            this.generate(c, parent);
        }
    },
    
    getType : function(classname) {
        if(classname.equalsIgnoreCase("com.ibm.xsp.LineBreak")) {
            return "LineBreak";
        } else if(classname.equalsIgnoreCase("javax.faces.Text") || classname.equalsIgnoreCase("javax.faces.Secret")) {
            return "Editbox";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.DateTimeHelper")) {
            return "Datetime/Editbox";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.Text")) {
            return "Computed Field";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.ButtonEx")) {
            return "Button";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.LinkEx")) {
            return "Link";
        } else if(classname.equalsIgnoreCase("javax.faces.Menu")) {
            return "Combobox";
        } else if(classname.equalsIgnoreCase("javax.faces.Radio") || classname.equalsIgnoreCase("com.ibm.xsp.Radio")) {
            return "Radio Button";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.Checkbox")) {
            return "Checkbox";
        } else if(classname.equalsIgnoreCase("javax.faces.Textarea")) {
            return "Multiline Editbox";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.Table")) {
            return "Table";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.TableCell")) {
            return "Table Cell";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.TableRow")) {
            return "Table Row";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.Section")) {
            return "Section";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.ImageEx")) {
            return "Image";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.Div")) {
            return "Div";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.OutputLabel")) {
            return "Label";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.OutputScript") || classname.equalsIgnoreCase('com.ibm.xsp.component.xp.XspOutputScript')) {
            return "Output Script";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.ViewPanel")) {
            return "View Panel";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.ViewColumn")) {
            return "View Column";
        } else if(classname.equalsIgnoreCase("javax.faces.Panel")) {
            return "Panel";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.DataIterator")) {
            return "Repeat Control";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.TableEx")) {
            return "Data Table";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.Column")) {
            return "Data Table Column";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.XPager")) {
            return "Pager";
        } else if(classname.equalsIgnoreCase("com.ibm.xsp.Include")) {
            return "Custom Control";
        } else {
            return classname;
        }
    }
}

Paste above code in the script library and following code in afterPageLoad event of XPage

1
Doc.generate(view, null);

Now preview your XPage into the browser. A list of documents has been created in the application with form name fDoc. Create a view to display all these documents and its field values.

CakePHP to Red Hat’s Openshift

There is only 6 easy steps to deploy your application to cloud.

Step 1 : Sign Up

Just visit to openshift and sign up a new account.

Step 2 : Install client tool

For installation instruction of client visit here

Step 3 : Create domain

1
$ rhc domain create -n <mydomain> -l <openshift login>

Domain is the unique namespace for every account. Execute following command to create your domain

1
$ rhc domain create -n mydomain -l test@abc.com

Step 4 : Create application

1
$ rhc app create -a -t

app name is the name of your application ant app type is the type of application you want to create. For a php application we execute following command:

1
$rhc app create -a mycake -t php-5.3

Step 5 : Add MySQL to your application

1
$rhc app cartridge -a mycake -c mysql-5.1

Step 6 : Deploy your application to cloud
Once the application is created, it needs to deployed to cloud. After execution of step 4, a folder with the application name is created in current directory. Goto current directory and add cakephp to it.

1
2
3
4
5
6
7
$ cd mycake
$ git remote add upstream -m master git://github.com/openshift/cakephp-example.git
$ git pull -s recursive -X theirs upstream master
$ git push

 

You can access your application from the URL :

http://mycake-mydomain.rhcloud.com

Rashid’s Socialize Button

Now I am back with my new plugin. With help of this plugin you can share your post on GooglePlus, twitter and facebook.
You can also download this plugin from here

Installation:

Download the plugin.

Upload to your blog (/wp-content/plugins/).

Activate it.

You are done!

Rashid’s Facebook Like Box Plugin for WordPress

I was searching for a plugin to add Facebook Like Box on my blog but I did not found any suitable plugin which suits my purpose. I found few plugins at WordPress.org but they don’t support my wordpress version. So I decided to write my own plugin. You can also download it and use it at your wordpress blog as well. Click here to download the plugin.

Installation:

Download the plugin.

Upload to your blog (/wp-content/plugins/).

Activate it.

Click the RA-FB Like Box.

Fill in the options.

Then go to widget and drag and drop Rashid’s Facebook Like Box in the area you want to display the plugin.

XPage – Sort View Column

I was searching for a work around to allow view column to be sortable by clicking on column header but I was not able to find any reliable solution using View Panel. Now I found a way to provide this feature using Repeat Control or Data Table.

Please go through the following code.

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var loView:NotesView = null;
var loEntryColl:NotesViewEntryCollection = null;
var loTreeMap:java.util.TreeMap = new java.util.TreeMap();
var lsSortBy = viewScope.get("sortBy");
try {
    loView = database.getView("view");
    if(null == lsSortBy || "" == lsSortBy) {
        lsSortBy = 0;
    }
    
    if(null != loView && loView.getEntryCount() > 0) {
        loEntryColl = loView.getAllEntries();
        var loEntry:NotesViewEntry = loEntryColl.getFirstEntry();
        var loTempEntry:NotesViewEntry = null;
        while(null != loEntry) {
            loDoc = loEntry.getDocument();
            var lsKey = loEntry.getColumnValues().get(lsSortBy);
            
            while(loTreeMap.containsKey(lsKey)) {
                lsKey += "~";
            }
            loTreeMap.put(lsKey, loEntry.getColumnValues());
            
            loTempEntry = loEntryColl.getNextEntry(loEntry);
            loEntry.recycle();
            loEntry = loTempEntry;
        }
    }
} catch(e) {
    print("Error : " + e);
} finally {
    if(null != loView) loView.recycle();
    if(null != loEntryColl) loEntryColl.recycle();
}
return loTreeMap.values();

In line 3 I am defining a TreeMap data structure. By definition TreeMap is sorted according to its natural ordering of its keys.

Since the data structure is always sorted so we can insert NotesViewEntry column values to the TreeMap and the corresponding column value (by which the view needs to be sorted) should be passed as key.

Look at line no 17 I am forming the key by which the view needs to be sorted. By default it is first column value.

At this point of time the only thing which creates problem is the duplicate values of the key. In TreeMap the value is overwritten if the key is already existing.

From line 18-21 I am appending additional character to make the key unique.

In line 37 I am returning value set from the TreeMap which is already sorted by key.

Rest of the code is quite easy to understand. I hope it may help in your application.