Showing posts with label open source. Show all posts
Showing posts with label open source. Show all posts

2010-08-15

XML Zen 0.2

After a long break a new version of XML Zen was finally released. It has several bug fixes along with some new features. The changelog:

Changes in version 0.2.0 (2010-08-15)

  • Fixed a bug which prevented getting attribute values in some cases (Issue #11)
  • Added a possibility to set some defaults for XmlBuilder (Issue #10)
  • Added XmlBuilderOutput interface with String and OutputStream implementations (Issue #8)
  • XmlBuilder builds formatted XML with declaration (if charset is provided) (Issue #9)
  • File support in XmlBuilder (through XmlBuilderStreamOutput) and XmlSlicer (Issue #7)
I would like to thank JetBrains for IntelliJ IDEA license which was issued for this project. I’m trying to switch from Eclipse to IDEA, and so far I feel quite excited about it.

2009-09-29

XML processing in Java

One of the things that most Java developers tackle on daily basis is dealing with XML. Despite the fact that XML is taking lots of criticism and new formats like YAML are emerging and becoming more popular, you cannot avoid XML it's too widespread and used everywhere. It's the main format for interchanging data across systems and even people. There is a great deal of fat books that show how to use various XML APIs and libraries to handle the beast with all it's standards and extensions. There are many solid tools that had been continuously developed for years by large communities (Xalan, Xerces, JDOM, DOM4J).

And still XML processing in Java is still a major pain in the ass.
I see two reasons for that: 
  1. XML is too bloated as a format. See the picture below (click to enlarge):
  2. Java libraries that deal with XML are bloated. It's natural because they simply try to implement the specifications

Let's say you have a Java application which receives some data in form of simple XML:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <entry id="1">entry number one</entry>
<entry id="2">entry number two</entry>
</data>
Your application has this class:

public class Entry {
private int id;
private String content;
//the usual setters and getters here
}
If you would want to parse this XML with Java, into Entry objects you would usually do something like this:

try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File("data.xml"));
NodeList nl = doc.getElementsByTagName("entry");
for (int i = 0; i < nl.getLength(); i++) {
Entry entry = new Entry();
entry.setId(Integer.parseInt(nl.item(i).getAttributes()
.getNamedItem("id").getNodeValue()));
entry.setContent(nl.item(i).getTextContent());
System.out.println(entry);
//do real stuff
}
}
catch (final Exception e) {
System.out.println("Failed parsing: " + e);
//do real handling
}
Expected output:

Entry:{id: 1; content: entry number one}
Entry:{id: 2; content: entry number two}
In Java 6 DocumentBuilderFactory.newInstance() will usually return an instance of this implementation: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl 
This is Xerces embedded into the JRE. What's wrong with that? First, it's a huge library with big memory footprint. It will be outdated in comparison with what you can get at the official homepage, so if you want to go for the latest version with all the bug fixes, you will have to add another megabyte of jars to your project, set a system property (javax.xml.parsers.DocumentBuilderFactory) to change the default implementation and hope your code works. Then you have to know DOM. You have to use an ugly for loop to iterate the results instead of doing it right (for (Node n : doc.getElementsByTagName("entry") { ... }).
Even though Java aims to be loosely coupled, you can use the API and switch implementations, you should keep in mind that API changes over time, and implementations work differently. I have seen legacy code where you can find sick things like DocumentBuilderFactoryImpl = (DocumentBuilderFactoryImpl) DocumentBuilderFactory.newInstance();, I have seen Axis failing to parse complex SOAP messages after switching to different, newer JDK, I have seen third party software vendors who start cursing when you change your web service implementation and your WSDL is generated with minor cosmetic differences (i.e.: xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" instead of previous version: xmlns:s="http://schemas.xmlsoap.org/wsdl/soap/"). In all these cases APIs and implementations failed to do what they were meant for. Of course, everything can be fixed, but it takes time and nerves, and these things are precious.
XML processing in Java is terrible, and the worst part is when you have to go through all this just to parse a simple piece of data. Why couldn't it be as simple as that:

for (XmlSlicer piece : XmlSlicer.cut(data).getTags("entry")) {
//each piece is: <entry id="...">...</entry>
Entry entry = new Entry();
entry.setId(Integer.parseInt(piece.getTagAttribute("entry", "id")));
entry.setContent(piece.get("entry").toString());
System.out.println(entry);   
//do real stuff
}
After being fed up with Java's great XML APIs and libraries I made a small tool for simple daily work with XML files.
The code above would work in XML Zen - a small and lightweight XML processing library that supports ~1% of what other XML processing libraries can do, however this 1% of functionality is what you use 90% of the time. There are no big APIs, just simple logic driven object oriented processing of XML strings. And it's just a little over 10Kb.
You can add XML Zen dependency with Maven, just set the dev.java.net repo first:

<repositories>
<repository>
  <id>maven2-repository.dev.java.net</id>
  <name>Java.net Repository for Maven</name>
  <url>http://download.java.net/maven/2</url>
  </repository>
  <!-- other repositories -->
</repositories>
Then the dependency:

<dependency>
    <groupId>com.googlecode.xmlzen<groupId>
    <artifactId>xmlzen</artifactId>
    <version>0.1.1</version>
</dependency>
That's it, you are ready to go. And when it comes to building XML and XML Zen is not enough for your needs, check out this great project: http://java.ociweb.com/mark/programming/WAX.html.

2009-06-17

A tool for unpacking multiple archives and other ramblings

I've always wondered why torrents are packed into multiple archives, sometimes even archives inside other archives. Anyway, I've got fed up with all the unpacking routines, especially after downloading several seasons of something that has each episode in an individual folder containing 20 rar or zip files. So, after one evening of coding this nightmare is now over.

Here is the screenshot of the stupidly named tool (click to visit project page):


It was also a good reason to try out new version of NetBeans. I still hate GUI builders, however for small "write and forget" kind of projects like Multi Unpacker it's a fairly good choice. However NetBeans is still slow and unresponsive in comparison with Eclipse.

So far Multi Unpacker is for Windows only, however it's a spare evening away from becoming cross-platform (and you are welcome to join the project). Too bad my MacBook broke down completely, so Macs will most probably not get any special treatment... This is also bad news for Hawkscope, unless someone is willing to donate me an old Mac? :)

2009-03-21

Gmail4J - Gmail API for Java



Seems that Google has no Gmail API available, so I made a small Java library called Gmail4J. The library is designed to be extensible, allowing various implementations. Currently the only available implementation allows getting new unread messages from their RSS feed. That's not much, but it's a start.

Here is the example code (updated to conform with Gmail4J 0.2):

GmailClient client = new RssGmailClient();
GmailConnection connection = new HttpGmailConnection("user", "pass".toCharArray());
client.setConnection(connection);
final List<GmailMessage> messages = client.getUnreadMessages();
for (GmailMessage message : messages) {
System.out.println(message);
}

Next implementation will probably be based on JavaMail IMAP functionality. It should be able to do more than getting unread messages.

2009-01-28

Hawkscope on Mac. Finally.

Last week I have quit sleeping and did hell of a coding on Hawkscope. And there's a new version, with many significant changes and improvements. To name a few:

  • Works on Mac OS X! (Java 5, Tiger / Leopard)

  • Installer packages for Windows, Mac and Debian (Ubuntu).

  • Settings can finally be changed via Settings Window, like in most normal applications...

  • Speed! Especially noticeable when you have many network drives.

  • Check for updates. A new way to annoy the users!

  • Blacklist. Remove all the shit you don't want to see.



Download links:
hawkscope_0.4.0-1_i386.deb: Debian Package for i386 GTK Linux (Ubuntu)
hawkscope_0.4.0-1_amd64.deb: Debian Package for amd64 GTK Linux (Ubuntu)
Hawkscope-0.4.0.dmg: Mac OS X i386 Package (Tiger/Leopard)
hawkscope-0.4.0-installer.exe: Windows i386 Installer (XP/Vista)

2009-01-22

Hawkscope: Getting Better



Finally, I've managed to finish the SWT implementation of Hawkscope GUI. Along with some other minor fixes and improvements it ended up as a new Hawkscope version: 0.3.0.

A list of key points for this release:

  • Tray icon should work with Mac OS X (at least with 64-bit Leopard /w Java 6)

  • Hawkscope menu is more responsive and usable

  • Keyboard navigation through the menu is finally available

  • Each OS/Architecture has it's own build

  • Added -delay <milliseconds> startup parameter as a workaround for Java bug #6438179 that prevented Hawkscope from auto-starting in operating systems like Ubuntu. Read more in the User Guide

By the way, if you're on 64-bit Vista or 64-bit Leopard with Java 6 and you've got Maven in your hands, you could be helpful by providing the build for your OS. Thank You!

If Java is your cocaine, you are welcome to join the development - just contact me.

Download links for the new Hawkscope 0.3.0:

hawkscope-0.3.0-linux-gtk-32.jar - Linux GTK 32-bit Executable JAR
hawkscope-0.3.0-linux-gtk-64.jar - Linux GTK 64-bit Executable JAR
hawkscope-0.3.0-win-32.exe - Windows XP/Vista 32-bit Executable
hawkscope-0.3.0-win-32.jar - Windows XP/Vista 32-bit Executable JAR

2008-10-07

Hawkscope 0.2.0

This little peace of software has lately become my passion that reminds me of those days when I was programming 16 hours a day 7 days a week. Anyway, here are the highlights for the new Hawkscope 0.2.0:

  • Size dropped down from 740Kb to 122Kb.

  • Fixed bugs that prevented writing the configuration file in Windows and reading it in all OS.

  • Added Quick Access List menu that allows custom folders to be listed on top of all partitions. User home is there by default. This list can contain dynamic variables like Java properties (${user.home}/Desktop) or environmental variables (${$JAVA_HOME}). Read the User Guide to find out how to configure your own Quick Access List.

  • Floppy drives are ignored by default to avoid annoying device buzz whenever mouse travels over floppy disk entry. This can be turned back on by changing display.floppy property to "1". By the way, same thing can be done with hidden files. They are hidden by default, but there is display.hidden property in [user_home]/.hawkscope.properties.

  • Improvements in About and Error dialogs. You can now copy nicely formatted bug reports to Clipboard for easy submission. If you use Hawkscope and find anything suspicious, please, copy the report and add new issue, it takes just 10-20 seconds.

  • You can find more changes in Hawkscope Changelog.

    Here's how the new version looks on Windows Vista:



    Stay tuned for future improvements that include a full blown plugin system, GUI driven configuration and more.

    2008-09-28

    Hawkscope: System Tray File Browser

    I'm happy to announce the first usable release of my new weekend project. It's Hawkscope - a simple productivity tool that allows you to find and open any file or folder in seconds by single-clicking a tray icon and navigating through dynamically generated menus that reflect the contents of your available file systems.

    Hawkscope is open source, it's built with Java 1.6, therefore it doesn't run on Mac OS X (for now...), even with SoyLatte JDK. I tested it on Windows (XP and Vista) and Linux (Ubuntu + Gnome). Should work perfectly where Java 6 System Tray and Desktop API are supported.

    Here's how it looks on Windows Vista (running inside VirtualBox):


    And on my Ubuntu:


    You can always download latest release here. Enjoy!

    2008-07-02

    CMS battle: Drupal vs Joomla vs Custom Programming

    In modern Content Management System (CMS) world there are two major figures - Joomla (descendant of Mambo CMS ) and Drupal. They both are open source and have large comunities with enormous amounts of extensions and themes. It's hard to choose which one to use without trying them out. As usually, there are more options - home grown custom programming or even building your own CMS (which I was once stupid enough to do). Programming from scratch is always fun and beneficial for your skills, however, if you need things up and running in no time or you don't do (or don't want to do) any programming, using a CMS is the way to go.

    If you are digging for CMS comparisons and trying to decide which one is best for you, here is a quick and dirty answer - go for Drupal, you won't regret it.

    Why?

    After test-driving them both I've came to these conclusions:

    • Joomla is bloated, Drupal is minimal
    • Drupal is easy to use and intuitive, Joomla is confusing

    That was more than enough for a minimalist like me.

    Here are some statistics from CMS Matrix for a more detailed comparison. It shows that Drupal is extremely modular and Joomla has a heavy core, thus a terrible architecture. That means Joomla is hard to extend and messy under the hood. Drupal, on the other hand, looks beautiful.


    Product Drupal 6.2 Joomla! 1.5.3
    Last Updated 4/10/2008 5/31/2008
    System Requirements Drupal Joomla!
    Application Server PHP 4.3.5+
    Approximate Cost Free Free
    Database MySQL, Postgres MySQL
    License GNU GPL GNU/GPL v2
    Operating System Any Any
    Programming Language PHP PHP
    Root Access No No
    Shell Access No No
    Web Server Apache, IIS Apache
    Security Drupal Joomla!
    Audit Trail Yes No
    Captcha Free Add On Free Add On
    Content Approval Yes Yes
    Yes Yes
    Granular Privileges Yes No
    Kerberos Authentication No No
    LDAP Authentication Free Add On Yes
    Yes Yes
    NIS Authentication No No
    NTLM Authentication Free Add On No
    Pluggable Authentication Yes Yes
    Problem Notification No No
    Sandbox No No
    Session Management Yes Yes
    SMB Authentication No No
    SSL Compatible Yes Yes
    SSL Logins No Yes
    SSL Pages No Yes
    Versioning Yes No
    Support Drupal Joomla!
    Certification Program No No
    Code Skeletons Yes No
    Commercial Manuals Yes Yes
    Commercial Support Yes Yes
    Commercial Training Yes Yes
    Developer Community Yes Yes
    Online Help Yes Yes
    Pluggable API Yes Yes
    Professional Hosting Yes Yes
    Professional Services Yes Yes
    Public Forum Yes Yes
    Public Mailing List Yes No
    Test Framework Free Add On Yes
    Third-Party Developers Yes Yes
    Users Conference Yes Yes
    Ease of Use Drupal Joomla!
    Drag-N-Drop Content Free Add On No
    Free Add On Free Add On
    Friendly URLs Yes Yes
    Image Resizing Free Add On Yes
    Macro Language Free Add On Yes
    Mass Upload Free Add On No
    Prototyping Limited Yes
    Server Page Language Yes Yes
    Site Setup Wizard Limited No
    Spell Checker Free Add On No
    Style Wizard Limited No
    Subscriptions Free Add On No
    Template Language Limited Yes
    UI Levels No Yes
    Undo Limited No
    WYSIWYG Editor Free Add On Yes
    Zip Archives No No
    Performance Drupal Joomla!
    Advanced Caching Yes Yes
    Database Replication Limited No
    Load Balancing Yes Yes
    Page Caching Yes Yes
    Static Content Export No No
    Management Drupal Joomla!
    Advertising Management Free Add On Yes
    Asset Management Yes Yes
    Clipboard No No
    Content Scheduling Free Add On Yes
    Content Staging Free Add On No
    Inline Administration Yes Yes
    Online Administration Yes Yes
    Package Deployment No No
    Sub-sites / Roots Yes Yes
    Themes / Skins Yes Yes
    Trash No Yes
    Web Statistics Yes Yes
    Web-based Style/Template Management Yes Yes
    Web-based Translation Management Yes Free Add On
    Workflow Engine Limited No
    Interoperability Drupal Joomla!
    Content Syndication (RSS) Yes Yes
    FTP Support Limited Yes
    iCal Free Add On No
    UTF-8 Support Yes Yes
    WAI Compliant Limited No
    WebDAV Support No No
    XHTML Compliant Yes No
    Flexibility Drupal Joomla!
    CGI-mode Support Yes Yes
    Content Reuse Limited Yes
    Extensible User Profiles Yes Yes
    Interface Localization Yes Yes
    Yes Yes
    Multi-lingual Content Yes Free Add On
    Multi-lingual Content Integration Free Add On Free Add On
    Multi-Site Deployment Yes Free Add On
    URL Rewriting Yes Yes
    Built-in Applications Drupal Joomla!
    Blog Yes Yes
    Chat Free Add On Free Add On
    Classifieds Free Add On Free Add On
    Contact Management Free Add On Yes
    Data Entry Free Add On Free Add On
    Database Reports No Free Add On
    Discussion / Forum Yes Free Add On
    Document Management Limited Free Add On
    Events Calendar Free Add On Free Add On
    Events Management Free Add On Free Add On
    Expense Reports No Free Add On
    FAQ Management Yes Yes
    File Distribution Free Add On Free Add On
    Graphs and Charts No Free Add On
    Groupware Free Add On Free Add On
    Guest Book Free Add On Free Add On
    Help Desk / Bug Reporting Free Add On Free Add On
    HTTP Proxy No No
    In/Out Board No No
    Job Postings Free Add On Free Add On
    Free Add On Yes
    Mail Form Free Add On Yes
    Matrix No No
    My Page / Dashboard Free Add On No
    Free Add On Free Add On
    Free Add On Free Add On
    Polls Yes Yes
    Product Management Free Add On Yes
    Project Tracking Free Add On Free Add On
    Search Engine Yes Yes
    Site Map Free Add On Free Add On
    Stock Quotes Free Add On No
    Surveys Free Add On Free Add On
    Syndicated Content (RSS) Yes Yes
    Tests / Quizzes Free Add On Free Add On
    Time Tracking Free Add On No
    User Contributions Yes Yes
    Weather Free Add On No
    Web Services Front End Limited Yes
    Wiki Free Add On Free Add On
    Commerce Drupal Joomla!
    Affiliate Tracking Free Add On Free Add On
    Inventory Management Free Add On Free Add On
    Pluggable Payments Free Add On Free Add On
    Pluggable Shipping Free Add On Free Add On
    Pluggable Tax Free Add On Free Add On
    Point of Sale No Free Add On
    Shopping Cart Free Add On Free Add On
    Subscriptions Free Add On Free Add On
    Wish Lists Free Add On Free Add On

    Hope this helps to make a choice.

    2008-05-30

    XSL Engine

    Amazingly, some bright minds of the company I work at supported the idea to release one of our products as an open source software. It's nice to see a huge "Nothing is Free" business opening up a little. I'm proud to present the release of the XSL Engine:

    XSLE at Google Code

    XSL Engine is an XSL transformation server and client. It provides united processing of XSL transformations, independent of any programming environment. This can remove load from other applications. It features high throughput, with the possibility to increase the throughput of the XSL transformations by setting up new servers. It operates in an Apache Tomcat Web container. XSL documents are loaded into cache. XSL Includes are supported. PDF can be generated (using XSL-FO). XSL cache can be automatically replicated among remote servers.