コード例 #1
0
ファイル: Tags.java プロジェクト: fraunhoferfokus/gemo
  /**
   * The search redirection.
   *
   * @return an empty string.
   */
  public String search() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    Object responseObject = facesContext.getExternalContext().getResponse();

    if (responseObject != null && responseObject instanceof ActionResponse) {
      ActionResponse actionResponse = (ActionResponse) responseObject;

      Query query = new Query();
      query.getTags().add(selectedTag);
      actionResponse.setEvent(
          new QName("http://fokus.fraunhofer.de/odplatform", "querydatasets"), query);

      String location = LiferayFacesContext.getInstance().getThemeDisplay().getPortalURL();
      Layout layout = LiferayFacesContext.getInstance().getThemeDisplay().getLayout();

      try {
        if (layout.isPublicLayout()) {
          location +=
              LiferayFacesContext.getInstance().getThemeDisplay().getPathFriendlyURLPublic();
        }

        location +=
            layout.hasScopeGroup()
                ? layout.getScopeGroup().getFriendlyURL()
                : layout.getGroup().getFriendlyURL();
        location += "/suchen";
      } catch (PortalException e) {
        e.printStackTrace();
      } catch (SystemException e) {
        e.printStackTrace();
      }

      try {
        facesContext.getExternalContext().redirect(location);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return "";
  }
コード例 #2
0
  protected void exportLayout(
      PortletDataContext portletDataContext,
      Portlet layoutConfigurationPortlet,
      LayoutCache layoutCache,
      List<Portlet> portlets,
      Map<String, Object[]> portletIds,
      boolean exportPermissions,
      boolean exportUserPermissions,
      Layout layout,
      Element layoutsElement)
      throws Exception {

    String path = portletDataContext.getLayoutPath(layout.getLayoutId()) + "/layout.xml";

    if (!portletDataContext.isPathNotProcessed(path)) {
      return;
    }

    LayoutRevision layoutRevision = null;

    if (LayoutStagingUtil.isBranchingLayout(layout)) {
      ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

      long layoutSetBranchId = ParamUtil.getLong(serviceContext, "layoutSetBranchId");

      if (layoutSetBranchId <= 0) {
        return;
      }

      layoutRevision = LayoutRevisionUtil.fetchByL_H_P(layoutSetBranchId, true, layout.getPlid());

      if (layoutRevision == null) {
        return;
      }

      LayoutStagingHandler layoutStagingHandler = LayoutStagingUtil.getLayoutStagingHandler(layout);

      layoutStagingHandler.setLayoutRevision(layoutRevision);
    }

    Element layoutElement = layoutsElement.addElement("layout");

    if (layoutRevision != null) {
      layoutElement.addAttribute(
          "layout-revision-id", String.valueOf(layoutRevision.getLayoutRevisionId()));
      layoutElement.addAttribute(
          "layout-branch-id", String.valueOf(layoutRevision.getLayoutBranchId()));
      layoutElement.addAttribute(
          "layout-branch-name", String.valueOf(layoutRevision.getLayoutBranch().getName()));
    }

    layoutElement.addAttribute("layout-uuid", layout.getUuid());
    layoutElement.addAttribute("layout-id", String.valueOf(layout.getLayoutId()));

    long parentLayoutId = layout.getParentLayoutId();

    if (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
      Layout parentLayout =
          LayoutLocalServiceUtil.getLayout(
              layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);

      if (parentLayout != null) {
        layoutElement.addAttribute("parent-layout-uuid", parentLayout.getUuid());
      }
    }

    boolean deleteLayout =
        MapUtil.getBoolean(portletDataContext.getParameterMap(), "delete_" + layout.getPlid());

    if (deleteLayout) {
      layoutElement.addAttribute("delete", String.valueOf(true));

      return;
    }

    portletDataContext.setPlid(layout.getPlid());

    if (layout.isIconImage()) {
      Image image = ImageLocalServiceUtil.getImage(layout.getIconImageId());

      if (image != null) {
        String iconPath = getLayoutIconPath(portletDataContext, layout, image);

        layoutElement.addElement("icon-image-path").addText(iconPath);

        portletDataContext.addZipEntry(iconPath, image.getTextObj());
      }
    }

    _portletExporter.exportPortletData(
        portletDataContext, layoutConfigurationPortlet, layout, null, layoutElement);

    // Layout permissions

    if (exportPermissions) {
      _permissionExporter.exportLayoutPermissions(
          portletDataContext,
          layoutCache,
          portletDataContext.getCompanyId(),
          portletDataContext.getScopeGroupId(),
          layout,
          layoutElement,
          exportUserPermissions);
    }

    if (layout.isTypeArticle()) {
      exportJournalArticle(portletDataContext, layout, layoutElement);
    } else if (layout.isTypeLinkToLayout()) {
      UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

      long linkToLayoutId =
          GetterUtil.getLong(
              typeSettingsProperties.getProperty("linkToLayoutId", StringPool.BLANK));

      if (linkToLayoutId > 0) {
        try {
          Layout linkedToLayout =
              LayoutLocalServiceUtil.getLayout(
                  portletDataContext.getScopeGroupId(), layout.isPrivateLayout(), linkToLayoutId);

          exportLayout(
              portletDataContext,
              layoutConfigurationPortlet,
              layoutCache,
              portlets,
              portletIds,
              exportPermissions,
              exportUserPermissions,
              linkedToLayout,
              layoutsElement);
        } catch (NoSuchLayoutException nsle) {
        }
      }
    } else if (layout.isTypePortlet()) {
      for (Portlet portlet : portlets) {
        if (portlet.isScopeable() && layout.hasScopeGroup()) {
          String key =
              PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portlet.getPortletId());

          portletIds.put(
              key,
              new Object[] {
                portlet.getPortletId(),
                layout.getPlid(),
                layout.getScopeGroup().getGroupId(),
                StringPool.BLANK,
                layout.getUuid()
              });
        }
      }

      LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

      for (String portletId : layoutTypePortlet.getPortletIds()) {
        javax.portlet.PortletPreferences jxPreferences =
            PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

        String scopeType = GetterUtil.getString(jxPreferences.getValue("lfrScopeType", null));
        String scopeLayoutUuid =
            GetterUtil.getString(jxPreferences.getValue("lfrScopeLayoutUuid", null));

        long scopeGroupId = portletDataContext.getScopeGroupId();

        if (Validator.isNotNull(scopeType)) {
          Group scopeGroup = null;

          if (scopeType.equals("company")) {
            scopeGroup = GroupLocalServiceUtil.getCompanyGroup(layout.getCompanyId());
          } else if (scopeType.equals("layout")) {
            Layout scopeLayout = null;

            scopeLayout =
                LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
                    scopeLayoutUuid, portletDataContext.getGroupId());

            if (scopeLayout == null) {
              continue;
            }

            scopeGroup = scopeLayout.getScopeGroup();
          } else {
            throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
          }

          if (scopeGroup != null) {
            scopeGroupId = scopeGroup.getGroupId();
          }
        }

        String key = PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId);

        portletIds.put(
            key,
            new Object[] {portletId, layout.getPlid(), scopeGroupId, scopeType, scopeLayoutUuid});
      }
    }

    fixTypeSettings(layout);

    layoutElement.addAttribute("path", path);

    portletDataContext.addExpando(layoutElement, path, layout);

    portletDataContext.addZipEntry(path, layout);
  }
