Archive for May, 2004

Potential obfuscation

Monday, May 31st, 2004

I like to keep track of a list of nasty things you can do to a Java source file. Things like putting $ at the front of all your variable names etc.

Anyway, realised another one today; which hides under all of our noses.

It’s easy to get into the habit of always coding public classes, so easy to fall into the trap of thinking that the Java class ‘XXX’ must be in a file named ‘XXX.java’.

This is true if ‘XXX’ is public, but not if it’s package level. If the class(es) in a Java source file (you did know you can put more than one class in a file right?) are all package level, then you can name the file anything you want.

OddsAndSods.java:
class Web {
int i = 0;
}
class Log {
int j = 0;
}

Of course, from this you get Web.class and Log.class.

Wildcard imports…not as bad anymore?

Saturday, May 29th, 2004

I’ve always been very against ‘import java.util.*;’ and its ilk, for 2 very good reasons.

Firstly, there is the classic clash possibility where java.util.Date and java.sql.Date hit each other and you have no idea which ‘new Date(42L)’ matches. Secondly, there is the readability problem where a developer new to the code has no idea which package a class came from.

While the latter is not a huge problem with the JDK classes, it is a pain in the arse with someone else’s code.

As a part of teaching a class, I had cause to try out the classic Date clash. In fact, I used ‘new Date()’, which can only hit java.util.Date as java.sql.Date has (long) and (int, int, int) as contructors. I got back the following compiler error:

reference to Date is ambiguous, both class java.util.Date in java.util and class java.sql.Date in java.sql match

I’m unsure when this turned up, but am pretty sure JDK 1.1 did not have it.

So my first reason no longer applies at all. The only reason to avoid a wildcard import (and I don’t mean the evil new JDK 1.5 ones) is to make code more readable.

As standard J2SE/J2EE classes should be known, I’m ready to start using ‘import java.util.*’.

(400th blog entry)

Image manipulation

Tuesday, May 25th, 2004

I’m playing with images at the moment, overlaying various different images into one image. I’m using PNGs, and have had a few J2SE problems. Linux JDK 1.4.1 and OS X both seem to have trouble with the PNG’s that have come out of Fireworks, but Linux 1.4.2 and Windows 1.4.2 seem fine.

After messing with AWT to prototype it, I needed to run it in a headless mode. Peeked at Hardy’s Java2D book, but the interesting part is his own library and I was unable to find a project page for it. I found the book page, but that suggests it’s not been updated much.

So I googled some more, and found Abel Mullassery’s PMIW, Poor Man’s Imaging Wrapper. Very cool and just what I needed. http://www.mullassery.com/software/PMIW/

The code became:

        String[] file = new String[] { “one.png”, “two.png”, “three.png”, “four.png” };        int[] x = new int[] { 0,50,50,0};        int[] y = new int[] { 0,0,50,50};        Imaging imaging = new ImagingFactory().createImagingInstance(ImagingFactory.JAVA2D);        BufferedImage image = imaging.read(file[0]);

        for(int i=1; i<file.length; i++) {            BufferedImage img = imaging.read(file[i]);            image = imaging.overlay(image, img, x[i], y[i]);        }        // little unsure of the “png” here        Util.saveImage(imaging, image, “png”, new File(”merge.png”));

Thanks Abel, saved much pain.

Keeping quiet…

Monday, May 24th, 2004

Or not as I’m actually saying something, but managed to make the superb screw-up of cronning my backups to happen at:

* 3 * * 6

ie) at 3am on Saturday.

Then at 3:01…3:02…until 3:59. I noticed the home bandwidth sucking around midday on Saturday and rebooted the machine. 10Gig or more went through, and went through my limits on the servers. Doh. A mistake that I’ll have to pay for out of my pocket when the bill comes in :)

I did however spend some more time playing with Roller. [Also, I owe the Pebble author an explanation of why I can’t get it to work]. I can’t get the current CVS version to work well, but I’ve written an MT-export to ATOM migration tool that I need to put on the list for use.

