Thursday, March 29, 2007

small tribute

Here's my tribute to the domino blogosphere. Instead of creating a blogroll list which is already a creepy process (nothing automatic, no import/export of OPLM file, write/maintain the list by hand), I am dynamically posting 10 latest posts from my public 'domino' feed from Google Reader.

I've tried in the past creating my blogroll and quickly drop the idea. Like I didn't had enough things to maintain by hand ...

So, turns out this Google Reader isn't a bad thing afterall, at least for this purpose.
Please let me know if you don't want your posts to appear here on this site, I hope you don't mind that :)

println 8192 chars limitation

I came across this strange (or not) limitation when writing a Domino Java agent.

Did I mentioned about json+jquery+domino new loving combination ?

So, I was designing a Java agent which is using my json.jar archive (compiled for Java 1.3 used by Domino 6 server). This agent would have the sole purpose of receiving a querystring parameter, hit a database, grab a view, grab the collection of all viewentries with a getAllEntriesByKey and returning a json string, all this part of a $.ajax call (google for jQuery).

The returned string (looked internally with Fiddler, then analysed with JuJuEdit) contained the non printable 'Enter' char each 8129 characters, thus breaking the meaning of my json String returned to the browser.

Lesson learned: do not return more than 8129 chars when designing Domino Java agent in one println statement.

sketch code before:

JSONArray jsonArray = new JSONArray();
while (viewEntry != null) {
....
JSONObject jsonObject = new JSONObject();
jsonObject.put("objAttr", objValue);
......
jsonArray.put(jsonObject);
jsonObject = null;
viewEntry = viewCollection.getNextEntry(viewEntry);
}
PrintWriter toBrowser.println (jsonArray)


as you see, I'm builing an array of jSon objects (jsonArray), which is thrown away in one println statement outside of the loop. Ntz, not good. If jsonArray contains more than the limit, the meaning of it is breaking.

Instead, I am now doing this:


toBrowser.println("["); //open the array by hand, drop jsonArray variable
while (viewEntry != null) {
....
JSONObject jsonObject = new JSONObject();
jsonObject.put("objAttr", objValue);
......
toBrowser.println(jsonObject + ",");
jsonObject = null;
viewEntry = viewCollection.getNextEntry(viewEntry);
}
toBrowser.println("]");


Now it's more like it: I am throwing back to browser each of the jsonObject, making sure to respect the jSon syntax (add a comma in the string).

One quick catch: last useful object in this string will contain a ',' which means in fact last jSon Object is null. So make sure in the browser, after the eval() compilation, when you loop the results, make the loop as:
for (var i=0 ; i < resultsObj.length-1 ; i ++)

If any guru will be reading this I'm hoping to hear more details about this limit. Is it of Java println ? Is it of Domino Java ? Am I too stupid for not knowing this before hand ?

Monday, March 26, 2007

this is way to funny not to mention ...

Though I've only declared to my friends, I think it won't hurt it for everybody to know: I will not work with Vista. Period. I don't want to learn anything about it, I don't want to install it on my working computers, I don't want to know about it. The same 'strategy' is true for the new Office version. At least for my common day-to-day tasks and work. Win XP and the current Office version are enough. More than enough. For diversity I'm digging Linux and OpenOffice. And Domino. And Java.

If by accident I will be hired by MS (which I doubt), I'll have to live with it. But they will have to pay me THE big bucks for me to work with Vista :)

Is this a bad decision ? Maybe so, maybe not ...

And here it is, maybe not ... reading Ed Brill's log regularly, this article came into my path: Dear Bill Gates (again)

Take the time and patience to read them (also the comments), worth the time spend. And probably you'll make you think twice before 'upgrading' to Vista and the next Office version.

difference about quotes and non-quotes in HTML select

I usually use a computed value with a dbcolumn to display values in a combo (the select HTML tag)
Suppose your returned HTML source looks like this:


<select id="mySelect" >

<option value=value 1>entry 1</option>

