Ejemplo n.º 1
0
  protected void setPortletScope(PortletDataContext portletDataContext, Element portletElement) {

    // Portlet data scope

    String scopeLayoutUuid =
        GetterUtil.getString(portletElement.attributeValue("scope-layout-uuid"));
    String scopeLayoutType =
        GetterUtil.getString(portletElement.attributeValue("scope-layout-type"));

    portletDataContext.setScopeLayoutUuid(scopeLayoutUuid);
    portletDataContext.setScopeType(scopeLayoutType);

    // Layout scope

    try {
      Group scopeGroup = null;

      if (scopeLayoutType.equals("company")) {
        scopeGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId());
      } else if (Validator.isNotNull(scopeLayoutUuid)) {
        Layout scopeLayout =
            LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
                scopeLayoutUuid, portletDataContext.getGroupId());

        if (scopeLayout.hasScopeGroup()) {
          scopeGroup = scopeLayout.getScopeGroup();
        } else {
          String name = String.valueOf(scopeLayout.getPlid());

          scopeGroup =
              GroupLocalServiceUtil.addGroup(
                  portletDataContext.getUserId(null),
                  Layout.class.getName(),
                  scopeLayout.getPlid(),
                  name,
                  null,
                  0,
                  null,
                  false,
                  true,
                  null);
        }

        Group group = scopeLayout.getGroup();

        if (group.isStaged() && !group.isStagedRemotely()) {
          try {
            Layout oldLayout =
                LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(
                    scopeLayoutUuid, portletDataContext.getSourceGroupId());

            Group oldScopeGroup = oldLayout.getScopeGroup();

            oldScopeGroup.setLiveGroupId(scopeGroup.getGroupId());

            GroupLocalServiceUtil.updateGroup(oldScopeGroup, true);
          } catch (NoSuchLayoutException nsle) {
            if (_log.isWarnEnabled()) {
              _log.warn(nsle);
            }
          }
        }

        portletDataContext.setScopeGroupId(scopeGroup.getGroupId());
      }
    } catch (PortalException pe) {
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
Ejemplo n.º 2
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();
  }
Ejemplo n.º 3
0
  @Override
  public String getDescriptiveName(Locale locale) throws PortalException {
    Group curGroup = this;

    String name = getName(locale);

    if (Validator.isNull(name)) {
      Locale siteDefaultLocale = PortalUtil.getSiteDefaultLocale(getGroupId());

      name = getName(siteDefaultLocale);
    }

    if (isCompany() && !isCompanyStagingGroup()) {
      name = LanguageUtil.get(locale, "global");
    } else if (isControlPanel()) {
      name = LanguageUtil.get(locale, "control-panel");
    } else if (isGuest()) {
      Company company = CompanyLocalServiceUtil.getCompany(getCompanyId());

      Account account = company.getAccount();

      name = account.getName();
    } else if (isLayout()) {
      Layout layout = LayoutLocalServiceUtil.getLayout(getClassPK());

      name = layout.getName(locale);
    } else if (isLayoutPrototype()) {
      LayoutPrototype layoutPrototype =
          LayoutPrototypeLocalServiceUtil.getLayoutPrototype(getClassPK());

      name = layoutPrototype.getName(locale);
    } else if (isLayoutSetPrototype()) {
      LayoutSetPrototype layoutSetPrototype =
          LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(getClassPK());

      name = layoutSetPrototype.getName(locale);
    } else if (isOrganization()) {
      long organizationId = getOrganizationId();

      Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

      name = organization.getName();

      curGroup = organization.getGroup();
    } else if (isUser()) {
      long userId = getClassPK();

      User user = UserLocalServiceUtil.getUser(userId);

      name = user.getFullName();
    } else if (isUserGroup()) {
      long userGroupId = getClassPK();

      UserGroup userGroup = UserGroupLocalServiceUtil.getUserGroup(userGroupId);

      name = userGroup.getName();
    } else if (isUserPersonalSite()) {
      name = LanguageUtil.get(locale, "user-personal-site");
    }

    if (curGroup.isStaged() && !curGroup.isStagedRemotely() && curGroup.isStagingGroup()) {

      Group liveGroup = getLiveGroup();

      name = liveGroup.getDescriptiveName(locale);
    }

    return name;
  }