Saturday, October 12, 2013

Parsing XML with XPath and a User Agent

Working on an android project, I need to parse XML RSS Feeds and use the given links further down the application. I opted for XPath, for simplicity and being built-in (XPathFactory).

It all worked fine, but one site. It detects devices (user Agent) on the RSS feed, and reformats the links accordingly. This means that I get the links of the mobile site, instead of the links of the main site. This is a strage implementation and unneccessary, in my point of view, still this was the case, and I had to deal with it.

XPath parser recives the XML document through an InputSource, which doesn't give me any control over the passed parameters to the site:

XPathFactory xPathFact = XPathFactory.newInstance();
XPath xPath = xPathFact.newXPath();

InputSource XPInputSrc = new InputSource(rss_url);

NodeList links_nodes = (NodeList) xPath.evaluate("//item/link", XPInputSrc, XPathConstants.NODESET);

Again, this worked greate with all sites but one.

What I needed was actually to pass a user-agent argument with the http request, but I couldn't find a direct way to pass that through the InputSource.

At one point, I thought I might use something like Jsoup to get the XML document, then pass that to the InputSource via a StringReader!

Good thing I dismissed this idea, and found that if I set a system property of "http.agent", it gets passed in all http reqests! So, I did this:

System.setProperty("http.agent", "Mozilla/5.0");

This did the trick!

Saturday, August 24, 2013

Connecting to Exchange Server from Linux

This has been one of the problems facing me every time I tried to fully switch to Linux. I can't properly connect to the corporate email, which uses MS-Exchange Server.

Currently there are two solutions available, that can provide some functionality to that area. The first, is Gnome's built-in Online Accounts (GOA); which does, theoretically provide means to access email, contacts and calendar, and make them available for the GOA-compatible applications; and the exQuilla, which is a Thunderbird addon, to connect to exchange mail servers.

I've tried the GOA, but it seems to be working randomly. It worked with some one of my accounts, but refused to work with the other, without any apparent reason. On another distro, it works with both of them, but on occasions needed to restart once or twice to connect, and gets disconnected on next boot.

On the other hand, exQuilla provides a better way to connect to exchange server for email access.

Setting up and exchange account using exQuilla is a straight forward process using its own menu item. A good help is presented to the used following installing the addon.

Although exQuilla provides a good way to connect to exchange mail servers, it lacks the calendar and contacts integration. Also, the use of Thunderbird doesn't give you a direct way to send Outlook-compatible meeting invitations or replies to meetings.

UPDATE: looks like exQuilla is "transitioning to a be a payed service". Which takes it out of my spotted services, as I'm deeply into FOSS. The hope now is for Gnome Online Accounts to get fixed, and overcome all the bugs.

Sunday, March 10, 2013

Alt+Shift for Keyboard Layout Change in Fedora 18

New installation of Fedora 18 and I know already some of the problems I need solved. The normal stuff: switchable graphics (I'm almost giving up on this one, though), flashcache, instant-on, battery life and power management.. the normal stuff.

But first thing is first, I use bi-lingual keyboard. I need my Arabic keyboard.

OK. The normal addition of the keyboard went as smooth as usual, but I couldn't get the normal Alt+Shift shortcut to change the layout. This is strange, as the system requested to have Alt+[alphanumeric]... hmmm... I wouldn't like that.

So, I remember an old friend of mine: the gnome-tweak-tool.

From Software (Add/Remove Software?), searched for gnome-tweak-tool, and installed it. A nice gesture of the Software panel is that it asked me if I wanted to run the freshly installed application, I did.

From there, I went to Typing, and from the Modifiers-only input sources switch selected the "Alt Shift".

This was even better than I anticipated, as I can now use either "Alt+Shift"'s to switch the keyboard input layout.

Sunday, February 17, 2013

[Angry!] Etisalat Mongez Notification Pages

I bought a new modem from Etisalat Egypt, which is working according to what they call "Mongez" plans. Fine with me, although a little bit over complicated in the way they force you to manage your subscription. Everything went OK, up-till that moment when I started being diverted to their web site for notifications regarding bandwidth consumption and that sort of thing.

Once again, OK, I can live with that. The notification pages usually have a button on them to get you out of the page, and continue to the website you asked for. But they DO NOT WORK! For more than once, I got stock in that page forever!

Calling their customer support number didn't solve this either. For one thing, they claim that these notifications cannot be disabled! (Well, probably they had some alien programmer do the thing, and then he got killed or vanished into thin air, or something, and there's no one else on planet earth has the required skills to modify his script!). The only solution they provide is to restart your browser. In many occasions, I can't restart my browser with on-going downloads, for instance. Those nasty not-resumable downloads.

To be frank here, my stand is: if your script has got bugs in it, don't use it -- fix it first before putting us, the users, into all this sort of sh*t!

A quick fix, I've worked out with Firefox, though, was by deleting the cookies, cache and active logins for the past hour. This is done via pressing Shift+Ctrl+Delete combination on the keyboard, selecting those items, and pressing "Clear Now". Still, this me, the customer, solving their issues! It doesn't work this way!