<option value=value 2>entry 2</option>

<option value=value 3>entry 3</option>

</select>



This bad ... the value attribute of should always be surrounded by quotes. Otherwise, jQuery will return only 'value' in IE (read that this is acceptable for FireFoxie, didn't verify, though)

So, always add an extra \" into my computed values, so that I will get:

<select id="mySelect" >

<option value="value 1">entry 1</option>

<option value="value 2">entry 2</option>

<option value="value 3">entry 3</option>

</select>


hmm, talk about little difference which wasted an hour of my time ... doh

Sunday, March 25, 2007

firefox 2 -> 2.0.0.2 upgrade on fedora 6 64bit proc.

having fun with linux ? me too, specially when things finally works.

I upgraded my firefox installation from 2.0 to 2.0.0.2, using :
yum -y -t –enable=development update firefox
(via this)

then imagine what, I found that java plugin was no longer working. While I fixed this when I first installed Fedora Core 6, I have forgotten that running 64bit Firefox will break any 32bit plugin, including Java and Flash.

So, I found myself having the two versions of Firefox (32 and 64bit):

> sudo yum list installed | grep firefox
firefox.x86_64 2.0.0.2-2.fc7 installed
firefox.i386 2.0.0.2-2.fc7 installed

good, it means that by default the 64bit is launched, I needed to launch the 32bit version instead.
What to do ? this article , while shows a how-to for Firefox 1.5, provided the idea: I've made a copy of /usr/bin/firefox and rename it as /usr/bin/firefox-32.sh; then, I've edited the renamed script. I found below declarations and the simple and fast track was to remove the '64' string, so that this firefox-32.sh script would only use /usr/lib instead of /usr/lib64.

##
## Variables
##
MOZ_ARCH=$(uname -m)
case $MOZ_ARCH in
x86_64 | ia64 | s390 )
MOZ_LIB_DIR="/usr/lib64"
SECONDARY_LIB_DIR="/usr/lib"
;;
* )
MOZ_LIB_DIR="/usr/lib"
SECONDARY_LIB_DIR="/usr/lib64"
;;
esac


I'm sure there are more elegant solutions, this one was simple enough and did the trick. Since I used to have all the fancy plugins working (in the 2.0 version), I didn't need to do anything else. It just worked, plain and simple.

Thursday, March 22, 2007

notes/domino ibmers

My feed reader of choice is the Google Reader.

At this moment, my domino-related blogosphere contains 30 feeds. Some of them are ibmers. Which ones ? Let's see: Domino IBMers

Cool list ... keep it growing

Thursday, March 15, 2007

quick one about why firefox does not load images

This is for Firefox 2.x on Windows. To me its the preffered browser, however it didn't load all the images. If you browse this blog and cannot see in Firefox the beautiful thumb of the screenshot in my previous article, check this:
- type about:config in your browser's URL, hit enter.
- filter and find permissions.default.image and change the value (double click the entry) to 1.

found this info via: mozillazine

how about this ?!



What can I say ? WOW !! So we really have a linux client for Domino 8 !! I didn't belived it truly until I've installed it on my home Fedora box. And it really installed, even with my low linux knowledge. After downloading the *.tar, launched the setup.bin, few clicks, need to disable XGL effects (something for eclipse as well on linux) and it basically installed itself. It even kept the well known /domino and /domino/data paths which I love (I always know where to look for binaries and/or data)

Now, where's the Designer and Admin client on linux ? not yet ? no problems, I can wait :) Then windoze will be bye bye at home :)

Monday, March 12, 2007

I feel like starting over ....

Is this good ? Is this bad ? 5+ years of Domino drilling down the drain ... this is my feeling after finished downloading and sparringly looking into the *.pdfs which came with the Lotus 8 Public Beta 2

