XPath with Axiom
Saliya Ekanayake
Apache Axiom, which is the popular open source StAX based XML infoset model, supports XPath out of the box. If you ever want to know how to use this feature, WSO2 Oxygentank has a very nice tutorial.
The tricky part is, how to work with Namespaces? To get an idea on to the matter consider the following XML document.

The following code fragment will retrieve the ns1:c1 element and the two ns2:color attributes of each element.
// root is the document
OMElement root = builder.getDocumentElement();
AXIOMXPath xpath = new AXIOMXPath("//a:c1");
xpath.addNamespace("a", "http://namespace1.com");
OMElement c1 = (OMElement)xpath.selectSingleNode(root);
System.out.println(c1);
xpath = new AXIOMXPath("//@b:color");
xpath.addNamespace("b", "http://namespace2.com");
List colors = xpath.selectNodes(root);
System.out.println(colors.get(0).getAttributeValue());
System.out.println(colors.get(1).getAttributeValue());
The important line in this code is the xpath.addNamespace(prefix, uri) method. This prefix doesn't have to be the exact prefix used in the actual document (which in fact is not known in most cases).
That's it, have fun with Axiom :)
The tricky part is, how to work with Namespaces? To get an idea on to the matter consider the following XML document.

The following code fragment will retrieve the ns1:c1 element and the two ns2:color attributes of each element.
// root is the document
OMElement root = builder.getDocumentElement();
AXIOMXPath xpath = new AXIOMXPath("//a:c1");
xpath.addNamespace("a", "http://namespace1.com");
OMElement c1 = (OMElement)xpath.selectSingleNode(root);
System.out.println(c1);
xpath = new AXIOMXPath("//@b:color");
xpath.addNamespace("b", "http://namespace2.com");
List
System.out.println(colors.get(0).getAttributeValue());
System.out.println(colors.get(1).getAttributeValue());
The important line in this code is the xpath.addNamespace(prefix, uri) method. This prefix doesn't have to be the exact prefix used in the actual document (which in fact is not known in most cases).
That's it, have fun with Axiom :)
ATI X1300 with Ubuntu 8.04 (Hardy)
Saliya Ekanayake
In one of my previous posts I mentioned how to setup ATI X1300 graphics card in Ubuntu Gusty. Recently I installed Ubuntu Hardy because Gusty came up with couple of bugs. Unfortunately I had to set up my graphics card again :(
So I tried with the Unofficial ATI Wiki and it worked just as expected. Try method 2 mentioned here.
The great news is hibernation works with it :)
So I tried with the Unofficial ATI Wiki and it worked just as expected. Try method 2 mentioned here.
The great news is hibernation works with it :)
Convert ByteArrayInputStream to String
Saliya Ekanayake
Recently one of my friends wanted to get the string contained in a ByteArrayInputStream in Java. The method do this was bit tricky and I thought it'd be nice to share it.
ByteArrayInputStream bais = // get your ByteArrayInputStream instance
int length = bais.available();
byte [] buff = new byte[length];
bais.read(buff);
That's it!!
ByteArrayInputStream bais = // get your ByteArrayInputStream instance
int length = bais.available();
byte [] buff = new byte[length];
bais.read(buff);
That's it!!
@ WSO2, Inc.
Saliya Ekanayake
The university life ended last Wednesday (7th May) and it was time to move into my first job in life :)
I joined WSO2 Inc. on 12th May and it has been few busy days until today :). I am waiting for some build to complete and thought to jump in and blog on this.
I feel life has changed a bit compared with the life at the university, yet it is the same old me sitting in front of the computer :)
I joined WSO2 Inc. on 12th May and it has been few busy days until today :). I am waiting for some build to complete and thought to jump in and blog on this.
I feel life has changed a bit compared with the life at the university, yet it is the same old me sitting in front of the computer :)
Repair Sony VAIO VGN FE855E Keyboard
Saliya Ekanayake
My girlfriend's notebook was "attacked" by ants recently. This is the famous attack of eating the rubber membrane of the keyboard. They have eaten the contact material of the rubber button and several keys were not working after that. The following picture gives you the model number of the notebook.

I searched for keyboard replacements and found that they are expensive (Sony service require 169$ to replace a keyboard). There are refurbished keyboards available in e-bay for prices around 70$, but I couldn't get one since I live in Sri Lanka. The price and tax is too much if I deliver something from US. So I gave a go by myself. Bottom line is I fixed all the keys for a price just around 1$ (one dollar :)
I thought of giving the steps I followed in case if some one else is in trouble like me.
Step 1: Identify the not working keys.
You can simply use a text pad to type the keys and identify the ones that doesn't work. To test function keys you can do many things. The easiest thing I did was to run a program in command line and then to press function keys in the same shell (note you should not run the particular program you chose as a background process). There each time you press a function key some kind of symbols appear. So you can see if it works or not. See this is a very primitive way but it works.
Step 2: Removing the plastic plate of the key
In notebook keyboards the plastic key plate is clipped to an underlying plastic support mechanism. See the following picture (the bad key in this case is F11)


Use a small flat screw driver to lift the plastic plate from top left corner and bottom left corner. Note: If you are trying to remove normal keys (like A, B, etc.) then you need to lift from bottom left and bottom right corners of the key plate. Once removed you can see it as follows.

Step 3: Removing the plastic hinges
You can use the same screw driver to remove the white plastic hinges. See IraqiGeek's blog to see more information. One advice is that don't force too much on these small plastic items as they tend to break easily. Once removed you will see something similar to the pictures given below.


Step 4: Peeling off the rubber button
The next step is removing the rubber button. It is little bit hard and needs lots of patience. The rubber button is fixed to the same plastic sheet which contains the touch points. So it is virtually irreplaceable :). The option I selected was to cut off the rubber button. You need a sharp blade to do this. I used a razor blade. Once again, be careful when you cut because a single mistake could damage the underlying carbon contact lines, leaving no option other than to replace the entire keyboard. Once you cut it off you can see it as follows (the second image shows another bad key, i.e. Esc key).


Step 5: Finding a replacement rubber button
If you can get away with this step then you are basically done with repairing. If you see the two images above you can clearly see the carbon touch plats (see the thin white "s" shape in the place where the rubber button is taken off. That is the margin separating the two carbon plates). The keyboard simply works if you can somehow find a button which will contact these two plates when pressed. There are numerous solutions you can find in day to day stuff which can be used as a replacement. The one I found was a simple push button. You can easily find a similar type of thing any electronic parts seller. See the images given below.



