Posts Tagged ‘Java’
Overcomming MS’s Local Machine Zone Lockdown in GWT
GWT developers will notice an annoying problem running the basic default GWT app locally in web mode in IE every time i try this I get a red warning message: “Your web browser must have JavaScript enabled in order for this application to display correctly”. I had to allow the active content in order to see the web app screen. running in GWT dev mode seems not to raise this warning message. So what’s this all about? it seems IE doesn’t like people opening JavaScript-laced web pages from the local drive for security concern. there is a detailed article here that speaks about this issue of Microsoft blocking local domain for web applications .
The article above speaks about a new concept introduced by Microsoft called Mark of the web. i tried the method of Mark of the web by adding these two lines at the begining of my GWT html file :
<!-- saved from url=(0014)about:internet --> <!-- saved from url=(0016)http://localhost -->
but when i add these two lines and then compile GWT app and open the html file with IE the web app doesn’t show even though the warning message is gone . The reason probably is that -by default- a GWT app is loaded within an iframe, i.e. as another HTML page (*.cache.html), which doesn’t contain the MotW (Mark of the web).
to overcome this problem we can try using the “xs” or “xsiframe” linker, i.e. add one of these lines to our *.gwt.xml:
<add-linker name="xs" /> <add-linker name="xsiframe" />
Those linkers use *.cache.js” files, so the MotW in our host page should be enough. adding the linker to GWT xml module file makes IE warning message go away and I can run the GWT web app locally with IE.
but The “xs” linker has one drawback : it prevents us from using GWT DevMode . another annoyance that we can overcome by using two *.gwt.xml module files: one for web mode testing with ‘xs’ linker and the other without the linker for testing in GWT DevMode.
This may give you an Idea about the coding acrobatics one should go through to overcome the weired Microsoft decision to block totally the Machine local zone for web applications!
GWT KeyPressHandler getCharCode issues
Like hundreds of GWT developers I stepped into the annoying GWT KeyPressEvent.getCharCode() bug problem described here
To turn around this bug i tried using:
event.getNativeEvent().getKeyCode()
the purpose is to access the native event to get the unprocessed code. However if you try the
event.getNativeEvent().getKeyCode()you will knock your head against browser-specific inconsistencies. For example the getCharCode() from NativeEvent works for me in FireFox 3 but it doesn’t work in Chrome . in Chrome if i press “ENTER” key
event.getNativeEvent().getKeyCode()=10But
KeyCodes.KEY_ENTER=13
in FF3 the two values are equal (’13′).
It appears that a fix for KeyPressHandler was completed and reviewed for this issue . but it is not clear when we could expect it to be released. The fix appears fairly complex, with different browser-specific implementations.
it turns out that this change set is actually exactly what causes the current behavior in Firefox. See the rationale and a workaround/fix (i.e. only use getNativeEvent() when getCharCode returns 0).
the workaround above works but we need to replace ’13′ with ’10′ in the fix code portion below :
} else if (charCode == 13) {
doOnEnterKeyPressed();
}using ’10′ instead of ’13′ in the else if conditional:
} else if (charCode == 10) {
doOnEnterKeyPressed();
}with this new change code works both in chrome and FF3.
Hope this could be helpful for anyone experiencing these GWT keyPress getCharCode() problems.
Eclipse GWT plugin Installation issue
I have been encountering a problem installing GWT eclipse plugin using the update site :
http://dl.google.com/eclipse/plugin/3.6
using this update url seems to raise an error:
Unable to Read repository at http://dl.google.com/eclipse/plugin/3.6/content.xml. Connection reset
A workaround that works for me is to replace gwt eclipse update site with:
https://dl-ssl.google.com/eclipse/plugin/3.6
Eclipse Helios Crash on Linux
I have eclipse Helios installed in a opensuse 10.3 box. it seems the eclipse editor keeps crashing eclipse application every time i type a dot ‘.’ to access object methods.
if you experience same problem you can try the following two fixes:
- if you don’t have xulrunner package then install it (example using Yast2 in opensuse).
make sure you only install latest xulrunner version. if you install two different xulrunner versions in your linux OS the two versions might conflict and cause eclipse to crash again. this was my problem. when i removed old xulrunner 191 and only kept xulrunner 192 then eclipse helios stops crashing and works well. - The second fix (that doesn’t require to install xulrunner but seamonkey) is to specify to the Java VM the location of xulrunner .
To do this :
1-Edit file : ~/eclipse/eclipse.ini
2- add the following text below the ‘-vmargs’ line :
-Dorg.eclipse.swt.browser.XULRunnerPath=/usr/lib/seamonkey
For further information on this second fix see this thread discussion.
Google's mod_pagespeed Tool for a faster web
mod_pagespeed is a New Google Tool which is supposed to Make Websites Twice as Fast.
Further Reading :
Java's Age of Anxiety
The collapse of Sun Inc. , steward of Java technology, was a saddening and frightening event. After Oracle bought Sun and addressed java community with their optimistic plans for advancing Java; most community looked forward for happier times. they hoped that java developers lives would return to normal after the trauma of Sun collapse. they hoped that once again Java development would make sense in the familiar pre-Oracle terms of openness, community participation and freedom. These hopes were in vain. The Break of Sun, dismantling of multiple open source java/Sun based projects and the patent war that waged between giant software building competitors had mangled too many things beyond repair. Java Development would no longer fit neatly into the old molds.
Great numbers of us feel themselves increasingly adrift in a strange , uncertain and uncontrollable world. even the father of Java has expressed these same feelings in very similar words : Quite the firestorm!. No doubt Java is living now in an age of anxiety, an age of continual crisis.
In fact i used Java as an example to express a wider and broader sentiment of the return of the so called Age of Anxiety. In almost every area of human experience today , people are searching for ways to put meaning back into life. am i the only one who have this sentiment? or is it a realistic fact?
I hate to be pessimistic but that’s how i see the world today ;and i hope deeply I’m wrong.
SugarCRM and Java Integration : Introduction
Overview Of The SugarCRM Platform:
SugarCRM is a widely adopted Customer Relationship Management System. the product is basically built on the LAMP (Linux, Apache, MySQL & PHP) open source stack. However, ever since the version 4.5 release in August 2006, the application also runs reasonably well on Microsoft’s Windows Server operating system and SQL Server database.
SugarCRM is released under the Mozilla Public License and the GNU-GPL license and has taken a lead among the approximately 20 open source CRM applications.
In my opinion SugarCRM company Has adopted a modern philosophy in software development .The company opted for a strategy to open their technology to complementors and create economic incentives (such as free or low licensing fees, or financial subsidies) for other firms to join their CRM ecosystem and adopt the SugarCRM platform technology as their own. In fact SugarCRM firm followed two main strategies in their software development model .The first strategy is based on the mantra of “free, but not free”. SugarCRM give one part of the system away to some users (community or the general consumer) but charge others (corporate users). However it seems they didn’t opted for the strategy of “open, but “not open” make access to the interfaces easily available but keep critical parts of the technology proprietary or very distinctive. Instead they choose to give complete access to the underlying source code , allowing clients & companies to customize, integrate and extend the SugarCRM application with in-house technical resources to control their own requirements.
By looking to their SugarForge.org web site, you can see the wealth of projects that have been developed as extensions or Integrations to the SugarCRM system. Available source code, good documentation, training programs and a relatively active community provide the hallmarks for a successful open source effort.
SugarCRM Integration:
While the core of SugarCRM application is designed to manage a Company’s Customer Relationship, it is very likely that at some points the company might feel the need to do some integration with its CRM system. For example it might integrate its phone system to automatically make entries to SugarCRM when inbound or outbound calls have been made, connect registration of a web application with sugar system to create new accounts automatically to SugarCRM, connect a LIMS in various ways to Sugar ..and so on…
I had the chance to be involved in a project to Integrate SugarCRM with OpenOffice.org suite applications using the Java Programming language. This project was first funded by Appinux.com who hired me to develop a “OpenOffice Addon for SugarCRM. The project is open sourced and freely available to sugarCRM community.
Unfortunately -due to funding limitations-I could only release a minimal version of the plugin which I’m hosting at sourceforge.net : “OpenOffice Addon for SugarCRM
I’m now in charge of the project & have future plans to enhance it with more features and better design. Due to luck of funding and limitation of time, my progress might be slow in this project . but i’m committed to bring it to a decent degree of maturity in future. Of-course Java Developers are welcome to join the project if they are interested!
This being said , I’m planning to blog every now and then about the “OpenOffice Addon for SugarCRM project ; covering topics on SugarSoap API , Sugar and Java Integration , Sugar and OpenOffice Integration and other topics that might raise interesting during the ongoing project development process.
In the next article I’ll introduce the SugarSoap In Java Tutorial. SugarSoap is the SOAP Based SugarCRM webservice which enables Java developers to connect to Sugarcrm and interface with the variety of sugar services exposed by SugarSoap API.
ODF Toolkit vs. jOpenDocument
Openoffice.org API allows Java developers to access (read/write/export) the different supported fileformats within OpenOffice.org. The Drawback of this solution is that OpenOffice.org must be installed on client machine to enable your Java application to bootstrap the default OpenOffice.org process on the user machine.This constitutes a limitation, as every Java application using Openoffice API must ship also an OpenOffice.org installation or require user to install it before using the application.
The answer to this Limitation is the ODF Toolkit Project. this library can manipulate ODF files without worrying if OpenOffice.org is installed on client machine.
ODF Toolkit is Great tool but has its limitations too . it is currently only able to read/write ODF files but there is no option to export ODF files as PDF or any other non-ODF format. Sadly, the ODF Toolkit has currently no converters included within the project.
with more research i found another project jOpenDocument which seems to be similar to ODF Project . It is A pure Java library for OASIS Open Document files manipulation . One Great feature of jOpenDocument is that it can be used to create PDF files from ODF files. PDF generation with jOpenDocument requires also the use of the iText library. The iText library is available for free under a multiple license: MPL and LGPL.
Read this tutorial about how to Create a PDF document from a spreadsheet using jOpenDocument and iText.
Runtime Introspection of OpenOffice OXT package
The OpenOffice.org Developer’s Guide defines A OpenOffice.org OXT Extension as follows :
An extension is a file intended for the distribution of code and / or data which is to be used by OpenOffice.org. The file has the file extension (formerly .uno.pkg and .zip), and it acts as a container for various items, such as libraries, JARs, configuration data, type libraries, Basic libraries, Basic dialogs, etc. Before OpenOffice.org can use any content of the extension, it needs to be installed by the Extension Manager.
An extension should also contain a description.xml and must contain a directory META-INF (all uppercase). The META-INF directory contains a manifest.xml which lists all items and their media-type.
Recently i was working on a Openoffice.org Addon in Java and at some point of the project i needed a way to extract -at runtime- some information stored in the OXT binary (in fact I was looking for the OXT Properties).
If you’re using Netbeans openoffice.org plugin, you can get the OOo Extension Properties by right-clicking your project in the projects list and selecting OXT Extension properties, it’s under the Extension Management tab.
Because I needed to dynamically query my OXT extension for some useful information stored in the “description.xml” file , I decided to write a Java class to browse and parse the OXT Extension Files and extract OXT Properties at Runtime.
The most important fields that this class must knows about are the Extension Identifier and the com.sun.start.XComponentContext Object. So it makes good sense to pass these two Objects as arguments to class constructor. (note : the complete listing of XPackageInformationParser class is down-loadable from resources section below)
/**
* constructor
* @param m_xContext
* @param extensionIdentifier
*/
public XPackageInformationParser(XComponentContext m_xContext, String extensionIdentifier) {
this.m_xContext = m_xContext;
this.extensionIdentifier = extensionIdentifier;
// some other initialization code goes here
}OpenOffice UNO API provides a class com.sun.star.deployment.XPackageInformationProvider which is the entry class to access the OXT Package Information at runtime.
The following method configures and initialize the important UNO Objects that will be used to extract information from the UNO package:
private void intitialize(){
try {
XPackageInformationProvider xPackageInformationProvider = PackageInformationProvider.get(m_xContext);
oxtLocation = xPackageInformationProvider.getPackageLocation(this.extensionIdentifier);
Object oTransformer = m_xContext.getServiceManager().createInstanceWithContext("com.sun.star.util.URLTransformer", m_xContext);
xTransformer = (XURLTransformer) UnoRuntime.queryInterface(XURLTransformer.class, oTransformer);
} catch (Exception ex) {
_logger.error(ex);
}
}this method calculates the OXT Package location path and stores it in a String variable OXTLocation. It also create a XURLTransformer Object that will be used to parse openoffice URLs.
To read all files contained within the OXT Extension Package I use the following method:
/**
* returns files list that are contained within current .oxt package at runtime
* @param dir directory to search files list (null for top level OXT directory)
* @return array of OXT files
*/
public String[] getFileList(String dir) {
com.sun.star.util.URL[] oURL = new com.sun.star.util.URL[1];
oURL[0] = new com.sun.star.util.URL();
oURL[0].Complete = (dir == null) ? oxtLocation + "/" : oxtLocation + "/" + dir;
xTransformer.parseStrict(oURL);
return new File(oURL[0].Path + oURL[0].Name).list();
}By passing a null argument to this method it will return an array of all file names at top level of the OXT Package hierarchy structure.
It’s also possible to get a Java File Object reference to a given file contained within the OXT Extension Package. The below method do this :
/**
* get file within OXT package
* @param filePath
* @return reference to OXT File
*/
public File getExtensionFile(String filePath) {
com.sun.star.util.URL[] oURL = new com.sun.star.util.URL[1];
oURL[0] = new com.sun.star.util.URL();
oURL[0].Complete = this.oxtLocation + "/" + filePath;
xTransformer.parseStrict(oURL);
return new File(oURL[0].Path + oURL[0].Name);
}To get a reference to the Java File Object of description.xml file located at top level of the OXT package , we call the method like this :
getExtensionFile(description.xml);
Now lets investigate the heart functionality of this class; which is the method that parses the OXT description.xml file and extract the OXT Properties and stores them in a Java Properties Object. The method is listed below:
/**
* parse OXT description file
*/
public void parseOXTProperties() {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// For HTML, we don't want to validate without a DTD
dbf.setValidating(false);
// Ignore text elements that are completely empty:
dbf.setIgnoringElementContentWhitespace(false);
dbf.setExpandEntityReferences(true);
dbf.setCoalescing(true);
// Ensure that getLocalName() returns the HTML element name
dbf.setNamespaceAware(true);
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
return;
}
Document document = null;
File description = this.getExtensionFile(EXTENSION_DESC_FILE);
_logger.debug("got OXT description file: " + description.getAbsolutePath());
try {
document = db.parse(description);
NodeList nodes = document.getDocumentElement().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node_i = nodes.item(i);
if (node_i.getNodeType() == Node.ELEMENT_NODE) {
Element element = ((Element) node_i);
if (element.getTagName().equals(VERSION)) {
this.properties.setProperty(VERSION, element.getAttribute(VALUE));
}
if (element.getTagName().equals(IDENTIFIER)) {
this.properties.setProperty(IDENTIFIER, element.getAttribute(VALUE));
}
if (element.getTagName().equals(DISPLAY_NAME)) {
NodeList nodeList = element.getElementsByTagName("name");
_logger.debug(nodeList.item(0).getNodeName());
this.properties.setProperty(DISPLAY_NAME, nodeList.item(0).getTextContent());
}
if (element.getTagName().equals(PUBLISHER)) {
NodeList nameNode = element.getElementsByTagName("name");
_logger.debug(nameNode.item(0).getNodeName());
this.properties.setProperty(PUBLISHER, nameNode.item(0).getTextContent());
}
}
}
} catch (SAXException ex) {
_logger.error(ex);
} catch (IOException ex) {
_logger.error(ex);
}
}This method simply uses a java DOM parser to parse file description.xml ( file resides by-default at top level of OXT package) .It extracts useful xml document’s data (such as “publisher”, “version”, “display-name” etc..) then stores them in a Java Properties Object.
(the complete listing of XPackageInformationParser class is down-loadable from resources section at top bottom of this article.)
A Test code for printing OXT Package properties at runtime would look like :
XPackageInformationParser oxtParser=new XPackageInformationParser(m_xContext,org.openoffice.example); System.out.println(oxtParser.getProperties());
you just replace string org.openoffice.example with your actual OOo Extension identifier (which you defined while creating your Addon component).
A sample output obtained by running above test code for my OXT Extension gives me the following Properties :
{display-name=OpenOffice.org Addon for SugarCRM , version=0.0.1, identifier=com.sun.star.addon.sugarcrm.OOoSugarAddOn, publisher=Othman El Moulat}
Now Of course you can do more useful things with this class by examining each file retrieved from OXT Package at runtime. for example the /META-INF/manifest.xml file contains some useful information that could be used at runtime by your Java OOo Add-on.
Resources:
Swinging HTML Forms
With the coming of xml powerful language the somewhat tedious task of building java swing UI has increasingly been shifted to use xml . A multitude of xml to swing libraries have been developed to ease the task of swing application development .probably the most popular library is -IMHO- the open source project swixml.
However I was surprised there exist very few Java libraries for converting HTML forms to swing. I would agree that HTML is a complex language and that writing a HTML to swing converter would fall in the range of writing a Java swing browser -Not A trivial task anyway-. Yet I’m convinced that there should be a simple java library to convert a sub-set of HTML – HTML forms- into swing application.
The only open source library I could find for this task was the swingx-ws project. Richard Bair has an Excellent article Web Swinging on this subject. The HTML Forms section of his article is especially interesting and gives an Insight on how a simple HTML forms to swing converter would look like.
I used swingx-ws library in one of my projects. However I felt that their JXHtmlForm class is fairely simplistic. It would Not correctly render all Kinds of HTML forms regarding the complexity of HTML language. I Managed however to extend the swingx-ws html form parser and JXHtmlForm class to meet my own project requirements.
swingx-ws’s JXHtmlForm class is a good example of a simple HTML forms to swing converter.