I public declared I'm not interested in Domino 7, I was expecting Domino 8. And now it came... and I sincerely have the feeling that my PCLP is close to useless :) Have to start all over again ... in terms of learning the Domino environment. Not that I've ever stopped, it's just that I could install a Domino server with my eyes closed (at least on windoze), not sure this would be possible anymore.

linux for an entire sunday

While my fellow blogger Ferdy switched to Ubuntu - called him a 'traitor' as I'm on Fedora, hope he doesn't mind that :) - I'm gonna share with you what I managed to do the entire Sunday.

For a linux security expert like my friend Florin which is handling the www.riss.ro this would have taken 20 minutes ... it took me the entire day. doh ...! But finally I'm quite proud of myself for finally not requesting any help and doing it my own way (google is my friend)

So, here the story goes: my wife (as always, women cause all the trouble ...) choose to add to the house a second computer.

All good for me as I will no longer have to let her share my computer, you say :) Well, yes, that too. But I had to make this second computer share the single IP on my computer, as the provider will not allow two home computers without extra payment. Since I am not going to extra pay for my wife's browsing, I needed to digg into NAT'ing and iptables of my Fedora Core 6 installation.

This is what I did:
- I installed a second network card on my computer and connected with a crossover cable to the second machine. So I have eth0 device with external IP given by the provider, and the eth1 device with 192.168.1.1/24 statically asigned. My wife's computer got the 192.168.1.2/24. This was the easiest part :)
- Testing connection between the two computers, everything works.
- It took me the entire day googling and reading to finally end up with the following /etc/rc.local file:

# add a static route to the internal host (not sure why it didn't worked without it)
/sbin/route add -host 192.168.1.2 dev eth1

#load the NAT module of iptables
modprobe iptable_nat

#tell the system we want to route
echo 1 > /proc/sys/net/ipv4/ip_forward

#mangle with the TTL on eth0. The provider thought that setting TTL=1 would stop me :)
/sbin/iptables -t mangle -A PREROUTING -i eth0 -j TTL --ttl-set 64
/sbin/iptables -t mangle -A OUTPUT -j TTL --ttl-set 64

#enable masquerading (or NAT) between external eth0 and the internal network
iptables -A POSTROUTING -t nat -o eth0 -s 192.168.1.0/24 -d 0/0 -j MASQUERADE
iptables -A FORWARD -t filter -o eth0 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -t filter -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

#finally, allow DNS queries from internal network
iptables -A OUTPUT -p udp -o eth1 --dport 53 --sport 1024:65535 -j ACCEPT
iptables -A INPUT -p udp -i eth1 --sport 53 --dport 1024:65535 -j ACCEPT

above instructions would be better in another file which could be loaded by /etc/rc.local. However, this did the trick, now I can have the computer for myself :)

I would also evaluate switching to Ubuntu (Ferdy's article triggered the curiosity), however I've done some things on my fedora which would be rather annoying to remember and do again on ubuntu. Then, what is the fun with linux if not digging with google how to do certain things ? If Ubuntu works kind of 'out of the box', I would miss the entire fun of discovering new things :)

For instance, the next challenge on my fedora is to discover how to configure udev and hal to perform automounting and gnome linking of an external usb hdd (80gb) which I've been recently using. Manually mounting works beautifully, but it won't automount. If this would work in Ubuntu, I wouldn't learn about udev and hal, would I ?

Thursday, March 08, 2007

phone rintones

does free ringtones enter the FOSS (free and open source software) category on this blog ? I choose to define it so, because I've just run on a cool site providing free ringtones: http://www.ringtonesoup.com

Tuesday, March 06, 2007

json with domino servlets

I have a domino servlet which basically receive a GET like: http://myserver/servlet/displayfolder?fld=name_of_folder

and should return that folder's server databases with couple of information: pathfile,database title,template name of the database.

Before discovering JSON, I've created my own convension for this string of parameters. The response to the browser was parsed by custom JS code, respecting my chosen syntax. This was not good, this was not standard but it worked.

Starting my JSON discovery (every day we learn something new), I've also learned that my required information about a server's folder can be put in a JSON string as following:

[{path:folder1\aaa.nsf,title:title_aaa,template:template_aaa},
{path:folder1\bbb.nsf,title:title_bbb,template:template_bbb},
{path:folder1\ccc.nsf,title:title_ccc,template:template_ccc}]

Above string is an JSON Array containing three JSON Objects, each with the path,title,template attributes (read http://json.org for more details about the syntax)

Now comes the big question: how to generate above from within my Domino servlet ? Fortunatelly, there are some JSON Java classes which comes to help.

In fact there are several frameworks for working with JSON under Java. For me as Domino dev, the first choice does the trick, as I'm gonna show you.

So, my objective was to add support for JSON into the Domino server JVM, available for my servlet.
- From the mentioned page I've downloaded the json.zip archive which contains all the *.org.json classes as source code.
- Next, I've added these classes to my eclipse project where I play with the Domino servlets - no, I'm not gonna tell you how to work with eclipse+domino, there are plenty of good articles already written :)
- build the eclipse project so that I could get the .class of the json libraries.
- archived the compiled classes into a json.jar archive
- upload the json.jar into domino\jvm\lib\ext on the server, so that they're available to other servlets I will be playing with (now jQuery/JSON is for me a standard when I talk about domino-ajax apps)
- give the server a restart and rethink the servlet, which now has the following code on the doGet function:


...
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import lotus.domino.Database;
import lotus.domino.DbDirectory;
import lotus.domino.NotesException;
import lotus.domino.NotesFactory;
import lotus.domino.NotesThread;
import lotus.domino.Session;
...

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

try {
res.setContentType("text");
PrintWriter toBrowser = res.getWriter();

NotesThread.sinitThread();
Session session = NotesFactory.createSession();

String query = req.getQueryString();
String searchFolder = parseQueryString (query);
if (searchFolder == null ) {
throw (new ServletException ("servlet should receive a query param like &fld=")); }

DbDirectory dir = session.getDbDirectory(null);
String server = session.getServerName();
Database db = dir.getFirstDatabase(DbDirectory.DATABASE);

//create the JSON Array which will hold all other objects
JSONArray jsonArray = new JSONArray();

//loop though all server databases
while (db != null) {
String fp = db.getFilePath();
StringTokenizer fpTokens = new StringTokenizer (fp, "\\") ;
while (fpTokens.hasMoreTokens()){
String token = fpTokens.nextToken().toLowerCase();
// System.out.println(token);
if (token.equals(searchFolder.toLowerCase())){
JSONObject jsonObject = new JSONObject();
String file = fp ;
String title = db.getTitle();
String template= db.getDesignTemplateName();

jsonObject.put("file", file);
jsonObject.put("title", title);
jsonObject.put("template", template);
jsonArray.put(jsonObject);
jsonObject = null ;
}
}

db = dir.getNextDatabase();
}
toBrowser.print(jsonArray) ;
session.recycle();
}
catch (JSONException e) {
e.printStackTrace();
}

catch (NotesException e) {
e.printStackTrace();
}
catch (ServletException e) {
e.printStackTrace();
}
finally {
NotesThread.stermThread();

}
}


please criticize me for the Java code, i'm kind of a newbie, I'm sure this can be improved :)

If you code Java agents instead of servlets, I'm sure you can get the same Java source classes and add them directly into your agent. I think it will grow its size, though ... Or you can pack the compiled classes into a similar json.jar and import it into the Java agent.

What I was surprised about was that no compilation errors were thrown, which makes JSON available in Domino Java agents or servlets starting at least with Domino 6.5.x which is my current server version.

Disclaimer: The information in this weblog is provided "AS IS" with no warranties whatsoever, and confers no rights to any institution/person/organization. These are my personal thoughts and ideas. When I am inspired by others I give credit, I do not assume other's work and efforts. This site is NOT supported, approved, blessed etc. by Lotus Software and/or IBM Corporation.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 License.