english
Aug 30, 2010
New ideas from RedTurtle....
RedTurtle Technology seeks to contribute to improving Notes
Aug 13, 2010
Where is my manage portlets link?
Check that your content implements plone.portlets.interfaces.ILocalPortletAssignable
It is the second time in a couple of days that I am asked why in some pages there is no link to the @@manage-portlets view. In both cases the archetypes missing the link (and the view) where inheriting from a very basic object.
After a small research I found that this view is registered for the interface plone.portlets.interfaces.ILocalPortletAssignable.
Making the object interface inherit from this interface solved the problem.
Jul 20, 2010
Aggregate zope munin graphs
Munin with munin.zope is a handy tool if you want to monitor your Zope instance. But it starts to be annoying when you have too many zeoclients and too many projects on one server. Using munin aggregate functionality you can create nice, human readable graphs reusing your existing data.
With the newest version of munin.zope you have 4 different plugins:
- ZServer threads
- ZODB activity
- Zope cache parameters
- Zope memory usage

Using aggregation you can end like this:

What it does? It takes data from multiple zeoclients (in this case every project from A-E have 4 zeoclients) and renders only total amount per project.
Here is munin.conf which does this trick:
[Server1;projectA]
address 127.0.0.1
[Server1;projectB]
address 127.0.0.2
[Server1;projectC]
address 127.0.0.3
[Server1;projectD]
address 127.0.0.4
[Server1;projectE]
address 127.0.0.5
[Server1;Aggregated]
update no
total_memory.update no
total_memory.graph_category Zope
total_memory.graph_title Aggregated Zope memory
total_memory.graph_order \
projectA \
projectB \
projectC \
projectD \
projectE
total_memory.projectA.sum \
projectA:projecta_zopememory_instance_1.VmSize \
projectA:projecta_zopememory_instance_2.VmSize \
projectA:projecta_zopememory_instance_3.VmSize \
projectA:projecta_zopememory_instance_4.VmSize
total_memory.projectA.label project A
total_memory.projectB.sum \
projectB:projectb_zopememory_instance_1.VmSize \
projectB:projectb_zopememory_instance_2.VmSize \
projectB:projectb_zopememory_instance_3.VmSize \
projectB:projectb_zopememory_instance_4.VmSize
total_memory.projectB.label project B
total_memory.projectC.sum \
projectC:projectc_zopememory_instance_1.VmSize \
projectC:projectc_zopememory_instance_2.VmSize \
projectC:projectc_zopememory_instance_3.VmSize \
projectC:projectc_zopememory_instance_4.VmSize
total_memory.projectC.label project C
total_memory.projectD.sum \
projectD:projectd_zopememory_instance_1.VmSize \
projectD:projectd_zopememory_instance_2.VmSize \
projectD:projectd_zopememory_instance_3.VmSize \
projectD:projectd_zopememory_instance_4.VmSize
total_memory.projectD.label project D
total_memory.projectE.sum \
projectE:projecte_zopememory_instance_1.VmSize \
projectE:projecte_zopememory_instance_2.VmSize \
projectE:projecte_zopememory_instance_3.VmSize \
projectE:projecte_zopememory_instance_4.VmSize
total_memory.projectE.label project E
For more information please check:
http://munin-monitoring.org/wiki/aggregate_examples
http://munin-monitoring.org/wiki/PercentGraphHowto
http://munin-monitoring.org/wiki/stack_examples
Jul 14, 2010
New collective.navigationtoggle release: integration with any theme (I hope)
The new release only fixed a small bug, but also add some better integration with Plone themes. What if fun: a bug inside Sunburst theme was the demonstration that the approach is good!
I already talked about the features of collective.navigationtoggle in previous post, but the new release helped me to be sure of one thing: the unobtrusive approach chosen was good.
The new version also add some refactoring and support for other themes than the classic Plone one. Plone 4 is coming... we must live with this and luckily the products migration has begun.
What is more difficult, after years the default theme is changed (for what I remember, the default theme you all know is with us from Plone 2.0... maybe some changes was done to it at Plone 2.1, but the core never changed). All products that act on Plone UI must check also the new Sunburst theme.
Going back to navigationtoggle, I choosed an approach that was "use existing Plone navigation element to know how to render new ones".
For the new release I only empowered some existings feature, like also generate CSS classes for new element on the navigation.
Why? In Plone 3 navigation main node is like this:
<li class="navTreeItem visualNoMarker">
<div>
<a title="..." class="state-... navTreeFolderish" href="...">
<img width="16" height="16" alt="..." src="...">
<span>Foo</span>
</a>
</div>
...
</li>
And Sunburst is like this:
<li class="navTreeItem visualNoMarker">
<a title="" class="state-... navTreeFolderish contenttype-..." href="...">
<img height="16" width="16" alt="Folder" src="...">
<span>Foo</span>
</a>
...
</li>
Apart some node difference (no more containing DIV) the new theme also rely on a contenttype-xxx class.
What is funny (and what make me say "thanks navigationtoggle") is an unwanted behavior of the current Sunburst theme. A bug that double the content type icon: one given from the IMG tag and another ones from CSS, thanks to the new class.
I'm not interested in this bug (Irene says that probably it has been already fixed), but using navigationtoggle with this bugged version of Sunburst... also make the bug applyed to elements navigation nodes generated by our script!
This (uncommonly) is good as respect the original idea: the original theme use doubled icons?! Is not a problem of navigationtoggle, so do it!
Jul 13, 2010
Evil Javascript... use strip() or trim()?
I hate doing the same error all the time! One time again: how to obtain a cross browser method for Javascript to remove leading and trailing whitespaces inside strings?
Every time I make the same stupid error! So, let's make quickly, a guide for obtaining this behavior.
The trim() function works only on Firefox and maybe other browsers, but not on IE.
In my experience the stript() function instead works better, both on Firefox and IE.
So what is the problem? That every time I forget to use this last one, and I use again trim instead of stript...
There is a solution for my lazy brain? Well... I use very often (AKA "always") jQuery for our projects, so... please Luca... from now just use jQuery.trim().
I feel better! No more error from now...
...
... until next time.
Jul 08, 2010
Scripted CSS Injection (or whatever better name you can find for this technique)
While trying to close a request for one of our customer for obtaining a random image portlet I tested an alternative way to deliver CSS. Using Javascript.
When Web pages load and run things
Let's start with CSS. Browsers load HTML source from the Web. Inside the page you will find resources that are CSS file. Immediately the resource is loaded and the rules inside are applied to your HTML.
Now switch to Javascript resources. For Javascript... it's the same. The Javascript code is executed as soon as it is found in the page...
...but for this reason, when we need to act using Javascript on an already loaded DOM, we rely onto Javascript events.
We read immediately the code, but the execution is postponed later, when the page is fully loaded.
As the use of jQuery became standard for those tasks (especially in Plone) we always use something like this:
jq(document).ready(function() {
// do something
});
When this lead to problems
Although we have really no choice, there are some cases where this "postpone things" is not perfect: when we need to apply (using Javascript) CSS classes on page elements at page load time.
But we can't avoid making those actions when page is loaded.
If we don't rely on onload event, we have no ready DOM to traverse. So we can't load and change a DOM node if the page is not fully loaded (even if we put the Javascript script after the HTML that define the node).
<html>
<body>
<div id="foo">Hello world</div>
<script type="text/javascript">
<!--
var foo = document.getElementById("foo");
alert(foo.innerHTML);
// -->
</script>
</body>
</html>
The code above is bad, even if you are using or not jQuery... So we really need to wait for the moment when DOM is ready. You can't act of the page DOM before it is fully loaded.
However: what is the problem applying CSS style when the DOM is loaded?
The nasty effect can be a visual flip.
The page in the browser show the DOM node with the original CSS style, then after some time (that can be not so brief sometimes if the page is full of elements and heavy scripts) the Javascript engine run your code, and the node is changed: your new CSS class or your new scripted style is applied.
<html>
<head>
<style type="text/css">
#foo {
background-color: red;
}
</style>
<script type="text/javascript">
<!--
window.onload = function() {
... MANY OTHER EXPENSIVE OPERATIONS
var foo = document.getElementById("foo");
alert(foo.innerHTML);
}
// -->
</script>
</head>
<body>
<div id="foo">Hello world</div>
... A LOT OF MANY AND MANY HTML NODES
<script type="text/javscript">
<!--
var foo = document.getElementById("foo");
alert(foo.innerHTML);
// -->
</script>
</body>
</html>
A practical example
A customer ask us to develop a Plone portlet that:
- show some random images when the page is load
- works behind a reverse proxy (Varnish)
- works with Javascript disabled (accessibility and graceful degradation)
Step 1
Varnish is caching all our resource, images and also HTML for every page. We can't (and don't want) change this.
How to cache everything but some little images inside a portlet?
The idea is to use Javascript for performing AJAX request for this portlet and obtain a structure of data. The cache of this kind of request can be avoided easily.
Step 2
So we are able to load an HTML for the portlet without images then, when the DOM is ready, we can populate the portlet waiting for the AJAX call to the server. For some time the visitor see and empty portlet that magically begin load images. The effect is pleasant (at least... it's not annoying).
But we can't!
The portlet must work also with disabled Javascript... So we must load random images also when the page is loaded.
NB: if the visitor use a browser with Javascript disabled, we can only give him some random pre-loaded images, but we can't prevent Varnish cache of the whole page. Reloading the same page will show him the same images for some minutes. This is acceptable for us (and for the customer!).
Step 3
The final result is to load the first "static" images in the portlet itself, then use Javascript as described at step 1: changing those images with new ones obtained from AJAX call.
This lead to the ugly visual flip effect I talked above.
I can't explain why (this is not my work), but see an empty section that is filled after a little delay is not ugly... instead seeing a set of images that suddenly change to other is... bothersome!
Step 4?
Ok, so we can simply load static images hidden by some CSS class, then using Javascript we can show them only after the AJAX call and...
Opss!
But in this way we don't see any image when Javascript is disabled!
Ok... step 4 aborted.
Scripted CSS Injection
The perfect world is the one where the step 4 is performed, but only with Javascript enabled.
I need a CSS that is loaded early like all other CSS in the page (so its style is applied immediately to the page) but only when Javascript is enabled.
I found a way to do this, but surfing the web I was not able to find other example like this one. So I called this approach Scripted CSS Injection (SCI)... maybe someone can point me to other original name or example?
However... how this works? Simply generating the additional CSS... with Javascript!
For this we use the standard window.write Javascript API. The window.write command is used commonly to write HTML inside windows (is more common to use it in popup windows for generating the contained HTML from scratch).
The additional Javascript is load in the page head section and it doesn't wait for DOM load. The one in our product is only one line:
document.write('<style type="text/css">.hideFlag img {display: none}</style>');
As I said at the beginning, Javascript is interpreted as CSS, so immediately when found in the page.
The browser will add to HTML the style node immediatly.
What is nice of SCI approach is obvious: a browser with no Javascript support can't add the CSS rule to the page!
Fairytale gone well
This technique finally lead us to a portlet that:
- will show cached images if without Javascript support, but images are still random (chosen server side and changed with some delay)
- will show random (and not cachable) images client side if Javascript is enabled
- No ugly visual flip effects. With Javascript enabled static images are loaded hidden, then new dynamic ones are taken from the server and show. Thanks to SCI approach.
For more info, check the code of auslfe.portlet.multimedia.
Jul 02, 2010
Generating pdf with iText and Xpages
Brief tutorial to simply create PDF's inside XPages
Many thanks to John Mackey:
http://www.jmackey.net/groupwareinc/johnblog/johnblog.nsf/d6plinks/GROC-7G9GT4
and to Daniele Vistalli http://factor-y.com for this idea, for their help and the great powers.
Since Domino 8.5 is Eclipse based, you can switch to the Java perspective and add Java code to your project. The nsf database is the project. (If you haven't done this yet, it is interesting to switch perspectives and look around at the structure and the code.) By switching to the Java perspective, you open up your code to the importing or referencing of Java libraries, or the creation of your own classes.
Now we investigate how to create PDF using XPages. This tutorial summarize John's article, with some other things that you have to pay attention to.
Step by step.....
- Create your own .nsf
- Switch to the Java perspective by selecting: Window->Open Perspective->Other.
- Expand your project on the Left hand Project navigator. Select the WebContent/WEB-INF Folder
- right click and select New->Folder. Name the folder source, click Finish.
- right click on the source folder and select New->Package. Name the Package mypackage click Finish.
- right click on the mypackage package and select New->File. Enter Test.java for the name. Click Finish.
- Now double click on the Test.java and paste in the following code:
package mypackage;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
/**
* First iText example: Hello World.
*/
public class Test {
public static void createPdf(String filename) throws Exception {
try {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
document.add(new Paragraph("Hello World!"));
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
- select the project and then select Project->Properties from the menu (or right click)
- select the Java Build Path and click on Add Folder button. Select the new source folder. Click OK.
- In WebContent\WEB-INF add the folder called lib
- Right-click on it and select Import->File System->Browse and select itext jar (i.e iText-5.0.2.jar)
- import itext jar (i.e iText-5.0.2.jar) in your Java Build Path: Project->Properties->Java Build Path->Libraries->Add Jar and select jar from WebContent\WEB-INF
- Note: you have to deploy jar in your server, in data\domino\java and append this line in notes.ini, JavaUserClasses variable
JavaUserClasses=......;C:\Programmi\IBM\Lotus\Domino\data\domino\java\iText-5.0.2.jar
this will not cause security problem when you call iText methods to generate PDF
- Create a Script Library Server Side called SLCode and save this code on it
function create(){
mypackage.Test.createPdf("hello.pdf");
}
- Now create an xpage
- in Resources section, include SLCode library
- Drag a Button control in Xpage
- Goto Event section of this button, onClick event, and put this JSS code
create();
- Open your XPage in a browser and click the button: pdf will be created in domino directory on server
That's all!
Jun 29, 2010
TextAreaBound: trying my first jQuery plugin
HTML has some nice attributes to control the size and bound of input fields. However those features aren't working for textarea. Our customer asked us for those features: max number of lines in a textarea, max numbers of character in the textarea AND in a line... Let's try to develop a jQuery plugin for obtaining this!
The APIs we want
We must reach this:
$(...).maxLinesLengthBound(n) $(...).maxLinesCountBound(n) $(...).maxTextLength(n)
Obviously, we like jQuery chaining so also this must work:
$("#textareaid").maxLinesLengthBound(20).maxLinesCountBound(15)
All of the 3 new jQuery feature take all the textarea element from the expression given and apply new bounds.
- The maxLinesLengthBound method will put a limit on the number of lines in a textarea
- The maxLinesCountBound method will put a limit in the number of characters of each line
- The maxTextLength method is the most simple: put a limit to the number of total character in textareas
Bad news one: Javascript events
When adding character in Javascript we can rely on 3 events:
- keydown event is called when a key is pressed (before it's released)
- keyup event is called when a key came up after keydown.
- keypress event is called when a key is... pressed! So it goes down and then up. More important, if you keep pressed a button, starting the characters-repeat, this even is called multiple times.
As you can see, the keypress is the best choice... but using this event has a great limitation.
When you rely on keydown event, the "actual" value of the field is the old one. When you bind an handler to the keyup or keypress events the value you can read is the new one. You have no way to know what was the old value of the field.
Don't think to use other events like change event. This type of event has the same problems and also is called only when the control loose focus.
Solution to bad news one
Yes, we can only read the new value of the field, but we can also use the event object and take from it the value of the pressed key, so we can know what new character will be added to the textarea
Bad news two: knowing where the cursor is (on Internet Explorer)
Unluckily in a textarea you not always append characters... you can also add new characters inside the text. The pressed key is still a very important resource, but we must also know in which position we are inside the textarea.
The task seems simple on all browsers, with only a single exception: you can read the selectionStart attribute of the textarea DOM element.
We really need this only for one of the 3 APIs we need above: the maxLinesLengthBound method. Other 2 APIs don't need to know where the cursor is...
The vary bad news is this: Internet Explorer do not support selectionStart!
Solution to bad news two (AKA: bad news three)
You can surf the Web looking for an alternative, and you will find a lot of blog post, articles and script for giving an alternative.
What is clear is that you must use some funny IE specific APIs like getBookmark and createRange... and you will fail.
I found no way to really have the same simple features. On Internet Explorer 7 I have a lot of problems when I go to the second line. Those APIs seems buggy and the browser don't see that you go on a new line.
Tired of this, I leave the problem to someone more expert than me with IE Javascript.
Wanna help me?
The jQuery plugin
You can find the plugin on the jQuery plugin official page, and also other info and the SVN repository in my Google Code space.
Jun 26, 2010
System.getProperty() returns null
How to avoid a null pointer using System.getProperty() within a java agent.
Sometimes, for some reason, you have to do it. I'm talking about the use of System.setProperty() method within a java agent. If you don't pay attention it's easy to get a null pointer as result. Infact I got it.
After a quick search I found out a way to solve the issue:
I will use "jna.library.path" as example.
First of all add the following line in "java.policy" file (in the "jvm\lib\security" folder below the Domino program folder).
permission java.util.PropertyPermission "jna.library.path", "read,write";
After that, add the java code to your agent :
String jnaProperty = "jna.library.path";
if(System.getProperty(jnaProperty) == null) {
System.setProperty(jnaProperty,"your path");
}
Jun 24, 2010
rt.vuvuzela is out!
Developed while watching Italy on tv. Suffering...
rt.vuvuzela is available from pypi
As usual add rt.vuvuzela to eggs and zcml into the [instance] section of your buildout.
Then you can just go to your site and you will have a nice vuvuzela view displaying a player stealed borrowed from wikipedia. Here you can see a snapshot of the view:

To see it live just append "vuvuzela" to your browser url, e.g.:
http://nohost.com/vuvuzela http://nohost.com/mycontent/vuvuzela
rt.vuvuzela logo???