Carrie’s done some work on it too that she needs to announce on the list, and we’ve got plans for a new blog. One thing I’ll definitely need to figure out is how to do the redirect/rewrite from MT’s index and RSS to Roller’s.

MT to Roller migration script

Wednesday, May 19th, 2004

If anyone is interested, I’ve spent a bit of the evening [after teaching class], hacking in perl. I love perl, but as I use it fitfully I’m fully prepared to accept any criticisms on my perl skills. Still:

http://www.generationjava.com/mt2roller.pl

It currently has two ‘flaws’.

1) After setting up a new blog, you have to find your website id [located in the website table] and put this inside the script. Easy enough to fix as a command line argument.

2) It assumes it can start counting id’s from 1 for the various primary keys. This works, but isn’t perfect and if it’s the 2nd blog you’re putting in, you’ll need to increase these numbers. This could be a huge issue as Roller aren’t actually using simple sequences, but some other kind of generated id [from Castor?].

I invoke it as:

./mt2roller.pl blog-export | mysql roller -u roller -p

The important part being, it has no database handling code. That’s why 2 is so pathetic right now. ‘blog-export’ is the name of the file I exported from my MT blog by the way.

Still, as far as I can tell it correctly pulled over 350 or so entries and assorted comments without any errors, and apart from an ‘update-time’ field which just isn’t available so I use ‘create-time’, I think everything is covered.

JavaBlogs.com user-agent analysis

Wednesday, May 19th, 2004

Decided to let my machine do a little work. I wanted to know which blogging engines were commonly of use for Java people.

Making the assumption that most Java blogs are subscribed to javablogs.com, I sucked down the OPML info from javablogs.com, then sucked down the xmlfeed for every blog mentioned. Once they were down, I merged them into similar groups using the various generator tags and ran a report-script to get numbers.

Of 800 entries in the OPML, 732 had working rss feeds. Of that 732, I was able to relatively easily extract counts for 591.

Here’s the report [ignoring blogs with only 1 user. See additional text for those]

288 - Roller Weblogger
163 - Movable Type
20 - Blojsom
17 - Radio Userland
16 - Pebble
15 - Blosxom
13 - Blogger
10 - SnipSnap
9 - Wordpress
6 - b2
4 - LiveJournal
3 - iBlog
3 - SourceForge
2 - Blogmento
2 - rssify

Of the 141 I did not identify, a very quick bit of grepping suggests that:

40 - blog-city
24 - java.net
14 - dead blog-city
11 - artima
37 - engimastation (??)

it’s pretty random, but would take 126 of the 141 out of the picture.

It suggests that the java blog world is much like Formula 1 grand prix racing often is. Dominated by 2 huge teams [Roller and MT], with a small also-ran group and then a lot of stragglers. Many of these stragglers are huge in other fields, just not this one.

Although I merged them in, there were only 3 typepad blogs. Unsure if that’s the only example of a commercial MT user at the moment. RollerWeblogger is obviously helped by the JRoller site.

Interesting to repeat this in 6 months.Entries with a single site:

1 - GeekBlog v1.0
1 - Nucleus v2.0 beta
1 - UserLand
1 - custom
1 - http://www.dotclear.net/
1 - XOOPS 2.0.5
1 - jTalk v1.0.32
1 - http://www.extreme.indiana.edu/~aslom/blog/micro
1 - http://www.xoltar.org/2004/jan/26/nice-generator.html”
1 - phposxom/0.6b
1 - http://www.blogbus.com
1 - newtelligence dasBlog 1.6.4121.0
1 - http://www.mijnkopthee.nl/pivot/?v=0.12
1 - Tug’s JavaBlogger
1 - dataFaber 1.5
1 - http://www.blogeasy.com
1 - Feedster RSS Creator/0.1x
1 - java.no portal
1 - blogg.de
1 - pMachine/2.3

More Roller-ing

Monday, May 17th, 2004

We both played with Roller tonight. Some frustration.

