Example usage for com.liferay.portal.kernel.util StringPool SLASH

List of usage examples for com.liferay.portal.kernel.util StringPool SLASH

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool SLASH.

Prototype

String SLASH

To view the source code for com.liferay.portal.kernel.util StringPool SLASH.

Click Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.store.FileSystemStore.java

License:Open Source License

protected File getRepositoryDir(long companyId, long repositoryId) {
    RepositoryDirKey repositoryDirKey = new RepositoryDirKey(companyId, repositoryId);

    File repositoryDir = _repositoryDirs.get(repositoryDirKey);

    if (repositoryDir == null) {
        File companyDir = getCompanyDir(companyId);

        repositoryDir = new File(companyDir + StringPool.SLASH + repositoryId);

        if (!repositoryDir.exists()) {
            repositoryDir.mkdirs();/*from w  ww.  j a  va2  s. c o  m*/
        }

        _repositoryDirs.put(repositoryDirKey, repositoryDir);
    }

    return repositoryDir;
}

From source file:com.liferay.portlet.documentlibrary.store.JCRStore.java

License:Open Source License

@Override
public void addFile(long companyId, long repositoryId, String fileName, InputStream is)
        throws PortalException, SystemException {

    Session session = null;//from w w w .  j  a  v a  2  s . c  o  m

    try {
        session = JCRFactoryUtil.createSession();

        Workspace workspace = session.getWorkspace();

        VersionManager versionManager = workspace.getVersionManager();

        Node rootNode = getRootNode(session, companyId);

        Node repositoryNode = getFolderNode(rootNode, repositoryId);

        if (fileName.contains(StringPool.SLASH)) {
            String path = fileName.substring(0, fileName.lastIndexOf(StringPool.SLASH));

            fileName = fileName.substring(path.length() + 1);

            repositoryNode = getFolderNode(repositoryNode, path);
        }

        if (repositoryNode.hasNode(fileName)) {
            throw new DuplicateFileException(fileName);
        }

        Node fileNode = repositoryNode.addNode(fileName, JCRConstants.NT_FILE);

        Node contentNode = fileNode.addNode(JCRConstants.JCR_CONTENT, JCRConstants.NT_RESOURCE);

        contentNode.addMixin(JCRConstants.MIX_VERSIONABLE);
        contentNode.setProperty(JCRConstants.JCR_MIME_TYPE, ContentTypes.TEXT_PLAIN);

        ValueFactory valueFactory = session.getValueFactory();

        Binary binary = valueFactory.createBinary(is);

        contentNode.setProperty(JCRConstants.JCR_DATA, binary);

        contentNode.setProperty(JCRConstants.JCR_LAST_MODIFIED, Calendar.getInstance());

        session.save();

        Version version = versionManager.checkin(contentNode.getPath());

        VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath());

        versionHistory.addVersionLabel(version.getName(), VERSION_DEFAULT, false);
    } catch (RepositoryException re) {
        throw new SystemException(re);
    } finally {
        JCRFactoryUtil.closeSession(session);
    }
}

From source file:com.liferay.portlet.documentlibrary.store.JCRStore.java

License:Open Source License

@Override
public void updateFile(long companyId, long repositoryId, long newRepositoryId, String fileName)
        throws PortalException, SystemException {

    Session session = null;/*from   w w  w  .ja v a  2  s.c  o  m*/

    try {
        session = JCRFactoryUtil.createSession();

        Node rootNode = getRootNode(session, companyId);

        Node repositoryNode = getFolderNode(rootNode, repositoryId);

        if (fileName.contains(StringPool.SLASH)) {
            String path = fileName.substring(0, fileName.lastIndexOf(StringPool.SLASH));

            fileName = fileName.substring(path.length() + 1);

            repositoryNode = getFolderNode(repositoryNode, path);
        }

        Node newRepositoryNode = getFolderNode(rootNode, newRepositoryId);

        if (newRepositoryNode.hasNode(fileName)) {
            throw new DuplicateFileException(fileName);
        }

        Node fileNode = repositoryNode.getNode(fileName);

        Node contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT);

        String contentNodePath = contentNode.getPath();

        Node newFileNode = newRepositoryNode.addNode(fileName, JCRConstants.NT_FILE);

        String newContentNodePath = newFileNode.getPath().concat(StringPool.SLASH)
                .concat(JCRConstants.JCR_CONTENT);

        session.move(contentNodePath, newContentNodePath);

        fileNode.remove();

        session.save();
    } catch (PathNotFoundException pnfe) {
        throw new NoSuchFileException(fileName);
    } catch (RepositoryException re) {
        throw new SystemException(re);
    } finally {
        JCRFactoryUtil.closeSession(session);
    }
}

From source file:com.liferay.portlet.documentlibrary.store.JCRStore.java

License:Open Source License

public void updateFile(long companyId, long repositoryId, String fileName, String newFileName)
        throws PortalException, SystemException {

    Session session = null;/*from   w w w . j a  v a  2  s .  com*/

    try {
        session = JCRFactoryUtil.createSession();

        Node rootNode = getRootNode(session, companyId);

        Node repositoryNode = getFolderNode(rootNode, repositoryId);

        if (fileName.contains(StringPool.SLASH)) {
            String path = fileName.substring(0, fileName.lastIndexOf(StringPool.SLASH));

            fileName = fileName.substring(path.length() + 1);

            repositoryNode = getFolderNode(repositoryNode, path);
        }

        if (repositoryNode.hasNode(newFileName)) {
            throw new DuplicateFileException(newFileName);
        }

        Node fileNode = repositoryNode.getNode(fileName);

        Node contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT);

        String contentNodePath = contentNode.getPath();

        Node newFileNode = repositoryNode.addNode(newFileName, JCRConstants.NT_FILE);

        String newContentNodePath = newFileNode.getPath().concat(StringPool.SLASH)
                .concat(JCRConstants.JCR_CONTENT);

        session.move(contentNodePath, newContentNodePath);

        fileNode.remove();

        session.save();
    } catch (PathNotFoundException pnfe) {
        throw new NoSuchFileException(fileName);
    } catch (RepositoryException re) {
        throw new SystemException(re);
    } finally {
        JCRFactoryUtil.closeSession(session);
    }
}

From source file:com.liferay.portlet.documentlibrary.store.JCRStore.java

License:Open Source License

@Override
public void updateFile(long companyId, long repositoryId, String fileName, String versionLabel, InputStream is)
        throws PortalException, SystemException {

    Session session = null;//  w  w w . j  av a 2s .c  om

    try {
        session = JCRFactoryUtil.createSession();

        Workspace workspace = session.getWorkspace();

        VersionManager versionManager = workspace.getVersionManager();

        Node rootNode = getRootNode(session, companyId);

        Node repositoryNode = getFolderNode(rootNode, repositoryId);

        if (fileName.contains(StringPool.SLASH)) {
            String path = fileName.substring(0, fileName.lastIndexOf(StringPool.SLASH));

            fileName = fileName.substring(path.length() + 1);

            repositoryNode = getFolderNode(repositoryNode, path);
        }

        Node fileNode = repositoryNode.getNode(fileName);

        Node contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT);

        versionManager.checkout(contentNode.getPath());

        contentNode.setProperty(JCRConstants.JCR_MIME_TYPE, ContentTypes.TEXT_PLAIN);

        ValueFactory valueFactory = session.getValueFactory();

        Binary binary = valueFactory.createBinary(is);

        contentNode.setProperty(JCRConstants.JCR_DATA, binary);

        contentNode.setProperty(JCRConstants.JCR_LAST_MODIFIED, Calendar.getInstance());

        session.save();

        Version version = versionManager.checkin(contentNode.getPath());

        VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath());

        versionHistory.addVersionLabel(version.getName(), versionLabel,
                PropsValues.DL_STORE_JCR_MOVE_VERSION_LABELS);
    } catch (PathNotFoundException pnfe) {
        throw new NoSuchFileException("{fileName=" + fileName + ", versionLabel=" + versionLabel + "}");
    } catch (RepositoryException re) {
        throw new SystemException(re);
    } finally {
        JCRFactoryUtil.closeSession(session);
    }
}

From source file:com.liferay.portlet.documentlibrary.store.JCRStore.java

License:Open Source License

protected Node getFolderNode(Node node, String name) throws RepositoryException {

    if (name.contains(StringPool.SLASH)) {
        String[] nameParts = name.split(StringPool.SLASH, 2);

        node = getFolderNode(node, nameParts[0]);

        return getFolderNode(node, nameParts[1]);
    }//from  w ww.  j  av  a  2 s . c  o m

    Node folderNode = null;

    if (node.hasNode(name)) {
        folderNode = node.getNode(name);
    } else {
        folderNode = node.addNode(name, JCRConstants.NT_FOLDER);
    }

    return folderNode;
}

From source file:com.liferay.portlet.documentlibrary.store.S3Store.java

License:Open Source License

public void updateFile(long companyId, long repositoryId, String fileName, String newFileName)
        throws SystemException {

    try {//from w  w w .j a v  a  2  s . c o m
        S3Object[] s3Objects = _s3Service.listObjects(_s3Bucket, getKey(companyId, repositoryId, fileName),
                null);

        for (int i = 0; i < s3Objects.length; i++) {
            S3Object oldS3Object = s3Objects[i];

            String oldKey = oldS3Object.getKey();

            oldS3Object = _s3Service.getObject(_s3Bucket, oldKey);

            File tempFile = new File(SystemProperties.get(SystemProperties.TMP_DIR) + File.separator
                    + PortalUUIDUtil.generate());

            FileUtil.write(tempFile, oldS3Object.getDataInputStream());

            InputStream is = new FileInputStream(tempFile);

            String newPrefix = getKey(companyId, repositoryId, newFileName);

            int x = oldKey.indexOf(StringPool.SLASH);

            x = oldKey.indexOf(CharPool.SLASH, x + 1);

            x = oldKey.indexOf(CharPool.SLASH, x + 1);

            String newKey = newPrefix + oldKey.substring(x + 1, oldKey.length());

            S3Object newS3Object = new S3Object(_s3Bucket, newKey);

            newS3Object.setDataInputStream(is);

            _s3Service.putObject(_s3Bucket, newS3Object);
            _s3Service.deleteObject(_s3Bucket, oldKey);

            FileUtil.delete(tempFile);
        }
    } catch (IOException ioe) {
        throw new SystemException(ioe);
    } catch (S3ServiceException s3se) {
        throw new SystemException(s3se);
    }
}

From source file:com.liferay.portlet.documentlibrary.store.S3Store.java

License:Open Source License

protected String getKey(long companyId, long repositoryId) {
    StringBundler sb = new StringBundler(4);

    sb.append(companyId);/*from w w  w  .  j  a  va 2  s  . c  om*/
    sb.append(StringPool.SLASH);
    sb.append(repositoryId);
    sb.append(StringPool.SLASH);

    return sb.toString();
}

From source file:com.liferay.portlet.documentlibrary.store.S3Store.java

License:Open Source License

protected String getKey(long companyId, long repositoryId, String fileName) {

    StringBundler sb = new StringBundler(6);

    sb.append(companyId);/*from w  w w.  j  a va2s.  co m*/
    sb.append(StringPool.SLASH);
    sb.append(repositoryId);
    sb.append(StringPool.SLASH);
    sb.append(fileName);
    sb.append(StringPool.SLASH);

    return sb.toString();
}

From source file:com.liferay.portlet.documentlibrary.store.S3Store.java

License:Open Source License

protected String getKey(long companyId, long repositoryId, String fileName, String versionLabel) {

    StringBundler sb = new StringBundler(7);

    sb.append(companyId);//from www  .  java2  s. c o m
    sb.append(StringPool.SLASH);
    sb.append(repositoryId);
    sb.append(StringPool.SLASH);
    sb.append(fileName);
    sb.append(StringPool.SLASH);
    sb.append(versionLabel);

    return sb.toString();
}