Since version 7 OpenCms is a Servlet 2.4 and JSP 2.0 conforming application. In addition to the improved expression language (EL) JSP 2.0 also brings in the possibility of developing custom tags(actions) using JSP rather than writing Java code. This allows for some pretty neat things and enables you to go one step further towards cleaner view code. I’ve used this in one of my last projects extensively to refactor common code like pagers and link generation. For example:
Not does it only look cleaner and is much more focused, it also decouples your view more from the underlying CMS solution. Of course you could also develop a custom tag library using Java (which I have done a few times) but using a JSP the advantage that code can be changed on the fly and even from a web designer. You can always refactor your JSP taglib into a Java one if you need to do it. There are some limitations of JSP tag files (like you can’t use scriptlets in the body) but they are easy to get around.
But as always: This is no silver bullet. There are problems with tag files which may not be obvious at the first glance.
I recently discovered the freshly released RSS4JSP tag library. Its a wrapper around the mature and widely used Rome RSS library which was developed by Sun and then open sourced. The library allows you to simply display (news) feeds inside your JSP pages.
While it’s certainly a young project, I found it very useful and easy to use. I gave it a try to create the Latest blog posts box on my, OpenCms based, homepage. The box was created during 5 minutes which I think is impressive (given that you have to type the HTML too).
Unfortunately the project does not allow the syndication of multiple feeds into one feed (This is a nice feature of Rome which I used in a recent project) but maybe it will be added in the future (or I will add it myself).
I recently had to restart a Java webapplication because somehow the JDBC connection to the database server was hanging completely. This reminded me of a sentence a friend of mine told me during the OpenCms Days 2008.
“Enterprise software just means that it’s targeted at customers who can afford the guy who restarts the application server every few hours.”
I had to laugh because while the quote is clearly cynical it has a true core. Especially if you compare languages like Java and PHP it’s true that PHP doesn’t have these kind problems. This is mostly because of the throw-away-the-state nature of PHP. After every served request PHP forgets what it’s done before and has to completely rebuild the working environment at the next request. Java in contrast is able to remember things between requests. Which makes it more powerful but also harder to maintain (more state, more problems). I’m really not sure if I’m buying into this enterprise-thing anymore. Especially if you need scalability you definitely want to keep application state at a minimum and without state you don’t really need those big interconnected clusters of application servers any more.
Here is a nice talk about scalability and serious (speak enterprise) languages I found recently. It’s from Cal Henderson a software development guy at Flickr. It’s really worth watching. Even if you’re not into Python and Django.
Just a quick note: There was a long standing problem regarding the FCKEditor (HTML editor) in OpenCms 6.2.X using Firefox 3. Adding links always produced an URL like javascript:void(0)/*1241321*/. Since most customers are already on OpenCms 7 this is not such a big problem but recently I had to look for a fix. It turned out the bug was quite popular and there is quite an easy workaround.
Open the file /system/workplace/resources/editors/fckeditor/editor/js/fckeditorcode_gecko_2.js in OpenCms and replace the text:
Publish the file and this should be it. Don’t forget to empty your browser cache afterwards (don’t just press CTRL+F5) otherwise you will still get the old file.
Of course this is not a real fix, but if you have to get rid of the problem fast. This can help.
Update: In OpenCms 6.2.3 the file is called fckeditorcode_gecko.js notfckeditorcode_gecko_2.js.
If you put an external link into the OpenCms navigation the resulting link will target the external link file which then in turns redirects the surfer to the external page. This is bad if you really want to optimize your navigation for search engines, because search engines won’t see the real link inside the navigation.
The solution
You can use the following JSP snippet to get the real URL from a CmsJspNavElement.
// We assume that the variable "link" holds an CmsJspNavElement and
// "cmsa" holds an CmsJspActionElement.
// Prevent external links from beeing a redirect
// therefore extract the real URL out of the file
String fileUri = link.getResourceName();
CmsResource navResource = cmsa.getCmsObject().readResource(fileUri);
if (navResource.getTypeId() == CmsResourceTypePointer.getStaticTypeId()) {
CmsFile navFile = CmsFile.upgrade(navResource,cmsa.getCmsObject());
String externalLink = new String(navFile.getContents());
externalLink = externalLink.trim();
}
I recently discovered runkit for PHP and thought it could be a solution for a few problems I ran into during my work on various projects.
At heart runkit allows you do to stuff with PHP you shouldn’t, but eventually want to, do. In my case this is basically Sandboxing and redefining (even PHP-internal) functions. It really adds some cool stuff to your PHP toolbox. Have a look at the function reference for the complete list.
Sadly enough the runkit PECL package does not work on Debian Etch (because Etch uses PHP 5.2.0+) so I had to build the package myself. Read on to find out how to build and install runkit on Debian etch and things to keep in mind when using runkit.
Important: If you are unsure of using runkit have a look at The sections The Caveat and Final Remarks before you walk through the hassle of installing it.
For a while I have been using Google Analytics for my website statistics (additionally to AWStats) and I really like the reports (Note: Yahoo! now has a competing product out there called “Yahoo! Web Analytics” which I might check out in the future). I’ve also installed various tracking software (like etracker - which is a German service) on different CMS solutions at customer sites.
Nearly all services offer some copy&paste code to throw into your HTML/JSP/PHP/Whatever, but if you’re using a CMS system things might be a bit more complicated. In most CMS systems you have two different kinds of traffic: Visitor generated and editor generated. Editors browse the site while checking their changes or proofreading text in the offline area (unpublished content). You most likely don’t want to have this traffic screw up your statistics, so it makes sense to filter out the traffic. Mostly a simple if(…)-clause is all that’s needed to achieve this. Here is my solution for OpenCms:
finally I have decided to join the trend and start blogging. There are several reasons why I chose do so. The two main ones are:
I want to publish information in a more informal way. I have many ideas regarding small articles and code-snippets which may be useful for other people and are very useful for myself because I keep forgetting stuff.
I started working as a freelance software developer and since I’m mostly working at home this means no more (or much less) office chat. I hope this blog is a way to keep in touch with old (and new) colleagues and customers to inform them of what I’m working on right now. Hopefully it will spur some discussion.
There’s really not much more to say. We’ll see how this blog will develop. I must admit I’m very exited about it.