Skip to content

Instantly share code, notes, and snippets.

@touhami92
Created June 12, 2013 14:06
Show Gist options
  • Save touhami92/5765573 to your computer and use it in GitHub Desktop.
Save touhami92/5765573 to your computer and use it in GitHub Desktop.
Test
public String getStringJSON(docFullName, property){
this.setDocument(docFullName);
String propertyValue = this.theDoc.getValue(property, this.theObj);
if(!propertyValue || propertyValue == null) return "null";
def propertyArray = propertyValue.split(',');
String json = "[";
String tempProp;
Document tempDoc;
Object tempsObj;
if(propertyArray.size() == 0){
return "";
}else{
for(int i=0; i<propertyArray.size(); i++){
if(propertyArray[i] != ""){
if(xwiki.exists(propertyArray[i])){
tempProp = xwiki.getUserName(propertyArray[i], "\$first_name \$last_name", false);
}else{
tempProp = propertyArray[i];
}
json = json + '{"value":"' + propertyArray[i] + '","name":"' + tempProp + '"}';
if(i + 1 < propertyArray.size()){
json = json + ',';
}
}
}
}
json += "]";
return json;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment