private static void _checkFileEntry(String[] pathArray) throws Exception {
    if (pathArray.length == 1) {
      long dlFileShortcutId = GetterUtil.getLong(pathArray[0]);

      DLFileShortcut dlFileShortcut = DLAppLocalServiceUtil.getFileShortcut(dlFileShortcutId);

      DLAppLocalServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId());
    } else if (pathArray.length == 2) {

      // Unable to check with UUID because of multiple repositories

    } else if (pathArray.length == 3) {
      long groupId = GetterUtil.getLong(pathArray[0]);
      long folderId = GetterUtil.getLong(pathArray[1]);
      String fileName = pathArray[2];

      try {
        DLAppLocalServiceUtil.getFileEntry(groupId, folderId, fileName);
      } catch (RepositoryException re) {
      }
    } else {
      long groupId = GetterUtil.getLong(pathArray[0]);

      String uuid = pathArray[3];

      try {
        DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
      } catch (RepositoryException re) {
      }
    }
  }
  @Override
  public FileEntry fetchStagedModelByUuidAndGroupId(String uuid, long groupId) {

    try {
      return DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
    } catch (PortalException pe) {
      return null;
    }
  }
  @Override
  public FileEntry fetchStagedModelByUuidAndGroupId(String uuid, long groupId) {

    try {
      return DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
    } catch (PortalException pe) {
      if (_log.isDebugEnabled()) {
        _log.debug(pe, pe);
      }

      return null;
    }
  }
  @Override
  public FileEntry getPortletFileEntry(String uuid, long groupId)
      throws PortalException, SystemException {

    return DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
  }
Esempio n. 5
0
  protected static String exportDLFileEntries(
      PortletDataContext portletDataContext,
      Element dlFileEntryTypesElement,
      Element dlFoldersElement,
      Element dlFileEntriesElement,
      Element dlFileRanksElement,
      Element dlRepositoriesElement,
      Element dlRepositoryEntriesElement,
      Element entityElement,
      String content,
      boolean checkDateRange)
      throws Exception {

    Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getGroupId());

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    if (group.isStaged()
        && !group.isStagedRemotely()
        && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) {

      return content;
    }

    StringBuilder sb = new StringBuilder(content);

    int beginPos = content.length();
    int currentLocation = -1;

    boolean legacyURL = true;

    while (true) {
      String contextPath = PortalUtil.getPathContext();

      currentLocation =
          content.lastIndexOf(contextPath.concat("/c/document_library/get_file?"), beginPos);

      if (currentLocation == -1) {
        currentLocation =
            content.lastIndexOf(contextPath.concat("/image/image_gallery?"), beginPos);
      }

      if (currentLocation == -1) {
        currentLocation = content.lastIndexOf(contextPath.concat("/documents/"), beginPos);

        legacyURL = false;
      }

      if (currentLocation == -1) {
        return sb.toString();
      }

      beginPos = currentLocation + contextPath.length();

      int endPos1 = content.indexOf(CharPool.APOSTROPHE, beginPos);
      int endPos2 = content.indexOf(CharPool.CLOSE_BRACKET, beginPos);
      int endPos3 = content.indexOf(CharPool.CLOSE_CURLY_BRACE, beginPos);
      int endPos4 = content.indexOf(CharPool.CLOSE_PARENTHESIS, beginPos);
      int endPos5 = content.indexOf(CharPool.LESS_THAN, beginPos);
      int endPos6 = content.indexOf(CharPool.QUESTION, beginPos);
      int endPos7 = content.indexOf(CharPool.QUOTE, beginPos);
      int endPos8 = content.indexOf(CharPool.SPACE, beginPos);

      int endPos = endPos1;

      if ((endPos == -1) || ((endPos2 != -1) && (endPos2 < endPos))) {
        endPos = endPos2;
      }

      if ((endPos == -1) || ((endPos3 != -1) && (endPos3 < endPos))) {
        endPos = endPos3;
      }

      if ((endPos == -1) || ((endPos4 != -1) && (endPos4 < endPos))) {
        endPos = endPos4;
      }

      if ((endPos == -1) || ((endPos5 != -1) && (endPos5 < endPos))) {
        endPos = endPos5;
      }

      if ((endPos == -1) || ((endPos6 != -1) && (endPos6 < endPos) && !legacyURL)) {

        endPos = endPos6;
      }

      if ((endPos == -1) || ((endPos7 != -1) && (endPos7 < endPos))) {
        endPos = endPos7;
      }

      if ((endPos == -1) || ((endPos8 != -1) && (endPos8 < endPos))) {
        endPos = endPos8;
      }

      if ((beginPos == -1) || (endPos == -1)) {
        break;
      }

      try {
        String oldParameters = content.substring(beginPos, endPos);

        while (oldParameters.contains(StringPool.AMPERSAND_ENCODED)) {
          oldParameters = oldParameters.replace(StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND);
        }

        Map<String, String[]> map = new HashMap<String, String[]>();

        if (oldParameters.startsWith("/documents/")) {
          String[] pathArray = oldParameters.split(StringPool.SLASH);

          map.put("groupId", new String[] {pathArray[2]});

          if (pathArray.length == 4) {
            map.put("uuid", new String[] {pathArray[3]});
          } else if (pathArray.length == 5) {
            map.put("folderId", new String[] {pathArray[3]});

            String title = HttpUtil.decodeURL(pathArray[4]);

            int pos = title.indexOf(StringPool.QUESTION);

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

            map.put("title", new String[] {title});
          } else if (pathArray.length > 5) {
            String uuid = pathArray[5];

            int pos = uuid.indexOf(StringPool.QUESTION);

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

            map.put("uuid", new String[] {uuid});
          }
        } else {
          oldParameters = oldParameters.substring(oldParameters.indexOf(CharPool.QUESTION) + 1);

          map = HttpUtil.parameterMapFromString(oldParameters);
        }

        FileEntry fileEntry = null;

        String uuid = MapUtil.getString(map, "uuid");

        if (Validator.isNotNull(uuid)) {
          String groupIdString = MapUtil.getString(map, "groupId");

          long groupId = GetterUtil.getLong(groupIdString);

          if (groupIdString.equals("@group_id@")) {
            groupId = portletDataContext.getScopeGroupId();
          }

          fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
        } else {
          String folderIdString = MapUtil.getString(map, "folderId");

          if (Validator.isNotNull(folderIdString)) {
            long folderId = GetterUtil.getLong(folderIdString);
            String name = MapUtil.getString(map, "name");
            String title = MapUtil.getString(map, "title");

            String groupIdString = MapUtil.getString(map, "groupId");

            long groupId = GetterUtil.getLong(groupIdString);

            if (groupIdString.equals("@group_id@")) {
              groupId = portletDataContext.getScopeGroupId();
            }

            if (Validator.isNotNull(title)) {
              fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, title);
            } else {
              DLFileEntry dlFileEntry =
                  DLFileEntryLocalServiceUtil.getFileEntryByName(groupId, folderId, name);

              fileEntry = new LiferayFileEntry(dlFileEntry);
            }
          } else if (map.containsKey("image_id")
              || map.containsKey("img_id")
              || map.containsKey("i_id")) {

            long imageId = MapUtil.getLong(map, "image_id");

            if (imageId <= 0) {
              imageId = MapUtil.getLong(map, "img_id");

              if (imageId <= 0) {
                imageId = MapUtil.getLong(map, "i_id");
              }
            }

            DLFileEntry dlFileEntry =
                DLFileEntryLocalServiceUtil.fetchFileEntryByAnyImageId(imageId);

            if (dlFileEntry != null) {
              fileEntry = new LiferayFileEntry(dlFileEntry);
            }
          }
        }

        if (fileEntry == null) {
          beginPos--;

          continue;
        }

        beginPos = currentLocation;

        DLPortletDataHandler.exportFileEntry(
            portletDataContext,
            dlFileEntryTypesElement,
            dlFoldersElement,
            dlFileEntriesElement,
            dlFileRanksElement,
            dlRepositoriesElement,
            dlRepositoryEntriesElement,
            fileEntry,
            checkDateRange);

        Element dlReferenceElement = entityElement.addElement("dl-reference");

        dlReferenceElement.addAttribute(
            "default-repository", String.valueOf(fileEntry.isDefaultRepository()));

        String path = null;

        if (fileEntry.isDefaultRepository()) {
          path = DLPortletDataHandler.getFileEntryPath(portletDataContext, fileEntry);

        } else {
          path =
              DLPortletDataHandler.getRepositoryEntryPath(
                  portletDataContext, fileEntry.getFileEntryId());
        }

        dlReferenceElement.addAttribute("path", path);

        String dlReference = "[$dl-reference=" + path + "$]";

        sb.replace(beginPos, endPos, dlReference);
      } catch (Exception e) {
        if (_log.isDebugEnabled()) {
          _log.debug(e, e);
        } else if (_log.isWarnEnabled()) {
          _log.warn(e.getMessage());
        }
      }

      beginPos--;
    }

    return sb.toString();
  }
Esempio n. 6
0
  @Override
  public Serializable getDisplayFieldValue(
      ThemeDisplay themeDisplay, Serializable fieldValue, String type) throws Exception {

    if (fieldValue instanceof Date) {
      Date valueDate = (Date) fieldValue;

      DateFormat dateFormat = DateFormatFactoryUtil.getDate(themeDisplay.getLocale());

      fieldValue = dateFormat.format(valueDate);
    } else if (type.equals(DDMImpl.TYPE_CHECKBOX)) {
      Boolean valueBoolean = (Boolean) fieldValue;

      if (valueBoolean) {
        fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "yes");
      } else {
        fieldValue = LanguageUtil.get(themeDisplay.getLocale(), "no");
      }
    } else if (type.equals(DDMImpl.TYPE_DDM_DOCUMENTLIBRARY)) {
      if (Validator.isNull(fieldValue)) {
        return StringPool.BLANK;
      }

      String valueString = String.valueOf(fieldValue);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

      String uuid = jsonObject.getString("uuid");
      long groupId = jsonObject.getLong("groupId");

      FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);

      fieldValue =
          DLUtil.getPreviewURL(
              fileEntry, fileEntry.getFileVersion(), null, StringPool.BLANK, false, true);
    } else if (type.equals(DDMImpl.TYPE_DDM_LINK_TO_PAGE)) {
      if (Validator.isNull(fieldValue)) {
        return StringPool.BLANK;
      }

      String valueString = String.valueOf(fieldValue);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject(valueString);

      long groupId = jsonObject.getLong("groupId");
      boolean privateLayout = jsonObject.getBoolean("privateLayout");
      long layoutId = jsonObject.getLong("layoutId");

      Layout layout = LayoutLocalServiceUtil.getLayout(groupId, privateLayout, layoutId);

      fieldValue = PortalUtil.getLayoutFriendlyURL(layout, themeDisplay);
    } else if (type.equals(DDMImpl.TYPE_RADIO) || type.equals(DDMImpl.TYPE_SELECT)) {

      String valueString = String.valueOf(fieldValue);

      JSONArray jsonArray = JSONFactoryUtil.createJSONArray(valueString);

      String[] stringArray = ArrayUtil.toStringArray(jsonArray);

      fieldValue = stringArray[0];
    }

    return fieldValue;
  }