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.document.library.web.internal.portlet.action.DownloadEntriesMVCResourceCommand.java

License:Open Source License

protected void zipFileEntry(FileEntry fileEntry, String path, ZipWriter zipWriter) throws Exception {

    zipWriter.addEntry(path + StringPool.SLASH + fileEntry.getFileName(), fileEntry.getContentStream());
}

From source file:com.liferay.document.library.web.internal.portlet.action.DownloadEntriesMVCResourceCommand.java

License:Open Source License

protected void zipFolder(long repositoryId, long folderId, String path, ZipWriter zipWriter) throws Exception {

    List<Object> foldersAndFileEntriesAndFileShortcuts = _dlAppService.getFoldersAndFileEntriesAndFileShortcuts(
            repositoryId, folderId, WorkflowConstants.STATUS_APPROVED, false, QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);//from   w ww . j  a  va 2s.  c o m

    for (Object entry : foldersAndFileEntriesAndFileShortcuts) {
        if (entry instanceof Folder) {
            Folder folder = (Folder) entry;

            zipFolder(folder.getRepositoryId(), folder.getFolderId(),
                    path.concat(StringPool.SLASH).concat(folder.getName()), zipWriter);
        } else if (entry instanceof FileEntry) {
            zipFileEntry((FileEntry) entry, path, zipWriter);
        } else if (entry instanceof FileShortcut) {
            FileShortcut fileShortcut = (FileShortcut) entry;

            FileEntry fileEntry = _dlAppService.getFileEntry(fileShortcut.getToFileEntryId());

            zipFileEntry(fileEntry, path, zipWriter);
        }
    }
}

From source file:com.liferay.document.library.web.webdav.DLWebDAVStorageImpl.java

License:Open Source License

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

    try {//from  www .j  a v  a  2 s .c o  m
        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);

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

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

        return new Status(location, HttpServletResponse.SC_CREATED);
    } catch (DuplicateFolderNameException dfne) {
        if (_log.isDebugEnabled()) {
            _log.debug(dfne, dfne);
        }

        return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
    } catch (DuplicateFileEntryException dfee) {
        if (_log.isDebugEnabled()) {
            _log.debug(dfee, dfee);
        }

        return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
    } catch (NoSuchFolderException nsfe) {
        if (_log.isDebugEnabled()) {
            _log.debug(nsfe, nsfe);
        }

        return new Status(HttpServletResponse.SC_CONFLICT);
    } catch (PrincipalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return new Status(HttpServletResponse.SC_FORBIDDEN);
    } catch (Exception e) {
        throw new WebDAVException(e);
    }
}

From source file:com.liferay.document.library.web.webdav.DLWebDAVStorageImpl.java

License:Open Source License

@Override
public int putResource(WebDAVRequest webDAVRequest) throws WebDAVException {
    File file = null;//from   w  ww.ja  v a 2  s.c om

    try {
        HttpServletRequest request = webDAVRequest.getHttpServletRequest();

        String[] pathArray = webDAVRequest.getPathArray();

        long companyId = webDAVRequest.getCompanyId();
        long groupId = webDAVRequest.getGroupId();
        long parentFolderId = getParentFolderId(companyId, pathArray);
        String title = getTitle(pathArray);
        String description = StringPool.BLANK;
        String changeLog = StringPool.BLANK;

        ServiceContext serviceContext = ServiceContextFactory.getInstance(request);

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

        String extension = FileUtil.getExtension(title);

        file = FileUtil.createTempFile(extension);

        FileUtil.write(file, request.getInputStream());

        String contentType = getContentType(request, file, title, extension);

        try {
            FileEntry fileEntry = _dlAppService.getFileEntry(groupId, parentFolderId, title);

            if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) {

                return WebDAVUtil.SC_LOCKED;
            }

            long fileEntryId = fileEntry.getFileEntryId();

            description = fileEntry.getDescription();

            populateServiceContext(serviceContext, fileEntry);

            serviceContext.setCommand(Constants.UPDATE_WEBDAV);

            _dlAppService.updateFileEntry(fileEntryId, title, contentType, title, description, changeLog, false,
                    file, serviceContext);
        } catch (NoSuchFileEntryException nsfee) {
            if (_log.isDebugEnabled()) {
                _log.debug(nsfee, nsfee);
            }

            serviceContext.setCommand(Constants.ADD_WEBDAV);

            _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title, description,
                    changeLog, file, serviceContext);
        }

        if (_log.isInfoEnabled()) {
            _log.info("Added " + StringUtil.merge(pathArray, StringPool.SLASH));
        }

        return HttpServletResponse.SC_CREATED;
    } catch (FileSizeException fse) {
        if (_log.isDebugEnabled()) {
            _log.debug(fse, fse);
        }

        return HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE;
    } catch (NoSuchFolderException nsfe) {
        if (_log.isDebugEnabled()) {
            _log.debug(nsfe, nsfe);
        }

        return HttpServletResponse.SC_CONFLICT;
    } catch (PrincipalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return HttpServletResponse.SC_FORBIDDEN;
    } catch (PortalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn(pe, pe);
        }

        return HttpServletResponse.SC_CONFLICT;
    } catch (Exception e) {
        throw new WebDAVException(e);
    } finally {
        FileUtil.delete(file);
    }
}

From source file:com.liferay.events.global.mobile.Utils.java

License:Open Source License

public static String getJSONLikenessDescription(EventContact me, EventContact targetContact)
        throws JSONException {

    JSONArray result = JSONFactoryUtil.createJSONArray();

    Map<String, Double> desires1 = getJSONWordWeightsFromString(me.getDesires());
    Map<String, Double> desires2 = getJSONWordWeightsFromString(targetContact.getDesires());
    Map<String, Double> expertise1 = getJSONWordWeightsFromString(me.getExpertise());
    Map<String, Double> expertise2 = getJSONWordWeightsFromString(targetContact.getExpertise());

    // how many of my desires do they have expertise in?
    Set<String> common1 = new HashSet<String>(desires1.keySet());
    common1.retainAll(expertise2.keySet());

    // how many of my expertises do they desire?
    Set<String> common2 = new HashSet<String>(desires2.keySet());
    common2.retainAll(expertise1.keySet());

    if (common1.size() > 0) {
        JSONObject bit = JSONFactoryUtil.createJSONObject();

        List<String> myNeeds = new ArrayList<String>(common1);
        JSONArray args = JSONFactoryUtil.createJSONArray();
        args.put(targetContact.getGivenName());
        args.put(StringUtils.join(myNeeds.size() > 5 ? myNeeds.subList(0, 5) : myNeeds,
                " " + StringPool.SLASH + " "));

        bit.put("key", "HAS_EXPERTISE_IN_MY_AREAS");
        bit.put("args", args);
        result.put(bit);//  w  ww . j  a v  a 2  s.co  m
    }

    if (common2.size() > 0) {
        JSONObject bit = JSONFactoryUtil.createJSONObject();
        JSONArray args = JSONFactoryUtil.createJSONArray();

        List<String> myExpertise = new ArrayList<String>(common2);
        args.put(targetContact.getGivenName());
        args.put(StringUtils.join(myExpertise.size() > 5 ? myExpertise.subList(0, 5) : myExpertise,
                " " + StringPool.SLASH + " "));

        bit.put("key", "HAS_NEEDS_IN_MY_AREAS");
        bit.put("args", args);
        result.put(bit);

    }

    double industrySimilarity = getJaroWinklerDistance(me.getIndustry(), targetContact.getIndustry());
    double jobTitleSimilarity = getJaroWinklerDistance(me.getJobTitle(), targetContact.getJobTitle());
    double locationDistance;

    if (me.getLat() == 0 || me.getLng() == 0 || targetContact.getLat() == 0 || targetContact.getLng() == 0) {
        locationDistance = 100000;
    } else {
        locationDistance = getDistanceBetween(me.getLat(), me.getLng(), targetContact.getLat(),
                targetContact.getLng());
    }

    double locationSimilarity = 1.0 - (locationDistance / 1000.0);
    if (locationSimilarity < 0)
        locationSimilarity = 0;

    if (locationSimilarity > .5 && me.getCountry().equals(targetContact.getCountry())) {

        JSONObject bit = JSONFactoryUtil.createJSONObject();
        JSONArray args = JSONFactoryUtil.createJSONArray();
        args.put(targetContact.getGivenName());
        args.put(targetContact.getCity());
        bit.put("key", "IS_NEARBY");
        bit.put("args", args);
        result.put(bit);

    } else if (me.getCountry().equals(targetContact.getCountry())) {
        JSONObject bit = JSONFactoryUtil.createJSONObject();
        JSONArray args = JSONFactoryUtil.createJSONArray();
        args.put(targetContact.getGivenName());
        bit.put("key", "LIVES_WORKS_IN_COUNTRY");
        bit.put("args", args);
        result.put(bit);

    }

    if (industrySimilarity > .7) {
        JSONObject bit = JSONFactoryUtil.createJSONObject();
        JSONArray args = JSONFactoryUtil.createJSONArray();
        args.put(targetContact.getGivenName());
        args.put(targetContact.getIndustry());
        bit.put("key", "SIMILAR_INDUSTRY");
        bit.put("args", args);
        result.put(bit);

    }
    if (jobTitleSimilarity > .7) {
        JSONObject bit = JSONFactoryUtil.createJSONObject();
        JSONArray args = JSONFactoryUtil.createJSONArray();
        args.put(targetContact.getGivenName());
        args.put(targetContact.getJobTitle());
        bit.put("key", "SIMILAR_JOB");
        bit.put("args", args);
        result.put(bit);

    }

    JSONArray words1o = JSONFactoryUtil.createJSONArray(me.getInterests());
    JSONArray words2o = JSONFactoryUtil.createJSONArray(targetContact.getInterests());

    List<String> words1 = new ArrayList<String>();
    List<String> words2 = new ArrayList<String>();
    final Map<String, Integer> count1 = new HashMap<String, Integer>();
    final Map<String, Integer> count2 = new HashMap<String, Integer>();
    final Map<String, Double> weight1 = new HashMap<String, Double>();
    final Map<String, Double> weight2 = new HashMap<String, Double>();

    for (int i = 0; i < words1o.length(); i++) {
        JSONObject o = words1o.getJSONObject(i);

        String word = o.getString("word");
        int count = o.getInt("count");
        double weight = o.getDouble("weight");

        words1.add(word);
        count1.put(word, count);
        weight1.put(word, weight);
    }

    for (int i = 0; i < words2o.length(); i++) {
        JSONObject o = words2o.getJSONObject(i);

        String word = o.getString("word");
        int count = o.getInt("count");
        double weight = o.getDouble("weight");

        words2.add(word);
        count2.put(word, count);
        weight2.put(word, weight);
    }

    Set<String> commonWords = new HashSet<String>(words1);
    commonWords.retainAll(words2);

    List<String> sortedCommon = new SortedArrayList<String>(new Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            return (int) Math.floor(
                    ((((double) count1.get(o2) * weight1.get(o2)) + ((double) count2.get(o2) * weight2.get(o2)))
                            - (((double) count1.get(o1) * weight1.get(o1))
                                    + ((double) count2.get(o1) * weight2.get(o1)))));

        }
    });

    sortedCommon.addAll(commonWords);

    if (!sortedCommon.isEmpty()) {
        JSONObject bit = JSONFactoryUtil.createJSONObject();
        JSONArray args = JSONFactoryUtil.createJSONArray();
        args.put(StringUtils.join(sortedCommon.size() > 5 ? sortedCommon.subList(0, 5) : sortedCommon, " / "));
        bit.put("key", "SIMILAR_SKILLS_INTERESTS");
        bit.put("args", args);
        result.put(bit);

    }

    if (result.length() <= 0) {
        List<String> sortedTargetWords = new SortedArrayList<String>(new Comparator<String>() {
            @Override
            public int compare(String a, String b) {
                return (int) Math.floor(((weight2.get(b) * (double) count2.get(b))
                        - (weight2.get(a) * (double) count2.get(a))));
            }
        });
        sortedTargetWords.addAll(words2);

        if (!sortedTargetWords.isEmpty()) {
            JSONObject bit = JSONFactoryUtil.createJSONObject();
            JSONArray args = JSONFactoryUtil.createJSONArray();
            args.put(StringUtils.join(
                    sortedTargetWords.size() > 3 ? sortedTargetWords.subList(0, 3) : sortedTargetWords, " / "));
            bit.put("key", "MIGHT_BE_INTERESTED");
            bit.put("args", args);
            result.put(bit);

        }
    }
    return result.toString();
}

From source file:com.liferay.faces.demos.list.DocLibFileEntry.java

License:Open Source License

public DocLibFileEntry(DLFileEntry dlFileEntry, String portalURL, String pathContext, long scopeGroupId,
        boolean permittedToView) {
    super(dlFileEntry);
    this.kilobytes = Long.toString(dlFileEntry.getSize() / 1024L) + " KB";
    this.permittedToView = permittedToView;
    this.url = portalURL + pathContext + "/documents/" + Long.toString(scopeGroupId) + StringPool.SLASH
            + dlFileEntry.getFolderId() + StringPool.SLASH
            + HttpUtil.encodeURL(HtmlUtil.unescape(dlFileEntry.getTitle()));
    this.userName = dlFileEntry.getUserName();

    // this.url = portalURL + pathContext + "/documents/" + Long.toString(scopeGroupId) + StringPool.SLASH +
    // dlFileEntry.getUuid();
}

From source file:com.liferay.faces.demos.tree.FolderTreeRootNode.java

License:Open Source License

private static String getGroupName(Group group) {

    String groupName = group.getName();
    boolean longValue = true;

    try {/*from  w w w .  j a v a 2 s  .  c o m*/
        Long.parseLong(groupName);
    } catch (NumberFormatException e) {
        longValue = false;
    }

    if (longValue) {
        String friendlyURL = group.getFriendlyURL();

        if (friendlyURL != null) {
            groupName = friendlyURL.replace(StringPool.SLASH, StringPool.BLANK);
        }
    }

    return groupName;
}

From source file:com.liferay.frontend.taglib.soy.servlet.taglib.TemplateRendererTag.java

License:Open Source License

private Template _getTemplate() throws TemplateException {
    SoyTemplateResourcesCollector soyTemplateResourcesCollector = new SoyTemplateResourcesCollector(_bundle,
            StringPool.SLASH);

    return TemplateManagerUtil.getTemplate(TemplateConstants.LANG_TYPE_SOY,
            soyTemplateResourcesCollector.getAllTemplateResources(), false);
}

From source file:com.liferay.google.apps.connector.GEmailSettingsManagerImpl.java

License:Open Source License

protected String getEmailSettingsURL(long userId) {
    return emailSettingsURL.concat(StringPool.SLASH).concat(String.valueOf(userId));
}

From source file:com.liferay.google.apps.connector.GGroupManagerImpl.java

License:Open Source License

@Override
public void addGGroupMember(String groupEmailAddress, String memberEmailAddress) throws GoogleAppsException {

    Document document = SAXReaderUtil.createDocument();

    Element atomEntryElement = addAtomEntry(document);

    addAppsProperty(atomEntryElement, "memberId", memberEmailAddress);

    StringBundler sb = new StringBundler(4);

    sb.append(groupURL);/*from w ww . jav a2 s .c  o  m*/
    sb.append(StringPool.SLASH);
    sb.append(groupEmailAddress);
    sb.append("/member");

    submitAdd(sb.toString(), document);
}