コード例 #1
0
ファイル: UploadAction.java プロジェクト: thaond/progate-lmis
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    String fileLogoParam = "file";
    File file = uploadRequest.getFile(fileLogoParam);
    ServiceContext sc;

    try {

      sc = ServiceContextFactory.getInstance(this.getClass().getName(), actionRequest);
      // Make sure the uploaded images can be view by any one;
      sc.setAddCommunityPermissions(true);
      sc.setAddGuestPermissions(true);

      IGFolder folder = Functions.getIGFolder(sc);
      // String fileName = uploadRequest.getFileName(fileLogoParam);
      String contentType = uploadRequest.getContentType(fileLogoParam);

      IGImage image =
          IGImageLocalServiceUtil.addImage(
              sc.getUserId(),
              folder.getFolderId(),
              file.getName() + (new Time()).toString(),
              file.getName(),
              file,
              contentType,
              sc);

      HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(actionRequest);
      String res =
          image.getImageId()
              + "|"
              + ProGateUtil.getImageURL(image.getSmallImageId(), servletRequest)
              + "|"
              + ProGateUtil.getImageURL(image.getLargeImageId(), servletRequest);
      ProGateUtil.servletPrint(actionResponse, res);

    } catch (PortalException e) {
      // TODO Auto-generated catch block

      e.printStackTrace();
    } catch (SystemException se) {

      se.printStackTrace();
    } catch (NullPointerException e2) {

      e2.printStackTrace();
    }
  }
コード例 #2
0
  @Override
  protected void handleActionRequestInternal(ActionRequest request, ActionResponse response)
      throws Exception {

    request.setCharacterEncoding("UTF-8");
    String msg = "";
    int articleId = 0;
    int isAdd = 0;
    int addSuccess = 0;

    UploadPortletRequest uploadPortlet = PortalUtil.getUploadPortletRequest(request);
    String currentURL = uploadPortlet.getParameter(News_Const.CURRENT_URL);
    String title = uploadPortlet.getParameter(News_Const.TITLE);
    String content = uploadPortlet.getParameter(News_Const.CONTENT);
    String keyword = uploadPortlet.getParameter(News_Const.KEY_WORD);
    String mark = uploadPortlet.getParameter(News_Const.MARK);
    String description = uploadPortlet.getParameter(News_Const.DESCRIPTION);
    String smallImagePath =
        Functions.getPathOfUploadImage(request, response, uploadPortlet, News_Const.SMALL_IMAGE);
    try {
      // Get current User
      com.liferay.portal.service.ServiceContext sc =
          ServiceContextFactory.getInstance(this.getClass().getName(), request);
      com.liferay.portal.model.User user = UserLocalServiceUtil.getUser(sc.getUserId());
      Long userIdTemp = user.getUserId();
      int userId = userIdTemp.intValue();
      String articleType = ProGateJournalArticleTypesLocalServiceUtil.getArticleTypeNews();
      ProGateJournalArticle article = null;
      if (mark != null) {
        article =
            ProGateJournalArticleLocalServiceUtil.createNews(
                Integer.toString(0),
                userId,
                title,
                articleType,
                description,
                content,
                smallImagePath,
                "",
                true,
                "");
      } else {
        article =
            ProGateJournalArticleLocalServiceUtil.createNews(
                Integer.toString(0),
                userId,
                title,
                articleType,
                description,
                content,
                smallImagePath,
                "",
                false,
                "");
      }

      if (article != null) {
        msg = "Bạn đã thêm tin tức thành công.";
        addSuccess = 1;
        articleId = article.getPrimaryKey();
      }
    } catch (Exception e) {
      // TODO: handle exception
      addSuccess = 2;
      msg = "Đã có lỗi xảy ra trong quá trình thêm tin tức.";
    }
    isAdd = 1;
    response.setRenderParameter(News_Const.CMD, Integer.toString(isAdd));
    response.setRenderParameter(News_Const.MSG_TEXT, msg);
    response.setRenderParameter(News_Const.ADD_SUCCESS, Integer.toString(addSuccess));
    response.setRenderParameter(News_Const.ARTICLE_ID, Integer.toString(articleId));
    response.setRenderParameter(News_Const.CURRENT_URL, currentURL);
    response.setRenderParameter("action", "updateNewsProGate");
  }