コード例 #3
0
  protected void exportLayout(
      PortletDataContext portletDataContext,
      List<Portlet> portlets,
      long[] layoutIds,
      Map<String, Object[]> portletIds,
      Layout layout)
      throws Exception {

    if (!ArrayUtil.contains(layoutIds, layout.getLayoutId())
        && (layoutIds != null)
        && (layoutIds.length > 0)) {

      Element layoutElement = portletDataContext.getExportDataElement(layout);

      layoutElement.addAttribute("action", Constants.SKIP);

      return;
    }

    StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, layout);

    if (!layout.isSupportsEmbeddedPortlets()) {

      // Only portlet type layouts support page scoping

      return;
    }

    if (layout.isTypePortlet()) {
      for (Portlet portlet : portlets) {
        if (portlet.isScopeable() && layout.hasScopeGroup()) {
          String key =
              PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portlet.getPortletId());

          Group scopeGroup = layout.getScopeGroup();

          portletIds.put(
              key,
              new Object[] {
                portlet.getPortletId(),
                layout.getPlid(),
                scopeGroup.getGroupId(),
                StringPool.BLANK,
                layout.getUuid()
              });
        }
      }
    }

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    // The getAllPortlets method returns all effective nonsystem portlets
    // for any layout type, including embedded portlets, or in the case of
    // panel type layout, selected portlets

    for (Portlet portlet : layoutTypePortlet.getAllPortlets(false)) {
      String portletId = portlet.getPortletId();

      javax.portlet.PortletPreferences jxPortletPreferences =
          PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

      String scopeType = GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeType", null));
      String scopeLayoutUuid =
          GetterUtil.getString(jxPortletPreferences.getValue("lfrScopeLayoutUuid", null));

      long scopeGroupId = portletDataContext.getScopeGroupId();

      if (Validator.isNotNull(scopeType)) {
        Group scopeGroup = null;

        if (scopeType.equals("company")) {
          scopeGroup = GroupLocalServiceUtil.getCompanyGroup(layout.getCompanyId());
        } else if (scopeType.equals("layout")) {
          Layout scopeLayout = null;

          scopeLayout =
              LayoutLocalServiceUtil.fetchLayoutByUuidAndGroupId(
                  scopeLayoutUuid,
                  portletDataContext.getGroupId(),
                  portletDataContext.isPrivateLayout());

          if (scopeLayout == null) {
            continue;
          }

          scopeGroup = scopeLayout.getScopeGroup();
        } else {
          throw new IllegalArgumentException("Scope type " + scopeType + " is invalid");
        }

        if (scopeGroup != null) {
          scopeGroupId = scopeGroup.getGroupId();
        }
      }

      String key = PortletPermissionUtil.getPrimaryKey(layout.getPlid(), portletId);

      portletIds.put(
          key,
          new Object[] {portletId, layout.getPlid(), scopeGroupId, scopeType, scopeLayoutUuid});
    }
  }
