Latest Posts

Archives [+]

Flexling: CRX for Flex developers

Flex developers interested in working with CRX or CQ5 might want to have a look at a package I have recently uploaded to the public section of the Package Share. It is called "Flexling" and contains:

  • an Actionscript library for read and write access to CRX (as well as search)
  • a help file and API docs for the library
  • an example Flex application

Preview of the package:

file

After installation of the package point your browser to localhost:(port)/apps/flexling/docs/flexling.html where the introductory document is located.

file

How it works

The library basically wraps the Sling http API into an Actionscript object com.day.sling.Sling. There are three methods for reading and searching content: getContent (synchronous), loadContent (asynchronous) and search (asynchronous). Under the hood these leverage the json rendering of JCR content that Sling provides. In a similar fashion the methods saveContent and removeContent wrap the SlingPostServlet's functionality for writing to the repository (both are asynchronous).  All asynchronous methods dispatch com.day.sling.SlingEvent events when done (inherited from flash.events.Event).

The method getContent exists basically for educational purposes - loadContent would be sufficient to read from the repository. getContent shows how to leverage the browser's XHR object for reading from the repository (using flash.external.ExternalInterface) while loadContent uses the flash.net.URLLoader.

Alternatives

Through flash.external.ExternalInterface there is actually a third possibility to interface the repository (though not implemented in this package): Sling provides a Javascript file located at /system/sling.js (Apache svn http://svn.apache.org/repos/asf/sling/trunk/bundles/servlets/post/src/main/resources/system/sling.js). You could use e.g. Sling.httpGet to retrieve content.

This is exactly the approach taken by the Flex-based CQ5 standard slideshow component (see screenshot below). It ships with the complete Flex source code in the repository at /libs/foundation/components/slideshow/src.

the slideshow component in the goemetrixx demo site

Kudos to Josh Oransky who collaborated with me on the Flexling package.

 

COMMENTS

  • By Mike Slinn - 4:58 PM on Dec 20, 2010   Reply
    Can you point newbies to 'public section of the Package Share'?
  • By Ronald Kamp - 9:38 AM on Apr 12, 2011   Reply
    I have been trying to get this to work with images, and not just with text. the problem that I am expriencing now is that when I try to load the following url: /content/dam/geometrixx/travel/packing.jpg/jcr:content/renditions/original, (with some rewrite of the code), it throws a security error event. Yet, when I try it with just /content/dam/geometrixx/travel/packing.jpg, it shows me the data (in textform in an Alert box).

    Do you have any idea how to get images with flexling from you crx repository?

    Thanks in advance for your answer.

    Kind regards,
  • By Taylor Bastien - 11:33 PM on May 19, 2011   Reply
    Hello, Michael.

    First off, thank you for sharing this code with us. It is a great start in integrating Flex with CRX.

    Second, I am trying to figure out how to POST binary data (e.g. PDFs) to CRX through a Flex UI. Unfortunately, all I seem to be able to crate are Strings (even if I'm actually POSTing a byte array). Can you please share an example of how this might be done?

    Thank you.