When I need to parse XML files in JAVA projects, I use SAX parser.
I like using SAX. It’s quite easy.
Of course, there’s nothing like parsing in PHP ( at least for me ) but SAX can also be interesting…
In one of my projects , I had this situation:
I had a thread that needed to parse N .xml documents , and in case of SaxException or IOException my thread needed to delete or move the current file to some new location.
I was using SAX parser.
It looks really easy thing to do, and it is! well, if you know and do some extra things…
Probably everyone who had this kind of situation very soon noticed that SAX parser won’t delete or move this file!
Why is that so?
Well , I don’t know if this is bug,or it just could have been done better, but it seems that XMLReader used when creating parser does not “release” that document when Exception occurs!
I cannot believe this is the way SAX works, but seems like it is!
What we need to do in a case of Exception? We need to somehow explicitly close this file.
And how can this be done?

I recommend you not to use

void parse(String systemId) method when parsing.

Use

void parse(InputSource input) instead!

This way, you can always explicitly close this InputSource when you need to “release” parsing document when Exception occurs.

Here is the example:

Let’s make some class called XMLDocumentParser that implements ContentHandler:

public class XmlDocumentParser implements ContentHandler

and let’s make some method doParse() that returns some wanted object that represents parsed document data:

I came up to this problem when parsing xml files with large text inside tags.
When a tag values is a small text or a number, SAX will parse your document without a problem, but when a tag value is some large text, then the SAX will return only a part of that text. The last part of that text.
Why is this so?
Do not ever assume and expect that a SAX parser will return entire String it finds inside some tag. SAX parser ( and a great number of other parsers) will return several chunks of that value, and it is your job to put that pieces together…

Lets see how this works:
In sax, in order to read tag values, among other methods, we need to implement characters() method.

Friday, 18 July 2008

One of my friends called me and asked me today how to enable TDBGrid in Borland C++ Builder to resize it’s columns on showing data in it.

He had a problem with TDBGrids that need to show some tables or query results with large number of columns.

He needed all of them to be visible without horizontal scrolling.

As I am aware, this function does not exist in TDBGrid, and it has to be made.

If it does exist I’m really not aware of it, and please tell me about it.

So, I wrote him code that I often used and what worked well for me :

I made a function called AdjustGrid() which will iterate through all columns and set their width to some equal value. This way, we can always see all the columns in some DBGrid , almost regardless to it’s size.

Let’s look at the example I made. Button1 just shows the data in the DBGrid, without adjusting any size ( default ).

and when we click on Button2, we get:

…And – it helped him… ;-) ! He even told me he will buy me a beer! ( psss: he never does! ;-) )

…and why am I writing about this trivial thing?

Because I remembered than that many people asked me the same thing before. I hope this will helpful to some of you how are looking for something like this…

One of the problems people often come up to while installing joomla is Session save path Unwriteable error.

In this quick tip you’ll learn how to solve this problem.

Of course , the first thing you need to do is to contact technical support and a webmaster of your server, and to see if he can ( wants to ) help.

If this doesn’t work, install joomla regardless to this error , and in a folder containing configuration.php create new folder , for example temp_folder.
Set it’s CHMOD so it is allowed to write in it.
From configuration.php copy the value of $mosConfig_absolute_path entry ( without quotes ) , and then add a new line to this file:

Sunday, 13 July 2008

Probably anyone who uses Oracle Forms Builder, at some point found himself with a certain problem that is very hard to fix using Oracle Forms Builder only, although it gives prety much everything you need to build a database application.

On the other hand , large number of those who managed to solve the problem weren’t even aware of a fact that they were able to solve that ’large’ and unusual problem by using Java beans, which can be used in Oracle Forms Builder.

Not to mention that many developers don’t even know about this functionality of Forms Builder that enables us to use Java code in our Oracle Forms application, and those who do know about it don’t know HOW to do it!

What I now plan to do is to show you how you can create and use some simple java bean in your Oracle Forms application.

These examples are far from usefull and complex but it will help you understand how to make a java bean and then you can create very usefull and complexe modules using almost complete power of Java...

I use Oracle 10g , and Developer suite 10g , and that means that we must use 1.4 version of java while building our bean.

Let’s open Eclipse and create new Java Project. Let’s call it „MyBean“ , and let’s create one Java class called „FirstBean“. For now, we have something like this:

The easiest way of creating a java bean that we can use in oracle forms builder, is to extend Vbean class. Vbean is located in frmall.jar. You can find it in %ORACLE_HOME%\forms\java on windows. ( for example, I have it on location C:\oracle\DevSuite\forms\java )

In order to use it, open project -> properties in eclipse , and under „java build path“ click on the Libraries tab , and then select frmall.jar by clicking on the „Add external jars“ button.

I mentioned before that we must use 1.4 compiler compliance level , so select it from drop down list, under „Java compiler“.

Click apply .

I will make a bean that we can use to:

- Get our own IP address

- Switch letters case of some string to upper case

- and to show input dialog for a user to enter some string and retrieve that string.

These examples are more than trivial , but they will help you understand a logic of building java beans that you can use in oracle forms builder.

You will soon see that we communicate with java beans by setting and getting some custom properties. all this is done by the use of the getPropery and setPropety methods defined in the Iview interface. Each property is created and stored within the oracle.forms.properties.ID class.

Let’s make 5 of it:

We will use I_TEXT to set an input dialog text, IP to retrieve ip address , SET_STRING to set a string for which we change letters case , SHOW_INPUT to say a java bean that we want to show input dialog, and UPPER_CASE to say a java bean that we want to retrieve (upper cased) string that we sent earlier.

So, the only two things we need to set before getting the result from java bean are I_TEXT ( text to be shown on input dialog) and SET_STRING ( the string that is about to be upper cased ).

In order to set it, we must use setter setProperty() :

and later when we call SET_CUSTOM_PROPERTY in PL/SQL we will send it’s value.

example:

If we have a BEAN_AREA in oracle forms called BLOCK4.BEAN_AREA11 , and want to set I_TEXT ( input dialog text ) to be : „Please insert a value:“ , we would call