Example usage for java.io Serializable toString

List of usage examples for java.io Serializable toString

Introduction

In this page you can find the example usage for java.io Serializable toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.pentaho.platform.repository2.unified.jcr.JcrRepositoryFileDao.java

/**
 * {@inheritDoc}/* w ww  . j  av a2s . co m*/
 */
@Override
public void restoreFileAtVersion(final Serializable fileId, final Serializable versionId,
        final String versionMessage) {
    if (isKioskEnabled()) {
        throw new RuntimeException(
                Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED")); //$NON-NLS-1$
    }
    Assert.notNull(fileId);
    Assert.notNull(versionId);
    jcrTemplate.execute(new JcrCallback() {
        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            Node fileNode = session.getNodeByIdentifier(fileId.toString());
            session.getWorkspace().getVersionManager().restore(fileNode.getPath(), versionId.toString(), true);
            return null;
        }
    });
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.converter.impl.CswRecordConverter.java

private void writeValue(HierarchicalStreamWriter writer, MarshallingContext context,
        AttributeDescriptor attributeDescriptor, QName field, Serializable value) {

    String xmlValue = null;/* w w  w  .j  a v a2 s.c  o  m*/

    AttributeFormat attrFormat = null;
    if (attributeDescriptor != null && attributeDescriptor.getType() != null) {
        attrFormat = attributeDescriptor.getType().getAttributeFormat();
    }
    if (attrFormat == null) {
        attrFormat = AttributeFormat.STRING;
    }
    String name = null;
    if (!StringUtils.isBlank(field.getNamespaceURI())) {
        if (!StringUtils.isBlank(field.getPrefix())) {
            name = field.getPrefix() + CswConstants.NAMESPACE_DELIMITER + field.getLocalPart();
        } else {
            name = field.getLocalPart();
        }
    } else {
        name = field.getLocalPart();
    }
    switch (attrFormat) {
    case BINARY:
        xmlValue = Base64.encodeBase64String((byte[]) value);
        break;
    case DATE:
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime((Date) value);
        xmlValue = XSD_FACTORY.newXMLGregorianCalendar(cal).toXMLFormat();
        break;
    case OBJECT:
        break;
    case GEOMETRY:
    case XML:
    default:
        xmlValue = value.toString();
        break;
    }
    // Write the node if we were able to convert it.
    if (xmlValue != null) {
        writer.startNode(name);
        if (!StringUtils.isBlank(field.getNamespaceURI())) {
            if (!StringUtils.isBlank(field.getPrefix())) {
                writeNamespace(writer, field);
            } else {
                writer.addAttribute(XMLConstants.XMLNS_ATTRIBUTE, field.getNamespaceURI());
            }
        }

        writer.setValue(xmlValue);
        writer.endNode();
    }
}

From source file:org.nuxeo.ecm.core.storage.dbs.DBSDocument.java

protected void writeComplexProperty(ComplexProperty complexProperty, State state, Runnable markDirty)
        throws PropertyException {
    if (complexProperty instanceof BlobProperty) {
        writeBlobProperty((BlobProperty) complexProperty, state);
        return;/* w w  w .  j ava2s  .co  m*/
    }
    for (Property property : complexProperty) {
        String name = property.getField().getName().getPrefixedName();
        name = internalName(name);
        // TODO XXX
        // if (checkReadOnlyIgnoredWrite(doc, property, map)) {
        // continue;
        // }
        Type type = property.getType();
        if (type.isSimpleType()) {
            // simple property
            Serializable value = property.getValueForWrite();
            markDirty.run();
            state.put(name, value);
            if (value instanceof Delta) {
                value = ((Delta) value).getFullValue();
                ((ScalarProperty) property).internalSetValue(value);
            }
        } else if (type.isListType()) {
            ListType listType = (ListType) type;
            if (listType.getFieldType().isSimpleType()) {
                // array
                Serializable value = property.getValueForWrite();
                if (value instanceof List) {
                    value = ((List<?>) value).toArray(new Object[0]);
                } else if (!(value == null || value instanceof Object[])) {
                    throw new IllegalStateException(value.toString());
                }
                markDirty.run();
                state.put(name, value);
            } else {
                // complex list
                Collection<Property> children = property.getChildren();
                List<Serializable> childMaps = new ArrayList<Serializable>(children.size());
                for (Property childProperty : children) {
                    State childMap = new State();
                    writeComplexProperty((ComplexProperty) childProperty, childMap, markDirty);
                    childMaps.add(childMap);
                }
                markDirty.run();
                state.put(name, (Serializable) childMaps);
            }
        } else {
            // complex property
            State childMap = (State) state.get(name);
            if (childMap == null) {
                childMap = new State();
                markDirty.run();
                state.put(name, childMap);
            }
            writeComplexProperty((ComplexProperty) property, childMap, markDirty);
        }
    }
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.common.source.AbstractCswSource.java

@Override
public ResourceResponse retrieveResource(URI resourceUri, Map<String, Serializable> requestProperties)
        throws IOException, ResourceNotFoundException, ResourceNotSupportedException {

    if (canRetrieveResourceById()) {
        // If no resource reader was found, retrieve the product through a GetRecordById request
        Serializable serializableId = null;
        if (requestProperties != null) {
            serializableId = requestProperties.get(Metacard.ID);
        }/*ww w .  j  a v a 2 s .  com*/

        if (serializableId == null) {
            throw new ResourceNotFoundException(
                    "Unable to retrieve resource because no metacard ID was found.");
        }
        String metacardId = serializableId.toString();

        LOGGER.debug("Retrieving resource for ID : {}", metacardId);
        Csw csw = factory.getClient();
        GetRecordByIdRequest getRecordByIdRequest = new GetRecordByIdRequest();
        getRecordByIdRequest.setService(CswConstants.CSW);
        getRecordByIdRequest.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
        getRecordByIdRequest.setOutputFormat(MediaType.APPLICATION_OCTET_STREAM);
        getRecordByIdRequest.setId(metacardId);

        String rangeValue = "";
        if (requestProperties.containsKey(CswConstants.BYTES_TO_SKIP)) {
            rangeValue = String.format("%s%s-", CswConstants.BYTES_EQUAL,
                    requestProperties.get(CswConstants.BYTES_TO_SKIP).toString());
            LOGGER.debug("Range: {}", rangeValue);
        }
        CswRecordCollection recordCollection;
        try {
            recordCollection = csw.getRecordById(getRecordByIdRequest, rangeValue);

            Resource resource = recordCollection.getResource();
            if (resource != null) {
                return new ResourceResponseImpl(
                        new ResourceImpl(new BufferedInputStream(resource.getInputStream()),
                                resource.getMimeTypeValue(), FilenameUtils.getName(resource.getName())));
            }
        } catch (CswException e) {
            throw new ResourceNotFoundException(String.format(ERROR_ID_PRODUCT_RETRIEVAL, metacardId), e);
        }

    }
    LOGGER.debug("Retrieving resource at : {}", resourceUri);
    return resourceReader.retrieveResource(resourceUri, requestProperties);
}

From source file:org.apache.jsp.html.taglib.aui.input.page_jsp.java

private long _getClassPK(Object bean, long classPK) {
        if ((bean != null) && (classPK <= 0)) {
            if (bean instanceof BaseModel) {
                BaseModel baseModel = (BaseModel) bean;

                Serializable primaryKeyObj = baseModel.getPrimaryKeyObj();

                if (primaryKeyObj instanceof Long) {
                    classPK = (Long) primaryKeyObj;
                } else {
                    classPK = GetterUtil.getLong(primaryKeyObj.toString());
                }/*  w ww .  ja  va  2  s.  c o  m*/
            }
        }

        return classPK;
    }

From source file:org.pentaho.platform.security.userroledao.jackrabbit.AbstractJcrBackedUserRoleDao.java

private RepositoryFile internalCreateFolder(final Session session, final Serializable parentFolderId,
        final RepositoryFile folder, final RepositoryFileAcl acl, final String versionMessage)
        throws RepositoryException {
    PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
    JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants,
            parentFolderId);/* w w  w.jav  a  2  s .co m*/
    Node folderNode = JcrRepositoryFileUtils.createFolderNode(session, pentahoJcrConstants, parentFolderId,
            folder);
    // we must create the acl during checkout
    JcrRepositoryFileAclUtils.createAcl(session, pentahoJcrConstants, folderNode.getIdentifier(),
            acl == null ? defaultAclHandler.createDefaultAcl(folder) : acl);
    session.save();
    if (folder.isVersioned()) {
        JcrRepositoryFileUtils.checkinNearestVersionableNodeIfNecessary(session, pentahoJcrConstants,
                folderNode, versionMessage);
    }
    JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants,
            parentFolderId,
            Messages.getInstance().getString("JcrRepositoryFileDao.USER_0001_VER_COMMENT_ADD_FOLDER",
                    folder.getName(), (parentFolderId == null ? "root" : parentFolderId.toString()))); //$NON-NLS-1$ //$NON-NLS-2$
    return JcrRepositoryFileUtils.nodeToFile(session, pentahoJcrConstants, pathConversionHelper, lockHelper,
            folderNode);
}

From source file:org.egov.services.cheque.ChequeAssignmentService.java

public EntityType getEntity(final Integer detailTypeId, final Serializable detailKeyId)
        throws ApplicationException {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Starting getEntity...");
    EntityType entity;//from www. jav a  2 s . c  om
    try {
        final Accountdetailtype accountdetailtype = (Accountdetailtype) persistenceService
                .find(" from Accountdetailtype where id=?", detailTypeId);
        final Class<?> service = Class.forName(accountdetailtype.getFullQualifiedName());
        // getting the entity type service.
        final String detailTypeName = service.getSimpleName();
        String dataType = "";
        final java.lang.reflect.Method method = service.getMethod("getId");
        dataType = method.getReturnType().getSimpleName();
        if (dataType.equals("Long"))
            entity = (EntityType) persistenceService.find(
                    "from " + detailTypeName + " where id=? order by name",
                    Long.valueOf(detailKeyId.toString()));
        else
            entity = (EntityType) persistenceService.find(
                    "from " + detailTypeName + " where id=? order by name",
                    Integer.valueOf(detailKeyId.toString()));
    } catch (final Exception e) {
        LOGGER.error("Exception to get EntityType=" + e.getMessage() + "for detailTypeId=" + detailTypeId
                + "  for Detail key " + detailKeyId);
        throw new ApplicationException("Exception to get EntityType=" + e.getMessage());
    }
    if (entity == null) {
        LOGGER.error("Exception to get EntityType  for detailTypeId=" + detailTypeId + "  for Detail key "
                + detailKeyId);
        throw new ApplicationException("Exception to get EntityType");
    }
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Completed getEntity.");
    return entity;
}

From source file:org.craftercms.cstudio.alfresco.service.impl.PersistenceManagerServiceImpl.java

protected DmContentItemTO createDmContentItem(String site, String fullPath, NodeRef nodeRef,
        Map<QName, Serializable> nodeProperties) {
    DmPathTO path = new DmPathTO(fullPath);
    String name = DefaultTypeConverter.INSTANCE.convert(String.class,
            nodeProperties.get(ContentModel.PROP_NAME));

    String relativePath = path.getRelativePath();
    ServicesConfig servicesConfig = getService(ServicesConfig.class);
    String timeZone = servicesConfig.getDefaultTimezone(site);
    DmContentItemTO item = new DmContentItemTO();
    item.setTimezone(timeZone);//www . jav  a 2s.c om
    item.setInternalName(name);
    item.setNodeRef(nodeRef.toString());
    boolean isDisabled = false;
    Serializable value = nodeProperties.get(CStudioContentModel.PROP_DISABLED);
    if (value != null) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("isDisabled: " + value.toString());
        }
        isDisabled = DefaultTypeConverter.INSTANCE.convert(Boolean.class, value);
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("isDisabled property not found");
        }
    }
    item.setDisabled(isDisabled);

    /**
     * Setting isNavigation property
     */
    boolean placeInNav = false;
    Serializable placeInNavProp = nodeProperties.get(CStudioContentModel.PROP_PLACEINNAV);
    if (placeInNavProp != null) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("placeInNav: " + placeInNavProp.toString());
        }
        placeInNav = DefaultTypeConverter.INSTANCE.convert(Boolean.class, placeInNavProp);
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("placeInNav property not found");
        }
    }
    item.setNavigation(placeInNav);

    item.setName(name);

    //Checks that the node is a folder, not if cont
    boolean isFolder = this.getFileInfo(nodeRef).isFolder();
    item.setContainer(isFolder || fullPath.endsWith(DmConstants.INDEX_FILE));
    if (isFolder) {
        item.setUri(relativePath);
        String folderPath = (name.equals(DmConstants.INDEX_FILE)) ? relativePath.replace("/" + name, "")
                : relativePath;
        item.setPath(folderPath);
    } else {
        item.setUri(relativePath);
        if (relativePath != null) {
            int index = path.getRelativePath().lastIndexOf("/");
            if (index > 0) {
                item.setPath(relativePath.substring(0, index));
            }
        }
    }
    item.setDefaultWebApp(path.getDmSitePath());

    SimpleDateFormat sdf = new SimpleDateFormat();
    try {
        Serializable strLastEditDate = nodeProperties.get(CStudioContentModel.PROP_WEB_LAST_EDIT_DATE);
        if (strLastEditDate != null && !StringUtils.isEmpty(strLastEditDate.toString())) {
            Date lastEditDate = sdf.parse(strLastEditDate.toString());
            item.setLastEditDate(lastEditDate);
        }
    } catch (ParseException e) {
        // do nothing
    }

    // default event date is the modified date
    item.setEventDate(
            DefaultTypeConverter.INSTANCE.convert(Date.class, nodeProperties.get(ContentModel.PROP_MODIFIED)));
    // read the author information
    String modifier = DefaultTypeConverter.INSTANCE.convert(String.class,
            nodeProperties.get(CStudioContentModel.PROP_LAST_MODIFIED_BY));
    if (modifier != null && !StringUtils.isEmpty(modifier.toString())) {
        item.setUser(modifier);
        ProfileService profileService = getService(ProfileService.class);
        UserProfileTO profile = profileService.getUserProfile(modifier, site, false);
        if (profile != null) {
            item.setUserFirstName(profile.getProfile().get(ContentModel.PROP_FIRSTNAME.getLocalName()));
            item.setUserLastName(profile.getProfile().get(ContentModel.PROP_LASTNAME.getLocalName()));
        }
    }

    // get the content type and form page info
    String contentType = DefaultTypeConverter.INSTANCE.convert(String.class,
            nodeProperties.get(CStudioContentModel.PROP_CONTENT_TYPE));
    if (contentType != null && !StringUtils.isEmpty(contentType)) {
        item.setContentType(contentType);
        loadContentTypeProperties(site, item, contentType);
    } else {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        String mimeType = fileNameMap.getContentTypeFor(item.getUri());
        if (mimeType != null && !StringUtils.isEmpty(mimeType)) {
            item.setPreviewable(
                    DmUtils.matchesPattern(mimeType, servicesConfig.getPreviewableMimetypesPaterns(site)));
        }
    }

    item.setTimezone(servicesConfig.getDefaultTimezone(site));

    return item;
}

From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.DataLayer.java

/**
 * Gets a label built from all non-null properties in the BlueXML namespace.
 * Similar to {@link #getLabelForNodeAllText(Map, Set)} except there's no
 * restriction to textual fields./*ww w.  j  a va 2s  .c o  m*/
 * 
 * @param nodeRef
 * @param properties
 * @param names
 * @return the computed label, or the node id if the label is empty.
 */
private String getLabelForNodeAll(NodeRef nodeRef, Map<QName, Serializable> properties, Set<QName> names) {
    Serializable propValue;
    String res = "";
    int nb = 0;
    for (QName propertyName : names) {
        if (propertyName.getNamespaceURI().startsWith(BLUEXML_MODEL_URI)) {
            PropertyDefinition propertyDef = dictionaryService.getProperty(propertyName);
            if (propertyDef != null) { // may happen if propertyName was removed from the
                // current version of the content type
                propValue = makePropertyValue(propertyDef, properties.get(propertyName));
                if (propValue != null) {
                    String propStr = propValue.toString();
                    if (StringUtils.trimToNull(propStr) != null) {
                        if (nb > 0) {
                            res += ", ";
                        }
                        res += StringUtils.trimToEmpty(getDisplayLabelForProperty(propertyDef)) + ": "
                                + propStr;
                        nb++;
                    }
                }
            }
        }
    }
    return StringUtils.trimToNull(res) == null ? nodeRef.getId() : res;
}