Skip to content

Instantly share code, notes, and snippets.

Created May 24, 2012 06:48
Show Gist options
  • Save agea/2779867 to your computer and use it in GitHub Desktop.
Save agea/2779867 to your computer and use it in GitHub Desktop.
Alfresco Short URL

How to create a simple url shortener for Alfresco (>=4.0):

  1. Create the Shortable Aspect:

    • Copy shortUrlModel.xml in the repository in /Data dictionary/Models
    • edit document properties and activate the model
  2. Make the aspect and the property visible:

    • Add the content of share-config-custom.xml to /tomcat/shared/classes/alfresco/web-extension/share-config-custom.xml
    • restart Alfresco
  3. Create the script to generate the short url:

  4. Create a Rule in a folder (can be the root of the document library of your share site):

    • When the content is added
    • For all the content NOT having the aspect "Short url enabled"
    • Execute two actions:
      • Add "Short url enabled" aspect
      • Execute Script createShortUrl.js
    • Apply rule to subfolders
  5. If you add a document to the folder you will see it will have a property (dw:shorturl) of 3 or 4 chars eg. xyz

  6. To have a really short url you can use, for example, a rewrite rule on Apache as in rewrite-rule.conf

var shortUrl =['dw:shorturl'];
while (!shortUrl){
var newUrl = "";
var length = 3;
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < length; i++ ){
newUrl += possible.charAt(Math.floor(Math.random() * possible.length));
var nodes = search.luceneSearch("@dw\\:shorturl:"+newUrl);
if (nodes.length==0){
shortUrl = newUrl;['dw:shorturl']=shortUrl;
RewriteEngine On
RewriteRule ^/s/(.*)$ /share/page/search?t=dw:shorturl:$1 [R]
<config evaluator="aspect" condition="dw:shortable">
<show id="dw:shorturl" for-mode="view"/>
<config evaluator="string-compare" condition="DocumentLibrary">
<aspect name="dw:shortable" />
<model xmlns="" name="dw:shortable">
<description>Shortable Aspect</description>
<author>Andrea Agili</author>
<import uri="" prefix="d"/>
<import uri="" prefix="cm"/>
<namespace uri="" prefix="dw"/>
<aspect name="dw:shortable">
<title>Short url enabled</title>
<property name="dw:shorturl">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment