Another Jaxer 1.0 Release Candidate with new APIs

Written by on August 1st, 2008 in Uncategorized.

Greg Murray has blogged about a new release candidate for Aptana Jaxer that contains a lot of new features.

Kevin Hakman told us about the release:

We’ve had server-side JS database APIs all along, but now handing result sets is even easier. There’s also now full fine grain control and access to the entire communication cycle with APIs for message headers, redirects, content and types. Speaking of types… for the first time with Jaxer, you can return content types other than HTML including JSON, XML, GIF, etc… Yes, even GIFs. Jaxer has a fresh new Image API that among other things can convert Canvas to static images and serve them up. Like, Greg, I too really like the idea of using Jaxer for easily creating JSON data services which is a rapidly growing trend as developers discover the powerful capabilities of JSON more and more. In Jaxer, it’s very cool since it’s all native JavaScript on the client, on the wire, and on the server. There’s even enhanced JSON serialization to make it even easier than before on both client and server. JSON services also open Jaxer to be useful in combination with rich internet clients other than Ajax UIs such as Flash, Flex or even Silverlight since all those support JavaScript on the client and can consume JSON data. For Ajax and RIA developers this is a boon since you can now write your client-side and server-side code in the same language. And if you prefer XML data services Jaxer’s native E4X (ECMAScript for XML) support means you can handle XML docs natively in JS on Jaxer as well.

This release also includes a totally new concept: a secure sandbox which as Greg explains, “lets you load, on the server, pages from other domains and allow their JavaScript to execute without giving them access to the Jaxer API or your own server-side code, but still gives your code access to their window objects and anything inside them”. For anyone who has ever done screenscaping for mashups or other applications, this really helps a lot since Ajax pages have historically thwarted scraping operations. With this feature in Jaxer you can securely get a remote page, execute its functions, and scrape the resulting DOM nodes (yes, you need not do tedious manipulations with strings) and voila!

Here are the features:

  • Application context settings that allowing for easier app configuration, app properties, database settings, etc…
  • Database API enhancements with richer APIs for working with result sets.
  • Server-side image manipulation including server-side canvas support and ability to convert to other image types.
  • Native command execution API so that you can run system commands and handle the output from those.
  • Asynchronous server-side JavaScript processing lets you implement callbacks in your server-side code too.
  • Ability to return custom content types (e.g. json, xml, gif, html, etc…)
  • Full control of the request/response lifecycle including setting redirects, headers, content, etc…
  • Secure sandbox supporting cross domain calls, sandboxed JavaScript execution, META refreshes, …
  • Serialization support for JavaScript objects to and from XML, E4X and JSON.

Uri Sarid has a great post that shows how you can do DOM Scraping with Jaxer, and updates it for this latest release:

There’s a lot of other new goodness in Jaxer 1.0, as well as the official released version of the Mozilla engine found in Firefox 3. So for example getElementsByClassName is natively implemented (see John Resig’s speed comparison), in addition to the other Mozilla features such as built-in XPath functionality and a very robust DOM feature set — just what you need for some serious ’screen scraping’, mashups, and content repurposing.

Let’s see it in action!

It includes code that shows the Sandbox in action, as well as the DOM work:

JAVASCRIPT:

  1.  
  2. // Gets a fragment of the remote page’s HTML, after some cleanup 
  3. function getFragment(title, url, isClassName, identifier, classesToRemove) 
  4. { 
  5.     var sandbox = new Jaxer.Sandbox(url)
  6.     var contents = sandbox.document[isClassName ? ‘getElementsByClassName’ : ‘getElementById’](identifier)
  7.     var container = addToPage(title, contents)
  8.     if (classesToRemove) 
  9.     { 
  10.         if (typeof classesToRemove == “string”) classesToRemove = [classesToRemove]
  11.         classesToRemove.forEach(function(className) 
  12.         { 
  13.             removeNodeList(container.getElementsByClassName(className))
  14.         })
  15.     } 
  16.     return container.innerHTML
  17. } 
  18. getFragment.proxy = true
  19.  

Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/352885199/another-jaxer-10-release-candidate-with-new-apis

Comments are closed.



Site Navigation