Category Archives: Java2Script

Implementing Gmail-alike Web Mail Client by Java2Script

WeMail, this to-be-implemented Gmail-alike web mail client, is based on technologies of Java, SWT, JavaMail and Java2Script.

Before going into designing and implementing details, here are some background information.

Java2Script (J2S) Pacemaker provides an Eclipse Java to JavaScript compiler plugin and an implementation of JavaScript version of Eclipse Standard Widget Toolkit (SWT) with other common utilities, such as java.lang.* and java.util.*. You can convert your SWT-base Rich Client Platform (RCP) into Rich Internet Application (RIA) by Java2Script Pacemaker.

JavaMail is a Java API used to receive and send email via SMTP,POP3 and IMAP. JavaMail is built into the Java EE platform, but also provides an optional package for use in Java SE.

SWT is an open source widget toolkit for Java designed to provide efficient, portable access to the user-interface facilities of the operating systems on which it is implemented.

Google Web Toolkit (GWT) is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. Other than a few native libraries, everything is Java source that can be built on any supported platform with the included GWT Ant build files.

Why implementing another Gmail-alike web mail client?

When GWT is released, lots of developers ask whether GWT will be used in Google’s major products, like Gmail, Google Reader or other products. Yeas went by, but there is still no Gmail powered by GWT. So using Java-to-JavaScript technology to build another Gmail web client should be fun for technical geeks. I choose Java2Script to build this web mail client, hoping it would help improving Java2Script toolkit.

I like Gmail UI, but I can not use its UI for other mail providers, like Hotmail or Yahoo! Mail. So I believe WeMail will help users doing their email jobs like receiving, composing and replying emails, in Gmail-alike UI for all mail providers. And it will sure increase their daily email processing efficiency.

And there are lots of companies that might block web access to Gmail, Yahoo! Mail or other mail providers. In these cases, a web mail client for general POP/IMAP & SMTP will help those users accessing emails even behind firewalls.

So I finally made up my mind to build it. And it was my two weeks’ fun.

Dang, dang, dang! Here it comes WeMail – Web Mail Client for Gmail/Hotmail/Live Mail/Yahoo! Mail/AOL Mail.

Configureing mail servers and login:
wemail-web-login

WeMail main window, listing emails:
wemail-list

Viewing an email:
Click for large view of wemail-message-viewer

Composing an email:
wemail-composing

How is this Gmail alike web mail client being implemented?

I use WindowsBuilder Pro (formerly known as SWTDesigner) to design all the UI elements. Here are screenshots of its UI components being designed:

Overview of WeMail in designer:
wemail-design-overview

Designing top menu bar:
Click for large view of wemail-menubar

Designing logo and search bar:
wemail-toolbar

Designing left side widget:
wemail-widget

Designing email selector bar:
wemail-selector

Designing email message header:
wemail-mail-header

Designing email message viewer:
wemail-viewer

Designing email composer:
wemail-composer

Designing footer panel:
wemail-footer

Designing login window:
wemail-login-window

Designing mail server configuring window:
wemail-configure-window

Designing and adjust user interfaces causes lots of time.

And what about the receiving and sending emails? I use JavaMail to do email jobs. Between SWT UI and JavaMail, Java2Script’s Simple RPC technology is used. Those mail jobs are separated into following RPCs:
1. CheckMails
2. DiscardEmails
3. FetchMailContent
4. ListFolderMails
5. MarkMailAsRead
6. SaveDraft
7. SendMail

UI events will trigger those RPCs being called in separate threads and UI will be updates after their jobs are done.After RPCs get woven into UI elements. It is ready to be run as a native Java desktop application. So it is:

wemail-desktop

Running, debugging, testing, bug-fixing, all take times. But up until now, all I do is native Java developments. No HTML, no JavaScript technologies is needed.

After the Java desktop version of WeMail is OK, it will be ready for being converted in an AJAX based web browser application. That is the Java2Script job (I am not going into Java2Script details, more information can be found on Java2Script at Sourceforge.net.): Install Java2Script Eclipse plugin and convert existed project into a Java2Script project. All those *.java files will be compiled int JavaScript automatically. Then pack all necessary files into a Servlet *.war file and deploy it into Java Servlet container server like Tomcat. And work is done. WeMail is available at http://webuzz.im/mail/ .