The first image shows the small switch I found and the next one shows the rubber button of it removed. You can remove it simply by pulling off gently from the sides of the rubber button (Note: be careful not to tear it off). The third one shows the underside of the rubber button and you can clearly see the carbon dot in it. This is the one which get pressed on to the carbon plates of the keyboard. The side view of this button is given below (in fact this is the same side view of the original notebook's rubber button as well).

The replacement button I found had this problem that the distance of pressing is smaller than that is of the original button. So when you fix the key plate it acts much like a touch button. I didn't like that feeling. So I simply shorten the rubber cylinder by removing a part of it and gluing the two parts. This is though seems simple requires a lot of patience. So drink lot of water before you do this :D and take a deep breath. Ah! one thing I forgot to tell was that not all type of glues can be used to bond rubber. So better to find a super glue which can bond rubber. In my case I found a cheap Indian made super glue (I think the name was Evlico or something like that).
Once you adjust the pressing distance and the button is ready to go you need to one more thing. The rubber button used here acts as a vacuum when pressed and sticks to the key board's plastic sheet. So I made two tiny holes symmetrically. That way it becomes very easy to press and feels much like the original button. See the images given below. I think you can see the tiny holes.


Step 6: Replacing the key plate
First replace the plastic hinges. I think you can do it by yourself. The advice here is don't push too much if the thing isn't attaching. You may probably trying to fit it wrongly. Then place the key plate on top of the rubber button and gently push from four corners (you can hear the "tick" sound as you press which indicates the correct fitting of the plate).
This completes the repair and following is a list of additional rubber button replacements you can use.
1. The calculator touch pads have a nice a rubber membrane with touch switches similar to the one I used.
2. TV / VCR remote controllers too have nice rubber buttons inside.
3. There are various types of rubber push buttons available in the market. So better to find a similar one that suits your machine.
If you have any doubt on the matter just drop a reply to this post.
I searched for keyboard replacements and found that they are expensive (Sony service require 169$ to replace a keyboard). There are refurbished keyboards available in e-bay for prices around 70$, but I couldn't get one since I live in Sri Lanka. The price and tax is too much if I deliver something from US. So I gave a go by myself. Bottom line is I fixed all the keys for a price just around 1$ (one dollar :)
I thought of giving the steps I followed in case if some one else is in trouble like me.
Step 1: Identify the not working keys.
You can simply use a text pad to type the keys and identify the ones that doesn't work. To test function keys you can do many things. The easiest thing I did was to run a program in command line and then to press function keys in the same shell (note you should not run the particular program you chose as a background process). There each time you press a function key some kind of symbols appear. So you can see if it works or not. See this is a very primitive way but it works.
Step 2: Removing the plastic plate of the key
In notebook keyboards the plastic key plate is clipped to an underlying plastic support mechanism. See the following picture (the bad key in this case is F11)
Use a small flat screw driver to lift the plastic plate from top left corner and bottom left corner. Note: If you are trying to remove normal keys (like A, B, etc.) then you need to lift from bottom left and bottom right corners of the key plate. Once removed you can see it as follows.
Step 3: Removing the plastic hinges
You can use the same screw driver to remove the white plastic hinges. See IraqiGeek's blog to see more information. One advice is that don't force too much on these small plastic items as they tend to break easily. Once removed you will see something similar to the pictures given below.
Step 4: Peeling off the rubber button
The next step is removing the rubber button. It is little bit hard and needs lots of patience. The rubber button is fixed to the same plastic sheet which contains the touch points. So it is virtually irreplaceable :). The option I selected was to cut off the rubber button. You need a sharp blade to do this. I used a razor blade. Once again, be careful when you cut because a single mistake could damage the underlying carbon contact lines, leaving no option other than to replace the entire keyboard. Once you cut it off you can see it as follows (the second image shows another bad key, i.e. Esc key).
Step 5: Finding a replacement rubber button
If you can get away with this step then you are basically done with repairing. If you see the two images above you can clearly see the carbon touch plats (see the thin white "s" shape in the place where the rubber button is taken off. That is the margin separating the two carbon plates). The keyboard simply works if you can somehow find a button which will contact these two plates when pressed. There are numerous solutions you can find in day to day stuff which can be used as a replacement. The one I found was a simple push button. You can easily find a similar type of thing any electronic parts seller. See the images given below.
The first image shows the small switch I found and the next one shows the rubber button of it removed. You can remove it simply by pulling off gently from the sides of the rubber button (Note: be careful not to tear it off). The third one shows the underside of the rubber button and you can clearly see the carbon dot in it. This is the one which get pressed on to the carbon plates of the keyboard. The side view of this button is given below (in fact this is the same side view of the original notebook's rubber button as well).
The replacement button I found had this problem that the distance of pressing is smaller than that is of the original button. So when you fix the key plate it acts much like a touch button. I didn't like that feeling. So I simply shorten the rubber cylinder by removing a part of it and gluing the two parts. This is though seems simple requires a lot of patience. So drink lot of water before you do this :D and take a deep breath. Ah! one thing I forgot to tell was that not all type of glues can be used to bond rubber. So better to find a super glue which can bond rubber. In my case I found a cheap Indian made super glue (I think the name was Evlico or something like that).
Once you adjust the pressing distance and the button is ready to go you need to one more thing. The rubber button used here acts as a vacuum when pressed and sticks to the key board's plastic sheet. So I made two tiny holes symmetrically. That way it becomes very easy to press and feels much like the original button. See the images given below. I think you can see the tiny holes.
Step 6: Replacing the key plate
First replace the plastic hinges. I think you can do it by yourself. The advice here is don't push too much if the thing isn't attaching. You may probably trying to fit it wrongly. Then place the key plate on top of the rubber button and gently push from four corners (you can hear the "tick" sound as you press which indicates the correct fitting of the plate).
This completes the repair and following is a list of additional rubber button replacements you can use.
1. The calculator touch pads have a nice a rubber membrane with touch switches similar to the one I used.
2. TV / VCR remote controllers too have nice rubber buttons inside.
3. There are various types of rubber push buttons available in the market. So better to find a similar one that suits your machine.
If you have any doubt on the matter just drop a reply to this post.
How to Access Linux (Ext2) Partitions from Windows OS
Saliya Ekanayake
I've been using Explore2fs for sometime to access my Linux partition from Windows OS. But it was very boring to copy files from Ext2 partition all the time when I wanted to access them. So I decided to search for a better option. So here it is, Ext2 installable file system. It's very cool. You can even write to Ext2 partition. Here is the good article where I found these stuff.
My Woodwork
Saliya Ekanayake
Google Pages
Saliya Ekanayake
Google always come up with cool ideas. This is not boasting but they really do. I recently came across this idea of Google pages. I was searching for a place to share some of my files with others. It's then I found this and it was more than a place to share files. I gave it a try and here is my hOme up and running :)
Saliya Ekanayake
Brain and Your Fist
This is some nice fact I've noticed but it may not mean anything. Have you seen a diagram of the brain from side view? I guess you probably have. Now try to keep your fingers in the right hand as if you are going for a fight (fisted). Then see your fist from side view. You will see a similar shape to that of brain. Isn't that interesting?
This is some nice fact I've noticed but it may not mean anything. Have you seen a diagram of the brain from side view? I guess you probably have. Now try to keep your fingers in the right hand as if you are going for a fight (fisted). Then see your fist from side view. You will see a similar shape to that of brain. Isn't that interesting?
10:57 AM
life
ATI x1300 with Ubuntu Gusty (7.10)
Saliya Ekanayake
Ah! I had to give another fight to get my x1300 ATI card working properly with Ubuntu Gusty. The restricted driver that comes by default would correct the wide screen problem but video quality is changed. You will find lot of illuminant people while watching a film in totem.
So here goes the answer
Good luck and have fun :)
So here goes the answer
Good luck and have fun :)
Ubuntu 7.10 on DELL E1505 Notebook
Saliya Ekanayake
I installed Ubuntu (Gusty Gibbon) on my Dell notebook and I felt the beauty of it from the very beginning.
The two most interesting features I see:
1. Read/Write facility to NTFS (Windows) partitions
2. Easy configuration of restricted drivers (no need to worry about setting up your ATI video card :)
The two most interesting features I see:
1. Read/Write facility to NTFS (Windows) partitions
2. Easy configuration of restricted drivers (no need to worry about setting up your ATI video card :)
Saliya Ekanayake
Perceptron in Java
I'm following Neural Networks class for my final year and I felt it's a cool subject. I'm still a newbie in this field. But I gave a try to implement a simple perceptron to train few logic gates. It was a cool experience.
I'm following Neural Networks class for my final year and I felt it's a cool subject. I'm still a newbie in this field. But I gave a try to implement a simple perceptron to train few logic gates. It was a cool experience.
Saliya Ekanayake
HUAWEI ETS 2251 with Ubuntu 6.10
We recently purchased a CDMA data phone and I wanted to connect to the Internet with Linux (Ubuntu 6.10). Try the following steps:
1. plug-in the USB cable (your cable should be Serial (phone side) to USB one).
2. sudo dmesg -c
you should see the following at the bottom
ti_usb_3410_5052 2-1:2.0: TI USB 3410 1 port adapter converter detected
if you see ti_usb_3410_5052: probe of 1-1:1.0 failed with error -5 after the above line then copy the following lines,
#TI USB 3410
SUBSYSTEM=="usb_device" ACTION=="add" SYSFS{idVendor}=="0451",SYSFS{idProduct}=="3410" \
SYSFS{bNumConfigurations}=="2" \
SYSFS{bConfigurationValue}=="1" \
RUN+="/bin/sh -c 'echo 2 > /sys%p/device/bConfigurationValue'"
and save them as /etc/udev/rules.d/026_ti_usb_3410.rules
Now run sudo dmesg -c again and you'll see the following two lines,
ti_usb_3410_5052 1-1:2.0: TI USB 3410 1 port adapter converter detected
usb 1-1: TI USB 3410 1 port adapter converter now attached to /dev/ttyUSB0
3. Now configure the /etc/wvdial.conf as follows, please note that you need to replace your given username, password and phone number with my configuration (abc@prepaid, 1234, #777) given here.
[Dialer suntel]
Modem = /dev/ttyUSB0
Baud = 230400
Phone = #777
Init1 = ATZ
Stupid Mode = 1
Dial Command = ATDT
Username = abc@prepaid
Password = 1234
4. Now type sudo wvdial suntel and enjoy the Internet. If you can't browse then plese add the DNS addresses to /etc/resolv.conf (these DNS addresses can be found in the command line while connecting).
Thanks Farhan Naeem for sharing knowledge on this matter
We recently purchased a CDMA data phone and I wanted to connect to the Internet with Linux (Ubuntu 6.10). Try the following steps:
1. plug-in the USB cable (your cable should be Serial (phone side) to USB one).
2. sudo dmesg -c
you should see the following at the bottom
ti_usb_3410_5052 2-1:2.0: TI USB 3410 1 port adapter converter detected
if you see ti_usb_3410_5052: probe of 1-1:1.0 failed with error -5 after the above line then copy the following lines,
#TI USB 3410
SUBSYSTEM=="usb_device" ACTION=="add" SYSFS{idVendor}=="0451",SYSFS{idProduct}=="3410" \
SYSFS{bNumConfigurations}=="2" \
SYSFS{bConfigurationValue}=="1" \
RUN+="/bin/sh -c 'echo 2 > /sys%p/device/bConfigurationValue'"
and save them as /etc/udev/rules.d/026_ti_usb_3410.rules
Now run sudo dmesg -c again and you'll see the following two lines,
ti_usb_3410_5052 1-1:2.0: TI USB 3410 1 port adapter converter detected
usb 1-1: TI USB 3410 1 port adapter converter now attached to /dev/ttyUSB0
3. Now configure the /etc/wvdial.conf as follows, please note that you need to replace your given username, password and phone number with my configuration (abc@prepaid, 1234, #777) given here.
[Dialer suntel]
Modem = /dev/ttyUSB0
Baud = 230400
Phone = #777
Init1 = ATZ
Stupid Mode = 1
Dial Command = ATDT
Username = abc@prepaid
Password = 1234
4. Now type sudo wvdial suntel and enjoy the Internet. If you can't browse then plese add the DNS addresses to /etc/resolv.conf (these DNS addresses can be found in the command line while connecting).
Thanks Farhan Naeem for sharing knowledge on this matter
Saliya Ekanayake
TMNT Two Thumbs Up!!
I loved watching Teenage Mutant Ninja Turtles cartoon when I was a little kid and now I got hand on the movie. I really like it, two thumbs up TMNT!!
I loved watching Teenage Mutant Ninja Turtles cartoon when I was a little kid and now I got hand on the movie. I really like it, two thumbs up TMNT!!
8:00 AM
Saliya Ekanayake
Advanced OS Paper - Nightmare
Oh! boy, today we had our Advanced Operating Systems paper. It was one hello of a paper.
Anyway may be things happen for good. That's all I know :)
Oh! boy, today we had our Advanced Operating Systems paper. It was one hello of a paper.
Anyway may be things happen for good. That's all I know :)
12:55 AM
Saliya Ekanayake
Sri Lanka Telecom ADSL Service Sucks
I and my roommate took an ADSL Internet connection to the boarding from Sri Lanka Telecom. It was great in the first few months. But now it sucks. We bought the package which advertises 512Kbit/s (kilo bits per second) down load speed and 128Kbit/s upload speed. But the damn thing won't support even 100Kbit/s download speed. Damn, that sucks.
The most funny thing is that their customer service guy came and inspect the system and said that he feels it's normal. Can you believe it? He even says if we don't like it then we better disconnect it. Yea that's what we wanted as a solution, yikes.
I and my roommate took an ADSL Internet connection to the boarding from Sri Lanka Telecom. It was great in the first few months. But now it sucks. We bought the package which advertises 512Kbit/s (kilo bits per second) down load speed and 128Kbit/s upload speed. But the damn thing won't support even 100Kbit/s download speed. Damn, that sucks.
The most funny thing is that their customer service guy came and inspect the system and said that he feels it's normal. Can you believe it? He even says if we don't like it then we better disconnect it. Yea that's what we wanted as a solution, yikes.
12:46 AM
Saliya Ekanayake
Mailing list is much like Instant Messaging
Google announce that code submission for GSOC 2007 is available few minutes before. The student's mailing list got fired with the news :) Everybody (including myself) was posting questions telling that link for the submission doesn't work. Oh! Leslie (at google) must have had a nightmare replying to those emails and we really appreciate your kind and speedy responses.
The mailing list became like a chat room with mails flying within seconds :)
Google announce that code submission for GSOC 2007 is available few minutes before. The student's mailing list got fired with the news :) Everybody (including myself) was posting questions telling that link for the submission doesn't work. Oh! Leslie (at google) must have had a nightmare replying to those emails and we really appreciate your kind and speedy responses.
The mailing list became like a chat room with mails flying within seconds :)
1:45 PM
Subscribe to:
Posts
(
Atom
)
