RSS

Category Archives: Domino

Paid per line programming code? – Why I love refactoring

Earlier this month I’ve started to read a new book called “Effective Java“. Jesse Gallagher mentioned this book as a “must read”. After my positive journey with reading “Design Pattern” (The head first edition) was it no question that I definitely read the sample of “Effective Java”. And yes, after reading the sample, I bought it. (To my colleges at WebGate: Yes be afraid – I have now a new book – Ho Ho Ho).

But reading a book without bring the new knowledge into the daily work is only the half of fun. So where to start? One of the first thing that has attracted me while reading “Effective Java” was the initialization of a Singleton.

A Singleton is an object, which exist only one time in specific context like a jvm, plugin or a XPages Application. The “normal” code to initialize a singleton is the following construct:

public class DocumentProcessor {
private static DocumentProcessor m_Processor;
private DocumentProcessor() {
}

public static DocumentProcessor getInstance() {
if (m_Processor == null) {
m_Processor = new DocumentProcessor();
}
return m_Processor;
}
}

One of the disadvantage of this code is, that this code is not “safe” if you try to create an instance of DocumentProcessor with Java Reflection and modifying the constructor. The other thing that I’m not loving is the amount of code, that I always have to write. But Joshua Bloch explains a simple way with enums to have a singleton look at this code:

public enum DocumentProcessor {
INSTANCE;
}

How smart is this! And not much code. I’m not paid per line of code I write, so it’s not touching my income :). Now you can access with DocumentProcessor.INSTANCE the singleton. It’s very cool, but what, if I have already a lots of Singleton? How can I make that my code will not break the code of other clients (classes which calls my API).

Remember all client classes call the current code (before refactoring) with WordProcessor.getInstance(). I can easy change this in my classes, but external clients which calls my WordProcessor will fail, when the do not have the WordProcessor.getInstance().

The following code is a “defensive” approach which makes this safe to all the other clients:

public enum DocumentProcessor {
INSTANCE;

/**
* gets the Instance of the DocumentProcessor.
*
* @deprecated -> Use DocumentProcessor.INSTANCE instead
*
* @return Instance of the DocumentProcessor
*/
@Deprecated
public static DocumentProcessor getInstance() {
return DocumentProcessor.INSTANCE;
}

This code is not only safe, it gives the other developer also an instruction, how to adapt the new API.

Will I now go to all my code (and it’s a lot of code I wrote each year) and change this all? And what about all the other cools stuff that I will learn while reading the book?

No, that’s not my approach. But I will challenge my code, myself and later the WebGate Development Team with the knowledge. Each code that I’ve to touch will also be reviewed with my new knowledge.

Have fun

Christian

 
1 Comment

Posted by on December 21, 2013 in Design Pattern, Domino, Java, XPages

 
Video

Replay: A Deep Dive into OpenNTF Essentials

 
Leave a comment

Posted by on December 18, 2013 in Domino, IBM, Java, OpenNTF, XPages, XPT

 

Ready for todays webinar about OpenNTF Essentials?

I hope that you have already dowloaded OpenNTF Essentials and at least installed on your development computer. If not, it’s a 5 minute job as you can see in this youtube video http://youtu.be/EUrLfJcCQhY (starting 12:00).

In Todays webinar, Mark will cover some cool stuff about debugging and Nathan takes a deep dive into the OpenNTF Domino API. My part will be about some cool @nnotations. Imagine this:

Your are writing a call center application and you have designed the “Call” object as a java object according the java bean specification. With the ObjectData Source from the ExtLib are you know ready to edit each field of this java object, but now you have to save….. and read …. and delete ….. the object from the database.

I will show you in todays webinar how you can do this with writing only “3 or 4” lines of code 🙂

I hope you will join us, today 10:30 EST, register now!

 
Leave a comment

Posted by on December 12, 2013 in Architektur, Design Pattern, Domino, Java, OpenNTF, XPT

 

Rendering HTML Code with DJANGO and DOJO

One of the things that I like about dojo is the django rendering engine. It provides an easy way to build HTML Templates and let you render values form a json object. The following example of a template is used to loop through a json array response.

<div>
{% for entry in feed.entries%}
<div style=”height: auto;”>
<div>
<div>{{entry.created}}</div>
<h2>
<a target=”_blank” href=”{{entry.link}}”>{{entry.title}}</a>
</h2>
</div>
<div>
<div>
{{entry.content|safe}}
</div>
</div>
</div>
{%endfor%}
</div>

This code is used in the dojo widget:

dojo.provide(“xptrss.list.feedcontroller”);
dojo.require(“dijit._Widget”);
dojo.require(“dojox.dtl._Templated”);
dojo.declare(“xptrss.list.feedcontroller”, [ dijit._Widget, dojox.dtl._Templated ], {
proxyurl:null,
feed : null,
templateString : dojo.cache(“xptrss.list.feedcontroller”,    “../../html/rssTemplate.html”),
targetid: null,
postCreate: function() {
var mySelf = this;
var xhrArgs = {
url : mySelf.proxyurl,
handleAs : “json”,
preventCache : true,
load : function(data) {
mySelf.feed = data;
mySelf.render();
dojo.style(mySelf.targetid +”_feedLoader”, {
display : “none”
});
},
error : function(error) {
alert(error);
}

}
var deferred = dojo.xhrGet(xhrArgs);
}

});

With the statement  templateString : dojo.cache(“xptrss.list.feedcontroller”,    “../../html/rssTemplate.html”) the html will be loaded. The “postCreation()” handles the loading of the values. With “mySelf.render()” the loaded JSON object will be applied to the HTML Template and the django engine loops through all entries and applies the code between {% for …. } {%endfor%} for each entry.

But what if an element in an entry (like the content value) is pure HTML Code?

The django engine is so clever and escapse all content correct, but we need the content unescaped in this particular case. The statement  {{entry.content|safe}} does the trick!

This is code from our new project XPages Toolkit.

 
Leave a comment

Posted by on July 19, 2013 in Domino, Java, XPages

 

POI 4 XPages Version 1.1.0 released!

Hi All

Only a few hours and I will travel with Roman, Peter and Andre to the IBMConnect2013. The last years “LotusSphere 2012” (the old name of the IBMConnect) was a game changer in my life. I meet great people like Niklas Heidloff, Philippe Riand, Martin Donnelly, Dan O’Conner and many more.

But these guys have inspired me to build myWebGate and POI 4 XPages.

We have greate news about both projects, but this post ist about POI 4 XPages. We have made some progresses on the project that we would like to share in the version 1.1.0:

  1. The POI 4 XPages supports now the version 3.9 of the brilliant Apache POI Project, which is the newest release
  2. We fixed some typos and a bug in the creation of Workbooks. If you try to export data to a sheet wich doesn’t exist on the exceltemplate and you choose “create” = “false”, the export fails. This was not the idea behind the “create”=”false” option. Now the export definition with this settings will be ignored, if the sheet doesn’t exist. (Marco Baumann has reported this issue at the gitHub.com)
  3. We implemented the POI  – ListObjectDataSource which is designed to export the java.util.List<?> object in version 1.0.1 but we did make a mistake in the value definition. This values have to be assigned with a SSJS function, but our binding was against a value property. We fixed this with a new “MethodBinding” assignment (like the createObject function from the ObjectDataSource in the ExtLib) called “buildValues”. This means that “values” is deprecated and only for backwards compatibilty available
  4. With version 1.1.0 we introduce a brand new feature in the workbook and document controll. A binding which we called postGenerationProcess. This feature is really powerful, let me explain why.

postGenerationProcess – all power of apache poi in your hand:

POI 4 XPages build your Workbook or Document with the “generate….” function. But when the action is started, you don’t have access to the Workbook or Document object. “postGenerationProcess” change this. In the postGenerationProcess your SSJS / Java Code will be executed, right before the Workbook or Document is transmitted from the server to the client.

The follwowing code in the postGenerationProcess prints the name of the first sheet on a workbook to the server console:

print( workbook.getSheetAt(0).getSheetName() );

While we are calling the postGenerationProcess, the POI 4 XPages Code assign the current workbook to the variable workbook, or the current document to the variable xwpfdocument. This variable are representation of the the following apache poi classes:

workbook: org.apache.poi.ss.usermodell.Workbook -> javadoc

xwpfdocument: org.apache.poi.xwpf.usermodell.XWPFDocument -> javadoc

Imagine what you can do now, afert a document or a workbook is created!

Have Fun
Christian

Download POI4XPages here

 

40th birthday – time for a present

Hello All

Today is my 40th birthday. I think this is a good moment for a little present. Today we release the first version of POI 4 XPages. A powerfull extension for the XPages community. I started developing this project in august 2012 focussed on the 4th DeveloperContest. But as a lucky guy, my boss nominated for the position as one of the OpenNTF Directors and they community voted for me.

The contest changed my role in this project. As a director you are not allowed to contribute projects for the contest. But our plans to release our POI 4 XPages extension where still intact. The pressure form the contest was gone,but  some short demonstrations to customers showed us the high value. So some of our team asked: “Why contributing POI 4 XPages – its so powerfull, it’s so handy and it’s such a strong work – Let us sell this piece of work”.

The answer was very simple: You have just given all the reasons, why we should opensource this project!”

So on my 40th birthday I can give the developer community a powerful extension. Generating Word and Excel Files out of XPages was never easier. The groundbreaking work was done by the Apache POI team, our job was to bring this in the XPages Developer Framework.

So I hope that every XPage developer enjoy this.

Download here

 
1 Comment

Posted by on December 22, 2012 in Domino, Java, XPages

 

Documents and Spreadsheets with XPages – the Idea (Part I)

In several projects we are faced with the request to export data to a spreadsheet (mostly excel) or build a document for ms-word. So our development team requested the following: “Build an extension that helps us generate word documents or export datasets to spreadsheets”.
After some research, I found a project called Apache POI.

Apache POI covers all the stories, which we try to implement. So let’s begin with the first story: “Generating a new ms-word document”.
The story is very simple, but also very powerful. In our example the starting point is a document like the OpenNTF Contributor License Agreement. This document is needed for a company to contribute code to OpenNTF. Typically, this document has some lines (fields), which you have to fill in with your values.  Let’s try to automate this process. We will build a form in the XPages application, where you can fill in your company name, address and other things. Then we modify the standard OpenNTF form a little bit, as you can see on the screenshot below:


In your XPages form we implement the new POI Document element and then we do some wiring:

  1. We define where the modified OpenNTF Licence Agreement is. This could be a file resource in the application, or a document accessible via view and a predefined key.
  2. Defining “Bookmarks”:
    As you see on the word document, we have defined several “<<NAME OF BOOKMARK>>” tags in the text. This text must be in the same style, so they are in the same “run” Element on the document.
  3. In our “POI Document” – Control could we now define a bookmark for each <<…>> element, which contains the name and a value.
  4. As you see, the value can be computed (so a binding to a viewScope variable is possible)
  5. We define a “download” button and connect the onClick event on a new action called “Generate Document”

The user can now fill in their values on the page and generate a customized word document.  Developers are able to build in applications to produce customized documents in a very short time.
In the next blog entries, we will show you how we have build an extension of this function.

 

Tags: , , , ,