@Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect) {

    try {
      ThemeDisplay themeDisplay =
          (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      User user = themeDisplay.getUser();

      long portletPlid =
          PortalUtil.getPlidFromPortletId(user.getGroupId(), true, PortletKeys.TASKS);

      PortletURL portletURL =
          PortletURLFactoryUtil.create(
              liferayPortletRequest, PortletKeys.TASKS, portletPlid, PortletRequest.RENDER_PHASE);

      portletURL.setParameter("mvcPath", "/tasks/view.jsp");

      return portletURL.toString();
    } catch (Exception e) {
    }

    return null;
  }
  protected Date getDate(String param, HttpServletRequest request) {
    int month = ParamUtil.getInteger(request, param + "Month");
    int day = ParamUtil.getInteger(request, param + "Day");
    int year = ParamUtil.getInteger(request, param + "Year");
    int hour = ParamUtil.getInteger(request, param + "Hour", -1);
    int minute = ParamUtil.getInteger(request, param + "Minute");

    int amPm = ParamUtil.getInteger(request, param + "AmPm");

    if (amPm == Calendar.PM) {
      hour += 12;
    }

    if (hour == -1) {
      return PortalUtil.getDate(month, day, year);
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    User user = themeDisplay.getUser();

    try {
      return PortalUtil.getDate(month, day, year, hour, minute, user.getTimeZone(), null);
    } catch (PortalException pe) {
      return null;
    }
  }
  protected String[][] getCategorySectionLabels() {
    if (_categorySections != null) {
      return _categorySections;
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String[] categoryKeys = getCategoryKeys();

    String[][] categorySectionLabels = new String[0][];

    for (int i = 0; i < categoryKeys.length; i++) {
      String categoryKey = categoryKeys[i];

      categorySectionLabels =
          ArrayUtil.append(
              categorySectionLabels,
              FormNavigatorEntryUtil.getLabels(
                  _id,
                  categoryKey,
                  themeDisplay.getUser(),
                  _formModelBean,
                  themeDisplay.getLocale()));
    }

    return categorySectionLabels;
  }
  protected void downloadApp(
      PortletRequest portletRequest,
      PortletResponse portletResponse,
      long appPackageId,
      boolean unlicensed,
      File file)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, getServerPortletURL());

    setBaseRequestParameters(portletRequest, portletResponse, oAuthRequest);

    String serverNamespace = getServerNamespace();

    addOAuthParameter(
        oAuthRequest, serverNamespace.concat("appPackageId"), String.valueOf(appPackageId));
    addOAuthParameter(oAuthRequest, "p_p_lifecycle", "2");

    if (unlicensed) {
      addOAuthParameter(oAuthRequest, "p_p_resource_id", "serveUnlicensedApp");
    } else {
      addOAuthParameter(oAuthRequest, "p_p_resource_id", "serveApp");
    }

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    FileUtil.write(file, response.getStream());
  }
  public void processAction(ActionRequest request, ActionResponse response)
      throws PortletException, IOException {
    _log.info("***processAction****");

    boolean error = false;

    String saveButton = (String) request.getParameter("saveButton");
    String resetButton = (String) request.getParameter("resetButton");

    _log.info("saveButton: " + saveButton);
    _log.info("resetButton: " + resetButton);

    String nameTelescope = (String) request.getParameter("nameTelescope");
    String nameObservatory = (String) request.getParameter("nameObservatory");
    String briefDescription = (String) request.getParameter("briefDescription");
    String nameCountry = (String) request.getParameter("nameCountry");
    String nameCity = (String) request.getParameter("nameCity");
    String latitude = (String) request.getParameter("latitude");
    String longitude = (String) request.getParameter("longitude");
    String urlTelescope = (String) request.getParameter("urlTelescope");

    _log.info("nameTelescope: " + nameTelescope);
    _log.info("nameObservatory: " + nameObservatory);
    _log.info("briefDescription: " + briefDescription);
    _log.info("nameCountry: " + nameCountry);
    _log.info("nameCity: " + nameCity);
    _log.info("latitude: " + latitude);
    _log.info("longitude: " + longitude);
    _log.info("urlTelescope: " + urlTelescope);

    ThemeDisplay td = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    User user = td.getUser();
    _log.info("user: "******"error01");
    }

    try {
      repository.registerObservatory(nameObservatory, nameCity, nameCountry);
    } catch (RTRepositoryException_Exception e) {
      error = true;
      _log.error(e.getMessage());
    } catch (Exception e) {
      _log.error(e.getMessage());
    } finally {
      SessionErrors.add(request, "error01");
    }

    if (!error) SessionMessages.add(request, "success");
  }
  public void getPrepackagedApps(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, getServerPortletURL());

    setBaseRequestParameters(actionRequest, actionResponse, oAuthRequest);

    addOAuthParameter(oAuthRequest, "p_p_lifecycle", "1");
    addOAuthParameter(oAuthRequest, "p_p_state", WindowState.NORMAL.toString());

    String serverNamespace = getServerNamespace();

    addOAuthParameter(
        oAuthRequest,
        serverNamespace.concat("compatibility"),
        String.valueOf(ReleaseInfo.getBuildNumber()));
    addOAuthParameter(
        oAuthRequest, serverNamespace.concat("javax.portlet.action"), "getPrepackagedApps");

    Map<String, String> prepackagedApps = _appLocalService.getPrepackagedApps();

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    Set<String> keys = prepackagedApps.keySet();

    for (String key : keys) {
      jsonObject.put(key, prepackagedApps.get(key));
    }

    addOAuthParameter(
        oAuthRequest, serverNamespace.concat("prepackagedApps"), jsonObject.toString());

    Response response = getResponse(themeDisplay.getUser(), oAuthRequest);

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject(response.getBody());

    writeJSON(actionRequest, actionResponse, responseJSONObject);
  }
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

      Token accessToken = oAuthManager.getAccessToken(themeDisplay.getUser());

      if (accessToken == null) {
        include("/login.jsp", renderRequest, renderResponse);

        return;
      }
    } catch (PortalException pe) {
      throw new PortletException(pe);
    }

    renderRequest.setAttribute(MarketplaceStoreWebKeys.OAUTH_AUTHORIZED, Boolean.TRUE);

    super.doDispatch(renderRequest, renderResponse);
  }
  @Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect) {

    try {
      ThemeDisplay themeDisplay =
          (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);

      User user = themeDisplay.getUser();

      long portletPlid =
          PortalUtil.getPlidFromPortletId(user.getGroupId(), true, "1_WAR_microblogsportlet");

      PortletURL portletURL =
          PortletURLFactoryUtil.create(
              liferayPortletRequest,
              "1_WAR_microblogsportlet",
              portletPlid,
              PortletRequest.RENDER_PHASE);

      portletURL.setParameter("mvcPath", "/microblogs/view.jsp");

      long microblogsEntryId = _entry.getMicroblogsEntryId();

      if (_entry.getReceiverMicroblogsEntryId() > 0) {
        microblogsEntryId = _entry.getReceiverMicroblogsEntryId();
      }

      portletURL.setParameter("receiverMicroblogsEntryId", String.valueOf(microblogsEntryId));

      return portletURL.toString();
    } catch (Exception e) {
    }

    return null;
  }
  public void saveOrUpdateBrokerMessageListener(ActionRequest request, ActionResponse response)
      throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    PortletConfig portletConfig =
        (PortletConfig) request.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);

    long brokerMessageListenerId = ParamUtil.getLong(request, "brokerMessageListenerId");
    boolean isNew = brokerMessageListenerId == 0;
    BrokerMessageListener bml = null;

    if (!isNew) {
      bml =
          BrokerMessageListenerLocalServiceUtil.fetchBrokerMessageListener(brokerMessageListenerId);

    } else {
      bml =
          BrokerMessageListenerLocalServiceUtil.createBrokerMessageListener(
              CounterLocalServiceUtil.increment(BrokerMessageListener.class.getName()));
      bml.setCreateDate(new Date());
    }

    if (isNew
            && BrokerModelPermission.contains(
                themeDisplay.getPermissionChecker(),
                themeDisplay.getScopeGroupId(),
                ActionKeys.ADD_ENTRY)
        || !isNew
            && BrokerMessageListenerPermission.contains(
                themeDisplay.getPermissionChecker(), bml, ActionKeys.UPDATE)) {
      try {
        String brokerMessageListenerName = ParamUtil.getString(request, "name");
        String brokerMessageListenerDescription = ParamUtil.getString(request, "description");
        long brokerId = ParamUtil.getLong(request, "brokerId");
        String[] topicsArr = ParamUtil.getParameterValues(request, "topic");
        StringBuilder topics = new StringBuilder();
        for (int i = 0; i < topicsArr.length; i++) {
          topics.append(topicsArr[i] + ";");
        }
        String typeStr = ParamUtil.getString(request, "type");
        BrokerMessageListenerType type = BrokerMessageListenerType.valueOf(typeStr);

        bml.setCompanyId(themeDisplay.getCompanyId());
        bml.setGroupId(themeDisplay.getCompanyGroupId());
        bml.setUserName(themeDisplay.getUser().getScreenName());
        bml.setUserId(themeDisplay.getUserId());
        bml.setModifiedDate(new Date());
        bml.setName(brokerMessageListenerName);
        bml.setDescription(brokerMessageListenerDescription);
        bml.setBrokerId(brokerId);
        bml.setTopics(topics.toString());
        bml.setType(typeStr);
        if (type.equals(BrokerMessageListenerType.MESSAGE_BUS)) {
          String messageBusDestination = ParamUtil.getString(request, "messageBusDestination");
          bml.setMessageBusDestination(messageBusDestination);
        }

        BrokerMessageListenerLocalServiceUtil.saveOrUpdateBrokerMessageListener(
            bml, themeDisplay.getLocale(), portletConfig);
      } catch (Exception e) {
        response.setRenderParameter("mvcPath", "/html/brokermessagelistener/edit.jsp");
        response.setRenderParameter("errorMessage", e.getMessage());
        request.setAttribute("brokerMessageListener", bml);
        SessionErrors.add(request, "it.acsoftware.brokerportlet.error");
      }
    }
  }
示例#10
0
  @Override
  public int doStartTag() throws JspException {
    NavBarTag navBarTag = (NavBarTag) findAncestorWithClass(this, NavBarTag.class);

    if ((navBarTag != null) && (!_calledCollapsibleSetter || getCollapsible())) {

      setCollapsible(true);

      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      StringBundler sb = navBarTag.getResponsiveButtonsSB();

      sb.append("<a class=\"btn navbar-btn navbar-toggle");

      String cssClass = getCssClass();

      if (Validator.isNotNull(cssClass)) {
        String[] cssClassParts = StringUtil.split(cssClass, CharPool.SPACE);

        for (int i = 0; i < cssClassParts.length; i++) {
          sb.append(StringPool.SPACE);
          sb.append(cssClassParts[i]);
          sb.append("-btn");
        }
      }

      if (_hasSearchResults()) {
        sb.append(" hide");
      }

      sb.append("\" id=\"");
      sb.append(_getNamespacedId());
      sb.append("NavbarBtn\" ");
      sb.append("data-navId=\"");
      sb.append(_getNamespacedId());
      sb.append("\" tabindex=\"0\">");

      String icon = getIcon();

      if (Validator.isNull(icon)) {
        sb.append("<i class=\"icon-reorder\"></i>");
      } else if (icon.equals("user") && themeDisplay.isSignedIn()) {
        try {
          User user = themeDisplay.getUser();

          sb.append("<img alt=\"");
          sb.append(LanguageUtil.get(request, "my-account"));
          sb.append("\" class=\"user-avatar-image\" ");
          sb.append("src=\"");
          sb.append(user.getPortraitURL(themeDisplay));
          sb.append("\">");
        } catch (Exception e) {
          throw new JspException(e);
        }
      } else {
        sb.append("<i class=\"icon-");
        sb.append(icon);
        sb.append("\"></i>");
      }

      sb.append("</a>");
    }

    return super.doStartTag();
  }
示例#11
0
  public static String getLayoutsJSON(
      HttpServletRequest request,
      long groupId,
      boolean privateLayout,
      long parentLayoutId,
      long[] expandedLayoutIds)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    List<Layout> layoutAncestors = null;

    long selPlid = ParamUtil.getLong(request, "selPlid");

    if (selPlid != 0) {
      Layout selLayout = LayoutLocalServiceUtil.getLayout(selPlid);

      layoutAncestors = selLayout.getAncestors();
    }

    List<Layout> layouts = getLayouts(request, groupId, privateLayout, parentLayoutId);

    for (Layout layout : layouts) {
      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      if ((layoutAncestors != null) && layoutAncestors.contains(layout)
          || ArrayUtil.contains(expandedLayoutIds, layout.getLayoutId())) {

        String childrenJSON = StringPool.BLANK;

        if (layout instanceof VirtualLayout) {
          VirtualLayout virtualLayout = (VirtualLayout) layout;

          childrenJSON =
              getLayoutsJSON(
                  request,
                  virtualLayout.getSourceGroupId(),
                  virtualLayout.getPrivateLayout(),
                  virtualLayout.getLayoutId(),
                  expandedLayoutIds);

        } else {
          childrenJSON =
              getLayoutsJSON(
                  request,
                  groupId,
                  layout.getPrivateLayout(),
                  layout.getLayoutId(),
                  expandedLayoutIds);
        }

        jsonObject.put("children", JSONFactoryUtil.createJSONArray(childrenJSON));
      }

      jsonObject.put("contentDisplayPage", layout.isContentDisplayPage());
      jsonObject.put("friendlyURL", layout.getFriendlyURL());

      if (layout instanceof VirtualLayout) {
        VirtualLayout virtualLayout = (VirtualLayout) layout;

        jsonObject.put("groupId", virtualLayout.getSourceGroupId());
      } else {
        jsonObject.put("groupId", layout.getGroupId());
      }

      jsonObject.put("hasChildren", layout.hasChildren());
      jsonObject.put("layoutId", layout.getLayoutId());
      jsonObject.put("name", layout.getName(themeDisplay.getLocale()));
      jsonObject.put("parentLayoutId", layout.getParentLayoutId());
      jsonObject.put("plid", layout.getPlid());
      jsonObject.put("priority", layout.getPriority());
      jsonObject.put("privateLayout", layout.isPrivateLayout());
      jsonObject.put("type", layout.getType());
      jsonObject.put("updateable", SitesUtil.isLayoutUpdateable(layout));
      jsonObject.put("uuid", layout.getUuid());

      LayoutRevision layoutRevision = LayoutStagingUtil.getLayoutRevision(layout);

      if (layoutRevision != null) {
        User user = themeDisplay.getUser();

        long recentLayoutSetBranchId =
            StagingUtil.getRecentLayoutSetBranchId(user, layout.getLayoutSet().getLayoutSetId());

        if (StagingUtil.isIncomplete(layout, recentLayoutSetBranchId)) {
          jsonObject.put("incomplete", true);
        }

        long layoutSetBranchId = layoutRevision.getLayoutSetBranchId();

        LayoutSetBranch layoutSetBranch =
            LayoutSetBranchLocalServiceUtil.getLayoutSetBranch(layoutSetBranchId);

        LayoutBranch layoutBranch = layoutRevision.getLayoutBranch();

        if (!layoutBranch.isMaster()) {
          jsonObject.put("layoutBranchId", layoutBranch.getLayoutBranchId());
          jsonObject.put("layoutBranchName", layoutBranch.getName());
        }

        jsonObject.put("layoutRevisionId", layoutRevision.getLayoutRevisionId());
        jsonObject.put("layoutSetBranchId", layoutSetBranchId);
        jsonObject.put("layoutSetBranchName", layoutSetBranch.getName());
      }

      jsonArray.put(jsonObject);
    }

    return jsonArray.toString();
  }
  public AssetEntryQuery getAssetEntryQuery() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    long[] groupIds = getGroupIds();

    if (!ArrayUtil.contains(groupIds, themeDisplay.getScopeGroupId())) {
      groupIds = ArrayUtil.append(groupIds, themeDisplay.getScopeGroupId());
    }

    AssetEntryQuery assetEntryQuery =
        AssetPublisherUtil.getAssetEntryQuery(_portletPreferences, groupIds);

    long[] classNameIds = getClassNameIds();
    long[] classTypeIds = getClassTypeIds();

    if (isSubtypeFieldsFilterEnabled()
        && (classNameIds.length == 1)
        && (classTypeIds.length == 1)
        && Validator.isNotNull(getDDMStructureFieldName())
        && Validator.isNotNull(getDDMStructureFieldValue())) {

      AssetRendererFactory assetRendererFactory =
          AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(
              PortalUtil.getClassName(classNameIds[0]));

      Tuple classTypeFieldName =
          assetRendererFactory.getClassTypeFieldName(
              classTypeIds[0], getDDMStructureFieldName(), themeDisplay.getLocale());

      long ddmStructureId = GetterUtil.getLong(classTypeFieldName.getObject(3));

      assetEntryQuery.setAttribute(
          "ddmStructureFieldName",
          DDMIndexerUtil.encodeName(
              ddmStructureId, getDDMStructureFieldName(), themeDisplay.getLocale()));
      assetEntryQuery.setAttribute("ddmStructureFieldValue", getDDMStructureFieldValue());
    }

    AssetPublisherUtil.processAssetEntryQuery(
        themeDisplay.getUser(), _portletPreferences, assetEntryQuery);

    assetEntryQuery.setAllCategoryIds(getAllAssetCategoryIds());

    if (hasLayoutGroup(groupIds)) {
      assetEntryQuery.setAllTagIds(
          AssetTagLocalServiceUtil.getTagIds(groupIds, getAllAssetTagNames()));
    } else {
      assetEntryQuery.setAllTagIds(
          AssetTagLocalServiceUtil.getTagIds(getGroupIds(), getAllAssetTagNames()));
    }

    assetEntryQuery.setClassTypeIds(classTypeIds);
    assetEntryQuery.setEnablePermissions(isEnablePermissions());
    assetEntryQuery.setExcludeZeroViewCount(isExcludeZeroViewCount());

    String portletName = getPortletName();

    if (!portletName.equals(PortletKeys.RELATED_ASSETS)) {
      assetEntryQuery.setGroupIds(getGroupIds());
    }

    if (isShowOnlyLayoutAssets()) {
      assetEntryQuery.setLayout(themeDisplay.getLayout());
    }

    if (portletName.equals(PortletKeys.RELATED_ASSETS)) {
      AssetEntry layoutAssetEntry = (AssetEntry) _request.getAttribute(WebKeys.LAYOUT_ASSET_ENTRY);

      if (layoutAssetEntry != null) {
        assetEntryQuery.setLinkedAssetEntryId(layoutAssetEntry.getEntryId());
      }
    }

    assetEntryQuery.setPaginationType(getPaginationType());
    assetEntryQuery.setOrderByCol1(getOrderByColumn1());
    assetEntryQuery.setOrderByCol2(getOrderByColumn2());
    assetEntryQuery.setOrderByType1(getOrderByType1());
    assetEntryQuery.setOrderByType2(getOrderByType2());

    return assetEntryQuery;
  }
  protected ActionForward processLayout(
      ActionMapping mapping, HttpServletRequest request, HttpServletResponse response, long plid)
      throws Exception {

    HttpSession session = request.getSession();

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    try {
      Layout layout = themeDisplay.getLayout();

      boolean resetLayout =
          ParamUtil.getBoolean(request, "p_l_reset", PropsValues.LAYOUT_DEFAULT_P_L_RESET);

      String portletId = ParamUtil.getString(request, "p_p_id");

      Layout previousLayout = (Layout) session.getAttribute(WebKeys.PREVIOUS_LAYOUT);

      if ((previousLayout == null) || (layout.getPlid() != previousLayout.getPlid())) {

        session.setAttribute(WebKeys.PREVIOUS_LAYOUT, layout);

        if (themeDisplay.isSignedIn()
            && PropsValues.AUDIT_MESSAGE_COM_LIFERAY_PORTAL_MODEL_LAYOUT_VIEW
            && MessageBusUtil.hasMessageListener(DestinationNames.AUDIT)) {

          User user = themeDisplay.getUser();

          AuditMessage auditMessage =
              new AuditMessage(
                  ActionKeys.VIEW,
                  user.getCompanyId(),
                  user.getUserId(),
                  user.getFullName(),
                  Layout.class.getName(),
                  String.valueOf(layout.getPlid()));

          AuditRouterUtil.route(auditMessage);
        }
      }

      if (!PropsValues.TCK_URL
          && resetLayout
          && (Validator.isNull(portletId)
              || ((previousLayout != null) && (layout.getPlid() != previousLayout.getPlid())))) {

        // Always clear render parameters on a layout url, but do not
        // clear on portlet urls invoked on the same layout

        RenderParametersPool.clear(request, plid);
      }

      if (themeDisplay.isLifecycleAction()) {
        Portlet portlet = processPortletRequest(request, response, PortletRequest.ACTION_PHASE);

        if (portlet != null) {
          ActionResponseImpl actionResponseImpl =
              (ActionResponseImpl) request.getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);

          String redirectLocation = actionResponseImpl.getRedirectLocation();

          if (Validator.isNotNull(redirectLocation)) {
            response.sendRedirect(redirectLocation);

            return null;
          }

          if (portlet.isActionURLRedirect()) {
            redirectActionURL(request, response, actionResponseImpl, portlet);

            return null;
          }
        }
      } else if (themeDisplay.isLifecycleRender()) {
        processPortletRequest(request, response, PortletRequest.RENDER_PHASE);
      }

      if (themeDisplay.isLifecycleResource()) {
        processPortletRequest(request, response, PortletRequest.RESOURCE_PHASE);

        return null;
      } else {
        if (response.isCommitted()) {
          return null;
        }

        if (layout != null) {

          // Include layout content before the page loads because
          // portlets on the page can set the page title and page
          // subtitle

          includeLayoutContent(request, response, themeDisplay, layout);

          if (themeDisplay.isStateExclusive()) {
            renderExclusive(request, response, themeDisplay);

            return null;
          }
        }

        return mapping.findForward("portal.layout");
      }
    } catch (Exception e) {
      PortalUtil.sendError(e, request, response);

      return null;
    } finally {
      if (!ServerDetector.isResin()) {
        PortletRequest portletRequest =
            (PortletRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);

        if (portletRequest != null) {
          PortletRequestImpl portletRequestImpl = (PortletRequestImpl) portletRequest;

          portletRequestImpl.cleanUp();
        }
      }
    }
  }
  public String search(
      HttpServletRequest request,
      long groupId,
      long userId,
      String keywords,
      int startPage,
      int itemsPerPage,
      String format)
      throws SearchException {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

      int start = (startPage * itemsPerPage) - itemsPerPage;
      int end = startPage * itemsPerPage;

      Hits results =
          CompanyLocalServiceUtil.search(themeDisplay.getCompanyId(), userId, keywords, start, end);

      String[] queryTerms = results.getQueryTerms();

      int total = results.getLength();

      Object[] values =
          addSearchResults(
              queryTerms,
              keywords,
              startPage,
              itemsPerPage,
              total,
              start,
              "Liferay Portal Search: " + keywords,
              SEARCH_PATH,
              format,
              themeDisplay);

      com.liferay.portal.kernel.xml.Document doc =
          (com.liferay.portal.kernel.xml.Document) values[0];
      Element root = (Element) values[1];

      for (int i = 0; i < results.getDocs().length; i++) {
        Document result = results.doc(i);

        String portletId = result.get(Field.PORTLET_ID);

        Portlet portlet =
            PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), portletId);

        if (portlet == null) {
          continue;
        }

        String portletTitle = PortalUtil.getPortletTitle(portletId, themeDisplay.getUser());

        long resultGroupId = GetterUtil.getLong(result.get(Field.GROUP_ID));

        String entryClassName = GetterUtil.getString(result.get(Field.ENTRY_CLASS_NAME));

        long entryClassPK = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK));

        String title = StringPool.BLANK;

        PortletURL portletURL = getPortletURL(request, portletId, resultGroupId);

        String url = portletURL.toString();

        Date modifedDate = result.getDate(Field.MODIFIED);

        String content = StringPool.BLANK;

        if (Validator.isNotNull(portlet.getIndexerClass())) {
          Indexer indexer = (Indexer) InstancePool.get(portlet.getIndexerClass());

          String snippet = results.snippet(i);

          Summary summary = indexer.getSummary(result, snippet, portletURL);

          title = summary.getTitle();
          url = portletURL.toString();
          content = summary.getContent();

          if (portlet.getPortletId().equals(PortletKeys.JOURNAL)) {
            url = getJournalURL(themeDisplay, resultGroupId, result);
          }
        }

        double score = results.score(i);

        addSearchResult(
            root,
            resultGroupId,
            entryClassName,
            entryClassPK,
            portletTitle + " " + CharPool.RAQUO + " " + title,
            url,
            modifedDate,
            content,
            score,
            format);
      }

      if (_log.isDebugEnabled()) {
        _log.debug("Return\n" + doc.asXML());
      }

      return doc.asXML();

    } catch (Exception e) {
      throw new SearchException(e);
    }
  }