org.json.simple.JSONAware Java Examples

The following examples show how to use org.json.simple.JSONAware. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TagPropertyDecorator.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
 */
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
    Collection<NodeRef> collection = (Collection<NodeRef>)value;
    JSONArray array = new JSONArray();

    for (NodeRef obj : collection)
    {
        try
        {
            JSONObject jsonObj = new JSONObject();
            jsonObj.put("name", this.nodeService.getProperty(obj, ContentModel.PROP_NAME));
            jsonObj.put("nodeRef", obj.toString());
            array.add(jsonObj);
        }
        catch (InvalidNodeRefException e)
        {
            logger.warn("Tag with nodeRef " + obj.toString() + " does not exist.");
        }
    }

    return array;
}
 
Example #2
Source File: CategoryPropertyDecorator.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
 */
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
    Collection<NodeRef> collection = (Collection<NodeRef>)value;
    JSONArray array = new JSONArray();

    for (NodeRef obj : collection)
    {
        try
        {
            JSONObject jsonObj = new JSONObject();
            jsonObj.put("name", this.nodeService.getProperty(obj, ContentModel.PROP_NAME));
            jsonObj.put("path", this.getPath(obj));
            jsonObj.put("nodeRef", obj.toString());
            array.add(jsonObj);
        }
        catch (InvalidNodeRefException e)
        {
            logger.warn("Category with nodeRef " + obj.toString() + " does not exist.");
        }
    }

    return array;
}
 
Example #3
Source File: JSONConversionComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Handles the work of converting values to JSON.
 * 
 * @param nodeRef NodeRef
 * @param propertyName QName
 * @param key String
 * @param value Serializable
 * @return the JSON value
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object propertyToJSON(final NodeRef nodeRef, final QName propertyName, final String key, final Serializable value)
{
	if (value != null)
    {
        // Has a decorator has been registered for this property?
        if (propertyDecorators.containsKey(propertyName))
        {
            JSONAware jsonAware = propertyDecorators.get(propertyName).decorate(propertyName, nodeRef, value);
            if (jsonAware != null)
            {
            	return jsonAware;
            }
        }
        else
        {
            // Built-in data type processing
            if (value instanceof Date)
            {
                JSONObject dateObj = new JSONObject();
                dateObj.put("value", JSONObject.escape(value.toString()));
                dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date)value)));
                return dateObj;
            }
            else if (value instanceof List)
            {
            	// Convert the List to a JSON list by recursively calling propertyToJSON
            	List<Object> jsonList = new ArrayList<Object>(((List<Serializable>) value).size());
            	for (Serializable listItem : (List<Serializable>) value)
            	{
            	    jsonList.add(propertyToJSON(nodeRef, propertyName, key, listItem));
            	}
            	return jsonList;
            }
            else if (value instanceof Double)
            {
                return (Double.isInfinite((Double)value) || Double.isNaN((Double)value) ? null : value.toString());
            }
            else if (value instanceof Float)
            {
                return (Float.isInfinite((Float)value) || Float.isNaN((Float)value) ? null : value.toString());
            }
            else
            {
            	return value.toString();
            }
        }
    }
	return null;
}
 
Example #4
Source File: IgnorePropertyDecorator.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
 */
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
    return null;
}
 
Example #5
Source File: UsernamePropertyDecorator.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
 */
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
    String username = value.toString();
    String firstName = null;
    String lastName = null;
    JSONObject map = new JSONObject();
    map.put("userName", username);
    
    // DO NOT change this to just use getPersonOrNullImpl
    //  - there is Cloud THOR prod hack see personServiceImpl.personExists
    //  - and THOR-293 
    if (username.isEmpty())
    {
        firstName = "";
        lastName = "";
    }
    // Check for System before going to the PersonService
    else if (username.equals("System") || username.startsWith("System@"))
    {
        firstName = "System";
        lastName = "User";
    }
    else if (this.personService.personExists(username))
    {
        NodeRef personRef = this.personService.getPerson(username, false);
        firstName = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
        lastName = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
    }
    else
    {
        map.put("isDeleted", true);
        return map;
    }
    
    map.put("firstName", firstName);
    map.put("lastName", lastName);
    map.put("displayName", ((firstName != null ? firstName + " " : "") + (lastName != null ? lastName : "")).replaceAll("^\\s+|\\s+$", ""));
    return map;
}
 
Example #6
Source File: PropertyDecorator.java    From alfresco-repository with GNU Lesser General Public License v3.0 votes vote down vote up
JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value);