Encode Special Character in Query

In my previous blog I have described few details related to Xpath Query in Alfresco. Now apart from from that there are  other type of queries like Lucene Query, FTS query, CMIS query are supported in Alfresco. Queries are very important part of development in any content management system because ultimately, you want to access nodes or contents stored in content management systems to either manipulate it or to expose its data to another application.

Now there are always few small tips which we tends to miss and it gives us real hard time during development. One of such point I had explained in my blog Lucene Stop words indexing issue. Similar to that there is one issue with XPath queries which is related to spacial characters in content name.

What is the Issue?

Issue in XPath is that whenever there is a special character like white blank space of parenthesis appears in the name of content those queries will not be executed in alfresco as internal engine will not be able to handle that queries and will throw exception to you during search.Something like follow

org.alfresco.repo.search.SearcherException: Failed to parse query:
/app:company_home/st:sites/cm:folder1/cm:documentLibrary/cm:name with space.txt


Here is the solution for that. Alfresco has ISO Encoding utility for that which encode the name with special character in such a way that it will be properly interpreted by Alfresco search engine.So during query generation whichever part you think could create such issue you could encode it using API of that utility class as follow.


StringBuffer query=new StringBuffer("/app:company_home/st:sites/cm:folder1/cm:documentLibrary/cm:");
String filename=name with space.txt;

This ISO9075.encode(filename) will return you something like this.

Note: Use this function with care do not use this to encode your full query as it will also encode those “/” path separators.You could use this with Path query as well

For more details on APIs supported by that Alfresco ISO9075 utility class you can refer this.
Hope this will reduce some burden for developer and will be useful.

Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , | Posted under Alfresco | RSS 2.0

Author Spotlight


I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

Leave a Reply

Your email address will not be published. Required fields are marked *