JsJava means Java-formed Javascript,namely creating a series of Javascript objects similar to API of J2SE and J2EE and other opensource projects.With advanced Javascript objects,we may build complex web client business logic.
JsJava is an excellent Javascript library.In fact it's more than a Javascript library and it's also a Javascript infrastructure!
Introduction to JsJava2.0(http://www.jsjava.com)
JsJava2.0 comes to being on Sep 10th 2007.It's completely based on the Javascript's
prototype mechanism and build most usefull data strutcture and class libraries.It references
to J2SE1.4.2 and J2EE1.4 and some other opensource Java project such as apache commons.
I now introduce the main contents of JsJava2.0.
JsJava2.0 implements much of collections framwork similar to Java collections framework.It
implements BitSet,Hashtable,Iterator,List,Properties,Set,Stack,Enumeration and so on,with which
we may deal well with data strutures.e.g as follows:
var list=new ArrayList();
list.add("a");
list.add("b");
list.add("c");
var v=new Vector();
v.addElement(new Date());
JsJava2.0 implements xml parser.It is the browser xml document parser which is compatible
among IE,Firfox and Opera.Moreover,you can use xpath with Jsjava2.0 .
var xp=new XmlBrowserParser();
var xml="user1user2user3";
xp.loadXml(xml);
var xmlDoc=xp.toDocument();
var usersElem=xmlDoc.getElementsByTagName("user");
document.write("The number of user tag:"+usersElem.length+" ");
document.write("The number of user tag:"+xmlDoc.documentElement.selectNodes("user").length);
JsJava2.0 implements some calculation of advanced mathematics,such as matrix,distribution,statistics
and so on.With in-built Math object and JaJava math solution,you can resolve more math problems.
JsJava2.0 implements date format with provided pattern.e.g as follows:
var df=new SimpleDateFormat();
df.applayPattern("MM-dd-yyyy hh:mm:ss");
var str=df.format(new Date());
alert(str);
JsJava2.0 implements number format with provided pattern.e.g as follows:
var df=new DecimalFormat();
df.applayPattern("00.000%");
var str=df.format(0.0678567);
alert(str);// the result is 6.786%
JsJava2.0 implements data validation,which is useful in form.It contains number validator,string validator,
mail validator,url validator and so on.Futhermore it implements locale validator.For example it provides oicq
validator,here oicq is chat tool popular in china.
var urlValidator=new URLValidator();
var flag=urlValidator.validate("http://www.jsjava.com");
alert(flag);
JsJava2.0 implements web page animation solution.You can read the chapter 3.
JsJava2.0 implements main function of Ajax,which is popular along with web2.0.
function parseXml(username,date){
var text=req.getResponseText();
}
var req=new AjaxRequest();
req.setRequestMethod("post");
req.setRequestURL("ajaxresponse.jsp");
req.setAsync(true);
req.setMethodOnSuccess(parseXml,["John",new Date()]);
req.setRequestHeader("Content-Type","text/html;charset=gb2312");
req.send();
JsJava2.0 implements I/O(Input/Output) mechanism,which is very important.
Of course,Javascript itself can not operation server I/O and we don't want
to operation server I/O either.But I/O is a universal concept,so you can use it
on the web in another form or way. Example as follows:
Console.open();
System.out.println("This is very good!");
System.out.println("Now ok!");
function getNowTime(){
System.out.println("start method");
for(var i=0;i<100;i++){
var str="";
str+=new String(i);
}
System.out.println("end method");
System.out.println("over");
System.err.println("Error!");
}
getNowTime();
//System.exit(0);
Above is an System console,which is similar to OS command window.The result:
JsJava2.0 implements blog parser,which is very useful on the web2.0.With JsJava2.0,
you can parse a blog rss to serials of JsJava objects,which are easy to use.Example as
fllows:
var xmlStr='...';
var reader=new BlogRssReader();
var blogRss=reader.readRss(xmlStr);
var channel=blogRss.getRssChannel();
document.write(channel.getImage()+" ");
var items=channel.getItems();
for(var i=0;i");
}
JsJava2.0 implements page print component,with which you can print part
of a page.Moreover it can be used in IE,Firefox.Example as follows:
var print=new HtmlPrint();
var printArea=new HtmlPrintArea("info");//info is the area id
print.setArea(printArea);
print.print();
JsJava2.0 implements cursor operations.With JsJava2.0,you can move cursor
to specified position in a textarea and you also can calculate the cursor position
in a textarea.Example as follows:
JsJava2.0 implements clipboard operation,with which you can copy text
to system clipboard and get text from clipboard.It can work in IE and Firefox.
Example as follows:
JsJava2.0 implements color operation,with which you can operate RGB
color and convert between RGB value and Hex value.Example as follows:
var hexColors=ColorUtils.toPaletteDatum(9,9);
var str="