So it is my WeMail’s development log. Having fun.

Posted in AJAX, Java, Java2Script | Tagged , , , , , | 5 Comments

Google Talk Client’s Java SWT Desktop Copy

Actually, Google Talk Client’s Java SWT desktop copy is the original source for Google Talk Client’s JavaScript copy.

And now it is available for download. Please take a trial.

Sources of Java2Script Google Talk will be available in the next week. Keep tuned.

Posted in AJAX, Google Talk, Java, Java2Script | 8 Comments

Google Talk Client’s JavaScript Copy

http://demo.java2script.org/gtalk/

Here is the screenshot:

Click for Large Screenshot: Google Talk Client’s JavaScript Copy

En, in beta …

Posted in AJAX, Google Talk, Java2Script | 5 Comments

Busy Days on Java2Script Google Talk

Ya, these days were very busy.

I had spent more than a month on rewriting Java2Script Google Talk. And today, it was almost finished. You can check it out right now.

More works are required to make it robuster and faster. Maybe Java2Script Google Talk will be publicly released in the next week.

And next release of Java2Script is on the way too. It will be a 1.0.0 RC release. Four months was a long long time since last release.

Posted in Google Talk, Java2Script | 2 Comments

Add Source Highlighting to WordPress Editor

If you are a technical geek, you may want to write some blog articles attaching some sources for discussion. And if you are using WordPress, you may find a lot of difficulties in struggling with WordPress’ messy TinyMCE editor in preserving codes format.

Thanks for early WordPress bloggers, there are some plugins trying to solve this problem. A known plugin is “Preserve Code Formatting“. But that plugin may be not good enough for you, at least not good enough for me.

I modify that plugin a little, and deploy it in my WordPress 2.2. And I also add my own source syntax highlighting tools.

Here is my modified preserve-code-formatting.php:

<?php
/*
Copyright (c) 2004-2005 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

function c2c_prep_code( $text ) {
$use_nbsp_for_spaces = false;

$text = preg_replace("/(\r\n|\n|\r)/", "\n", $text);
$text = preg_replace("/\n\n+/", "\n\n", $text);
$text = str_replace(array("&#36&;", "&#39&;"), array("$", "'"), $text);
//$text = htmlspecialchars($text, ENT_QUOTES);
$text = preg_replace("/\n\s+\n/", "\n&#160;\n", $text);
$text = str_replace("\t", ' ', $text);
if ($use_nbsp_for_spaces) $text = str_replace(' ', '&#160;&#160;', $text);
// Change other special characters before wptexturize() gets to them
$text = c2c_anti_wptexturize($text);
//$text = nl2br($text);
return $text;
} //end c2c_prep_code()

// This short-circuits wptexturize process by making ASCII substitutions before wptexturize sees the text
function c2c_anti_wptexturize( $text ) {
$text = str_replace('---', '&#45;&#45;-', $text);
$text = str_replace('--', '&#45;-', $text);
$text = str_replace('...', '&#46;..', $text);
$text = str_replace('``', '&#96;`', $text);

// This is a hack, look at this more later. It works pretty well though.
$cockney = array("'tain't","'twere","'twas","'tis","'twill","'til","'bout","'nuff","'round");
$cockneyreplace = array("&#39;tain&#39;t","&#39;twere","&#39;twas","&#39;tis","&#39;twill","&#39;til","&#39;bout","&#39;nuff","&#39;round");
$text = str_replace($cockney, $cockneyreplace, $text);

$text = preg_replace("/'s/", '&#39;s', $text);
$text = preg_replace("/'(\d\d(?:&#8217;|')?s)/", "&#39;$1", $text);
$text = preg_replace('/(\s|\A|")\'/', '$1&#39;', $text);
// $text = preg_replace('/(\d+)"/', '$1"', $text);
$text = preg_replace("/(\d+)'/", '$1&#39;', $text);
$text = preg_replace("/(\S)'([^'\s])/", "$1&#39;$2", $text);
// $text = preg_replace('/(\s|\A)"(?!\s)/', '$1"$2', $text);
// $text = preg_replace('/"(\s|\S|\Z)/', '"$1', $text);
$text = preg_replace("/'([\s.]|\Z)/", '&#39;$1', $text);
$text = preg_replace("/ \(tm\)/i", ' &#40;tm)', $text);
$text = str_replace("''", '&#39;&#39;', $text);

$text = preg_replace('/(d+)x(\d+)/', "$1&#120;$2", $text);

$text = str_replace("\n\n", "\n&#160;\n", $text);
return $text;
} //end c2c_anti_wptexturize()

function c2c_preserve_code_formatting( $text ) {
$text = str_replace(array('$', "'"), array('&#36&;', '&#39&;'), $text);
$tags = array('code', 'pre');
foreach ($tags as $tag) {
$text = preg_replace(
"^(<$tag>)\n?([\S|\s]*?)\n?(</$tag>)^ie",
"'<$tag>' . c2c_prep_code(\"$2\") . '</$tag>'",
$text
);
}
$text = str_replace(array('&#36&;', '&#39&;'), array('$', "'"), $text);
return $text;
} //end c2c_preserve_code_formatting()

add_filter('the_content', 'c2c_preserve_code_formatting', 9);
add_filter('the_excerpt', 'c2c_preserve_code_formatting', 9);
// Comment out this next line if you don't want to allow preserve code formatting for comments.
add_filter('get_comment_text', 'c2c_preserve_code_formatting', 9);

?>

And here is my css style:

.code {
overflow:scroll;
overflow-y:hidden;
background-color:#f0f0f0;
}

code {
white-space: pre;
color: #222;
}

.keyword {
color:blue;
}
.api {
color:navy;
font-weight:bold;
}
.scope {
color:#f0f;
}
.string {
color:green;
}
.comment {
color:#777;
}
.tag {
color:#f70;
}

And here is the instruction to add my source highlighting when editing:
1. Go to visit http://demo.java2script.org/syntaxor/ , and you can highlight your sources there;
2. Copy the link at left upper corner, which started by a blue block;
3. Bookmark any page, and then modify the bookmark’s URL property to the above link location (a “javascript:” link to load source syntax highlighting);
4. Try to write or edit a post in browser, and then click the above bookmarked link, and the same source highlighting application window shows up after a while, try to paste your highlighted HTML source in the wordpress’ TinyMCE editor.

Posted in Blog Tips, Java2Script, Wordpress | Comments Off on Add Source Highlighting to WordPress Editor

Java2Script ClassLoader’s Loading Modes

There are 3 loading modes in Java2Script ClassLoader.

  1. Loading classes by using <SCRIPT> tag asynchronously (Default mode).
  2. Loading classes by XMLHttpRequest(XHR) asynchronously.
  3. Loading classes by XHR synchronously (May freeze UI when classes are loading).

In order to switch to different loading mode, execute the following line after j2slib.z.js is loaded:

ClazzLoader.setLoadingMode (“xhr.async”); // XHR asynchronously loading

or

ClazzLoader.setLoadingMode (“xhr”); // XHR synchronously loading

or

ClazzLoader.setLoadingMode (“script”); // <SCRIPT> asynchronously loading. No synchronously loading

In asynchronously loading mode, you can specify a time lag between two *.js loading. The time lag may be useful for the browser (Internet Explorer) to update its UI changes. To set time lag as the following examples:

ClazzLoader.setLoadingMode (“xhr.async”, 5); // 5 ms lag

or

ClazzLoader.setLoadingMode (“script”, 5);

But

ClazzLoader.setLoadingMode (“xhr”, 5); // synchronously loading

makes no senses, as there are no time lag in synchronously loading mode.

For more information, please read Java2Script’s ClassLoader source.

Posted in Java2Script | Comments Off on Java2Script ClassLoader’s Loading Modes