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.hadoop.search.HadoopDLIndexerPostProcessor.java

License:Open Source License

public void postProcessDocument(Document document, Object obj) throws Exception {

    DLFileEntry dlFileEntry = (DLFileEntry) obj;

    long companyId = dlFileEntry.getCompanyId();
    long repositoryId = dlFileEntry.getRepositoryId();

    String stringObject = document.toString();

    // remove JSON chars

    stringObject = StringUtil.replace(stringObject, new String[] { "\"", ",", ":", "{", "}", "[", "]" },
            new String[] { StringPool.SPACE, StringPool.SPACE, StringPool.SPACE, StringPool.SPACE,
                    StringPool.SPACE, StringPool.SPACE, StringPool.SPACE });

    Path fullDirPath = HadoopManager.getFullDirPath(companyId, repositoryId, null);

    fullDirPath = new Path("/index".concat(fullDirPath.toString()));

    FSDataOutputStream outputStream = null;

    try {// ww w  .j av  a  2  s . com
        FileSystem fileSystem = HadoopManager.getFileSystem();

        String suffix = StringPool.SLASH.concat(document.getUID());

        outputStream = fileSystem.create(fullDirPath.suffix(suffix));

        PrintWriter pw = new PrintWriter(outputStream);

        pw.write(stringObject);

        pw.flush();
        pw.close();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        StreamUtil.cleanUp(outputStream);
    }
}

From source file:com.liferay.journal.exportimport.data.handler.JournalArticleStagedModelDataHandler.java

License:Open Source License

@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, JournalArticle article)
        throws Exception {

    Element articleElement = portletDataContext.getExportDataElement(article);

    articleElement.addAttribute("article-resource-uuid", article.getArticleResourceUuid());

    if (article.getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, article.getFolder(),
                PortletDataContext.REFERENCE_TYPE_PARENT);
    }//from   w  ww .ja v  a  2  s.  c o m

    DDMStructure ddmStructure = _ddmStructureLocalService.getStructure(article.getGroupId(),
            _portal.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true);

    StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, ddmStructure,
            PortletDataContext.REFERENCE_TYPE_STRONG);

    if (article.getClassNameId() != _portal.getClassNameId(DDMStructure.class)) {

        DDMTemplate ddmTemplate = _ddmTemplateLocalService.getTemplate(article.getGroupId(),
                _portal.getClassNameId(DDMStructure.class), article.getDDMTemplateKey(), true);

        StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, ddmTemplate,
                PortletDataContext.REFERENCE_TYPE_STRONG);
    }

    Layout layout = article.getLayout();

    if (layout != null) {
        portletDataContext.addReferenceElement(article, articleElement, layout,
                PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);
    }

    if (article.isSmallImage()) {
        if (Validator.isNotNull(article.getSmallImageURL())) {
            String smallImageURL = _journalArticleExportImportContentProcessor.replaceExportContentReferences(
                    portletDataContext, article, article.getSmallImageURL() + StringPool.SPACE, true, false);

            article.setSmallImageURL(smallImageURL);
        } else {
            Image smallImage = _imageLocalService.fetchImage(article.getSmallImageId());

            if ((smallImage != null) && (smallImage.getTextObj() != null)) {
                String smallImagePath = ExportImportPathUtil.getModelPath(article,
                        smallImage.getImageId() + StringPool.PERIOD + smallImage.getType());

                articleElement.addAttribute("small-image-path", smallImagePath);

                article.setSmallImageType(smallImage.getType());

                portletDataContext.addZipEntry(smallImagePath, smallImage.getTextObj());
            } else {
                if (_log.isWarnEnabled()) {
                    StringBundler sb = new StringBundler(4);

                    sb.append("Unable to export small image ");
                    sb.append(article.getSmallImageId());
                    sb.append(" to article ");
                    sb.append(article.getArticleId());

                    _log.warn(sb.toString());
                }

                article.setSmallImage(false);
                article.setSmallImageId(0);
            }
        }
    }

    JournalArticle latestArticle = _journalArticleLocalService.fetchLatestArticle(article.getResourcePrimKey());

    if ((latestArticle != null) && (latestArticle.getId() == article.getId())) {

        for (FileEntry fileEntry : article.getImagesFileEntries()) {
            StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, fileEntry,
                    PortletDataContext.REFERENCE_TYPE_WEAK);
        }
    }

    article.setStatusByUserUuid(article.getStatusByUserUuid());

    String content = _journalArticleExportImportContentProcessor.replaceExportContentReferences(
            portletDataContext, article, article.getContent(),
            portletDataContext.getBooleanParameter("journal", "referenced-content"), false);

    article.setContent(content);

    long defaultUserId = _userLocalService.getDefaultUserId(article.getCompanyId());

    if (defaultUserId == article.getUserId()) {
        articleElement.addAttribute("preloaded", "true");
    }

    portletDataContext.addClassedModel(articleElement, ExportImportPathUtil.getModelPath(article), article);
}

From source file:com.liferay.journal.exportimport.data.handler.test.JournalExportImportTest.java

License:Open Source License

@Override
protected void validateImportedStagedModel(StagedModel stagedModel, StagedModel importedStagedModel)
        throws Exception {

    super.validateImportedStagedModel(stagedModel, importedStagedModel);

    JournalArticle article = (JournalArticle) stagedModel;
    JournalArticle importedArticle = (JournalArticle) importedStagedModel;

    Assert.assertEquals((Double) article.getVersion(), (Double) importedArticle.getVersion());
    Assert.assertEquals(article.getTitle(), importedArticle.getTitle());
    Assert.assertEquals(article.getUrlTitle(), importedArticle.getUrlTitle());
    Assert.assertEquals(article.getDescription(), importedArticle.getDescription());
    Assert.assertEquals(article.getContent(), importedArticle.getContent());
    Assert.assertTrue(//from   ww  w . java2 s  .c o m
            String.valueOf(article.getDisplayDate()) + StringPool.SPACE + importedArticle.getDisplayDate(),
            DateUtil.equals(article.getDisplayDate(), importedArticle.getDisplayDate()));
    Assert.assertTrue(
            String.valueOf(article.getExpirationDate()) + StringPool.SPACE
                    + importedArticle.getExpirationDate(),
            DateUtil.equals(article.getExpirationDate(), importedArticle.getExpirationDate()));
    Assert.assertTrue(
            String.valueOf(article.getReviewDate()) + StringPool.SPACE + importedArticle.getReviewDate(),
            DateUtil.equals(article.getReviewDate(), importedArticle.getReviewDate()));
    Assert.assertEquals(article.getSmallImage(), importedArticle.getSmallImage());
    Assert.assertEquals(article.getSmallImageURL(), importedArticle.getSmallImageURL());
    Assert.assertEquals(article.getStatus(), importedArticle.getStatus());
    Assert.assertTrue(
            String.valueOf(article.getStatusDate()) + StringPool.SPACE + importedArticle.getStatusDate(),
            DateUtil.equals(article.getStatusDate(), importedArticle.getStatusDate()));

    JournalArticleResource articleResource = article.getArticleResource();
    JournalArticleResource importedArticleArticleResource = importedArticle.getArticleResource();

    Assert.assertEquals(articleResource.getUuid(), importedArticleArticleResource.getUuid());
}

From source file:com.liferay.journal.model.JournalFolderConstants.java

License:Open Source License

