Badass Alfresco JavaScript Console

Badass Alfresco JavaScript Console

I love a fast feedback loop. And I love throwing code at running applications.

The Alfresco JavaScript Console may not provide state of the art scripting capabilities. Nevertheless, it has been accompanying me for years, and I still use it pretty frequently. I always found it a bit disappointing that only loading and saving from or to the repo is supported, because that in turn makes code management and sharing unnecessarily hard.

Implementation

The basic idea was to allow resource access at various locations: Spring resources (classpath, filesystem), the repository (multiple configured folders), and via http. For some, I decided to implement write support (save/remove). While I was at it, I extended save to create missing folders on the fly.

The following fragment shows a Spring bean configuration for those locations.

    <!-- That's where we look up scripts in the repo -->
    <util:list id="jsconsole.extension.repoXPaths">
      <!-- first one is where we save to by default -->
      <value>/app:company_home/app:dictionary/app:scripts</value>
      <value>/app:company_home/cm:more-scripts</value>
    </util:list>
    <!-- That's where we look up using Spring resource matches.
         Works with files and classpath  -->
    <util:list id="jsconsole.extension.scriptPattern">
      <value>classpath*:/alfresco/module/contentreich_sandbox/**/*.js</value>
      <value>classpath*:/alfresco/alf-js-from-cp/**/*.js</value>
      <value>file:/home/deas/tmp/alf-js-from-fs/**/*.js</value>
    </util:list>
    <!-- Finally, thats where we include URLs to load scripts -->
    <util:list id="jsconsole.extension.urlPattern">
      <value>https://www.contentreich.de/alf-js-cr-public/</value>
      <value>http://localhost6:81/alf-js-localhost/</value>
    </util:list>

Also while I was add it, I introduced a badass JavaScript root object which I came up with in another project. Amongst other things, it allows external program execution and filesystem access. That may seem odd, but in fact you can already do that anyways, so essentially, it’s about convenience only.

Along the way, I also fixed some issues (menu item z-index/interference) and hacked up a PHP script companion to list JavaScript files for http based locations.

In case you’d like to try it out, you’ll find a zip-download containing repo and share jars below. The files javascript-console-share-1.1-SNAPSHOT.jar and javascript-console-repo-1.1-SNAPSHOT.jar go to webapps/share/WEB-INF/lib and webapps/alfresco/WEB-INF/lib respectively. For custom configuration, put your bean configuration in shared/classes/alfresco/extension/your-tweaks-context.xml. Feel free to use my scripts at https://www.contentreich.de/alf-js-cr-public/.

You may want to check the video where you can see me poking around.

Alfresco Scripting Future

JavaScript (Rhino based) and the JavaScript console have limitations. Still, both work fine and reliable today. Everything else I am aware of is pretty much bleeding edge. Personally I am going with Clojure in the long run. Your mileage may vary.

Download Alfresco JavaScript Console 1.1-SNAPSHOT

References

Andreas Steffan
Pragmatic ? Scientist and DevOps Mind @ Contentreich. Believes in Open Source, the Open Web and Linux. Freelancing in DevOps-, Cloud-, Kubernetes, JVM- and Contentland and speaks Clojure, Kotlin, Groovy, Go, Python, JavaScript, Java, Alfresco and WordPress. Built infrastructure before it was cool. ❤️ Emacs.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert