Exemplo n.º 1
0
  @Override
  public void render(RenderRequest req, RenderResponse res) throws PortletException, IOException {
    // TODO Auto-generated method stub

    PortletPreferences prefs = req.getPreferences();
    try {
      List listCategory = ClipTypeServiceUtil.findAll();
      List listTopClip = ClipServiceUtil.getAll(0, 5);
      req.setAttribute(WebKeysVClip.CLIP_TYPE_RESULT_SEARCH, listCategory);

      String obj = ParamUtil.getString(req, WebKeysVClip.OBJECT);

      if (obj.equals(ClipType.class.getName())) {
        String clipTypeId = ParamUtil.getString(req, WebKeysVClip.CLIP_TYPE_ID);
        ClipType tfCategory = new ClipTypeImpl();
        if (Validator.isNotNull(Long.valueOf(clipTypeId))) {
          tfCategory = ClipTypeServiceUtil.findById(clipTypeId);
        }
        req.setAttribute("tfCategory", tfCategory);

        Clip clipFirst = ClipServiceUtil.getByClipTypeId(clipTypeId);
        req.setAttribute(WebKeysVClip.CLIP, clipFirst);

      } else {
        Clip clipSecond = ClipServiceUtil.getFirst();
        req.setAttribute(WebKeysVClip.CLIP, clipSecond);
        req.setAttribute(WebKeysVClip.LIST_TOP_CLIP, listTopClip);
      }
    } catch (Exception e) {
      // TODO: handle exception
    }

    super.render(req, res);
  }
Exemplo n.º 2
0
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws PortletException, IOException {

    try {
      int status = getStatus(renderRequest);

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);

      KBArticle kbArticle = null;

      long resourcePrimKey = ParamUtil.getLong(renderRequest, "resourcePrimKey");

      if (resourcePrimKey > 0) {
        kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status);
      }

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException || e instanceof PrincipalException) {

        SessionErrors.add(renderRequest, e.getClass().getName());
      } else {
        throw new PortletException(e);
      }
    }

    super.render(renderRequest, renderResponse);
  }
  @Override
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    LOGGER.info("do view  AssetCategoriesImporter");
    super.doView(renderRequest, renderResponse);
  }
Exemplo n.º 4
0
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws PortletException, IOException {

    try {
      int status = getStatus(renderRequest);

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);

      KBArticle kbArticle = null;

      long resourcePrimKey = getResourcePrimKey(renderRequest);

      if (resourcePrimKey > 0) {
        kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status);
      }

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException || e instanceof PrincipalException) {

        SessionErrors.add(renderRequest, e.getClass().getName());

        PortletConfig portletConfig = getPortletConfig();

        SessionMessages.add(
            renderRequest,
            portletConfig.getPortletName() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
      } else {
        throw new PortletException(e);
      }
    }

    super.render(renderRequest, renderResponse);
  }
  @Override
  public void serveResource(ResourceRequest request, ResourceResponse response)
      throws IOException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    String layoutPK = String.valueOf(themeDisplay.getLayout().getPrimaryKey());

    String action = ParamUtil.getString(request, CMD);

    if (action.equals(NOTCOMPLETED)) {
      String userId = ParamUtil.getString(request, USER_ID);
      Date currentDate = new Date();

      AnnouncerTools.addToNotCompleted(userId, layoutPK, currentDate);

    } else if (action.equals(COMPLETED)) {
      String userId = ParamUtil.getString(request, USER_ID);
      String articleSerial = ParamUtil.getString(request, ARTICLE_SERIAL);

      AnnouncerTools.addToCompleted(userId, layoutPK, articleSerial);

    } else if (UPDATE_ARTICLE_SELECTION.equalsIgnoreCase(action)) {

      String articleId = ParamUtil.getString(request, ARTICLE_ID);
      updateArticleSelection(request, response, articleId);
    } else if (IS_CHECKED.equalsIgnoreCase(action)) {
      String articleId = ParamUtil.getString(request, ARTICLE_ID);
      isChecked(request, response, articleId);
    }

    super.serveResource(request, response);
  }
  @Override
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    renderRequest.setAttribute("now", new Date());

    super.doView(renderRequest, renderResponse);
  }
Exemplo n.º 7
0
 public void init() throws PortletException {
   super.init();
   _responseJSP = getInitParameter("response-view");
   _defaultJSP = getInitParameter("view-template");
   _proxyHandler = new ProxyHandler();
   // create default portlet action
   log.info("init");
 }
Exemplo n.º 8
0
  @Override
  protected void addSuccessMessage(ActionRequest actionRequest, ActionResponse actionResponse) {

    String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME);

    if (actionName.equals("updateAttachments")) {
      return;
    }

    super.addSuccessMessage(actionRequest, actionResponse);
  }
  @Override
  public void render(RenderRequest request, RenderResponse response)
      throws PortletException, IOException {

    PortletPreferences preferences = request.getPreferences();
    String defaultArticle = preferences.getValue(DEFAULT_ARTICLE, LR_EMPTY_VALUE);
    String[] addedArticleIds =
        preferences.getValue(ARTICLE_ID, LR_EMPTY_VALUE).split(ARTICLE_SELECTION_DELIMITER);
    request.setAttribute(DEFAULT_ARTICLE, defaultArticle);
    request.setAttribute(ADDED_ARTICLE_IDS, addedArticleIds);
    super.render(request, response);
  }
Exemplo n.º 10
0
  @Override
  protected void doDispatch(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    if (SessionErrors.contains(renderRequest, NoSuchArticleException.class.getName())
        || SessionErrors.contains(renderRequest, NoSuchCommentException.class.getName())
        || SessionErrors.contains(renderRequest, NoSuchSubscriptionException.class.getName())
        || SessionErrors.contains(renderRequest, PrincipalException.class.getName())) {

      include(templatePath + "error.jsp", renderRequest, renderResponse);
    } else {
      super.doDispatch(renderRequest, renderResponse);
    }
  }
Exemplo n.º 11
0
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws PortletException, IOException {

    PortletPreferences prefs = renderRequest.getPreferences();
    String[] guestbookEntries = prefs.getValues("guestbook-entries", new String[1]);

    if (guestbookEntries != null) {

      List<Entry> entries = parseEntries(guestbookEntries);

      renderRequest.setAttribute("entries", entries);
    }

    super.render(renderRequest, renderResponse);
  }
  @Override
  public void doEdit(RenderRequest request, RenderResponse response)
      throws IOException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long groupId = themeDisplay.getScopeGroupId();
    request.setAttribute(GROUP_ID, groupId);

    PortletPreferences preferences = request.getPreferences();
    String[] ids =
        preferences.getValue(ARTICLE_ID, LR_EMPTY_VALUE).split(ARTICLE_SELECTION_DELIMITER);
    String defaultArticle = preferences.getValue(DEFAULT_ARTICLE, LR_EMPTY_VALUE);
    request.setAttribute(DEFAULT_ARTICLE, defaultArticle);
    request.setAttribute(IDS, ids);

    super.doEdit(request, response);
  }
  /* (non-Javadoc)
   * @see com.liferay.util.bridges.mvc.MVCPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
   */
  @Override
  public void doView(RenderRequest request, RenderResponse response)
      throws IOException, PortletException {

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

    try {
      long[] categoryIds = new long[0];

      TipOfTheDayUtil.retrieveCategories(request, themeDisplay, categoryIds);

    } catch (Exception e) {
      logger.error("Error retrieving categories", e);
    }

    super.doView(request, response);
  }
  @Override
  public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
      throws PortletException {

    try {
      String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME);

      if (actionName.equals("deleteEntry")) {
        deleteEntry(actionRequest, actionResponse);
      } else if (actionName.equals("saveEntry")) {
        saveEntry(actionRequest, actionResponse);
      } else {
        super.processAction(actionRequest, actionResponse);
      }
    } catch (Exception e) {
      throw new PortletException(e);
    }
  }
Exemplo n.º 15
0
  @Override
  public void processAction(ActionRequest req, ActionResponse res)
      throws IOException, PortletException {
    // TODO Auto-generated method stub
    String cmd = ParamUtil.getString(req, Constants.CMD);
    String id = ParamUtil.getString(req, "clipId");
    try {
      if (cmd.equals(ConstantsExt.HITCOUNT)) {
        ClipServiceUtil.increaseHitCount(id);
      }
      if (cmd.equals(ConstantsExt.HITCOUNTVIEW)) {
        ClipServiceUtil.increaseHitCountView(id);
      }
    } catch (Exception ex) {

    }
    super.processAction(req, res);
  }
Exemplo n.º 16
0
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

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

      int status = getStatus(renderRequest);

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);

      KBArticle kbArticle = null;

      long resourcePrimKey = getResourcePrimKey(renderRequest);

      if (resourcePrimKey > 0) {
        kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status);
      } else {
        List<KBArticle> kbArticles =
            KBArticleLocalServiceUtil.getGroupKBArticles(
                themeDisplay.getScopeGroupId(), status, 0, 1, new KBArticlePriorityComparator());

        if (!kbArticles.isEmpty()) {
          kbArticle = kbArticles.get(0);
        }
      }

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException || e instanceof PrincipalException) {

        SessionErrors.add(renderRequest, e.getClass());

        SessionMessages.add(
            renderRequest,
            PortalUtil.getPortletId(renderRequest)
                + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
      } else {
        throw new PortletException(e);
      }
    }

    super.render(renderRequest, renderResponse);
  }
  @Override
  public void doView(RenderRequest request, RenderResponse response)
      throws IOException, PortletException {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    long groupId = themeDisplay.getScopeGroupId();

    PortletPreferences preferences = request.getPreferences();
    boolean showAnnouncer = false;
    if (themeDisplay.isSignedIn()) {
      String articleVersionId = preferences.getValue(ARTICLE_ID_CONSECUTIVE, LR_EMPTY_VALUE);
      String articleIds = preferences.getValue(ARTICLE_ID, LR_EMPTY_VALUE);
      if (!articleIds.equals(LR_EMPTY_VALUE)) {
        for (String articleId : articleIds.split(ARTICLE_SELECTION_DELIMITER)) {
          if (!AnnouncerTools.isArticle(groupId, articleId)) {
            AnnouncerTools.removeArticle(preferences, themeDisplay, articleId);
          }
          try {
            String layoutPK = String.valueOf(themeDisplay.getLayout().getPrimaryKey());
            showAnnouncer =
                AnnouncerTools.showAnnouncer(
                    themeDisplay.getRealUser().getUuid(), layoutPK, articleVersionId);
            request.setAttribute(ARTICLE_VERSION_ID, articleVersionId);
          } catch (SystemException e) {
            LOG.error(e);
          }
        }
      }
    }
    request.setAttribute(GROUP_ID, groupId);
    request.setAttribute(SHOW_ANNOUNCER, showAnnouncer);
    request.setAttribute(SIGNED_IN, themeDisplay.isSignedIn());
    String defaultArticle = preferences.getValue(DEFAULT_ARTICLE, LR_EMPTY_VALUE);
    request.setAttribute(DEFAULT_ARTICLE, defaultArticle);

    super.doView(request, response);
  }
  public void markNotSpamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

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

    checkWikiPagePermission(themeDisplay.getScopeGroupId());

    long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "notSpamWikiPageIds");

    List<String> wikiPageLinks = new ArrayList<String>();

    for (long wikiPageId : wikiPageIds) {
      WikiPage wikiPage = WikiPageLocalServiceUtil.getPageByPageId(wikiPageId);

      WikiPage latestVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), false);

      String latestContent = null;

      if (latestVersionWikiPage != null) {
        latestContent = latestVersionWikiPage.getContent();
      }

      WikiPage previousVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), true);

      String previousContent = null;

      if (previousVersionWikiPage != null) {
        previousContent = previousVersionWikiPage.getContent();
      }

      // Selected version

      wikiPage.setStatus(WorkflowConstants.STATUS_APPROVED);
      wikiPage.setSummary(StringPool.BLANK);

      wikiPage = WikiPageLocalServiceUtil.updateWikiPage(wikiPage);

      // Latest version

      if ((latestContent != null)
          && ((previousContent == null) || latestContent.equals(previousContent))) {

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        WikiPageLocalServiceUtil.revertPage(
            themeDisplay.getUserId(),
            wikiPage.getNodeId(),
            wikiPage.getTitle(),
            wikiPage.getVersion(),
            serviceContext);
      } else {
        StringBundler sb = new StringBundler(5);

        sb.append("<a href=\"");

        long plid = PortalUtil.getPlidFromPortletId(wikiPage.getGroupId(), PortletKeys.WIKI);

        LiferayPortletURL liferayPortletURL =
            PortletURLFactoryUtil.create(
                actionRequest, PortletKeys.WIKI, plid, PortletRequest.RENDER_PHASE);

        WikiNode wikiNode = wikiPage.getNode();

        liferayPortletURL.setParameter("struts_action", "/wiki/view");
        liferayPortletURL.setParameter("nodeName", wikiNode.getName());
        liferayPortletURL.setParameter("title", wikiPage.getTitle());
        liferayPortletURL.setParameter("version", String.valueOf(wikiPage.getVersion()));

        sb.append(liferayPortletURL.toString());
        sb.append("\" target=\"_blank\">");
        sb.append(HtmlUtil.escape(wikiPage.getTitle()));
        sb.append("</a>");

        wikiPageLinks.add(sb.toString());
      }

      // Akismet

      if (AkismetUtil.isWikiEnabled(wikiPage.getCompanyId())) {
        AkismetUtil.submitHam(wikiPage);
      }
    }

    if (!wikiPageLinks.isEmpty()) {
      SessionMessages.add(actionRequest, "requestProcessed");

      SessionMessages.add(
          actionRequest,
          "anotherUserHasMadeChangesToThesePages",
          StringUtil.merge(wikiPageLinks, "<br />"));

      super.sendRedirect(actionRequest, actionResponse);
    }
  }
 @Override
 public void init() throws PortletException {
   COUNTER = BigInteger.ZERO;
   EDIT_URL = getInitParameter(EDIT_TEMPLATE);
   super.init();
 }
Exemplo n.º 20
0
  @Override
  public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    List<AssetVocabulary> vocabularies = new ArrayList<AssetVocabulary>();
    Map<AssetVocabulary, List<AssetCategory>> vocabulariesMap =
        new HashMap<AssetVocabulary, List<AssetCategory>>();
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
    long[] categoryIds = ParamUtil.getLongValues(renderRequest, "categoryIds");
    try {

      Group siteGroup = themeDisplay.getSiteGroup();
      long scopeGroupId = themeDisplay.getScopeGroupId();
      vocabularies.addAll(
          AssetVocabularyServiceUtil.getGroupVocabularies(siteGroup.getGroupId(), false));

      if (scopeGroupId != themeDisplay.getCompanyGroupId()) {
        vocabularies.addAll(
            AssetVocabularyServiceUtil.getGroupVocabularies(
                themeDisplay.getCompanyGroupId(), false));
      }

      long classNameId = PortalUtil.getClassNameId(Announcement.class);

      // Select announcement vocabularies for announcement only.
      for (AssetVocabulary vocabulary : vocabularies) {
        vocabulary = vocabulary.toEscapedModel();

        int vocabularyCategoriesCount =
            AssetCategoryServiceUtil.getVocabularyCategoriesCount(
                vocabulary.getGroupId(), vocabulary.getVocabularyId());

        if (vocabularyCategoriesCount == 0) {
          continue;
        }

        UnicodeProperties settingsProperties = vocabulary.getSettingsProperties();

        long[] selectedClassNameIds =
            StringUtil.split(settingsProperties.getProperty("selectedClassNameIds"), 0L);

        if ((selectedClassNameIds.length > 0)
            && (selectedClassNameIds[0] != AssetCategoryConstants.ALL_CLASS_NAME_IDS)
            && !ArrayUtil.contains(selectedClassNameIds, classNameId)) {
          continue;
        }

        List<AssetCategory> assetCategories =
            AssetCategoryServiceUtil.getVocabularyRootCategories(
                themeDisplay.getScopeGroupId(),
                vocabulary.getVocabularyId(),
                QueryUtil.ALL_POS,
                QueryUtil.ALL_POS,
                null);
        vocabulariesMap.put(vocabulary, assetCategories);
      }
    } catch (SystemException e) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(e);
      }
      LOGGER.error("SystemException: unable to get types or currencies or vocabularies");
    } catch (PortalException e) {
      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(e);
      }
      LOGGER.error("SystemException: unable to get types or currencies or vocabularies");
    }

    renderRequest.setAttribute("vocabulariesMap", vocabulariesMap);
    renderRequest.setAttribute("categoryIds", StringUtil.merge(categoryIds));
    renderRequest.setAttribute("htmlUtil", HtmlUtil.getHtml());

    super.doView(renderRequest, renderResponse);
  }