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.util.DLFileEntryIndexer.java

License:Open Source License

@Override
public void postProcessContextQuery(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {

    addStatus(contextQuery, searchContext);

    if (searchContext.isIncludeAttachments()) {
        addRelatedClassNames(contextQuery, searchContext);
    }//from  w w  w.  java 2  s  .c  o m

    contextQuery.addRequiredTerm(Field.HIDDEN, searchContext.isIncludeAttachments());

    addSearchClassTypeIds(contextQuery, searchContext);

    String ddmStructureFieldName = (String) searchContext.getAttribute("ddmStructureFieldName");
    Serializable ddmStructureFieldValue = searchContext.getAttribute("ddmStructureFieldValue");

    if (Validator.isNotNull(ddmStructureFieldName) && Validator.isNotNull(ddmStructureFieldValue)) {

        String[] ddmStructureFieldNameParts = StringUtil.split(ddmStructureFieldName, StringPool.SLASH);

        DDMStructure structure = DDMStructureLocalServiceUtil
                .getStructure(GetterUtil.getLong(ddmStructureFieldNameParts[1]));

        String fieldName = StringUtil.replaceLast(ddmStructureFieldNameParts[2],
                StringPool.UNDERLINE.concat(LocaleUtil.toLanguageId(searchContext.getLocale())),
                StringPool.BLANK);

        try {
            ddmStructureFieldValue = DDMUtil.getIndexedFieldValue(ddmStructureFieldValue,
                    structure.getFieldType(fieldName));
        } catch (StructureFieldException sfe) {
        }

        contextQuery.addRequiredTerm(ddmStructureFieldName,
                StringPool.QUOTE + ddmStructureFieldValue + StringPool.QUOTE);
    }

    String[] mimeTypes = (String[]) searchContext.getAttribute("mimeTypes");

    if (ArrayUtil.isNotEmpty(mimeTypes)) {
        BooleanQuery mimeTypesQuery = BooleanQueryFactoryUtil.create(searchContext);

        for (String mimeType : mimeTypes) {
            mimeTypesQuery.addTerm("mimeType",
                    StringUtil.replace(mimeType, CharPool.FORWARD_SLASH, CharPool.UNDERLINE));
        }

        contextQuery.add(mimeTypesQuery, BooleanClauseOccur.MUST);
    }
}

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

License:Open Source License

@Override
public String getDividedPath(long id) {
    StringBundler sb = new StringBundler(16);

    long dividend = id;

    while ((dividend / _DIVISOR) != 0) {
        sb.append(StringPool.SLASH);
        sb.append(dividend % _DIVISOR);//  w ww .j a v  a  2 s . c om

        dividend = dividend / _DIVISOR;
    }

    sb.append(StringPool.SLASH);
    sb.append(id);

    return sb.toString();
}

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

License:Open Source License

@Override
public String getPreviewURL(FileEntry fileEntry, FileVersion fileVersion, ThemeDisplay themeDisplay,
        String queryString, boolean appendVersion, boolean absoluteURL) {

    StringBundler sb = new StringBundler(17);

    if (themeDisplay != null) {
        if (absoluteURL) {
            sb.append(themeDisplay.getPortalURL());
        }//from  ww w.j  a  v a 2 s . co  m
    }

    sb.append(PortalUtil.getPathContext());
    sb.append("/documents/");
    sb.append(fileEntry.getRepositoryId());
    sb.append(StringPool.SLASH);
    sb.append(fileEntry.getFolderId());
    sb.append(StringPool.SLASH);

    String fileName = fileEntry.getFileName();

    if (fileEntry.isInTrash()) {
        fileName = TrashUtil.getOriginalTitle(fileEntry.getFileName());
    }

    sb.append(HttpUtil.encodeURL(HtmlUtil.unescape(fileName)));

    sb.append(StringPool.SLASH);
    sb.append(HttpUtil.encodeURL(fileEntry.getUuid()));

    if (appendVersion) {
        sb.append("?version=");
        sb.append(fileVersion.getVersion());
    }

    if (ImageProcessorUtil.isImageSupported(fileVersion)) {
        if (appendVersion) {
            sb.append("&t=");
        } else {
            sb.append("?t=");
        }

        Date modifiedDate = fileVersion.getModifiedDate();

        sb.append(modifiedDate.getTime());
    }

    sb.append(queryString);

    String previewURL = sb.toString();

    if ((themeDisplay != null) && themeDisplay.isAddSessionIdToURL()) {
        return PortalUtil.getURLWithSessionId(previewURL, themeDisplay.getSessionId());
    }

    return previewURL;
}

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;
    }/* ww w . j  a  va2 s.c o  m*/

    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 getWebDavURL(ThemeDisplay themeDisplay, Folder folder, FileEntry fileEntry,
        boolean manualCheckInRequired, boolean openDocumentUrl) throws PortalException {

    StringBundler webDavURL = new StringBundler(8);

    boolean secure = false;

    if (themeDisplay.isSecure() || PropsValues.WEBDAV_SERVLET_HTTPS_REQUIRED) {

        secure = true;/*from   w  w w .  j a  v  a2 s  . c  om*/
    }

    String portalURL = PortalUtil.getPortalURL(themeDisplay.getServerName(), themeDisplay.getServerPort(),
            secure);

    webDavURL.append(portalURL);

    webDavURL.append(themeDisplay.getPathContext());
    webDavURL.append("/webdav");

    if (manualCheckInRequired) {
        webDavURL.append(MANUAL_CHECK_IN_REQUIRED_PATH);
    }

    String fileEntryFileName = null;

    Group group = null;

    if (fileEntry != null) {
        fileEntryFileName = HtmlUtil.unescape(fileEntry.getFileName());

        group = GroupLocalServiceUtil.getGroup(fileEntry.getGroupId());
    } else {
        group = themeDisplay.getScopeGroup();
    }

    webDavURL.append(group.getFriendlyURL());
    webDavURL.append("/document_library");

    StringBuilder sb = new StringBuilder();

    if ((folder != null) && (folder.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

        Folder curFolder = folder;

        while (true) {
            sb.insert(0, HttpUtil.encodeURL(curFolder.getName(), true));
            sb.insert(0, StringPool.SLASH);

            if (curFolder.getParentFolderId() == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

                break;
            }

            curFolder = DLAppLocalServiceUtil.getFolder(curFolder.getParentFolderId());
        }
    }

    if (fileEntry != null) {
        sb.append(StringPool.SLASH);
        sb.append(HttpUtil.encodeURL(fileEntryFileName, true));
    }

    webDavURL.append(sb.toString());

    return webDavURL.toString();
}

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

License:Open Source License

protected static String getPathSegment(long groupId, long fileEntryId, long fileVersionId, boolean preview) {

    StringBundler sb = null;//from  w w  w .ja  va2  s  .  c o  m

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

    if (preview) {
        sb.append(PREVIEW_PATH);
    } else {
        sb.append(THUMBNAIL_PATH);
    }

    sb.append(groupId);
    sb.append(DLUtil.getDividedPath(fileEntryId));

    if (fileVersionId > 0) {
        sb.append(StringPool.SLASH);
        sb.append(fileVersionId);
    }

    return sb.toString();
}

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

License:Open Source License

protected String getBinPath(PortletDataContext portletDataContext, FileEntry fileEntry, int index) {

    StringBundler sb = new StringBundler(8);

    sb.append(ExportImportPathUtil.getPortletPath(portletDataContext, PortletKeys.DOCUMENT_LIBRARY));
    sb.append("/bin/");
    sb.append(fileEntry.getFileEntryId());
    sb.append(StringPool.SLASH);
    sb.append(THUMBNAIL_PATH);/*from w w w  . j a  v a 2s .  c om*/
    sb.append(fileEntry.getVersion());
    sb.append(StringPool.SLASH);
    sb.append(index);

    return sb.toString();
}

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

License:Open Source License

protected String getBinPath(PortletDataContext portletDataContext, FileEntry fileEntry, String type) {

    StringBundler sb = new StringBundler(8);

    sb.append(ExportImportPathUtil.getPortletPath(portletDataContext, PortletKeys.DOCUMENT_LIBRARY));
    sb.append("/bin/");
    sb.append(fileEntry.getFileEntryId());
    sb.append(StringPool.SLASH);
    sb.append(PREVIEW_PATH);/*from  ww  w  .ja va2s.  co  m*/
    sb.append(fileEntry.getVersion());
    sb.append(StringPool.SLASH);
    sb.append(type);

    return sb.toString();
}

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   w w w . j a v  a2  s. com*/

    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.webdav.DLWebDAVStorageImpl.java

License:Open Source License

@Override
public Status makeCollection(WebDAVRequest webDavRequest) throws WebDAVException {

    try {//w  ww.  j  ava 2 s  .  c om
        HttpServletRequest request = webDavRequest.getHttpServletRequest();

        if (request.getContentLength() > 0) {
            return new Status(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        }

        String[] pathArray = webDavRequest.getPathArray();

        long companyId = webDavRequest.getCompanyId();
        long groupId = webDavRequest.getGroupId();
        long parentFolderId = getParentFolderId(companyId, pathArray);
        String name = WebDAVUtil.getResourceName(pathArray);
        String description = StringPool.BLANK;

        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId));
        serviceContext.setAddGuestPermissions(true);

        DLAppServiceUtil.addFolder(groupId, parentFolderId, name, description, serviceContext);

        String location = StringUtil.merge(pathArray, StringPool.SLASH);

        return new Status(location, HttpServletResponse.SC_CREATED);
    } catch (DuplicateFolderNameException dfne) {
        return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
    } catch (DuplicateFileException dfe) {
        return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
    } catch (NoSuchFolderException nsfe) {
        return new Status(HttpServletResponse.SC_CONFLICT);
    } catch (PrincipalException pe) {
        return new Status(HttpServletResponse.SC_FORBIDDEN);
    } catch (Exception e) {
        throw new WebDAVException(e);
    }
}