First off, some pains in the arse. There are inline styles and presentation aspects that are not available to the user. They got heavily in the way of Carrie’s attempts to make it look like her site and after a bit of a peek I found them in the Velocity .vm files. 22 BR tags and 30 DIV tags. The DIV part I can see some aspect for, but not the BRs. Even with the DIVs, the macros need more power to allow you to put pre-loop and post-loop elements in, as well as delimiters. My suggestion would be to put all DIVs in the ‘Weblog’ Page, and remove all DIVs from the vm’s that go into it.

The only DIVs which would need to stay are for things like comment sections, and this is largely because there’s no way for the user to modify this [that I can see].

Next up, Themes and Pages. What a confusion. Eventually we twigged.
A Theme is nothing but a set of Pages. Namely, your Weblog, _day and _css pages. You can edit these pages, but when you switch Themes, your customisations are overwritten.

This can be very confusing when you’re looking at the css etc. It also means that you can (have to) choose a theme as your initial starting point. All in all, we were both confused trying to get started.

Errors are another fun-ness. I screwed up some velocity and managed to break my site [though not Carrie’s oddly enough]. I keep putting commas in velocity macro parameter lists and it does not like it. When it dies, I cannot publish new blog entries in anyway unless I restart [refreshing the cache fails to improve things].

The next/prev on the calendar seems to work. Unsure why I had problems with it before.

Something we need to figure out is how to emulate the MT archive page, and the list-by-category page. It’d also be nice to have some kind of plugin to manage the classic ‘currently reading’, ‘currently knitting’, ‘quotes’ kind of thing.

Images and attachments were a bit odd. They have their own top level area, so pages/nico and resources/nico, rather than nico/resources and nico/pages. This forces you to web-absolute link to get things working, which doesn’t fit the idea of a blog with data inside it.

Velocity also seems to not be editable live. I had to restart the system after modifying a .vm file, which is a complete pain in the arse for a scripted language.

That’s all that springs to mind so far, more to come as we play.

Playing more with blogging tools

Monday, May 17th, 2004

Mainly we looked at Roller in tonight’s investigation, but before I get onto that in the next post, we spent a bit of time on other blog tools.

I figured out my problem with Blojsom, there’s what appeared to be an optional configuration in the installation instructions, but is actually essential: blojsom-default-user. Once I fixed that, the blog itself worked fine, however the basic setup appears to be to create webpages by hand (or vi). David Czarnecki mentioned in an email that there’s an entire admin system, and gave me a couple of links to set it up, so sometime tomorrow I’ll play with that.

Pebble still refutes my attempts to set it up. It runs happily without error, but won’t let me log in. More effort needed there. [Carrie wants it to have a component called BamBam. Too much TV, not enough video games as a kid. ]

Blogmento refuses to do the publish step. Unsure how to debug this, but attempting to scp to the server. One bad part with blogmento, the password is is shown in plaintext.

Lastly, I installed SnipSnap. Nice and easy, Carrie has not looked at it yet as she doesn’t have much interest in the idea of trying to customise a wiki to the extent she would want to customise her website/blog.

Blogmento, comments

Monday, May 17th, 2004

Jeremy Rayner, www.javanicus.com - the author of blogmento, emailed me to clear up a couple of my loosely-cast comments on blogmento.

My comment that blogmento is not a server solution is a little misleading in that blogmento can run on the command line as the blogmento jar can operate happily in a headless mode. By server solution I meant something that I can use it from many different desktops.

There is a JNLP install as well as the Windows install.

The reason I mention it now is that I found myself recommending that someone try it out. He isn’t in the luxurious position of having a server to install all his things on, but does carry his laptop everywhere.

I’ll also get Carrie to see how it feels, just in case she likes it. Possibly it might integrate nicely with dreamweaver in terms of customisation. It uploads the data via FTP or SCP.

SnipSnap mention..

Monday, May 17th, 2004

More to come on the Java blog software, but having just installed SnipSnap I felt I had to immediately exclaim my happiness at how wonderful it is to install.

I chose to install the WAR version, had to look in catalina.out for the installation key and I was away. Only complaint is that when you choose a theme, there’s no way to preview a theme. I had to choose one then hit the back button to see the current theme.

Anyway, will set this up at home and unleash Carrie on it.