Java Code Examples for java.io.Serializable.toString()

The following are Jave code examples for showing how to use toString() of the java.io.Serializable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alfresco-repository   File: SystemTemplateLocationsConstraint.java   View Source Code Vote up 6 votes
@Override
public String getDisplayLabel(String constraintAllowableValue, MessageLookup messageLookup)
{
    if (constraintAllowableValue.startsWith("N"))
    {
        Serializable nameProperty = nodeService.getProperty(new NodeRef(constraintAllowableValue.substring(1)),
                                                            ContentModel.PROP_NAME);
        return nameProperty.toString();
    }
    else if (constraintAllowableValue.equals(SystemTemplateLocationsConstraint.NULL_SYSTEM_TEMPLATE))
    {
        String message = messageLookup.getMessage(SystemTemplateLocationsConstraint.NULL_SYSTEM_TEMPLATE_MESSAGE,
                                                  I18NUtil.getLocale());
        return message == null ? constraintAllowableValue : message;
    }
    else
    {
        return constraintAllowableValue.substring(constraintAllowableValue.lastIndexOf("/") + 1);
    }
}
 
Example 2
Project: alfresco-repository   File: RepositoryDescriptorDAOImpl.java   View Source Code Vote up 6 votes
public String getDescriptor(final String key)
{
    String strValue = null;
    final QName qname = QName.createQName(key, RepositoryDescriptorDAOImpl.this.namespaceService);
    final Serializable value = this.properties.get(qname);
    if (value != null)
    {
        if (value instanceof Collection)
        {
            final Collection<?> coll = (Collection<?>) value;
            if (coll.size() > 0)
            {
                strValue = coll.iterator().next().toString();
            }
        }
        else
        {
            strValue = value.toString();
        }
    }
    return strValue;
}
 
Example 3
Project: alfresco-repository   File: NodeServiceTest.java   View Source Code Vote up 6 votes
/**
 * Looks for a key that contains the toString() of the value
 */
private Object findCacheValue(SimpleCache<Serializable, ValueHolder<Serializable>> cache, Serializable key)
{
    Collection<Serializable> keys = cache.getKeys();
    for (Serializable keyInCache : keys)
    {
        String keyInCacheStr = keyInCache.toString();
        String keyStr = key.toString();
        if (keyInCacheStr.endsWith(keyStr))
        {
            Object value = TransactionalCache.getSharedCacheValue(cache, keyInCache);
            return value;
        }
    }
    return null;
}
 
Example 4
Project: meparty   File: BaseCrudController.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
@Override
public final RestResponse create(@Validated @RequestBody final DtoT dto)
    throws DtoCrudException {
  Serializable id = doInsert(dto);
  String location = getMappingUrlOfController() + "/" + id.toString();

  return RestResponse.of(ResponseEntity
      .status(HttpStatus.CREATED)
      .header("Location", location)
      .build());
}
 
Example 5
Project: alfresco-repository   File: PropertyAuditFilter.java   View Source Code Vote up 5 votes
/**
 * @param rootPath String
 * @return boolean
 */
@Override
public boolean accept(String rootPath, Map<String, Serializable> auditMap)
{
    String[] root = splitPath(rootPath);
    String rootProperty = getPropertyName(PROPERY_NAME_PREFIX, getPropertyName(root));
    String defaultRootProperty = getDefaultRootProperty(root);
  
    if ("true".equalsIgnoreCase(getProperty(rootProperty, defaultRootProperty, ENABLED)))
    {
        for (Map.Entry<String, Serializable> entry : auditMap.entrySet())
        {
            Serializable value = entry.getValue();
            if (value == null)
            {
                value = "null";
            }
            String stringValue = (value instanceof String) ? (String)value : value.toString();
            String[] key = splitPath(entry.getKey());
            String propertyValue = getProperty(rootProperty, defaultRootProperty, key);
            if (!acceptValue(stringValue, propertyValue, rootProperty, key))
            {
                if (logger.isDebugEnabled())
                {
                    logger.debug("Rejected \n\t            "+rootPath+'/'+entry.getKey()+"="+stringValue+
                            "\n\t"+getPropertyName(rootProperty, getPropertyName(key))+"="+propertyValue);                
                }
                return false;
            }
        }
    }
    
    return true;
}
 
Example 6
Project: alfresco-repository   File: UsernamePropertyDecorator.java   View Source Code Vote up 5 votes
/**
 * @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 = "";
    }
    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 if (username.equals("System") || username.startsWith("[email protected]"))
    {
        firstName = "System";
        lastName = "User";
    }
    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 7
Project: alfresco-remote-api   File: SOLRSerializer.java   View Source Code Vote up 5 votes
public String serializeToJSONString(Serializable value)
{
    if (value != null && typeConverter.INSTANCE.getConverter(value.getClass(), String.class) == null)
    {
        // There is no converter
        return value.toString();
    }
    else
    {
        return typeConverter.INSTANCE.convert(String.class, value);
    }
}
 
Example 8
Project: cas-5.1.0   File: NoOpCipherExecutor.java   View Source Code Vote up 4 votes
@Override
public String encode(final Serializable value) {
    return value.toString();
}
 
Example 9
Project: cas-5.1.0   File: NoOpCipherExecutor.java   View Source Code Vote up 4 votes
@Override
public String decode(final Serializable value) {
    return value.toString();
}
 
Example 10
Project: alfresco-repository   File: JSONConversionComponent.java   View Source Code Vote up 4 votes
/**
 * 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 11
Project: alfresco-repository   File: VirtualizationIntegrationTest.java   View Source Code Vote up 4 votes
protected void assertVirtualNode(NodeRef nodeRef, Map<QName, Serializable> expectedProperties)
{
    assertNotNull(Reference.fromNodeRef(nodeRef));

    assertTrue(nodeService.hasAspect(nodeRef,
                                     VirtualContentModel.ASPECT_VIRTUAL));
    Set<QName> aspects = nodeService.getAspects(nodeRef);
    assertTrue("Smart virtual node missing virtual aspect",aspects.contains(VirtualContentModel.ASPECT_VIRTUAL));
    //ACE-5303 injected properties title and description  require the titled aspect 
    assertTrue("Smaft virtual node missing titled aspect",aspects.contains(ContentModel.ASPECT_TITLED));

    Map<QName, Serializable> nodeProperties = nodeService.getProperties(nodeRef);

    List<QName> mandatoryProperties = Arrays.asList(ContentModel.PROP_STORE_IDENTIFIER,
                                                    ContentModel.PROP_STORE_PROTOCOL,
                                                    ContentModel.PROP_LOCALE,
                                                    ContentModel.PROP_MODIFIED,
                                                    ContentModel.PROP_MODIFIER,
                                                    ContentModel.PROP_CREATED,
                                                    ContentModel.PROP_CREATOR,
                                                    ContentModel.PROP_NODE_DBID,
                                                    ContentModel.PROP_DESCRIPTION);

    Set<QName> missingPropreties = new HashSet<>(mandatoryProperties);
    missingPropreties.removeAll(nodeProperties.keySet());

    assertTrue("Mandatory properties are missing" + missingPropreties,
               missingPropreties.isEmpty());

    assertFalse("ACE-5303 : ContentModel.PROP_TITLE should remain unset",nodeProperties.containsKey(ContentModel.PROP_TITLE));
    
    Set<Entry<QName, Serializable>> epEntries = expectedProperties.entrySet();
    StringBuilder unexpectedBuilder = new StringBuilder();
    for (Entry<QName, Serializable> entry : epEntries)
    {
        Serializable actualValue = nodeProperties.get(entry.getKey());
        Serializable expectedValue = expectedProperties.get(entry.getKey());
        boolean fail = false;
        String expectedValueStr = null;

        if (expectedValue != null)
        {
            expectedValueStr = expectedValue.toString();

            if (!expectedValue.equals(actualValue))
            {
                fail = true;
            }

        }
        else if (actualValue != null)
        {
            fail = true;
            expectedValueStr = "<null>";
        }

        if (fail)
        {
            unexpectedBuilder.append("\n");
            unexpectedBuilder.append(entry.getKey());
            unexpectedBuilder.append(" expected[");
            unexpectedBuilder.append(expectedValueStr);
            unexpectedBuilder.append("] != actua[");
            unexpectedBuilder.append(actualValue);
            unexpectedBuilder.append("]");
        }
    }
    String unexpectedStr = unexpectedBuilder.toString();
    assertTrue("Unexpected property values : " + unexpectedStr,
               unexpectedStr.isEmpty());
}
 
Example 12
Project: alfresco-data-model   File: Path.java   View Source Code Vote up 4 votes
/**
 * Return the human readable form of the specified node Path. Slow version of the method
 * that extracts the name of each node in the Path from the supplied NodeService.
 * 
 * @return human readable form of the Path excluding the final element
 */
public String toDisplayPath(NodeService nodeService, PermissionService permissionService)
{
    StringBuilder buf = new StringBuilder(64);
    
    for (int i=0; i<elements.size()-1; i++)
    {
        String elementString = null;
        Element element = elements.get(i);
        if (element instanceof ChildAssocElement)
        {
            ChildAssociationRef elementRef = ((ChildAssocElement)element).getRef();
            if (elementRef.getParentRef() != null)
            {
                Serializable nameProp = null;
                if (permissionService.hasPermission(
                        elementRef.getChildRef(), PermissionService.READ) == AccessStatus.ALLOWED)
                {
                    nameProp = nodeService.getProperty(elementRef.getChildRef(), ContentModel.PROP_NAME);
                    // use the name property if we are allowed access to it
                    elementString = nameProp.toString();
                }
                else
                {
                    // revert to using QName if not
                    elementString = elementRef.getQName().getLocalName();
                }
            }
        }
        else
        {
            elementString = element.getElementString();
        }
        
        if (elementString != null)
        {
            buf.append("/");
            buf.append(elementString);
        }
    }
    
    return buf.toString();
}
 
Example 13
Project: cas-5.1.0   File: BaseStringCipherExecutor.java   View Source Code Vote up 2 votes
/**
 * Serialize value as string.
 *
 * @param value the value
 * @return the string
 */
protected String serializeValue(final Serializable value) {
    return value.toString();
}