Category Archives: Domino

Java JSONWriter Domino Agent Class

If you’re like me, in the coarse of your web development years with Domino you’ve had to create plenty of agents that need to output little bits of JSON as output to the browser for some reason or another. Since these were just bits of JSON here and there, I created the code to do this from scratch every time I made a new agent — not the best way to do things, but it worked. I eventually got tired of that and created a small helper class for Java that simplified this process.

Simply add it to your Java agent, and then initialize it with a “JSONWriter.start()”, passing “getAgentOutput()” as the sole parameter. This can be done from anywhere in your code, as long as it’s before whenever you try to start printing JSON output. Just pass the string name of your JSON parameter, followed by either a string, variable, or boolean value. Close up the stream with “JSONWriter.end()” whenever you’re finished.

(I have a git repo of this code at https://github.com/mdmadph/mdmjava.)

package util;

import java.io.PrintWriter;
import lotus.domino.NotesException;

/**
* @author mdm-adph
*
*/
public class JSONWriter {

/**
*
*/
private static PrintWriter printOutput = null;

/**
*
*/
private static boolean firstParam = true;

/**
* Default constrctor.
* @constructor
*/
private JSONWriter() throws NotesException {
}

/**
* Initializes the JSONWriter singleton with the desired PrintWriter
* @param pOutput {PrintWriter}
* The PrintWriter object to associate with JSONWriter,
* usually the result of getAgentOutput()
*/
public static synchronized void start(PrintWriter pOutput) {
if (printOutput == null) {
printOutput = pOutput;

printOutput.println("Content-type: application/json");
printOutput.println("{");
}
}

/**
* Internal function that prints the actual JSON information
* @param param {String}
* The string value of the JSON parameter name.
* @param value {String}
* The value of the JSON parameter.
*/
private static synchronized void printLine(String param, String value) {
if (firstParam) {
firstParam = false;
}
else {
printOutput.println(",");
}

printOutput.println(""" + param + "":" + value);
}

/**
* Public interface for printLine() for string params
* @param param {String}
* The string value of the JSON parameter name.
* @param value {String}
* The value of the JSON parameter.
*/
public static void print(String param, String value) {
printLine(param, """ + value + """);
}

/**
* Public interface for printLine for integer params
* @param param {String}
* The string value of the JSON parameter name.
* @param value {int}
* The value of the JSON parameter.
*/
public static void print(String param, int value) {
printLine(param, Integer.toString(value));
}

/**
* Public interface for printLine for Boolean params
* @param param {String}
* The string value of the JSON parameter name.
* @param value {Boolean}
* The value of the JSON parameter.
*/
public static void print(String param, Boolean value) {
printLine(param, Boolean.toString(value));
}

/**
* Closes the JSON stream
*/
public static synchronized void end() {
printOutput.println("}");
}

@Override
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException(); // that'll teach 'em
}
}

Configuring the IBM Domino Server to Show the Mobile Login Form to Android Users

Just like many programmers have today, I’ve been starting to do a little bit of mobile development on the side with the Domino server, and I’ve been discovering the little tweaks IBM has been doing here and there to make Domino more mobile-friendly.  For instance, upon navigating your web browser to a Domino app with your iPhone or iPad, you’re greeted with a touch-friend version of the standard login screen:

Unfortunately, this special login view was apparently not extended to users of Android devices, as I found when I tried to login with my phone.  I was provided with the standard login screen, which is not very mobile-friendly at all.

Now, when you do finally login with your non-iOS mobile device, the actual database, such as your mailfile, will detect your non-iOS mobile device, and load an appropriate mobile interface.  Interesting.

So, I figured that a lot of the default Domino coding could detect non-iOS devices, but for some reason the login window portal (a database named DominoWebAccessRedirect.nsf) doesn’t.  I delved into the code for a bit, finding some interesting bits of code, and a reference to @GetProfileField that apparently grabbed a list of user-agent data (from a profile document) that was checked against the user trying to login. 

Figuring that there must be some way to edit that document, I did a little bit of Google searching, and found that it’s actually rather easy:

First, open up DominoWebAccessRedirect.nsf in your Notes Client:

Click on “Setup”, and then click on “Ultra-lite/Mobile Settings”:

Then, under “Mobile Device User Agent Keywords”, enter whatever you like.  Something tells me that “android” will probably be entered here already for you by default on the next release.

[ Resources: http://www.ibm.com/developerworks/lotus/library/inotes-ultra ]

Installing Notes 8.5.1 on Ubuntu 10.04

In short: it works, after a tiny bit of extra configuration (of course!). It took me a while to find out the answers about how to get this to work, but here you go, paraphrased from the LDD:

1) First of all, get your Notes .DEB file and install it.  If you get a message about a dependency that can’t be fulfilled, just search for the name of the library on google — you’ll find a link to it right away (usually on Ubuntu’s servers, directly). Download it and install it, and then restart the Notes .DEB.  (In my case it was libgnome-desktop-2 — perhaps Notes 8.5.1 is looking for a few Ubuntu 8.04 libs?)

2) When it’s done installing, download the file from this location, and unpack it:

http://linux-aha.de/wordpress/wp-content/uploads/2009/10/notes_libs_karmic.tgz

3) There are four files contained therein.

libgdk-x11-2.0.so.0
libgdk_pixbuf-2.0.so.0
libgdk_pixbuf_xlib-2.0.so.0
libgtk-x11-2.0.so.0

Give them root ownership and 755 permissions, and place them in “/opt/ibm/lotus/notes”.  Just a few commands like:

sudo chmod 755 *.so.0
sudo chown root:root *.so.0
sudo mv *.so.0 /opt/ibm/lotus/notes

from inside the folder you unpacked should do the trick.

4) Start Lotus Notes.  No, that’s it — no more steps.

Steps 2 and 3 are necessary because, for some reason, these files aren’t included with the Notes installation, and if you start Notes without having copied those four files over, nothing will display. Not documents, not applications, not your mail file — nothing.  It’s like nothing is being rendered.

At first I thought it may have been a problem with some sort of renderer that Notes is expecting to work a certain way, and since my Ubuntu install was heavily modified and hacked, I figured it was my fault.  So, I started up a virtual machine with a fresh install of 10.04, but no — same problem.

[Related links:]

http://www-10.lotus.com/ldd/nd85forum.nsf/5f27803bba85d8e285256bf10054620d/86db5333ddbe99e985257666003081ba?OpenDocument

http://www-10.lotus.com/ldd/nd85forum.nsf/DateAllFlatWeb/69b50f2db7bb7b0b85257659005ab79e?OpenDocument

http://www-10.lotus.com/ldd/nd85forum.nsf/5f27803bba85d8e285256bf10054620d/303b25b9cfc35789852576620030ae13?OpenDocument

Notes 8 HTML Email Image Loading

Well, my dev team has finally been instructed that we’re moving to Notes 8, and not a moment too soon! 

I know Notes 8 has been out for several years now, but when you’re maintaining the sheer amount of installations that my team deals with, I have a feeling it isn’t too out of the ordinary to wait a year or so before moving to a new version of a major environment.

I’ve been doing a little bit of dev here and there, and I reached my first roadblock today — HTML emails with images just won’t load up in Notes 8 or 8.5.  (They load up normally in Notes 7.)  Either the user has to right-click on the email and select “Load Images,” or the individual user has to set an option in his/her preference.

It looks a little different in Notes 8.5.

Now, of course, you can set this preference amongst many computers by using a Windows Policy, but the setting is disabled by default (viruses, spam, saving bandwidth — take your pick).  So, that idea was shot down, and I didn’t really argue that much — I’ve dealt with these kinds of problems in Notes before, and I had the nagging suspicion that there’s a hidden field or two you can set on a new email that will enable those images to load when the user opens the email.

And what do you know, there is: 

Looking through the design of the new mail template, I found that the “Show Images” link is on the (FollowUpMemoSubform) subform. The code indicates that a field named $DelayedImagesOK set to the value “ok” would display the inline images. In the mail template, this field is set using the ShowDelayedImages sub, in the DelayedImages script library. What the code does is to create the field $DelayedImagesOK, setting the value to “ok” and saving the document. The client then reloads the document, which displays the images. [Source]

I actually found this through a post at the Lotus Developer Forums — the dev wasn’t having very good luck with it (he seemed to be concerned with what type of field the “$DelayedImagesOK” field needed to be).  However, from what I’ve found, it doesn’t matter — or at least it doesn’t in the way that I’m creating these emails.

I create them in LS and Java agents, and it seems like just using

Call doc.ReplaceItemValue("$DelayedImagesOK", "ok")

in LotusScript or

memo.appendItemValue("$DelayedImagesOK","ok");

in Java works just fine.  Try it out!

Hitting close at home

Just saw today on Ed Brill’s blog about a few remarks made by the TwiT folks in regards to Lotus Notes!  Sadly, though, the remarks were the usual 90’s-era Notes complaints:

“The UI is ugly.”

“Who uses that?

I actually really like and respect the Twit guys, and try to catch their podcasts every chance I get (I apparently missed this episode in question, though).

I encounter this stuff all the time — if it isn’t constant insults from users at Slashdot, it’s little inside jokes like this (see if you can find it).  The worst insult was the one that Notes was “even worse than Exchange” — sorry, no!  I’ve used both, and Exchange is worse, and that’s not just bias, either.

Luckily, Jeff Jarvis redeems himself in this post at this blog from yesterday:

Now as for Lotus: In their office, Jeff Schick and a colleague generously spent a few hours giving me a tour of what they can do. I’ll concede: It’s impressive. What impressed me is that IBM integrated the functions of the collaborative, social internet — email, Twitter, wikis, LinkedIn, Facebook, Facebook Connect, directories, blogs, calendars, Skype, bookmarks, tagging — in a way that I wish they would all interroperate: click on a name and get everything about them (contact, place, tags, bookmarks); pull together people in calls or calendars just by dragging them; see how people are sharing your documents; see how people are connected…. 

Looks like I’ll have to keep checking back at the weekly TWIG podcast to see if they mention this matter again. ;)

Links:
http://www.edbrill.com/ebrill/edbrill.nsf/dx/have-you-been-following-the-why-does-howard-stern-use-notes-discussion
http://www.buzzmachine.com/2010/04/27/sternshow-digital-farts/
http://www.youtube.com/watch?v=FOn5XEz6DHs&feature=related

Google Docs Forms – Why was I not told of this?

First, take a look at the picture above.  Wow, an easy, information-storing, web-based form editor?  That’s pretty neat — kinda useless without a backend to support it, though, right?  Right?

…and it looks like the backend is automatic.  The form is loaded up, and the data is automatically collected and stored in a Google Spreadsheet.  Simple as that.

Google’s apparently trying to put me out of a job. :P

Two Things I Learned Today

Well, three.

1) If you’re planning on being sick, make sure it’s not on a day where you have a big exercise and you’re running the IT.

2) There’s a reason why the JSON spec says to always always use double quotes, and always quotify your keys:


// LIKE THIS:

{
"success": true,
"data": {
"RescPhone": "334-555-5555",
"RescStatus": "Available",
"RescComments": "Test%20test%20test."
},
"unid": "AABEF75B28304F008625755A007303D3",
"isEditable": true
}

//NOT THIS:

{
success: true,
data: {
RescPhone: '334-555-5555',
RescStatus: 'Available',
RescComments: 'Test%20test%20test.'
},
unid: 'AABEF75B28304F008625755A007303D3',
isEditable: true
}

If you haven’t yet discovered why, don’t worry, you one day will.

3) When using the Domino formula language “@Transform” function, always specify your variable (as the second parameter) with quotes around it. I bashed my head against a wall for hours trying to figure this out.

It’s a variable, not a string, right? Why do you need to declare it like a string? Because it’s not a variable yet, dummy. :P

Complex Conditional XTemplate Logic in ExtJS 2.2

Let’s say you’ve got a bit of JSON data — something like:


{
ReqPhoneSelection: "Primary",
ReqPrimaryPhone: "555-5555",
ReqAlt1Phone: "666-6666",
ReqAlt2Phone: "777-7777"
}

And you want to show just the one phone number as defined in “ReqPhoneSelection” in a fancy HTML template you’ve made in Ext.

How to do it? Well, you probably knew about ExtJS’s conditional logic in the XTemplate system, but you know you have to check against strings for something like this, so how to do it when you’ve already used your single and double quote allotments for that line of JavaScript?

Why, as I learned here, just start escaping single quotes:


ReadModeTemplate = new Ext.XTemplate(
''
, '{ReqPrimaryPhone}'
, '
'
, ''
, '{ReqAlt1Phone}'
, '
'
, ''
, '{ReqAlt2Phone}'
, '
'
);

(Yeah, duh, right? Took me hours to figure that out, so hush up. :P)

Now, no matter what JSON data you put into that template, you’ll only get out one number, depending upon what is stored in the “ReqPhoneSelection” property.