public static String getNameInvalidCharacters(String[] charBlacklist) {
    return StringUtil.merge(charBlacklist, StringPool.SPACE);
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

/**
 * Copies the web content article matching the group, article ID, and
 * version. This method creates a new article, extracting all the values
 * from the old one and updating its article ID.
 *
 * @param  userId the primary key of the web content article's creator/owner
 * @param  groupId the primary key of the web content article's group
 * @param  oldArticleId the primary key of the old web content article
 * @param  newArticleId the primary key of the new web content article
 * @param  autoArticleId whether to auto-generate the web content article ID
 * @param  version the web content article's version
 * @return the new web content article//w ww.  ja v  a2  s. co m
 */
@Indexable(type = IndexableType.REINDEX)
@Override
public JournalArticle copyArticle(long userId, long groupId, String oldArticleId, String newArticleId,
        boolean autoArticleId, double version) throws PortalException {

    // Article

    User user = userLocalService.getUser(userId);
    oldArticleId = StringUtil.toUpperCase(StringUtil.trim(oldArticleId));
    newArticleId = StringUtil.toUpperCase(StringUtil.trim(newArticleId));

    JournalArticle oldArticle = journalArticlePersistence.findByG_A_V(groupId, oldArticleId, version);

    if (autoArticleId) {
        newArticleId = String.valueOf(counterLocalService.increment());
    } else {
        validate(newArticleId);

        if (journalArticlePersistence.countByG_A(groupId, newArticleId) > 0) {

            StringBundler sb = new StringBundler(5);

            sb.append("{groupId=");
            sb.append(groupId);
            sb.append(", articleId=");
            sb.append(newArticleId);
            sb.append("}");

            throw new DuplicateArticleIdException(sb.toString());
        }
    }

    long id = counterLocalService.increment();

    long resourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(groupId, newArticleId);

    JournalArticle newArticle = journalArticlePersistence.create(id);

    newArticle.setResourcePrimKey(resourcePrimKey);
    newArticle.setGroupId(groupId);
    newArticle.setCompanyId(user.getCompanyId());
    newArticle.setUserId(user.getUserId());
    newArticle.setUserName(user.getFullName());
    newArticle.setFolderId(oldArticle.getFolderId());
    newArticle.setTreePath(oldArticle.getTreePath());
    newArticle.setArticleId(newArticleId);
    newArticle.setVersion(JournalArticleConstants.VERSION_DEFAULT);
    newArticle.setUrlTitle(getUniqueUrlTitle(id, groupId, newArticleId, oldArticle.getTitleCurrentValue()));

    try {
        copyArticleImages(oldArticle, newArticle);
    } catch (Exception e) {
        newArticle.setContent(oldArticle.getContent());
    }

    newArticle.setDDMStructureKey(oldArticle.getDDMStructureKey());
    newArticle.setDDMTemplateKey(oldArticle.getDDMTemplateKey());
    newArticle.setDefaultLanguageId(oldArticle.getDefaultLanguageId());
    newArticle.setLayoutUuid(oldArticle.getLayoutUuid());
    newArticle.setDisplayDate(oldArticle.getDisplayDate());
    newArticle.setExpirationDate(oldArticle.getExpirationDate());
    newArticle.setReviewDate(oldArticle.getReviewDate());
    newArticle.setIndexable(oldArticle.isIndexable());
    newArticle.setSmallImage(oldArticle.isSmallImage());
    newArticle.setSmallImageId(counterLocalService.increment());
    newArticle.setSmallImageURL(oldArticle.getSmallImageURL());

    WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil
            .getWorkflowHandler(JournalArticle.class.getName());

    WorkflowDefinitionLink workflowDefinitionLink = workflowHandler
            .getWorkflowDefinitionLink(oldArticle.getCompanyId(), oldArticle.getGroupId(), oldArticle.getId());

    if (oldArticle.isPending() || (workflowDefinitionLink != null)) {
        newArticle.setStatus(WorkflowConstants.STATUS_DRAFT);
    } else {
        newArticle.setStatus(oldArticle.getStatus());
    }

    ExpandoBridgeUtil.copyExpandoBridgeAttributes(oldArticle.getExpandoBridge(), newArticle.getExpandoBridge());

    journalArticlePersistence.update(newArticle);

    // Article localization

    String urlTitle = JournalUtil.getUrlTitle(id, oldArticle.getUrlTitle());

    int uniqueUrlTitleCount = _getUniqueUrlTitleCount(groupId, newArticleId, urlTitle);

    Map<Locale, String> newTitleMap = oldArticle.getTitleMap();

    for (Locale locale : newTitleMap.keySet()) {
        StringBundler sb = new StringBundler(5);

        sb.append(newTitleMap.get(locale));
        sb.append(StringPool.SPACE);
        sb.append(LanguageUtil.get(locale, "duplicate"));
        sb.append(StringPool.SPACE);
        sb.append(uniqueUrlTitleCount);

        newTitleMap.put(locale, sb.toString());
    }

    _addArticleLocalizedFields(newArticle.getCompanyId(), newArticle.getId(), newTitleMap,
            oldArticle.getDescriptionMap());

    // Resources

    addArticleResources(newArticle, true, true);

    // Small image

    if (oldArticle.isSmallImage()) {
        Image image = imageLocalService.fetchImage(oldArticle.getSmallImageId());

        if (image != null) {
            byte[] smallImageBytes = image.getTextObj();

            imageLocalService.updateImage(newArticle.getSmallImageId(), smallImageBytes);
        }
    }

    // Asset

    long[] assetCategoryIds = assetCategoryLocalService.getCategoryIds(JournalArticle.class.getName(),
            oldArticle.getResourcePrimKey());
    String[] assetTagNames = assetTagLocalService.getTagNames(JournalArticle.class.getName(),
            oldArticle.getResourcePrimKey());

    AssetEntry oldAssetEntry = assetEntryLocalService.getEntry(JournalArticle.class.getName(),
            oldArticle.getResourcePrimKey());

    List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(oldAssetEntry.getEntryId(), false);

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    updateAsset(userId, newArticle, assetCategoryIds, assetTagNames, assetLinkEntryIds,
            oldAssetEntry.getPriority());

    // Dynamic data mapping

    updateDDMLinks(id, groupId, oldArticle.getDDMStructureKey(), oldArticle.getDDMTemplateKey(), true);

    return newArticle;
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

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

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

    if (folderId == JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        return themeDisplay.translate("home");
    }/*w  ww  .jav a2  s . co m*/

    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(folderId);

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

    Collections.reverse(folders);

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

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

    for (JournalFolder 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.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public String getLayoutBreadcrumb(Layout layout) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    Locale locale = themeDisplay.getLocale();

    List<Layout> ancestors = layout.getAncestors();

    StringBundler sb = new StringBundler(4 * ancestors.size() + 5);

    if (layout.isPrivateLayout()) {
        sb.append(LanguageUtil.get(_request, "private-pages"));
    } else {/*from   w  w w .  jav a2s . c  om*/
        sb.append(LanguageUtil.get(_request, "public-pages"));
    }

    sb.append(StringPool.SPACE);
    sb.append(StringPool.GREATER_THAN);
    sb.append(StringPool.SPACE);

    Collections.reverse(ancestors);

    for (Layout ancestor : ancestors) {
        sb.append(HtmlUtil.escape(ancestor.getName(locale)));
        sb.append(StringPool.SPACE);
        sb.append(StringPool.GREATER_THAN);
        sb.append(StringPool.SPACE);
    }

    sb.append(HtmlUtil.escape(layout.getName(locale)));

    return sb.toString();
}

From source file:com.liferay.journal.web.internal.portlet.template.JournalTemplateHandler.java

License:Open Source License

@Override
public String getName(Locale locale) {
    ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", locale, getClass());

    String portletTitle = _portal.getPortletTitle(JournalPortletKeys.JOURNAL, resourceBundle);

    return portletTitle.concat(StringPool.SPACE).concat(LanguageUtil.get(locale, "template"));
}

From source file:com.liferay.knowledgebase.admin.importer.util.KBArticleMarkdownConverter.java

License:Open Source License

protected String getUrlTitle(String heading) {
    String urlTitle = null;//  ww  w  . j ava  2s .c  om

    int x = heading.indexOf("[](id=");
    int y = heading.indexOf(StringPool.CLOSE_PARENTHESIS, x);

    if (y > (x + 1)) {
        int equalsSign = heading.indexOf(StringPool.EQUAL, x);

        urlTitle = heading.substring(equalsSign + 1, y);

        urlTitle = StringUtil.replace(urlTitle, StringPool.SPACE, StringPool.DASH);

        urlTitle = StringUtil.toLowerCase(urlTitle);
    }

    if (!urlTitle.startsWith(StringPool.SLASH)) {
        urlTitle = StringPool.SLASH + urlTitle;
    }

    return urlTitle;
}

From source file:com.liferay.knowledgebase.admin.importer.util.KBArticleMarkdownConverter.java

License:Open Source License

protected String stripIds(String content) {
    int index = content.indexOf("[](id=");

    if (index == -1) {
        return content;
    }//from  w ww. j  av a  2s  .  c om

    StringBundler sb = new StringBundler();

    do {
        int x = content.indexOf(StringPool.EQUAL, index);
        int y = content.indexOf(StringPool.CLOSE_PARENTHESIS, x);

        if (y != -1) {
            sb.append(StringUtil.trimTrailing(content.substring(0, index)));

            content = content.substring(y + 1);
        } else {
            if (_log.isWarnEnabled()) {
                String msg = content.substring(index);

                // Get the invalid id text from the content

                int spaceIndex = content.indexOf(StringPool.SPACE);

                if (spaceIndex != -1) {
                    msg = content.substring(index, spaceIndex);
                }

                _log.warn("Missing ')' for web content containing header id " + msg);
            }

            // Since no close parenthesis remains in the content, stop
            // stripping out IDs and simply include all of the remaining
            // content

            break;
        }
    } while ((index = content.indexOf("[](id=")) != -1);

    sb.append(content);

    return sb.toString();
}