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

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

Introduction

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

Prototype

String SPACE

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

Click Source Link

Usage

From source file:com.liferay.portlet.asset.service.persistence.AssetEntryFinderImpl.java

License:Open Source License

protected SQLQuery buildAssetQuerySQL(AssetEntryQuery entryQuery, boolean count, Session session) {

    StringBundler sb = new StringBundler();

    if (count) {//from ww  w .  ja v  a 2  s  .  c om
        sb.append("SELECT COUNT(DISTINCT AssetEntry.entryId) AS COUNT_VALUE ");
    } else {
        sb.append("SELECT DISTINCT {AssetEntry.*} ");

        String orderByCol1 = entryQuery.getOrderByCol1();
        String orderByCol2 = entryQuery.getOrderByCol2();

        if (orderByCol1.equals("ratings") || orderByCol2.equals("ratings")) {

            sb.append(", RatingsEntry.score ");
        }
    }

    sb.append("FROM AssetEntry ");

    if (entryQuery.getAnyTagIds().length > 0) {
        sb.append("INNER JOIN ");
        sb.append("AssetEntries_AssetTags ON ");
        sb.append("(AssetEntries_AssetTags.entryId = ");
        sb.append("AssetEntry.entryId) ");
        sb.append("INNER JOIN ");
        sb.append("AssetTag ON ");
        sb.append("(AssetTag.tagId = AssetEntries_AssetTags.tagId) ");
    }

    if (entryQuery.getAnyCategoryIds().length > 0) {
        sb.append("INNER JOIN ");
        sb.append("AssetEntries_AssetCategories ON ");
        sb.append("(AssetEntries_AssetCategories.entryId = ");
        sb.append("AssetEntry.entryId) ");
        sb.append("INNER JOIN ");
        sb.append("AssetCategory ON ");
        sb.append("(AssetCategory.categoryId = ");
        sb.append("AssetEntries_AssetCategories.categoryId) ");
    }

    if (entryQuery.getLinkedAssetEntryId() > 0) {
        sb.append("INNER JOIN ");
        sb.append("AssetLink ON ");
        sb.append("(AssetEntry.entryId = AssetLink.entryId1) ");
        sb.append("OR (AssetEntry.entryId = AssetLink.entryId2)");
    }

    if (entryQuery.getOrderByCol1().equals("ratings") || entryQuery.getOrderByCol2().equals("ratings")) {

        sb.append(" LEFT JOIN ");
        sb.append("RatingsEntry ON ");
        sb.append("(RatingsEntry.classNameId = ");
        sb.append("AssetEntry.classNameId) AND ");
        sb.append("(RatingsEntry.classPK = AssetEntry.classPK)");
    }

    sb.append("WHERE ");

    int whereIndex = sb.index();

    if (entryQuery.getLinkedAssetEntryId() > 0) {
        sb.append(" AND ((AssetLink.entryId1 = ?) OR ");
        sb.append("(AssetLink.entryId2 = ?))");
        sb.append(" AND (AssetEntry.entryId != ?)");
    }

    if (entryQuery.isVisible() != null) {
        sb.append(" AND (visible = ?)");
    }

    if (entryQuery.isExcludeZeroViewCount()) {
        sb.append(" AND (AssetEntry.viewCount > 0)");
    }

    // Layout

    Layout layout = entryQuery.getLayout();

    if (layout != null) {
        sb.append(" AND (AssetEntry.layoutUuid = ?)");
    }

    // Category conditions

    if (entryQuery.getAllCategoryIds().length > 0) {
        if (PropsValues.ASSET_CATEGORIES_SEARCH_HIERARCHICAL) {
            buildAllCategoriesSQL(FIND_BY_AND_CATEGORY_IDS_TREE, entryQuery.getAllCategoryIds(), sb);
        } else {
            buildAllCategoriesSQL(FIND_BY_AND_CATEGORY_IDS, entryQuery.getAllCategoryIds(), sb);
        }
    }

    if (entryQuery.getAnyCategoryIds().length > 0) {
        if (PropsValues.ASSET_CATEGORIES_SEARCH_HIERARCHICAL) {
            sb.append(getCategoryIds(FIND_BY_AND_CATEGORY_IDS_TREE, entryQuery.getAnyCategoryIds()));
        } else {
            sb.append(getCategoryIds(FIND_BY_AND_CATEGORY_IDS, entryQuery.getAnyCategoryIds()));
        }
    }

    if (entryQuery.getNotAllCategoryIds().length > 0) {
        if (PropsValues.ASSET_CATEGORIES_SEARCH_HIERARCHICAL) {
            buildNotAnyCategoriesSQL(FIND_BY_AND_CATEGORY_IDS_TREE, entryQuery.getNotAllCategoryIds(), sb);
        } else {
            buildNotAnyCategoriesSQL(FIND_BY_AND_CATEGORY_IDS, entryQuery.getNotAllCategoryIds(), sb);
        }
    }

    if (entryQuery.getNotAnyCategoryIds().length > 0) {
        sb.append(" AND (");

        if (PropsValues.ASSET_CATEGORIES_SEARCH_HIERARCHICAL) {
            sb.append(getNotCategoryIds(FIND_BY_AND_CATEGORY_IDS_TREE, entryQuery.getNotAnyCategoryIds()));
        } else {
            sb.append(getNotCategoryIds(FIND_BY_AND_CATEGORY_IDS, entryQuery.getNotAnyCategoryIds()));
        }

        sb.append(") ");
    }

    // Asset entry subtypes

    if (entryQuery.getClassTypeIds().length > 0) {
        buildClassTypeIdsSQL(entryQuery.getClassTypeIds(), sb);
    }

    // Tag conditions

    if (entryQuery.getAllTagIds().length > 0) {
        buildAllTagsSQL(entryQuery.getAllTagIds(), sb);
    }

    if (entryQuery.getAnyTagIds().length > 0) {
        sb.append(" AND (");
        sb.append(getTagIds(entryQuery.getAnyTagIds(), StringPool.EQUAL));
        sb.append(") ");
    }

    if (entryQuery.getNotAllTagIds().length > 0) {
        buildNotAnyTagsSQL(entryQuery.getNotAllTagIds(), sb);
    }

    if (entryQuery.getNotAnyTagIds().length > 0) {
        sb.append(" AND (");
        sb.append(getNotTagIds(entryQuery.getNotAnyTagIds()));
        sb.append(") ");
    }

    // Other conditions

    sb.append(getDates(entryQuery.getPublishDate(), entryQuery.getExpirationDate()));
    sb.append(getGroupIds(entryQuery.getGroupIds()));
    sb.append(getClassNameIds(entryQuery.getClassNameIds()));

    if (!count) {
        sb.append(" ORDER BY ");

        if (entryQuery.getOrderByCol1().equals("ratings")) {
            sb.append("RatingsEntry.score");
        } else {
            sb.append("AssetEntry.");
            sb.append(entryQuery.getOrderByCol1());
        }

        sb.append(StringPool.SPACE);
        sb.append(entryQuery.getOrderByType1());

        if (Validator.isNotNull(entryQuery.getOrderByCol2())
                && !entryQuery.getOrderByCol1().equals(entryQuery.getOrderByCol2())) {

            if (entryQuery.getOrderByCol2().equals("ratings")) {
                sb.append(", RatingsEntry.score");
            } else {
                sb.append(", AssetEntry.");
                sb.append(entryQuery.getOrderByCol2());
            }

            sb.append(StringPool.SPACE);
            sb.append(entryQuery.getOrderByType2());
        }
    }

    if (sb.index() > whereIndex) {
        String where = sb.stringAt(whereIndex);

        if (where.startsWith(" AND")) {
            sb.setStringAt(where.substring(4), whereIndex);
        }
    }

    String sql = sb.toString();

    SQLQuery q = session.createSQLQuery(sql);

    if (count) {
        q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
    } else {
        q.addEntity("AssetEntry", AssetEntryImpl.class);
    }

    QueryPos qPos = QueryPos.getInstance(q);

    if (entryQuery.getLinkedAssetEntryId() > 0) {
        qPos.add(entryQuery.getLinkedAssetEntryId());
        qPos.add(entryQuery.getLinkedAssetEntryId());
        qPos.add(entryQuery.getLinkedAssetEntryId());
    }

    if (entryQuery.isVisible() != null) {
        qPos.add(entryQuery.isVisible());
    }

    if (layout != null) {
        qPos.add(layout.getUuid());
    }

    if (PropsValues.ASSET_CATEGORIES_SEARCH_HIERARCHICAL) {
        qPos.add(entryQuery.getAllLeftAndRightCategoryIds());
        qPos.add(entryQuery.getAnyLeftAndRightCategoryIds());
        qPos.add(entryQuery.getNotAllLeftAndRightCategoryIds());
        qPos.add(entryQuery.getNotAnyLeftAndRightCategoryIds());
    } else {
        qPos.add(entryQuery.getAllCategoryIds());
        qPos.add(entryQuery.getAnyCategoryIds());
        qPos.add(entryQuery.getNotAllCategoryIds());
        qPos.add(entryQuery.getNotAnyCategoryIds());
    }

    qPos.add(entryQuery.getAllTagIds());
    qPos.add(entryQuery.getAnyTagIds());
    qPos.add(entryQuery.getNotAllTagIds());
    qPos.add(entryQuery.getNotAnyTagIds());

    setDates(qPos, entryQuery.getPublishDate(), entryQuery.getExpirationDate());

    qPos.add(entryQuery.getGroupIds());
    qPos.add(entryQuery.getClassNameIds());

    return q;
}

From source file:com.liferay.portlet.documentlibrary.action.CompareVersionsAction.java

License:Open Source License

protected void compareVersions(RenderRequest renderRequest) throws Exception {

    long fileEntryId = ParamUtil.getLong(renderRequest, "fileEntryId");

    String sourceVersion = ParamUtil.getString(renderRequest, "sourceVersion");
    String targetVersion = ParamUtil.getString(renderRequest, "targetVersion");

    FileEntry fileEntry = DLAppServiceUtil.getFileEntry(fileEntryId);

    String extension = fileEntry.getExtension();

    FileVersion sourceFileVersion = fileEntry.getFileVersion(sourceVersion);

    String sourceTitle = sourceFileVersion.getTitle();

    FileVersion targetFileVersion = fileEntry.getFileVersion(targetVersion);

    String targetTitle = targetFileVersion.getTitle();

    InputStream sourceIs = fileEntry.getContentStream(sourceVersion);
    InputStream targetIs = fileEntry.getContentStream(targetVersion);

    if (extension.equals("htm") || extension.equals("html") || extension.equals("xml")) {

        String escapedSource = HtmlUtil.escape(StringUtil.read(sourceIs));
        String escapedTarget = HtmlUtil.escape(StringUtil.read(targetIs));

        sourceIs = new UnsyncByteArrayInputStream(escapedSource.getBytes(StringPool.UTF8));
        targetIs = new UnsyncByteArrayInputStream(escapedTarget.getBytes(StringPool.UTF8));
    }/*from w w  w .  j a  v a2 s .  c om*/

    if (DocumentConversionUtil.isEnabled() && DocumentConversionUtil.isConvertBeforeCompare(extension)) {

        String sourceTempFileId = DLUtil.getTempFileId(fileEntryId, sourceVersion);
        String targetTempFileId = DLUtil.getTempFileId(fileEntryId, targetVersion);

        sourceIs = new FileInputStream(
                DocumentConversionUtil.convert(sourceTempFileId, sourceIs, extension, "txt"));
        targetIs = new FileInputStream(
                DocumentConversionUtil.convert(targetTempFileId, targetIs, extension, "txt"));
    }

    List<DiffResult>[] diffResults = DiffUtil.diff(new InputStreamReader(sourceIs),
            new InputStreamReader(targetIs));

    renderRequest.setAttribute(WebKeys.SOURCE_NAME, sourceTitle + StringPool.SPACE + sourceVersion);
    renderRequest.setAttribute(WebKeys.TARGET_NAME, targetTitle + StringPool.SPACE + targetVersion);
    renderRequest.setAttribute(WebKeys.DIFF_RESULTS, diffResults);
}

