January 9, 2008

Alfresco and MySource Matrix

Filed under: PHP, Alfresco — Marcus @ 1:17 am

This isn’t a comparison of the two, which I may one day get to having worked extensively with both and having had good and bad experiences with both. Instead, due to the release of a PHP5 version of MySource Matrix recently, I had a few hours in which I quickly created a bridge to pull content from Alfresco into Matrix.

While not completely functional, here’s a quick screenshot because that’s what screenshots are for right? Code to come at a later point in time, but the goal is to be able to perform CRUD operations against an Alfresco repository from within the Matrix backend, and from within a Matrix powered website.

Alfresco in Matrix

“But why, when Alfresco has its own WCM?” you ask? A story for another time I’m sure…

July 9, 2007

Alfresco WCM virtualisation for ColdFusion

Filed under: Alfresco — Marcus @ 12:08 pm

If you’ve tried Alfreso’s WCM, you’d know that in current releases (pre 2.1), there’s not a great deal of functionality for building dynamic websites, and that the existing platform is more geared around the management of the administration of content assets that are served over the web, as opposed to providing the tools to build and present websites. (2.1 does introduce a lot more features for this though).  Where these assets are java based, the existing Alfresco virtual server works great; for others, not so great.  Recently I had to have ColdFusion virtualised via Alfresco’s WCM; here’s how.

The goal is simple; get ColdFusion changes to be previewable out of user sandboxes.

  1. Download Railo. Other ColdFusion engines may work, however this was the first one that correctly ran the application I was working with.
  2. Import your ColdFusion application to Alfresco. Extract the Railo war file’s WEB-INF directory to the the root of the webapp inside Alfresco

Unfortunately, if you start the virtualisation server now, you’ll receive errors due to the Railo server not being able to correctly read/write to the AVM directly. What you need to do is very similar to how the virtual server does things, but a little less directly.

  1. Download and extract a new tomcat application server
  2. Mount the Alfresco AVM as a CIFS drive on the server:
    mount -t smbfs -o username=admin,password=admin //alfresco_a/AVM /opt/alfresco/shares/avm
  3. Modify the newly extracted tomcat’s conf/server.xml file to map the requests to the correct sandbox
    <Host name=”domain.www–sandbox.127-0-0-1.ip.alfrescodemo.net” appBase=”/opt/alfresco/shares/avm/domain/HEAD/DATA/www/avm_webapps”>
    <Context path=”" docBase=”ROOT”/>
    </Host>
    <Host name=”admin.domain.www–sandbox.127-0-0-1.ip.alfrescodemo.net” appBase=”/opt/alfresco/shares/avm/domain–admin/HEAD/DATA/www/avm_webapps”>
    <Context path=”" docBase=”ROOT”/>
    </Host>

Alfresco takes the domain and port to use from the virtual server’s alfresco.virtserver.domain configuration located in virtual-tomcat/conf/alfresco-virtserver.properties file. The example above is the default, but chances are it’ll need to change. The more important one is the alfresco.virtserver.http.port configuration; you’ll have 3 tomcat instances running, and you need to make sure this port is that of the tomcat configured earlier. The virtual server MUST be running for the Alfresco web client to use the correct domain:port combination for your faux-virtual server.

When starting the servers, make sure to start the Alfresco WCM instance first as it needs to be up and running for mapping to its CIFS interface, before the faux-virtual server can be started.

May 17, 2007

Working with the Alfresco PHP Library - Browsing Folders

Filed under: PHP, Alfresco — Marcus @ 10:21 am

Alfresco’s 1.4 version of the PHP library has been around as a technical preview, but doesn’t seem to have progressed much further. Regardless, it’s still quite functional, and allows you to do most things in a more sane way than the previous releases of it. Over the next couple of weeks I’ll be playing around with some of the functionality available, and given that some people are still a bit unsure of how everything works in the new version, hopefully I can help shed some light on things. First up; browsing spaces.

Everything in the PHP API requires the use of the Session object, either directly or indirectly. Connecting to the repository must be done before anything else, and is quite simple; provide the username, password, and URL of where the repository is located (remember that api bit!).

Code (php)
  1.  
  2. $session = Session::create("admin", "admin", "http://localhost:8080/alfresco/api");
  3. $spacesStore = new SpacesStore($session);

Next, I’m going to get the selected node; note that if I haven’t specified one on the request, I’ll just get the company home.

Code (php)
  1.  
  2. $selected = isset($_GET[‘id’]) ? $_GET[‘id’] : null;
  3. $root = null;
  4. if (!$selected) {
  5. $root = $spacesStore->getCompanyHome();
  6. } else {
  7. $root = getNode($session, $spacesStore, $selected);
  8. }
  9.  
  10. function getNode($session, $store, $id)
  11. {
  12. $nodes = $session->query($store, ‘@sys:node-uuid:"’.$id.‘"’);
  13. return isset($nodes[0]) ? $nodes[0] : null;
  14. }

With the node in hand, I can now iterate over its children and list out a browseable listing.

Code (php)
  1.  
  2. $children = $root->getChildren();
  3. echo ‘<table>’;
  4. foreach ($children as $childAssociation) {
  5. /* @var $childAssociation ChildAssociation */
  6.  
  7. $child = $childAssociation->getChild();
  8. /* @var $child Node */
  9. echo ‘<tr>’;
  10. echo ‘<td>’;
  11. echo preg_replace(‘/{.*?}/’, , $child->getType());
  12. echo ‘</td>’;
  13. echo ‘<td>’;
  14. echo ‘<a href="?id=’.$child->getId().‘">’.$childAssociation->getChild()->cm_name."</a><br/>";
  15. echo ‘</td>’;
  16. echo ‘</tr>’;
  17. }
  18. echo ‘</table>’;

April 22, 2007

Filed under: Javascript, Alfresco — Marcus @ 9:44 pm

Alfresco has the ability to process server-side javascript via an external command processor (Alfresco Wiki). Any output of the script is then returned to the browser as HTML, meaning quite complex interfaces can be built without any Java code.

The following is a simple request processor that uses the idea of MVC (loosely…) with Action Controllers to process different actions and views depending on what method the user triggers. There’s some limitations as to what you can push through to the Freemarker templates, so some of the logic is needed in there, however overal it’s possible to do some quite sophisticated things.

Main entry point is JSRequest.prototype.doRequest

  • figures out what request action to execute based on an “action” parameter in the request (ie you need to specify one as a hidden field on your forms)
  • executes that action, getting a string back as the output of that action
  • wraps a global template (if it exists) around the whole lot for theming purposes.

The example includes just a simple search demonstration. The javascript is actually inside the .html files; you may need to change some of the config settings at the top of the files to make sure of the context path etc.

(Edited to add: you access it via a url like http://localhost:8080/alfresco/command/script/execute?scriptPath=/Company%20Home/web-scripts/index.html)
Javascript request processing example

.

Powered by WordPress