CSV parsing .. once again

Posted by Mike Haller on Sunday, December 31. 2006 at 17:11 in Java
Who hasn't dealt with comma separated values? These damn little .csv files. Okay, there are a few Java libraries to handle CSV files, such as the Ostermiller lib. However, it's not usable in some environments (e.g. licensing conflict).

"1000";1;;"0";"1000";;9;2000;"1000";"Sonstiges";"Stck";;1,00;1754" "1001";1;;"0";"1000";;9;2000;"1000";"Sonstiges";"Stck";;1,00;584" "1002";1;;"0";"1001";;9;2000;"1000";"Sonstiges";"Stck";;1,00;255"


Then, in a new Java project, one is undecided whether to write a small importer which just fits the one .csv file you need to import. Then, there will always be another one and yet another one. Oh, and then there are the charset problems. Does the file originate from a legacy DOS application, a legacy Windows application? Or is it totally weird, because csv is only a de-facto standard and you cannot find a real specification anywhere? How do you handle the empty values with no quotes?

At that time, it'd be good to have a Java CSV library within reach.

Apache has the commons-csv library, and hopefully it gets out of the sandbox soon and will be merged with an existing library such as commons-lang or commons-io.

MySQL's case-sensitivity

Posted by Mike Haller on Saturday, December 30. 2006 at 00:00 in Hosting
Yesterday, we transferred the database of a custgomer from his Windows machine to our linux-based database server. At the same time, we wanted to get this administration frontend working again. It was also deployed on that Windows machine, running on a Sun Application Server against the local MySQL database.

The problem with MySQL is, besides some other issues, that it is case-sensitive. Yes, MySQL treates database and table names case-sensitive if it runs on a case-sensitive file system. Hence, copying the database from a Windows machine to a Linux machine by exporting and reimporting created mixed-case mysql data files. Hence, the applications who access this database only used lower-case names. The SQL standard clearly states that identifiers are not case-sensitive. MySQL breaks that. There is a configuration parameter which makes mysql do auto-conversion. It will then automatically lower-case tablenames in the SQL statements.

However, it is not a good idea to do that with existing databases as this will break existing applications. Mysql won't find the files which are already mixed-case any more.

So, we needed to set up a second mysql instance with the case-sensitivity configuration parameter set to the value 1. That means, it will lower-case all tablenames and filenames automatically (on creation and within SQL statements).

To start a second mysql instance on a Gentoo-based system, edit /etc/conf.d/mysql
mysql_slot_0=() mysql_slot_0_1=( "mycnf=/etc/mysql/my_second.cnf" "server-id=3" "port=3307" )


The my_second.cnf contains the configuration parameter:

[mysqld] ... set-variable=lower_case_table_names=1 ...


Now, import your existing backup into the second mysql instance. You should probably use the --host and --port parameters, so your data won't accidently being imported into your primary mysql installation. Specify 127.0.0.1 instead of localhost if he still connects to the primary instance.

Accessing resource files within your Eclipse plugins

Posted by Mike Haller on Friday, December 29. 2006 at 00:00 in Eclipse
Sometimes, especially in the development phase, you want to get your Eclipse Plugin's absolute file system location on the disk. Usually, you want to have a java.io.File. Since Eclipse mainly uses URLs to locate resources, it's not an easy one-liner to get the location. However, the utility class org.eclipse.core.runtime.FileLocator comes to the rescue:

URL bundleRoot = getBundle().getEntry("/");
URL fileURL = FileLocator.toFileURL(bundleRoot);
java.io.File file = new java.io.File(fileURL.toURI());

System.out.println("Bundle location:" + file.getAbsolutePath());


Note: please be aware that your plugin should be normally packaged as jar file and thus the above code does not work any more in a packaged deployment! To get this working, you must set the unpack attribute in your feature for the plugin.

What you really want to do is to use getBundle().getEntry("/file.txt").openStream() to get the contents of a file which is located within your plugin.

The code above is called from within a Plugin Activator class and uses the shortcut getBundle() method. If you need the code outside of an Activator class, use the Platform to resolve the bundle first. A one-liner looks like this:

new File(FileLocator.toFileURL(Platform.getBundle(
     pluginId).getEntry("/")).toURI());


Optionally Required

Posted by Mike Haller on Thursday, December 28. 2006 at 00:00 in Eclipse
Ever wondered what the error message Missing optionally required bundle means?
!SUBENTRY 2 org.eclipse.emf.edit.ui 2 0 2007-01-02 16:42:41.082 !MESSAGE Missing optionally required bundle org.eclipse.ui.ide_[3.2.0,4.0.0).


Eclipse tries to tell you that the bundle org.eclipse.emf.edit.ui can make use of org.eclipse.ui.ide, but it is not strictly necessary for emf.edit.ui to work. In fact, emf.edit.ui uses services from ui.ide if they are existant. If not, it just doesn't use them.

The error message in the /configuration/.log is not an error message, but more an informative level message.

So, if your RCP application doesn't start and you find this message in the .log file, you can safely ignore it and focus on resolving the other messages first.

Product Launcher Icons

Posted by Mike Haller on Wednesday, December 27. 2006 at 00:00 in Eclipse
If you want to brand your Eclipse RCP product launcher with your own icons, you need to either supply some bitmaps or a single Windows Icon file. The problem here, besides the boring work of creating 7 similar files, is that you need some of them in 32-bit. None of the usual imaging tools I have installed were capable of creating 32 Bit Windows Bitmaps: Irfanview, The Gimp, .. not even Microsoft Paint of Windows XP could create this format.

Use the Eclipse Product Editor to specify which Icons to use for the Launcher Executable


Once again, the Eclipse IRC channel #eclipse on Freenode came to the rescue and provided some hints: The Microsoft MSDN Library contains a tool which can be used to create the 32 Bit Bitmaps used for Windows XP. However, I choosed to evaluate a tool named Microangelo Studio to creat the .ico File. Pasting the product logo into the editor and adding a new format for each of the required dimensions and color depths.

The last thing I need to do is to explain all that to my designer. My logos are pretty ugly and haven't even transparent background. This looks like Windows 3.0 and will probably frighten the users.

About

My name is Mike Haller and I'm a software developer and architect at Bosch Software Innovations in Germany. I love programming, playing games and reading books. I like good food, making photos and learning and mentoring about the craftsmanship of commercial software development. Stack Overflow profile for mhaller

Quicksearch