Tuesday, March 12, 2013
Freemind preview in Share
Code and instructions on http://code.google.com/p/alfresco-freemind/
thanks to the other contributions from which I build this!
Tuesday, February 26, 2013
Generic printing of properties in complex javascript object
I needed to make a generic solution for printing ScriptNode and the like object to JSON using FreeMarker, without knowing which keys to include before the script runs ... So I wanted just to print all property like key and value pair (String/String).
Turns out this is a little cumbersome, so here is my 5 cents:
<#assign keys=item?keys>
<#assign values=item?values>
<#assign max=keys?size>
<#assign jsonIndex=0>
{
<#list 0..max as index>
<#if keys[index]?exists>
<#if keys[index]?is_string>
<#if values[index]?exists>
<#if values[index]?is_string>
<#if jsonIndex!=0>,
<#else>
<#assign jsonIndex=jsonIndex+1>
</#if>
"${keys[index]}" : "${values[index]}"
</#if>
</#if>
</#if>
</#if>
</#list>
}
Well, what does it do ... it keeps two different indexes, one for the key/value pair being processed and one for number of json lines added for adding commas. It seems FreeMarker cannot handle Hashes with non-strings, so to bypass this restriction you must index your way through and test for existens and for type being String. This is done over the keys and values sequences, which are read from item (Javascript object, which become a FreeMarker SimpleHash).
Turns out this is a little cumbersome, so here is my 5 cents:
<#assign keys=item?keys>
<#assign values=item?values>
<#assign max=keys?size>
<#assign jsonIndex=0>
{
<#list 0..max as index>
<#if keys[index]?exists>
<#if keys[index]?is_string>
<#if values[index]?exists>
<#if values[index]?is_string>
<#if jsonIndex!=0>,
<#else>
<#assign jsonIndex=jsonIndex+1>
</#if>
"${keys[index]}" : "${values[index]}"
</#if>
</#if>
</#if>
</#if>
</#list>
}
Well, what does it do ... it keeps two different indexes, one for the key/value pair being processed and one for number of json lines added for adding commas. It seems FreeMarker cannot handle Hashes with non-strings, so to bypass this restriction you must index your way through and test for existens and for type being String. This is done over the keys and values sequences, which are read from item (Javascript object, which become a FreeMarker SimpleHash).
Friday, February 22, 2013
Easily make share the 'default' application in Tomcat
Normally you have a ROOT webapp in tomcat/webapps, which is a dummy Tomcat one.
To make this webapp redirect to i.e. alfresco share, when you type <server name>:<tomcat port> in your browser, but this in your tomcat/webapps/index.jsp file:
To make this webapp redirect to i.e. alfresco share, when you type <server name>:<tomcat port> in your browser, but this in your tomcat/webapps/index.jsp file:
<%
response.sendRedirect("/share");
%>
If there is an index.html og index.htm file remove it.
Now index.jsp will redirect and you do not need to change the share-webapp
Note: there is other ways using Tomcat context and stuff
Saturday, February 16, 2013
Visio preview in Alfresco
Just tested Alfresco CE 4.2.c and Libreoffice 4.0 release, and looking through the release notes, saw that it had much improve Visio support (improved libvisio) ...
Well uploaded some samples from M$ and they all renders fine in thumbnail and preview PDF :)
Alfresco uses PDF.js viewer and Libreoffice 4.0
Libreoffice 4 release notes: https://www.libreoffice.org/download/4-0-new-features-and-fixes#Filters
Please not some older star office and MS office formats are no longer supported!
I tried use 'soffice.bin' instead of 'soffice' as program in alfresco-global.properties, this had the effect on my installation, that oosplash process is not started!
Well uploaded some samples from M$ and they all renders fine in thumbnail and preview PDF :)
Alfresco uses PDF.js viewer and Libreoffice 4.0
Libreoffice 4 release notes: https://www.libreoffice.org/download/4-0-new-features-and-fixes#Filters
Please not some older star office and MS office formats are no longer supported!
I tried use 'soffice.bin' instead of 'soffice' as program in alfresco-global.properties, this had the effect on my installation, that oosplash process is not started!
Friday, February 1, 2013
Alfresco webscript description file schema ...
I was mocking about and decided to test reverse engineering the Alfresco / Spring framework Webscript description file schema ...
https://code.google.com/p/alfresco-webscript-schema/
Beware this contains alot of features and some are probable coupled to the webscript kind (attribute) :)
Another schema by SURF - eclipse plugin: https://anonsvn.springframework.org/svn/se-surf/trunk/spring-surf-devtools/spring-surf-eclipse-extensions/spring-surf-webscript-editor/schemas/DescriptionXMLSchema.xsd
https://code.google.com/p/alfresco-webscript-schema/
Beware this contains alot of features and some are probable coupled to the webscript kind (attribute) :)
Another schema by SURF - eclipse plugin: https://anonsvn.springframework.org/svn/se-surf/trunk/spring-surf-devtools/spring-surf-eclipse-extensions/spring-surf-webscript-editor/schemas/DescriptionXMLSchema.xsd
Thursday, January 3, 2013
Avoid coding by exceptions
generally it is a good practice to avoid using exception for standard coding control, like instead of using if-statements. This hold for javascript as well. There is a lot of reasons for this, one being performance and another debugger breaking. Normally a debugger will stop/break on an exception and the Alfresco Rhino debugger does this as well. So the following code-snipplet from Alfresco server-side JS file: header.get.js should be rewritten:
header.get.js
...
const PREF_COLLAPSED_TWISTERS = "org.alfresco.share.twisters.collapsed";
...
function getTwisterPrefs()
...
response = eval('(' + result + ')');collapsedTwisters = eval('try{(response.' + PREF_COLLAPSED_TWISTERS + ')}catch(e){}');
if (typeof collapsedTwisters != "string")
{
collapsedTwisters = "";
}
header.get.js (improved)
...
function getTwisterPrefs()
...
if (response.org.alfresco.share["twisters"] && typeof(response.org.alfresco.share.twisters["collapsed"]) === string){
collapsedTwisters = response.org.alfresco.share.twisters.collapsed;
}
else
{
collapsedTwisters = "";
}
So now the debugger does not break there if the twisters are not defined...
header.get.js
...
const PREF_COLLAPSED_TWISTERS = "org.alfresco.share.twisters.collapsed";
...
function getTwisterPrefs()
...
response = eval('(' + result + ')');collapsedTwisters = eval('try{(response.' + PREF_COLLAPSED_TWISTERS + ')}catch(e){}');
if (typeof collapsedTwisters != "string")
{
collapsedTwisters = "";
}
header.get.js (improved)
...
function getTwisterPrefs()
...
if (response.org.alfresco.share["twisters"] && typeof(response.org.alfresco.share.twisters["collapsed"]) === string){
collapsedTwisters = response.org.alfresco.share.twisters.collapsed;
}
else
{
collapsedTwisters = "";
}
So now the debugger does not break there if the twisters are not defined...
Wednesday, December 5, 2012
Generating Java sources from multiple DTD schemas
found out i could not generate Java source from multiple DTD's using xjc (JAXB), so I had to write this script. This script solves two thing: xjc cannot compile multiple DTDs and xjc will generate the same file ObjectFactory.java for each call (overwriting file from previous call).
#!/bin/sh
while IFS= read -r -u3 -d $'\0' file; do
filename="${file##*/}" # Strip longest match of */ from start
dir="${file:0:${#file} - ${#filename}}" # Substring from 0 thru pos of filename
base="${filename%.[^.]*}" # Strip shortest match of . plus at least one non-dot char from end
ext="${filename:${#base} + 1}"
newDir="$dir$base"
echo "Package dir to create $newDir"
DIRECTORY="generatedsrc/$newDir"
if [ ! -d "$DIRECTORY" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
mkdir -p $DIRECTORY
fi
PACKAGE=${newDir//.\//};
PACKAGE=${PACKAGE//\//.};
cmd="$JAVA_HOME/bin/xjc -dtd -d generatedsrc -p "$PACKAGE" $file"
echo "Running: $cmd"
$cmd
done 3< <(find . -iname *.dtd -type f -print0)
#!/bin/sh
while IFS= read -r -u3 -d $'\0' file; do
filename="${file##*/}" # Strip longest match of */ from start
dir="${file:0:${#file} - ${#filename}}" # Substring from 0 thru pos of filename
base="${filename%.[^.]*}" # Strip shortest match of . plus at least one non-dot char from end
ext="${filename:${#base} + 1}"
newDir="$dir$base"
echo "Package dir to create $newDir"
DIRECTORY="generatedsrc/$newDir"
if [ ! -d "$DIRECTORY" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
mkdir -p $DIRECTORY
fi
PACKAGE=${newDir//.\//};
PACKAGE=${PACKAGE//\//.};
cmd="$JAVA_HOME/bin/xjc -dtd -d generatedsrc -p "$PACKAGE" $file"
echo "Running: $cmd"
$cmd
done 3< <(find . -iname *.dtd -type f -print0)
Subscribe to:
Posts (Atom)

