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

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

Introduction

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

Prototype

String PERIOD

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

Click Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java

License:Open Source License

@Override
public int compareVersions(String version1, String version2) {
    int[] splitVersion1 = StringUtil.split(version1, StringPool.PERIOD, 0);
    int[] splitVersion2 = StringUtil.split(version2, StringPool.PERIOD, 0);

    if ((splitVersion1.length != 2) && (splitVersion2.length != 2)) {
        return 0;
    } else if (splitVersion1.length != 2) {
        return -1;
    } else if (splitVersion2.length != 2) {
        return 1;
    }/* ww  w.j ava  2  s.  c o m*/

    if (splitVersion1[0] > splitVersion2[0]) {
        return 1;
    } else if (splitVersion1[0] < splitVersion2[0]) {
        return -1;
    } else if (splitVersion1[1] > splitVersion2[1]) {
        return 1;
    } else if (splitVersion1[1] < splitVersion2[1]) {
        return -1;
    }

    return 0;
}

From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java

License:Open Source License

@Override
public String getFileName(long groupId, long folderId, String tempFileName) {

    String extension = FileUtil.getExtension(tempFileName);

    int pos = tempFileName.lastIndexOf(EditFileEntryAction.TEMP_RANDOM_SUFFIX);

    if (pos != -1) {
        tempFileName = tempFileName.substring(0, pos);

        if (Validator.isNotNull(extension)) {
            tempFileName = tempFileName + StringPool.PERIOD + extension;
        }/*ww w. j a  v a 2  s  . com*/
    }

    while (true) {
        try {
            DLAppLocalServiceUtil.getFileEntry(groupId, folderId, tempFileName);

            StringBundler sb = new StringBundler(5);

            sb.append(FileUtil.stripExtension(tempFileName));
            sb.append(StringPool.DASH);
            sb.append(StringUtil.randomString());

            if (Validator.isNotNull(extension)) {
                sb.append(StringPool.PERIOD);
                sb.append(extension);
            }

            tempFileName = sb.toString();
        } catch (Exception e) {
            break;
        }
    }

    return tempFileName;
}

From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java

License:Open Source License

@Override
public String getSanitizedFileName(String title, String extension) {
    String fileName = StringUtil.replace(title, StringPool.SLASH, StringPool.UNDERLINE);

    if (Validator.isNotNull(extension) && !StringUtil.endsWith(fileName, StringPool.PERIOD + extension)) {

        fileName += StringPool.PERIOD + extension;
    }/*from w ww  . j  av a  2s .c om*/

    if (fileName.length() > 255) {
        int x = fileName.length() - 1;

        if (Validator.isNotNull(extension)) {
            x = fileName.lastIndexOf(StringPool.PERIOD);
        }

        int y = x - (fileName.length() - 255);

        fileName = fileName.substring(0, y) + fileName.substring(x);
    }

    return fileName;
}

From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java

License:Open Source License

@Override
public String getTempFileId(long id, String version, String languageId) {
    if (Validator.isNull(languageId)) {
        return String.valueOf(id).concat(StringPool.PERIOD).concat(version);
    }/*from w ww. j  a v  a2s.  c om*/

    StringBundler sb = new StringBundler(5);

    sb.append(id);
    sb.append(StringPool.PERIOD);
    sb.append(version);
    sb.append(StringPool.PERIOD);
    sb.append(languageId);

    return sb.toString();
}

From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java

License:Open Source License

@Override
public String getTitleWithExtension(String title, String extension) {
    if (Validator.isNotNull(extension)) {
        String periodAndExtension = StringPool.PERIOD.concat(extension);

        if (!title.endsWith(periodAndExtension)) {
            title += periodAndExtension;
        }/*from   ww  w. ja  v a2 s .  co m*/
    }

    return title;
}

From source file:com.liferay.portlet.documentlibrary.util.DLImpl.java

License:Open Source License

@Override
public boolean isValidVersion(String version) {
    if (version.equals(DLFileEntryConstants.PRIVATE_WORKING_COPY_VERSION)) {
        return true;
    }//from   w  ww.  ja  v  a  2 s .  co m

    String[] versionParts = StringUtil.split(version, StringPool.PERIOD);

    if (versionParts.length != 2) {
        return false;
    }

    if (Validator.isNumber(versionParts[0]) && Validator.isNumber(versionParts[1])) {

        return true;
    }

    return false;
}

From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java

License:Open Source License

@Override
protected Document doGetDocument(Object obj) throws Exception {
    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    if (_log.isDebugEnabled()) {
        _log.debug("Indexing document " + dlFileEntry);
    }//from  www. j av  a  2 s .co m

    boolean indexContent = true;

    InputStream is = null;

    try {
        if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) {
            indexContent = false;
        } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) {
            if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) {

                indexContent = false;
            }
        }

        if (indexContent) {
            String[] ignoreExtensions = PrefsPropsUtil
                    .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA);

            if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) {

                indexContent = false;
            }
        }

        if (indexContent) {
            is = dlFileEntry.getFileVersion().getContentStream(false);
        }
    } catch (Exception e) {
    }

    if (indexContent && (is == null)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Document " + dlFileEntry + " does not have any content");
        }

        return null;
    }

    try {
        Document document = new DocumentImpl();

        long fileEntryId = dlFileEntry.getFileEntryId();

        document.addUID(PORTLET_ID, fileEntryId);

        List<AssetCategory> assetCategories = AssetCategoryLocalServiceUtil
                .getCategories(DLFileEntry.class.getName(), fileEntryId);

        long[] assetCategoryIds = StringUtil
                .split(ListUtil.toString(assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L);

        document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds);

        String[] assetCategoryNames = StringUtil
                .split(ListUtil.toString(assetCategories, AssetCategory.NAME_ACCESSOR));

        document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames);

        String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(DLFileEntry.class.getName(), fileEntryId);

        document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames);

        document.addKeyword(Field.COMPANY_ID, dlFileEntry.getCompanyId());

        if (indexContent) {
            try {
                document.addFile(Field.CONTENT, is, dlFileEntry.getTitle());
            } catch (IOException ioe) {
                throw new SearchException("Cannot extract text from file" + dlFileEntry);
            }
        }

        document.addText(Field.DESCRIPTION, dlFileEntry.getDescription());
        document.addKeyword(Field.ENTRY_CLASS_NAME, DLFileEntry.class.getName());
        document.addKeyword(Field.ENTRY_CLASS_PK, fileEntryId);
        document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId());
        document.addKeyword(Field.GROUP_ID, getParentGroupId(dlFileEntry.getGroupId()));
        document.addDate(Field.MODIFIED_DATE, dlFileEntry.getModifiedDate());
        document.addKeyword(Field.PORTLET_ID, PORTLET_ID);
        document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties());
        document.addKeyword(Field.SCOPE_GROUP_ID, dlFileEntry.getGroupId());

        DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();

        document.addKeyword(Field.STATUS, dlFileVersion.getStatus());
        document.addText(Field.TITLE, dlFileEntry.getTitle());

        long userId = dlFileEntry.getUserId();

        document.addKeyword(Field.USER_ID, userId);
        document.addKeyword(Field.USER_NAME, PortalUtil.getUserName(userId, dlFileEntry.getUserName()), true);

        document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId());
        document.addKeyword("extension", dlFileEntry.getExtension());
        document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId());
        document.addKeyword("path", dlFileEntry.getTitle());

        ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(),
                DLFileEntry.class.getName(), dlFileVersion.getFileVersionId());

        ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge);

        addFileEntryTypeAttributes(document, dlFileVersion);

        if (_log.isDebugEnabled()) {
            _log.debug("Document " + dlFileEntry + " indexed successfully");
        }

        return document;
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException ioe) {
            }
        }
    }
}

From source file:com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor.java

License:Open Source License

protected String getPreviewFilePath(long groupId, long fileEntryId, long fileVersionId, int index,
        String type) {//from ww w. jav  a2s  . co m

    StringBundler sb = null;

    if (index > 0) {
        sb = new StringBundler(5);
    } else {
        sb = new StringBundler(3);
    }

    sb.append(getPathSegment(groupId, fileEntryId, fileVersionId, true));

    if (index > 0) {
        sb.append(StringPool.SLASH);
        sb.append(index - 1);
    }

    if (Validator.isNotNull(type)) {
        sb.append(StringPool.PERIOD);
        sb.append(type);
    }

    return sb.toString();
}

From source file:com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor.java

License:Open Source License

protected int getPreviewTempFileCount(FileVersion fileVersion, String type) {

    String tempFileId = DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion());

    StringBundler sb = new StringBundler(5);

    sb.append(tempFileId);//from   w w w .ja  v a2s  .  co m
    sb.append(StringPool.DASH);
    sb.append("(.*)");

    if (Validator.isNotNull(type)) {
        sb.append(StringPool.PERIOD);
        sb.append(type);
    }

    File dir = new File(PREVIEW_TMP_PATH);

    File[] files = dir.listFiles(new FileFilter(sb.toString()));

    if (_log.isDebugEnabled()) {
        for (File file : files) {
            _log.debug("Preview page for " + tempFileId + " " + file);
        }
    }

    return files.length;
}

From source file:com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor.java

License:Open Source License

protected String getPreviewTempFilePath(String id, int index, String type) {
    StringBundler sb = null;/*  w  ww . ja  v a  2  s  .c o  m*/

    if (index > 0) {
        sb = new StringBundler(6);
    } else {
        sb = new StringBundler(4);
    }

    sb.append(PREVIEW_TMP_PATH);
    sb.append(id);

    if (index > 0) {
        sb.append(StringPool.DASH);
        sb.append(index - 1);
    } else if (index == -1) {
        sb.append("-%d");
    }

    if (Validator.isNotNull(type)) {
        sb.append(StringPool.PERIOD);
        sb.append(type);
    }

    return sb.toString();
}