371 Lotus blogs updated hourly. Who will post next? Home | Downloads | Events | Jobs | Twitter | Bookmarks | Pods | Forum | Blogs | Search | myPL | About 
 
Latest 7 Posts
Java JSONWriter Domino Agent Class
Tue, Sep 27th 2011 143
JS/ExtJS Code to Determine Age
Wed, Jul 20th 2011 95
LDDMonkey -- Greasemonkey Script for the IBM LDD Forums
Wed, Jul 13th 2011 101
It Always Felt Like Addon Support in IE was an Afterthought...
Tue, Jun 21st 2011 81
Configuring the IBM Domino Server to Show the Mobile Login Form to Android Users
Wed, Apr 20th 2011 163
Amazon Cloud Storage
Tue, Mar 29th 2011 105
Automatic Blogger Mobile Web Templates
Mon, Dec 20th 2010 63
Top 10
Configuring the IBM Domino Server to Show the Mobile Login Form to Android Users
Wed, Apr 20th 2011 163
Java JSONWriter Domino Agent Class
Tue, Sep 27th 2011 143
Notes 8 HTML Email Image Loading
Mon, Sep 27th 2010 134
Installing Notes 8.5.1 on Ubuntu 10.04
Wed, Oct 27th 2010 108
Amazon Cloud Storage
Tue, Mar 29th 2011 105
LDDMonkey -- Greasemonkey Script for the IBM LDD Forums
Wed, Jul 13th 2011 101
JS/ExtJS Code to Determine Age
Wed, Jul 20th 2011 95
It Always Felt Like Addon Support in IE was an Afterthought...
Tue, Jun 21st 2011 81
Automatic Blogger Mobile Web Templates
Mon, Dec 20th 2010 63
Kinect Hand Detection
Thu, Dec 9th 2010 52


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/JSONWriter.)
package mdm.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 
	}
}


---------------------
http://mdm-adph.blogspot.com/2011/09/java-jsonwriter-domino-agent-class.html
Sep 27, 2011
144 hits



Recent Blog Posts
144


Java JSONWriter Domino Agent Class
Tue, Sep 27th 2011 9:09a   Mdm Adph
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 [read] Keywords: agent domino lotus application blogger development interface java
95


JS/ExtJS Code to Determine Age
Wed, Jul 20th 2011 8:12a   Mdm Adph
Just something I came up with for a form I'm building -- is there a quicker way to do this? (_now.format('Y') - birthdate.format('Y')) - (_now.format('z') < birthdate.format('z') ? 1 : 0) [read] Keywords: blogger
101


LDDMonkey -- Greasemonkey Script for the IBM LDD Forums
Wed, Jul 13th 2011 1:16p   Mdm Adph
http://www.openntf.org/projects/pmt.nsf/ProjectLookup/LDDMonkey Here's a little Greasemonkey script I've been using for the past few years to make browsing the LDD forums at ibm.com tolerable -- I'm amazed constantly that this script still works! [read] Keywords: ibm ldd blogger openntf
81


It Always Felt Like Addon Support in IE was an Afterthought...
Tue, Jun 21st 2011 1:09p   Mdm Adph
For some reason, I took a look at the "addons" my copy of IE8 had installed -- I wanted to sort them by date (to see which was oldest), but no matter how many times I clicked on the column header, they wouldn't seem to sort. Just then, I realized they were sorting, just not the way you would think. We always knew addon support in IE was an afterthought, didn't we? Please tell me it's not supposed to be like that. (I used to have this problem as a budding Notes developer a LONG tim [read] Keywords: notes blogger
163


Configuring the IBM Domino Server to Show the Mobile Login Form to Android Users
Wed, Apr 20th 2011 2:09p   Mdm Adph
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 An [read] Keywords: agent domino ibm inotes lotus notes notes client blogger database development google interface iphone mobile profile server
105


Amazon Cloud Storage
Tue, Mar 29th 2011 3:08p   Mdm Adph
I've been looking at the Storage ecosystem that Amazon released today as part of it's "Cloud Drive" system, and I'll admit I'm impressed with what I see. I'm thinking from the view of a "regular" user: The system is available to any Amazon.com customer (at least in the US and UK right now). You get 5GB of storage by default. If you buy an album from them this year, you're automatically given a free subscription to their 20GB service for one year. You can easily upload your existing [read] Keywords: apple blogger google linux mac




63


Automatic Blogger Mobile Web Templates
Mon, Dec 20th 2010 12:14p   Mdm Adph
div class="separator" style="clear: both; text-align: center;"a href="http://1.bp.blogspot.com/_w7Oc-a0bbsk/TQ-MXyFqsxI/AAAAAAAABAo/uTzvYd7DGV0/s1600/blogger-mobile-web-template.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"img border="0" height="104" src="http://1.bp.blogspot.com/_w7Oc-a0bbsk/TQ-MXyFqsxI/AAAAAAAABAo/uTzvYd7DGV0/s400/blogger-mobile-web-template.jpg" width="400" //a/divbr / br / br / br / br / br / br / Thank you, t [read] Keywords: blogger mobile
27


The Future is Now
Fri, Dec 17th 2010 3:13p   Mdm Adph
I'm imagining a future in which I'm walking around in a foreign country, looking through augmented reality glasses and a href="http://dankaminsky.com/2010/12/15/dankam/"having my colorblindness corrected on the fly/a, all while having a href="http://www.youtube.com/watch?v=h2OfQdYrHR"signs in different languages being translated for me in real time/a.div class="blogger-post-footer"img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/31700389-345182600392554853 [read] Keywords: blogger
52


Kinect Hand Detection
Thu, Dec 9th 2010 5:12p   Mdm Adph
object height="385" width="480"param name="movie" value="http://www.youtube.com/v/tlLschoMhuE?fs=1amp;hl=en_US"/paramparam name="allowFullScreen" value="true"/paramparam name="allowscriptaccess" value="always"/paramembed src="http://www.youtube.com/v/tlLschoMhuE?fs=1amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"/embed/objectbr / br / I remember when iMinority Report/i came out eight years a [read] Keywords: application blogger
108


Installing Notes 8.5.1 on Ubuntu 10.04
Wed, Oct 27th 2010 1:26p   Mdm Adph
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:br / br / bspan style="font-size: large;"1)/span/b First of all, get your Notes .DEB file and install it.nbsp; 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). [read] Keywords: ibm ldd lotus notes applications blogger desktop google linux ubuntu




Created and Maintained by Yancy Lent - About - Blog Submission - Suggestions - Change Log - Blog Widget - Advertising - FAQ - Mobile Edition