コード例 #4
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);
    }
  }
コード例 #5
0
ファイル: SearchQuery.java プロジェクト: fraunhoferfokus/gemo
  /**
   * Submit.
   *
   * @return the string
   */
  public void submit() {
    // Query q = new Query();
    // q.setSearchterm(query);

    ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay();
    Layout layout = themeDisplay.getLayout();
    String currentPage = layout.getFriendlyURL();

    FacesContext facesContext = FacesContext.getCurrentInstance();
    Object responseObject = facesContext.getExternalContext().getResponse();
    if (responseObject != null && responseObject instanceof ActionResponse) {
      ActionResponse actionResponse = (ActionResponse) responseObject;
      // actionResponse.setEvent(new
      // QName("http://fokus.fraunhofer.de/odplatform", "querydatasets"),
      // q);

      if (query != null && !query.isEmpty()) {
        log.info("searching for '{}'", query);
        // String escapedQuery = StringEscapeUtils.escapeHtml(query);
        String escapedQuery = StringUtils.escapeColonString(query);
        // msg 8:5.2014 actionResponse.setRenderParameter("searchterm",
        // query);
        escapedQuery = StringUtils.removeBlankStrings(query);
        log.info("escapedQuery:" + escapedQuery);
        actionResponse.setRenderParameter("searchterm", escapedQuery);
      } else {
        actionResponse.removePublicRenderParameter("searchterm");
      }

      actionResponse.removePublicRenderParameter("searchcategory");
    }

    // if (currentPage.equals("/home")) {
    String location = themeDisplay.getPortalURL();
    if (layout.isPublicLayout()) {
      location += themeDisplay.getPathFriendlyURLPublic();
    }

    try {
      location +=
          layout.hasScopeGroup()
              ? layout.getScopeGroup().getFriendlyURL()
              : layout.getGroup().getFriendlyURL();
      if (currentPage.equals("/home")) {
        location += "/suchen";
      } else {
        location += layout.getFriendlyURL();
      }
    } catch (PortalException e) {
      log.error("add group to url", e);
    } catch (SystemException e) {
      log.error("add group to url", e);
    }

    try {
      facesContext.getExternalContext().redirect(location);
    } catch (IOException e) {
      log.error("redirect to result page", e);
    }
    // }

  }
コード例 #6
0
  @Override
  public long getGroupIdFromScopeId(String scopeId, long siteGroupId, boolean privateLayout)
      throws PortalException, SystemException {

    if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) {
      String scopeIdSuffix = scopeId.substring(SCOPE_ID_CHILD_GROUP_PREFIX.length());

      return GetterUtil.getLong(scopeIdSuffix);
    } else if (scopeId.startsWith(SCOPE_ID_GROUP_PREFIX)) {
      String scopeIdSuffix = scopeId.substring(SCOPE_ID_GROUP_PREFIX.length());

      if (scopeIdSuffix.equals(GroupConstants.DEFAULT)) {
        return siteGroupId;
      }

      return GetterUtil.getLong(scopeIdSuffix);
    } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_UUID_PREFIX)) {
      String layoutUuid = scopeId.substring(SCOPE_ID_LAYOUT_UUID_PREFIX.length());

      Layout scopeIdLayout =
          LayoutLocalServiceUtil.getLayoutByUuidAndGroupId(layoutUuid, siteGroupId, privateLayout);

      Group scopeIdGroup = null;

      if (scopeIdLayout.hasScopeGroup()) {
        scopeIdGroup = scopeIdLayout.getScopeGroup();
      } else {
        scopeIdGroup =
            GroupLocalServiceUtil.addGroup(
                PrincipalThreadLocal.getUserId(),
                GroupConstants.DEFAULT_PARENT_GROUP_ID,
                Layout.class.getName(),
                scopeIdLayout.getPlid(),
                GroupConstants.DEFAULT_LIVE_GROUP_ID,
                String.valueOf(scopeIdLayout.getPlid()),
                null,
                0,
                null,
                false,
                true,
                null);
      }

      return scopeIdGroup.getGroupId();
    } else if (scopeId.startsWith(SCOPE_ID_LAYOUT_PREFIX)) {

      // Legacy preferences

      String scopeIdSuffix = scopeId.substring(SCOPE_ID_LAYOUT_PREFIX.length());

      long scopeIdLayoutId = GetterUtil.getLong(scopeIdSuffix);

      Layout scopeIdLayout =
          LayoutLocalServiceUtil.getLayout(siteGroupId, privateLayout, scopeIdLayoutId);

      Group scopeIdGroup = scopeIdLayout.getScopeGroup();

      return scopeIdGroup.getGroupId();
    } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) {
      String scopeIdSuffix = scopeId.substring(SCOPE_ID_PARENT_GROUP_PREFIX.length());

      return GetterUtil.getLong(scopeIdSuffix);
    } else {
      throw new IllegalArgumentException("Invalid scope ID " + scopeId);
    }
  }