From source file:com.liferay.portlet.documentlibrary.lar.DLPortletDataHandlerImpl.java

License:Open Source License

public static void importFileEntry(PortletDataContext portletDataContext, Element fileEntryElement, String path)
        throws Exception {

    FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);

    long userId = portletDataContext.getUserId(fileEntry.getUserUuid());

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(DLFolder.class);

    long folderId = MapUtil.getLong(folderIds, fileEntry.getFolderId(), fileEntry.getFolderId());

    long[] assetCategoryIds = null;
    String[] assetTagNames = null;

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "categories")) {
        assetCategoryIds = portletDataContext.getAssetCategoryIds(DLFileEntry.class,
                fileEntry.getFileEntryId());
    }//  www . j ava2  s.  co m

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "tags")) {
        assetTagNames = portletDataContext.getAssetTagNames(DLFileEntry.class, fileEntry.getFileEntryId());
    }

    ServiceContext serviceContext = portletDataContext.createServiceContext(fileEntryElement, fileEntry,
            _NAMESPACE);

    serviceContext.setAttribute("sourceFileName", "A." + fileEntry.getExtension());
    serviceContext.setUserId(userId);

    String binPath = fileEntryElement.attributeValue("bin-path");

    InputStream is = null;

    if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) {

        try {
            is = FileEntryUtil.getContentStream(fileEntry);
        } catch (NoSuchFileException nsfe) {
        }
    } else {
        is = portletDataContext.getZipEntryAsInputStream(binPath);
    }

    if (is == null) {
        if (_log.isWarnEnabled()) {
            _log.warn("No file found for file entry " + fileEntry.getFileEntryId());
        }

        return;
    }

    if ((folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) && (folderId == fileEntry.getFolderId())) {

        String folderPath = getImportFolderPath(portletDataContext, folderId);

        Folder folder = (Folder) portletDataContext.getZipEntryAsObject(folderPath);

        Document document = fileEntryElement.getDocument();

        Element rootElement = document.getRootElement();

        Element folderElement = (Element) rootElement
                .selectSingleNode("//folder[@path='".concat(folderPath).concat("']"));

        importFolder(portletDataContext, folderPath, folderElement, folder);

        folderId = MapUtil.getLong(folderIds, fileEntry.getFolderId(), fileEntry.getFolderId());
    }

    importMetaData(portletDataContext, fileEntryElement, serviceContext);

    FileEntry importedFileEntry = null;

    String titleWithExtension = DLUtil.getTitleWithExtension(fileEntry);
    String extension = fileEntry.getExtension();

    String dotExtension = StringPool.PERIOD + extension;

    if (portletDataContext.isDataStrategyMirror()) {
        FileEntry existingFileEntry = FileEntryUtil.fetchByUUID_R(fileEntry.getUuid(),
                portletDataContext.getScopeGroupId());

        FileVersion fileVersion = fileEntry.getFileVersion();

        if (existingFileEntry == null) {
            String fileEntryTitle = fileEntry.getTitle();

            FileEntry existingTitleFileEntry = FileEntryUtil.fetchByR_F_T(portletDataContext.getScopeGroupId(),
                    folderId, fileEntryTitle);

            if (existingTitleFileEntry != null) {
                if ((fileEntry.getGroupId() == portletDataContext.getSourceGroupId())
                        && portletDataContext.isDataStrategyMirrorWithOverwriting()) {

                    DLAppLocalServiceUtil.deleteFileEntry(existingTitleFileEntry.getFileEntryId());
                } else {
                    boolean titleHasExtension = false;

                    if (fileEntryTitle.endsWith(dotExtension)) {
                        fileEntryTitle = FileUtil.stripExtension(fileEntryTitle);

                        titleHasExtension = true;
                    }

                    for (int i = 1;; i++) {
                        fileEntryTitle += StringPool.SPACE + i;

                        titleWithExtension = fileEntryTitle + dotExtension;

                        existingTitleFileEntry = FileEntryUtil.fetchByR_F_T(
                                portletDataContext.getScopeGroupId(), folderId, titleWithExtension);

                        if (existingTitleFileEntry == null) {
                            if (titleHasExtension) {
                                fileEntryTitle += dotExtension;
                            }

                            break;
                        }
                    }
                }
            }

            serviceContext.setAttribute("fileVersionUuid", fileVersion.getUuid());
            serviceContext.setUuid(fileEntry.getUuid());

            // LPS-37869
            if (PropsValuesExt.LAYOUT_IMPORT_DL_FILE_NAME_NORMALIZATION_ENABLED) {
                titleWithExtension = normalizeFileName(titleWithExtension);
                fileEntryTitle = normalizeFileName(fileEntryTitle);
            }

            importedFileEntry = DLAppLocalServiceUtil.addFileEntry(userId, portletDataContext.getScopeGroupId(),
                    folderId, titleWithExtension, fileEntry.getMimeType(), fileEntryTitle,
                    fileEntry.getDescription(), null, is, fileEntry.getSize(), serviceContext);
        } else {
            FileVersion latestExistingFileVersion = existingFileEntry.getLatestFileVersion();

            boolean indexEnabled = serviceContext.isIndexingEnabled();

            try {
                serviceContext.setIndexingEnabled(false);

                if (!fileVersion.getUuid().equals(latestExistingFileVersion.getUuid())) {

                    DLFileVersion alreadyExistingFileVersion = DLFileVersionLocalServiceUtil
                            .getFileVersionByUuidAndGroupId(fileVersion.getUuid(),
                                    existingFileEntry.getGroupId());

                    if (alreadyExistingFileVersion != null) {
                        serviceContext.setAttribute("existingDLFileVersionId",
                                alreadyExistingFileVersion.getFileVersionId());
                    }

                    serviceContext.setUuid(fileVersion.getUuid());

                    String fileEntryTitle = fileEntry.getTitle();

                    // LPS-37869
                    if (PropsValuesExt.LAYOUT_IMPORT_DL_FILE_NAME_NORMALIZATION_ENABLED) {
                        fileEntryTitle = normalizeFileName(fileEntryTitle);
                    }

                    importedFileEntry = DLAppLocalServiceUtil.updateFileEntry(userId,
                            existingFileEntry.getFileEntryId(), fileEntryTitle, fileEntry.getMimeType(),
                            fileEntryTitle, fileEntry.getDescription(), null, false, is, fileEntry.getSize(),
                            serviceContext);

                    /*
                    importedFileEntry =
                       DLAppLocalServiceUtil.updateFileEntry(
                          userId, existingFileEntry.getFileEntryId(),
                          fileEntry.getTitle(), fileEntry.getMimeType(),
                          fileEntry.getTitle(),
                          fileEntry.getDescription(), null, false, is,
                          fileEntry.getSize(), serviceContext);
                     */
                } else {
                    DLAppLocalServiceUtil.updateAsset(userId, existingFileEntry, latestExistingFileVersion,
                            assetCategoryIds, assetTagNames, null);

                    importedFileEntry = existingFileEntry;
                }

                if (importedFileEntry.getFolderId() != folderId) {
                    importedFileEntry = DLAppLocalServiceUtil.moveFileEntry(userId,
                            importedFileEntry.getFileEntryId(), folderId, serviceContext);
                }

                if (importedFileEntry instanceof LiferayFileEntry) {
                    LiferayFileEntry liferayFileEntry = (LiferayFileEntry) importedFileEntry;

                    Indexer indexer = IndexerRegistryUtil.getIndexer(DLFileEntry.class);

                    indexer.reindex(liferayFileEntry.getModel());
                }
            } finally {
                serviceContext.setIndexingEnabled(indexEnabled);
            }
        }
    } else {
        try {

            String fileEntryTitle = fileEntry.getTitle();

            // LPS-37869
            if (PropsValuesExt.LAYOUT_IMPORT_DL_FILE_NAME_NORMALIZATION_ENABLED) {
                titleWithExtension = normalizeFileName(titleWithExtension);
                fileEntryTitle = normalizeFileName(fileEntryTitle);
            }

            importedFileEntry = DLAppLocalServiceUtil.addFileEntry(userId, portletDataContext.getScopeGroupId(),
                    folderId, titleWithExtension, fileEntry.getMimeType(), fileEntryTitle,
                    fileEntry.getDescription(), null, is, fileEntry.getSize(), serviceContext);

            /*
            importedFileEntry = DLAppLocalServiceUtil.addFileEntry(
               userId, portletDataContext.getScopeGroupId(), folderId,
               titleWithExtension, fileEntry.getMimeType(),
               fileEntry.getTitle(), fileEntry.getDescription(), null, is,
               fileEntry.getSize(), serviceContext);
            */
        } catch (DuplicateFileException dfe) {
            String title = fileEntry.getTitle();

            // LPS-37869
            if (PropsValuesExt.LAYOUT_IMPORT_DL_FILE_NAME_NORMALIZATION_ENABLED) {
                title = normalizeFileName(title);
            }

            String[] titleParts = title.split("\\.", 2);

            title = titleParts[0] + PwdGenerator.getPassword();

            if (titleParts.length > 1) {
                title += StringPool.PERIOD + titleParts[1];
            }

            if (!title.endsWith(dotExtension)) {
                title += dotExtension;
            }

            importedFileEntry = DLAppLocalServiceUtil.addFileEntry(userId, portletDataContext.getScopeGroupId(),
                    folderId, title, fileEntry.getMimeType(), title, fileEntry.getDescription(), null, is,
                    fileEntry.getSize(), serviceContext);
        }
    }

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "previews-and-thumbnails")) {

        DLProcessorRegistryUtil.importGeneratedFiles(portletDataContext, fileEntry, importedFileEntry,
                fileEntryElement);
    }

    Map<String, String> fileEntryTitles = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(DLFileEntry.class.getName() + ".title");

    fileEntryTitles.put(fileEntry.getTitle(), importedFileEntry.getTitle());

    portletDataContext.importClassedModel(fileEntry, importedFileEntry, _NAMESPACE);
}

From source file:com.liferay.portlet.documentlibrary.model.impl.DLFileEntryImpl.java

License:Open Source License

public String getLuceneProperties() {
    UnicodeProperties extraSettingsProps = getExtraSettingsProperties();

    Iterator<Map.Entry<String, String>> itr = extraSettingsProps.entrySet().iterator();

    StringBundler sb = new StringBundler(extraSettingsProps.entrySet().size() + 4);

    sb.append(FileUtil.stripExtension(getTitle()));
    sb.append(StringPool.SPACE);
    sb.append(getDescription());//from   w  w w.  j  a va  2  s  . co m
    sb.append(StringPool.SPACE);

    while (itr.hasNext()) {
        Map.Entry<String, String> entry = itr.next();

        String value = GetterUtil.getString(entry.getValue());

        sb.append(value);
    }

    return sb.toString();
}

From source file:com.liferay.portlet.documentlibrary.social.DLActivityInterpreter.java

License:Open Source License

@Override
protected SocialActivityFeedEntry doInterpret(SocialActivity activity, ThemeDisplay themeDisplay)
        throws Exception {

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(activity.getClassPK());

    if (!DLFileEntryPermission.contains(permissionChecker, fileEntry.getFileEntryId(), ActionKeys.VIEW)) {

        return null;
    }/* ww w  .j av  a  2  s .co m*/

    String groupName = StringPool.BLANK;

    if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
        groupName = getGroupName(activity.getGroupId(), themeDisplay);
    }

    String creatorUserName = getUserName(activity.getUserId(), themeDisplay);

    int activityType = activity.getType();

    // Link

    String link = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
            + "/document_library/get_file?groupId=" + fileEntry.getRepositoryId() + "&folderId="
            + fileEntry.getFolderId() + "&title=" + HttpUtil.encodeURL(fileEntry.getTitle());

    // Title

    String titlePattern = null;

    if (activityType == DLActivityKeys.ADD_FILE_ENTRY) {
        titlePattern = "activity-document-library-add-file";
    } else if (activityType == DLActivityKeys.UPDATE_FILE_ENTRY) {
        titlePattern = "activity-document-library-update-file";
    }

    if (Validator.isNotNull(groupName)) {
        titlePattern += "-in";
    }

    String fileTitle = wrapLink(link, HtmlUtil.escape(cleanContent(fileEntry.getTitle())));

    Object[] titleArguments = new Object[] { groupName, creatorUserName, fileTitle };

    String title = themeDisplay.translate(titlePattern, titleArguments);

    // Body

    StringBundler sb = new StringBundler(3);

    String fileEntryLink = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
            + "/document_library/find_file_entry?fileEntryId=" + fileEntry.getFileEntryId();

    sb.append(wrapLink(fileEntryLink, "view-document", themeDisplay));
    sb.append(StringPool.SPACE);

    String folderLink = themeDisplay.getPortalURL() + themeDisplay.getPathMain()
            + "/document_library/find_folder?groupId=" + fileEntry.getRepositoryId() + "&folderId="
            + fileEntry.getFolderId();

    sb.append(wrapLink(folderLink, "go-to-folder", themeDisplay));

    String body = sb.toString();

    return new SocialActivityFeedEntry(link, title, body);
}

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

License:Open Source License

@Override
public String getAbsolutePath(PortletRequest portletRequest, long folderId) throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        return themeDisplay.translate("home");
    }//w w  w.jav a2s .co  m

    Folder folder = DLAppLocalServiceUtil.getFolder(folderId);

    List<Folder> folders = folder.getAncestors();

    Collections.reverse(folders);

    StringBundler sb = new StringBundler((folders.size() * 3) + 5);

    sb.append(themeDisplay.translate("home"));
    sb.append(StringPool.SPACE);

    for (Folder curFolder : folders) {
        sb.append(StringPool.RAQUO_CHAR);
        sb.append(StringPool.SPACE);
        sb.append(curFolder.getName());
    }

    sb.append(StringPool.RAQUO_CHAR);
    sb.append(StringPool.SPACE);
    sb.append(folder.getName());

    return sb.toString();
}

From source file:com.liferay.portlet.dynamicdatamapping.storage.ExpandoStorageAdapter.java

License:Open Source License

private String _toExpression(Junction junction) {
    StringBundler sb = new StringBundler();

    LogicalOperator logicalOperator = junction.getLogicalOperator();

    Iterator<Condition> itr = junction.iterator();

    while (itr.hasNext()) {
        Condition condition = itr.next();

        sb.append(_toExpression(condition));

        if (itr.hasNext()) {
            sb.append(StringPool.SPACE);
            sb.append(logicalOperator.toString());
            sb.append(StringPool.SPACE);
        }/*from  w ww .j  av a 2s .  com*/
    }

    return sb.toString();
}

From source file:com.liferay.portlet.dynamicdatamapping.storage.XMLStorageAdapter.java

License:Open Source License

private String _toXPath(Junction junction) {
    StringBundler sb = new StringBundler();

    LogicalOperator logicalOperator = junction.getLogicalOperator();

    String logicalOperatorString = logicalOperator.toString();

    Iterator<Condition> itr = junction.iterator();

    while (itr.hasNext()) {
        Condition condition = itr.next();

        sb.append(_toXPath(condition));//from   w w w . ja  va  2s.co  m

        if (itr.hasNext()) {
            sb.append(StringPool.SPACE);
            sb.append(logicalOperatorString.toLowerCase());
            sb.append(StringPool.SPACE);
        }
    }

    return sb.toString();
}

From source file:com.liferay.portlet.expando.util.ExpandoBridgeIndexerImpl.java

License:Open Source License

protected void addAttribute(Document document, ExpandoColumn expandoColumn, List<ExpandoValue> expandoValues)
        throws PortalException, SystemException {

    String fieldName = encodeFieldName(expandoColumn.getName());

    ExpandoValue expandoValue = new ExpandoValueImpl();

    expandoValue.setColumnId(expandoColumn.getColumnId());
    expandoValue.setData(expandoColumn.getDefaultData());

    boolean defaultValue = true;

    for (ExpandoValue curExpandoValue : expandoValues) {
        if (curExpandoValue.getColumnId() == expandoColumn.getColumnId()) {
            expandoValue = curExpandoValue;

            defaultValue = false;/*from  w w  w . j a v a  2s .  c  o  m*/

            break;
        }
    }

    UnicodeProperties typeSettingsProperties = expandoColumn.getTypeSettingsProperties();

    int indexType = GetterUtil
            .getInteger(typeSettingsProperties.getProperty(ExpandoColumnConstants.INDEX_TYPE));

    int type = expandoColumn.getType();

    if (type == ExpandoColumnConstants.BOOLEAN) {
        document.addKeyword(fieldName, expandoValue.getBoolean());
    } else if (type == ExpandoColumnConstants.BOOLEAN_ARRAY) {
        if (!defaultValue) {
            document.addKeyword(fieldName, expandoValue.getBooleanArray());
        } else {
            document.addKeyword(fieldName, new boolean[0]);
        }
    } else if (type == ExpandoColumnConstants.DATE) {
        document.addDate(fieldName, expandoValue.getDate());
    } else if (type == ExpandoColumnConstants.DOUBLE) {
        document.addKeyword(fieldName, expandoValue.getDouble());
    } else if (type == ExpandoColumnConstants.DOUBLE_ARRAY) {
        if (!defaultValue) {
            document.addKeyword(fieldName, expandoValue.getDoubleArray());
        } else {
            document.addKeyword(fieldName, new double[0]);
        }
    } else if (type == ExpandoColumnConstants.FLOAT) {
        document.addKeyword(fieldName, expandoValue.getFloat());
    } else if (type == ExpandoColumnConstants.FLOAT_ARRAY) {
        if (!defaultValue) {
            document.addKeyword(fieldName, expandoValue.getFloatArray());
        } else {
            document.addKeyword(fieldName, new float[0]);
        }
    } else if (type == ExpandoColumnConstants.INTEGER) {
        document.addKeyword(fieldName, expandoValue.getInteger());
    } else if (type == ExpandoColumnConstants.INTEGER_ARRAY) {
        if (!defaultValue) {
            document.addKeyword(fieldName, expandoValue.getIntegerArray());
        } else {
            document.addKeyword(fieldName, new int[0]);
        }
    } else if (type == ExpandoColumnConstants.LONG) {
        document.addKeyword(fieldName, expandoValue.getLong());
    } else if (type == ExpandoColumnConstants.LONG_ARRAY) {
        if (!defaultValue) {
            document.addKeyword(fieldName, expandoValue.getLongArray());
        } else {
            document.addKeyword(fieldName, new long[0]);
        }
    } else if (type == ExpandoColumnConstants.SHORT) {
        document.addKeyword(fieldName, expandoValue.getShort());
    } else if (type == ExpandoColumnConstants.SHORT_ARRAY) {
        if (!defaultValue) {
            document.addKeyword(fieldName, expandoValue.getShortArray());
        } else {
            document.addKeyword(fieldName, new short[0]);
        }
    } else if (type == ExpandoColumnConstants.STRING) {
        if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
            document.addKeyword(fieldName, expandoValue.getString());
        } else {
            document.addText(fieldName, expandoValue.getString());
        }
    } else if (type == ExpandoColumnConstants.STRING_ARRAY) {
        if (!defaultValue) {
            if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
                document.addKeyword(fieldName, expandoValue.getStringArray());
            } else {
                document.addText(fieldName, StringUtil.merge(expandoValue.getStringArray(), StringPool.SPACE));
            }
        } else {
            if (indexType == ExpandoColumnConstants.INDEX_TYPE_KEYWORD) {
                document.addKeyword(fieldName, StringPool.BLANK);
            } else {
                document.addText(fieldName, StringPool.BLANK);
            }
        }
    }
}

From source file:com.liferay.portlet.journal.util.JournalIndexer.java

License:Open Source License

protected void indexField(Document document, Element element, String elType, String elIndexType) {

    if (Validator.isNull(elIndexType)) {
        return;/* www. j a va2 s. c  o  m*/
    }

    com.liferay.portal.kernel.xml.Document structureDocument = element.getDocument();

    Element rootElement = structureDocument.getRootElement();

    String defaultLocale = GetterUtil.getString(rootElement.attributeValue("default-locale"));

    String name = encodeFieldName(element.attributeValue("name"));

    List<Element> dynamicContentElements = element.elements("dynamic-content");

    for (Element dynamicContentElement : dynamicContentElements) {
        String contentLocale = GetterUtil.getString(dynamicContentElement.attributeValue("language-id"));

        String[] value = new String[] { dynamicContentElement.getText() };

        if (elType.equals("multi-list")) {
            List<Element> optionElements = dynamicContentElement.elements("option");

            value = new String[optionElements.size()];

            for (int i = 0; i < optionElements.size(); i++) {
                value[i] = optionElements.get(i).getText();
            }
        }

        if (elIndexType.equals("keyword")) {
            if (Validator.isNull(contentLocale)) {
                document.addKeyword(name, value);
            } else {
                if (defaultLocale.equals(contentLocale)) {
                    document.addKeyword(name, value);
                }

                document.addKeyword(name.concat(StringPool.UNDERLINE).concat(contentLocale), value);
            }
        } else if (elIndexType.equals("text")) {
            if (Validator.isNull(contentLocale)) {
                document.addText(name, StringUtil.merge(value, StringPool.SPACE));
            } else {
                if (defaultLocale.equals(contentLocale)) {
                    document.addText(name, StringUtil.merge(value, StringPool.SPACE));
                }

                document.addText(name.concat(StringPool.UNDERLINE).concat(contentLocale),
                        StringUtil.merge(value, StringPool.SPACE));
            }
        }
    }
}