Example #1
0
  private void _import(ActionRequest req, ActionResponse res) throws Exception {

    UploadPortletRequest uploadReq = PortalUtil.getUploadPortletRequest(req);

    String importerType = ParamUtil.get(uploadReq, "importer_type", ABUtil.IE_OUTLOOK);

    byte[] bytes = FileUtil.getBytes(uploadReq.getFile("import_file"));

    if (bytes == null || bytes.length == 0) {
      throw new UploadException();
    }

    Importer importer = null;

    if (importerType.equals(ABUtil.IE_OUTLOOK)) {
      importer = new OutlookImporter();
    } else if (importerType.equals(ABUtil.IE_YAHOO)) {
      importer = new OutlookImporter();
    }

    if (importer != null) {
      importer.setData(bytes);

      ABContactServiceUtil.addContacts(importer);
    }

    // Send redirect

    res.sendRedirect(ParamUtil.getString(req, "redirect"));
  }
Example #2
0
  protected void addTempAttachment(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
    String sourceFileName = uploadPortletRequest.getFileName("file");

    InputStream inputStream = null;

    try {
      inputStream = uploadPortletRequest.getFileAsStream("file");

      String mimeType = uploadPortletRequest.getContentType("file");

      String tempFileName = TempFileEntryUtil.getTempFileName(sourceFileName);

      FileEntry fileEntry =
          _wikiPageService.addTempFileEntry(
              nodeId, _TEMP_FOLDER_NAME, tempFileName, inputStream, mimeType);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("groupId", fileEntry.getGroupId());
      jsonObject.put("name", fileEntry.getTitle());
      jsonObject.put("title", sourceFileName);
      jsonObject.put("uuid", fileEntry.getUuid());

      JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
  protected void updateWorkflowDefinition(ActionRequest actionRequest) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");

    File file = uploadPortletRequest.getFile("file");

    WorkflowDefinition workflowDefinition = null;

    if (file == null) {
      String name = ParamUtil.getString(actionRequest, "name");
      int version = ParamUtil.getInteger(actionRequest, "version");

      workflowDefinition =
          WorkflowDefinitionManagerUtil.getWorkflowDefinition(
              themeDisplay.getCompanyId(), name, version);

      WorkflowDefinitionManagerUtil.updateTitle(
          themeDisplay.getCompanyId(), themeDisplay.getUserId(), name, version, getTitle(titleMap));
    } else {
      workflowDefinition =
          WorkflowDefinitionManagerUtil.deployWorkflowDefinition(
              themeDisplay.getCompanyId(), themeDisplay.getUserId(),
              getTitle(titleMap), FileUtil.getBytes(file));
    }

    actionRequest.setAttribute(WebKeys.WORKFLOW_DEFINITION, workflowDefinition);
  }
  public void addAttachment(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    String portletId = PortalUtil.getPortletId(actionRequest);

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

    String dirName = ParamUtil.getString(uploadPortletRequest, "dirName");
    String fileName = uploadPortletRequest.getFileName("file");

    InputStream inputStream = null;

    try {
      inputStream = uploadPortletRequest.getFileAsStream("file");

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(KBArticle.class.getName(), actionRequest);

      KBArticleServiceUtil.addAttachment(
          portletId, resourcePrimKey, dirName, fileName, inputStream, serviceContext);
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
Example #5
0
  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();
    }
  }
  private Wards addDistrict(ActionRequest req) throws PortalException, SystemException {

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(req);

    String code = ParamUtil.getString(uploadRequest, "code");
    String name = ParamUtil.getString(uploadRequest, "name");
    String description = ParamUtil.getString(uploadRequest, "description");
    String districtId = ParamUtil.getString(uploadRequest, "districtId");

    Wards ward = WardsLocalServiceUtil.addWard(code, name, districtId, description, "1");

    return ward;
  }
  private Wards updateDistrict(ActionRequest req) throws PortalException, SystemException {

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(req);

    String districtId = ParamUtil.getString(uploadRequest, "districtId");
    String wardId = ParamUtil.getString(uploadRequest, "wardsId");
    String code = ParamUtil.getString(uploadRequest, "districtCode" + wardId);
    String name = ParamUtil.getString(uploadRequest, "districtName" + wardId);
    String description = ParamUtil.getString(uploadRequest, "districtDescription" + wardId);

    Wards ward = WardsLocalServiceUtil.updateWard(wardId, code, name, districtId, description, "1");

    return ward;
  }
Example #8
0
  protected void addAttachment(ActionRequest actionRequest) throws Exception {
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
    String title = ParamUtil.getString(actionRequest, "title");

    int numOfFiles = ParamUtil.getInteger(actionRequest, "numOfFiles");

    List<ObjectValuePair<String, InputStream>> inputStreamOVPs = new ArrayList<>();

    try {
      if (numOfFiles == 0) {
        String fileName = uploadPortletRequest.getFileName("file");
        InputStream inputStream = uploadPortletRequest.getFileAsStream("file");

        if (inputStream != null) {
          ObjectValuePair<String, InputStream> inputStreamOVP =
              new ObjectValuePair<>(fileName, inputStream);

          inputStreamOVPs.add(inputStreamOVP);
        }
      } else {
        for (int i = 1; i <= numOfFiles; i++) {
          String fileName = uploadPortletRequest.getFileName("file" + i);
          InputStream inputStream = uploadPortletRequest.getFileAsStream("file" + i);

          if (inputStream == null) {
            continue;
          }

          ObjectValuePair<String, InputStream> inputStreamOVP =
              new ObjectValuePair<>(fileName, inputStream);

          inputStreamOVPs.add(inputStreamOVP);
        }
      }

      _wikiPageService.addPageAttachments(nodeId, title, inputStreamOVPs);
    } finally {
      for (ObjectValuePair<String, InputStream> inputStreamOVP : inputStreamOVPs) {

        InputStream inputStream = inputStreamOVP.getValue();

        StreamUtil.cleanUp(inputStream);
      }
    }
  }
  protected void addAttachment(ActionRequest actionRequest) throws Exception {
    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    long nodeId = ParamUtil.getLong(actionRequest, "nodeId");
    String title = ParamUtil.getString(actionRequest, "title");

    int numOfFiles = ParamUtil.getInteger(actionRequest, "numOfFiles");

    List<ObjectValuePair<String, byte[]>> files = new ArrayList<ObjectValuePair<String, byte[]>>();

    if (numOfFiles == 0) {
      File file = uploadRequest.getFile("file");
      String fileName = uploadRequest.getFileName("file");

      if (file != null) {
        byte[] bytes = FileUtil.getBytes(file);

        if ((bytes != null) && (bytes.length > 0)) {
          ObjectValuePair<String, byte[]> ovp =
              new ObjectValuePair<String, byte[]>(fileName, bytes);

          files.add(ovp);
        }
      }
    } else {
      for (int i = 1; i <= numOfFiles; i++) {
        File file = uploadRequest.getFile("file" + i);

        String fileName = uploadRequest.getFileName("file" + i);

        if (file != null) {
          byte[] bytes = FileUtil.getBytes(file);

          if ((bytes != null) && (bytes.length > 0)) {
            ObjectValuePair<String, byte[]> ovp =
                new ObjectValuePair<String, byte[]>(fileName, bytes);

            files.add(ovp);
          }
        }
      }
    }

    WikiPageServiceUtil.addPageAttachments(nodeId, title, files);
  }
Example #10
0
  public void addAttachment(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    String portletId = PortalUtil.getPortletId(actionRequest);

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

    String dirName = ParamUtil.getString(uploadPortletRequest, "dirName");
    File file = uploadPortletRequest.getFile("file");
    String fileName = uploadPortletRequest.getFileName("file");

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(KBArticle.class.getName(), actionRequest);

    KBArticleServiceUtil.addAttachment(
        portletId, resourcePrimKey, dirName, fileName, FileUtil.getBytes(file), serviceContext);
  }
  protected FileEntry addTempImageFileEntry(PortletRequest portletRequest) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(portletRequest);

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

    String contentType = uploadPortletRequest.getContentType("fileName");

    if (!MimeTypesUtil.isWebImage(contentType)) {
      throw new ImageTypeException();
    }

    String fileName = uploadPortletRequest.getFileName("fileName");

    try {
      TempFileEntryUtil.deleteTempFileEntry(
          themeDisplay.getScopeGroupId(),
          themeDisplay.getUserId(),
          getTempImageFolderName(),
          fileName);
    } catch (Exception e) {
    }

    InputStream inputStream = null;

    try {
      inputStream = uploadPortletRequest.getFileAsStream("fileName");

      return TempFileEntryUtil.addTempFileEntry(
          themeDisplay.getScopeGroupId(),
          themeDisplay.getUserId(),
          getTempImageFolderName(),
          fileName,
          inputStream,
          contentType);
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
  @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");
  }
  protected Object[] updateEntry(ActionRequest actionRequest) throws Exception {

    long entryId = ParamUtil.getLong(actionRequest, "entryId");

    String title = ParamUtil.getString(actionRequest, "title");
    String description = ParamUtil.getString(actionRequest, "description");
    String content = ParamUtil.getString(actionRequest, "content");

    int displayDateMonth = ParamUtil.getInteger(actionRequest, "displayDateMonth");
    int displayDateDay = ParamUtil.getInteger(actionRequest, "displayDateDay");
    int displayDateYear = ParamUtil.getInteger(actionRequest, "displayDateYear");
    int displayDateHour = ParamUtil.getInteger(actionRequest, "displayDateHour");
    int displayDateMinute = ParamUtil.getInteger(actionRequest, "displayDateMinute");
    int displayDateAmPm = ParamUtil.getInteger(actionRequest, "displayDateAmPm");

    if (displayDateAmPm == Calendar.PM) {
      displayDateHour += 12;
    }

    boolean allowPingbacks = ParamUtil.getBoolean(actionRequest, "allowPingbacks");
    boolean allowTrackbacks = ParamUtil.getBoolean(actionRequest, "allowTrackbacks");
    String[] trackbacks = StringUtil.split(ParamUtil.getString(actionRequest, "trackbacks"));

    boolean smallImage = false;
    String smallImageURL = null;
    String smallImageFileName = null;
    InputStream smallImageInputStream = null;

    BlogsEntry entry = null;
    String oldUrlTitle = null;

    try {
      boolean ajax = ParamUtil.getBoolean(actionRequest, "ajax");

      if (!ajax) {
        smallImage = ParamUtil.getBoolean(actionRequest, "smallImage");
        smallImageURL = ParamUtil.getString(actionRequest, "smallImageURL");

        if (smallImage && Validator.isNull(smallImageURL)) {
          boolean attachments = ParamUtil.getBoolean(actionRequest, "attachments");

          if (attachments) {
            UploadPortletRequest uploadPortletRequest =
                PortalUtil.getUploadPortletRequest(actionRequest);

            smallImageFileName = uploadPortletRequest.getFileName("smallFile");
            smallImageInputStream = uploadPortletRequest.getFileAsStream("smallFile");
          }
        }
      }

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(BlogsEntry.class.getName(), actionRequest);

      entry = null;
      oldUrlTitle = StringPool.BLANK;

      if (entryId <= 0) {

        // Add entry

        entry =
            BlogsEntryServiceUtil.addEntry(
                title,
                description,
                content,
                displayDateMonth,
                displayDateDay,
                displayDateYear,
                displayDateHour,
                displayDateMinute,
                allowPingbacks,
                allowTrackbacks,
                trackbacks,
                smallImage,
                smallImageURL,
                smallImageFileName,
                smallImageInputStream,
                serviceContext);

        AssetPublisherUtil.addAndStoreSelection(
            actionRequest, BlogsEntry.class.getName(), entry.getEntryId(), -1);
      } else {

        // Update entry

        entry = BlogsEntryLocalServiceUtil.getEntry(entryId);

        String tempOldUrlTitle = entry.getUrlTitle();

        entry =
            BlogsEntryServiceUtil.updateEntry(
                entryId,
                title,
                description,
                content,
                displayDateMonth,
                displayDateDay,
                displayDateYear,
                displayDateHour,
                displayDateMinute,
                allowPingbacks,
                allowTrackbacks,
                trackbacks,
                smallImage,
                smallImageURL,
                smallImageFileName,
                smallImageInputStream,
                serviceContext);

        if (!tempOldUrlTitle.equals(entry.getUrlTitle())) {
          oldUrlTitle = tempOldUrlTitle;
        }

        AssetPublisherUtil.addAndStoreSelection(
            actionRequest, BlogsEntry.class.getName(), entry.getEntryId(), -1);
      }
    } finally {
      StreamUtil.cleanUp(smallImageInputStream);
    }

    return new Object[] {entry, oldUrlTitle};
  }
  public void loadCategoriesFromCsv(ActionRequest actionRequest, ActionResponse actionResponse)
      throws IOException, PortletException, PortalException, SystemException {

    LOGGER.info("Begin  AssetCategoriesImporter");
    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    ThemeDisplay themeDisplay =
        (ThemeDisplay) uploadPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    Map<String, FileItem[]> multipartParameterMap = uploadPortletRequest.getMultipartParameterMap();

    File file = null;
    BufferedReader bufferedReader = null;
    AssetVocabulary assetVocabulary = null;
    long userId = themeDisplay.getUserId();
    long groupId = themeDisplay.getScopeGroupId();

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(AssetCategory.class.getName(), uploadPortletRequest);

    // create vocabulary
    try {

      assetVocabulary =
          AssetVocabularyLocalServiceUtil.addVocabulary(
              userId,
              "Announcements",
              ServiceContextFactory.getInstance(
                  AssetVocabulary.class.getName(), uploadPortletRequest));
    } catch (DuplicateVocabularyException dve) {
      try {
        assetVocabulary =
            AssetVocabularyLocalServiceUtil.getGroupVocabulary(groupId, "Announcements");
      } catch (PortalException e) {
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug(e);
        }
        LOGGER.error(e.getMessage());
      } catch (SystemException e) {
        if (LOGGER.isDebugEnabled()) {
          LOGGER.debug(e);
        }
        LOGGER.error(e.getMessage());
      }
    }

    if (multipartParameterMap.keySet().contains("fileCategory")
        && Validator.isNotNull(assetVocabulary)) {
      try {
        file = uploadPortletRequest.getFile("fileCategory");
        bufferedReader = new BufferedReader(new FileReader(file.getAbsolutePath()));
        String line = StringPool.BLANK;
        long vocabularyId = assetVocabulary.getVocabularyId();

        String parentCategoryName = StringPool.BLANK;
        AssetCategory parentCategory = null;

        while ((line = bufferedReader.readLine()) != null) {

          // use comma as separator
          String[] categories = line.split(StringPool.SEMICOLON);

          if (categories.length == 4) {
            String parentCategoryCode = categories[0];

            if (Validator.isNull(parentCategory) || !parentCategoryName.equals(categories[1])) {
              parentCategoryName = categories[1];
              try {
                parentCategory =
                    AssetCategoryLocalServiceUtil.addCategory(
                        userId, parentCategoryName, vocabularyId, serviceContext);
                AssetCategoryPropertyLocalServiceUtil.addCategoryProperty(
                    userId, parentCategory.getCategoryId(), "Code", parentCategoryCode);
              } catch (Exception e) {
                if (LOGGER.isDebugEnabled()) {
                  LOGGER.debug(e);
                }
                LOGGER.error(e.getMessage());
              }
            }

            Map<Locale, String> titles = new HashMap<Locale, String>();
            Map<Locale, String> descriptionMap = new HashMap<Locale, String>();

            titles.put(LocaleUtil.fromLanguageId("fr_FR"), categories[3]);
            titles.put(LocaleUtil.fromLanguageId("en_US"), categories[3]);

            try {
              AssetCategory child =
                  AssetCategoryLocalServiceUtil.addCategory(
                      userId,
                      parentCategory.getCategoryId(),
                      titles,
                      descriptionMap,
                      vocabularyId,
                      null,
                      serviceContext);
              AssetCategoryPropertyLocalServiceUtil.addCategoryProperty(
                  userId, child.getCategoryId(), "Code", categories[2]);
            } catch (Exception e) {
              if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(e);
              }
              LOGGER.error(e.getMessage());
            }
          }
        }
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      } finally {
        if (bufferedReader != null) {
          try {
            bufferedReader.close();
          } catch (IOException e) {
            if (LOGGER.isDebugEnabled()) {
              LOGGER.debug(e);
            }
            LOGGER.error(e.getMessage());
          }
        }
      }
    }
    LOGGER.info("End  AssetCategoriesImporter");
  }
  protected void updateProductEntry(ActionRequest actionRequest) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    long productEntryId = ParamUtil.getLong(actionRequest, "productEntryId");

    String name = ParamUtil.getString(actionRequest, "name");
    String type = ParamUtil.getString(actionRequest, "type");
    String tags = ParamUtil.getString(actionRequest, "tags");
    String shortDescription = ParamUtil.getString(actionRequest, "shortDescription");
    String longDescription = ParamUtil.getString(actionRequest, "longDescription");
    String pageURL = ParamUtil.getString(actionRequest, "pageURL");
    String author = ParamUtil.getString(actionRequest, "author");
    String repoGroupId = ParamUtil.getString(actionRequest, "repoGroupId");
    String repoArtifactId = ParamUtil.getString(actionRequest, "repoArtifactId");

    long[] licenseIds = ParamUtil.getLongValues(actionRequest, "licenses");

    List<byte[]> thumbnails = getThumbnails(uploadPortletRequest);
    List<byte[]> fullImages = getFullImages(uploadPortletRequest);

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(SCProductEntry.class.getName(), actionRequest);

    if (productEntryId <= 0) {

      // Add product entry

      SCProductEntryServiceUtil.addProductEntry(
          name,
          type,
          tags,
          shortDescription,
          longDescription,
          pageURL,
          author,
          repoGroupId,
          repoArtifactId,
          licenseIds,
          thumbnails,
          fullImages,
          serviceContext);
    } else {

      // Update product entry

      SCProductEntryServiceUtil.updateProductEntry(
          productEntryId,
          name,
          type,
          tags,
          shortDescription,
          longDescription,
          pageURL,
          author,
          repoGroupId,
          repoArtifactId,
          licenseIds,
          thumbnails,
          fullImages);
    }
  }
  public void updateMeetupsEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

    Group group = GroupLocalServiceUtil.getGroup(themeDisplay.getScopeGroupId());

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (!permissionChecker.isCompanyAdmin()) {
      return;
    }

    long meetupsEntryId = ParamUtil.getLong(uploadRequest, "meetupsEntryId");

    String title = ParamUtil.getString(uploadRequest, "title");
    String description = ParamUtil.getString(uploadRequest, "description");

    int startDateMonth = ParamUtil.getInteger(uploadRequest, "startDateMonth");
    int startDateDay = ParamUtil.getInteger(uploadRequest, "startDateDay");
    int startDateYear = ParamUtil.getInteger(uploadRequest, "startDateYear");
    int startDateHour = ParamUtil.getInteger(uploadRequest, "startDateHour");
    int startDateMinute = ParamUtil.getInteger(uploadRequest, "startDateMinute");
    int startDateAmPm = ParamUtil.getInteger(uploadRequest, "startDateAmPm");

    if (startDateAmPm == Calendar.PM) {
      startDateHour += 12;
    }

    int endDateMonth = ParamUtil.getInteger(uploadRequest, "endDateMonth");
    int endDateDay = ParamUtil.getInteger(uploadRequest, "endDateDay");
    int endDateYear = ParamUtil.getInteger(uploadRequest, "endDateYear");
    int endDateHour = ParamUtil.getInteger(uploadRequest, "endDateHour");
    int endDateMinute = ParamUtil.getInteger(uploadRequest, "endDateMinute");
    int endDateAmPm = ParamUtil.getInteger(uploadRequest, "endDateAmPm");

    if (endDateAmPm == Calendar.PM) {
      endDateHour += 12;
    }

    int totalAttendees = ParamUtil.getInteger(uploadRequest, "totalAttendees");
    int maxAttendees = ParamUtil.getInteger(uploadRequest, "maxAttendees");
    double price = ParamUtil.getDouble(uploadRequest, "price");

    File file = uploadRequest.getFile("fileName");
    byte[] bytes = FileUtil.getBytes(file);

    if (meetupsEntryId <= 0) {
      MeetupsEntryLocalServiceUtil.addMeetupsEntry(
          themeDisplay.getUserId(),
          title,
          description,
          startDateMonth,
          startDateDay,
          startDateYear,
          startDateHour,
          startDateMinute,
          endDateMonth,
          endDateDay,
          endDateYear,
          endDateHour,
          endDateMinute,
          totalAttendees,
          maxAttendees,
          price,
          bytes,
          group.getGroupId());
    } else {
      MeetupsEntryLocalServiceUtil.updateMeetupsEntry(
          themeDisplay.getUserId(),
          meetupsEntryId,
          title,
          description,
          startDateMonth,
          startDateDay,
          startDateYear,
          startDateHour,
          startDateMinute,
          endDateMonth,
          endDateDay,
          endDateYear,
          endDateHour,
          endDateMinute,
          totalAttendees,
          maxAttendees,
          price,
          bytes,
          group.getGroupId());
    }
  }
  protected FileEntry addFileEntry(ActionRequest actionRequest) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

    long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
    String sourceFileName = uploadPortletRequest.getFileName("file");
    String title = ParamUtil.getString(uploadPortletRequest, "title");
    String description = ParamUtil.getString(uploadPortletRequest, "description");
    String changeLog = ParamUtil.getString(uploadPortletRequest, "changeLog");

    if (folderId > 0) {
      Folder folder = DLAppServiceUtil.getFolder(folderId);

      if (folder.getGroupId() != themeDisplay.getScopeGroupId()) {
        throw new NoSuchFolderException("{folderId=" + folderId + "}");
      }
    }

    InputStream inputStream = null;

    try {
      String contentType = uploadPortletRequest.getContentType("file");

      long size = uploadPortletRequest.getSize("file");

      if (size == 0) {
        contentType = MimeTypesUtil.getContentType(title);
      }

      if (size > 0) {
        HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);

        String[] mimeTypes = DocumentSelectorUtil.getMimeTypes(request);

        if (ArrayUtil.isNotEmpty(mimeTypes) && !ArrayUtil.contains(mimeTypes, contentType)) {

          throw new FileMimeTypeException(contentType);
        }
      }

      inputStream = uploadPortletRequest.getFileAsStream("file");

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(DLFileEntry.class.getName(), uploadPortletRequest);

      FileEntry fileEntry =
          DLAppServiceUtil.addFileEntry(
              themeDisplay.getScopeGroupId(),
              folderId,
              sourceFileName,
              contentType,
              title,
              description,
              changeLog,
              inputStream,
              size,
              serviceContext);

      AssetPublisherUtil.addRecentFolderId(actionRequest, DLFileEntry.class.getName(), folderId);

      return fileEntry;
    } catch (Exception e) {
      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if (uploadException != null) {
        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException();
        } else if (uploadException.isExceededSizeLimit()) {
          throw new FileSizeException(uploadException.getCause());
        }
      }

      throw e;
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
Example #18
0
  public void updateMeetupsEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(uploadRequest);
    ThemeDisplay themeDisplay = (ThemeDisplay) uploadRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    // get selected tags
    String[] assetTagNames = null;

    String assetTagCSV = ParamUtil.getString(uploadRequest, "assetTagNames");

    assetTagNames = assetTagCSV != null ? assetTagCSV.split(",") : null;

    // set asset tag names in service context
    serviceContext.setAssetTagNames(
        (null != assetTagCSV && !assetTagCSV.equals("")) ? assetTagNames : null);

    if (!permissionChecker.isCompanyAdmin()) {
      return;
    }

    long meetupsEntryId = ParamUtil.getLong(uploadRequest, "meetupsEntryId");

    String title = ParamUtil.getString(uploadRequest, "title");
    String description = ParamUtil.getString(uploadRequest, "description");

    int startDateMonth = ParamUtil.getInteger(uploadRequest, "startDateMonth");
    int startDateDay = ParamUtil.getInteger(uploadRequest, "startDateDay");
    int startDateYear = ParamUtil.getInteger(uploadRequest, "startDateYear");
    int startDateHour = ParamUtil.getInteger(uploadRequest, "startDateHour");
    int startDateMinute = ParamUtil.getInteger(uploadRequest, "startDateMinute");
    int startDateAmPm = ParamUtil.getInteger(uploadRequest, "startDateAmPm");

    if (startDateAmPm == Calendar.PM) {
      startDateHour += 12;
    }

    int endDateMonth = ParamUtil.getInteger(uploadRequest, "endDateMonth");
    int endDateDay = ParamUtil.getInteger(uploadRequest, "endDateDay");
    int endDateYear = ParamUtil.getInteger(uploadRequest, "endDateYear");
    int endDateHour = ParamUtil.getInteger(uploadRequest, "endDateHour");
    int endDateMinute = ParamUtil.getInteger(uploadRequest, "endDateMinute");
    int endDateAmPm = ParamUtil.getInteger(uploadRequest, "endDateAmPm");

    if (endDateAmPm == Calendar.PM) {
      endDateHour += 12;
    }

    int totalAttendees = ParamUtil.getInteger(uploadRequest, "totalAttendees");
    int maxAttendees = ParamUtil.getInteger(uploadRequest, "maxAttendees");
    double price = ParamUtil.getDouble(uploadRequest, "price");

    File file = uploadRequest.getFile("fileName");
    byte[] bytes = FileUtil.getBytes(file);

    if (meetupsEntryId <= 0) {
      // Add Meetups Entry
      MeetupsEntryLocalServiceUtil.addMeetupsEntry(
          themeDisplay.getUserId(),
          title,
          description,
          startDateMonth,
          startDateDay,
          startDateYear,
          startDateHour,
          startDateMinute,
          endDateMonth,
          endDateDay,
          endDateYear,
          endDateHour,
          endDateMinute,
          totalAttendees,
          maxAttendees,
          price,
          bytes,
          serviceContext);

    } else {
      MeetupsEntryLocalServiceUtil.updateMeetupsEntry(
          themeDisplay.getUserId(),
          meetupsEntryId,
          title,
          description,
          startDateMonth,
          startDateDay,
          startDateYear,
          startDateHour,
          startDateMinute,
          endDateMonth,
          endDateDay,
          endDateYear,
          endDateHour,
          endDateMinute,
          totalAttendees,
          maxAttendees,
          price,
          bytes,
          serviceContext);
    }
  }
  public void updateArticle(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadException uploadException =
        (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

    if (uploadException != null) {
      if (uploadException.isExceededLiferayFileItemSizeLimit()) {
        throw new LiferayFileItemException();
      } else if (uploadException.isExceededSizeLimit()) {
        throw new ArticleContentSizeException();
      }

      throw new PortalException(uploadException.getCause());
    }

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    if (_log.isDebugEnabled()) {
      _log.debug("Updating article " + MapUtil.toString(uploadPortletRequest.getParameterMap()));
    }

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

    long groupId = ParamUtil.getLong(uploadPortletRequest, "groupId");
    long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
    long classNameId = ParamUtil.getLong(uploadPortletRequest, "classNameId");
    long classPK = ParamUtil.getLong(uploadPortletRequest, "classPK");

    String articleId = ParamUtil.getString(uploadPortletRequest, "articleId");

    boolean autoArticleId = ParamUtil.getBoolean(uploadPortletRequest, "autoArticleId");
    double version = ParamUtil.getDouble(uploadPortletRequest, "version");

    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap =
        LocalizationUtil.getLocalizationMap(actionRequest, "description");

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(JournalArticle.class.getName(), uploadPortletRequest);

    String ddmStructureKey = ParamUtil.getString(uploadPortletRequest, "ddmStructureKey");

    DDMStructure ddmStructure =
        _ddmStructureLocalService.getStructure(
            PortalUtil.getSiteGroupId(groupId),
            PortalUtil.getClassNameId(JournalArticle.class),
            ddmStructureKey,
            true);

    Object[] contentAndImages = ActionUtil.getContentAndImages(ddmStructure, serviceContext);

    String content = (String) contentAndImages[0];
    Map<String, byte[]> images = (HashMap<String, byte[]>) contentAndImages[1];

    Boolean fileItemThresholdSizeExceeded =
        (Boolean) uploadPortletRequest.getAttribute(WebKeys.FILE_ITEM_THRESHOLD_SIZE_EXCEEDED);

    if ((fileItemThresholdSizeExceeded != null) && fileItemThresholdSizeExceeded.booleanValue()) {

      throw new ArticleContentSizeException();
    }

    String ddmTemplateKey = ParamUtil.getString(uploadPortletRequest, "ddmTemplateKey");
    String layoutUuid = ParamUtil.getString(uploadPortletRequest, "layoutUuid");

    Layout targetLayout = JournalUtil.getArticleLayout(layoutUuid, groupId);

    if (targetLayout == null) {
      layoutUuid = null;
    }

    int displayDateMonth = ParamUtil.getInteger(uploadPortletRequest, "displayDateMonth");
    int displayDateDay = ParamUtil.getInteger(uploadPortletRequest, "displayDateDay");
    int displayDateYear = ParamUtil.getInteger(uploadPortletRequest, "displayDateYear");
    int displayDateHour = ParamUtil.getInteger(uploadPortletRequest, "displayDateHour");
    int displayDateMinute = ParamUtil.getInteger(uploadPortletRequest, "displayDateMinute");
    int displayDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "displayDateAmPm");

    if (displayDateAmPm == Calendar.PM) {
      displayDateHour += 12;
    }

    int expirationDateMonth = ParamUtil.getInteger(uploadPortletRequest, "expirationDateMonth");
    int expirationDateDay = ParamUtil.getInteger(uploadPortletRequest, "expirationDateDay");
    int expirationDateYear = ParamUtil.getInteger(uploadPortletRequest, "expirationDateYear");
    int expirationDateHour = ParamUtil.getInteger(uploadPortletRequest, "expirationDateHour");
    int expirationDateMinute = ParamUtil.getInteger(uploadPortletRequest, "expirationDateMinute");
    int expirationDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "expirationDateAmPm");
    boolean neverExpire = ParamUtil.getBoolean(uploadPortletRequest, "neverExpire");

    if (expirationDateAmPm == Calendar.PM) {
      expirationDateHour += 12;
    }

    int reviewDateMonth = ParamUtil.getInteger(uploadPortletRequest, "reviewDateMonth");
    int reviewDateDay = ParamUtil.getInteger(uploadPortletRequest, "reviewDateDay");
    int reviewDateYear = ParamUtil.getInteger(uploadPortletRequest, "reviewDateYear");
    int reviewDateHour = ParamUtil.getInteger(uploadPortletRequest, "reviewDateHour");
    int reviewDateMinute = ParamUtil.getInteger(uploadPortletRequest, "reviewDateMinute");
    int reviewDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "reviewDateAmPm");
    boolean neverReview = ParamUtil.getBoolean(uploadPortletRequest, "neverReview");

    if (reviewDateAmPm == Calendar.PM) {
      reviewDateHour += 12;
    }

    boolean indexable = ParamUtil.getBoolean(uploadPortletRequest, "indexable");

    boolean smallImage = ParamUtil.getBoolean(uploadPortletRequest, "smallImage");
    String smallImageURL = ParamUtil.getString(uploadPortletRequest, "smallImageURL");
    File smallFile = uploadPortletRequest.getFile("smallFile");

    String articleURL = ParamUtil.getString(uploadPortletRequest, "articleURL");

    JournalArticle article = null;
    String oldUrlTitle = StringPool.BLANK;

    if (actionName.equals("addArticle")) {

      // Add article

      article =
          _journalArticleService.addArticle(
              groupId,
              folderId,
              classNameId,
              classPK,
              articleId,
              autoArticleId,
              titleMap,
              descriptionMap,
              content,
              ddmStructureKey,
              ddmTemplateKey,
              layoutUuid,
              displayDateMonth,
              displayDateDay,
              displayDateYear,
              displayDateHour,
              displayDateMinute,
              expirationDateMonth,
              expirationDateDay,
              expirationDateYear,
              expirationDateHour,
              expirationDateMinute,
              neverExpire,
              reviewDateMonth,
              reviewDateDay,
              reviewDateYear,
              reviewDateHour,
              reviewDateMinute,
              neverReview,
              indexable,
              smallImage,
              smallImageURL,
              smallFile,
              images,
              articleURL,
              serviceContext);
    } else {

      // Update article

      article = _journalArticleService.getArticle(groupId, articleId, version);

      String tempOldUrlTitle = article.getUrlTitle();

      if (actionName.equals("previewArticle") || actionName.equals("updateArticle")) {

        article =
            _journalArticleService.updateArticle(
                groupId,
                folderId,
                articleId,
                version,
                titleMap,
                descriptionMap,
                content,
                ddmStructureKey,
                ddmTemplateKey,
                layoutUuid,
                displayDateMonth,
                displayDateDay,
                displayDateYear,
                displayDateHour,
                displayDateMinute,
                expirationDateMonth,
                expirationDateDay,
                expirationDateYear,
                expirationDateHour,
                expirationDateMinute,
                neverExpire,
                reviewDateMonth,
                reviewDateDay,
                reviewDateYear,
                reviewDateHour,
                reviewDateMinute,
                neverReview,
                indexable,
                smallImage,
                smallImageURL,
                smallFile,
                images,
                articleURL,
                serviceContext);
      }

      if (!tempOldUrlTitle.equals(article.getUrlTitle())) {
        oldUrlTitle = tempOldUrlTitle;
      }
    }

    // Recent articles

    JournalUtil.addRecentArticle(actionRequest, article);

    // Journal content

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

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

    PortletPreferences portletPreferences =
        PortletPreferencesFactoryUtil.getStrictPortletSetup(
            themeDisplay.getLayout(), portletResource);

    if (portletPreferences != null) {
      portletPreferences.setValue("groupId", String.valueOf(article.getGroupId()));
      portletPreferences.setValue("articleId", article.getArticleId());

      portletPreferences.store();

      updateContentSearch(actionRequest, portletResource, article.getArticleId());
    }

    sendEditArticleRedirect(actionRequest, actionResponse, article, oldUrlTitle);
  }
  protected FileEntry updateFileEntry(
      PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

    String cmd = ParamUtil.getString(uploadPortletRequest, Constants.CMD);

    long fileEntryId = ParamUtil.getLong(uploadPortletRequest, "fileEntryId");

    long repositoryId = ParamUtil.getLong(uploadPortletRequest, "repositoryId");
    long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
    String sourceFileName = uploadPortletRequest.getFileName("file");
    String title = ParamUtil.getString(uploadPortletRequest, "title");
    String description = ParamUtil.getString(uploadPortletRequest, "description");
    String changeLog = ParamUtil.getString(uploadPortletRequest, "changeLog");
    boolean majorVersion = ParamUtil.getBoolean(uploadPortletRequest, "majorVersion");

    if (folderId > 0) {
      Folder folder = _dlAppService.getFolder(folderId);

      if (folder.getGroupId() != themeDisplay.getScopeGroupId()) {
        throw new NoSuchFolderException("{folderId=" + folderId + "}");
      }
    }

    InputStream inputStream = null;

    try {
      String contentType = uploadPortletRequest.getContentType("file");
      long size = uploadPortletRequest.getSize("file");

      if ((cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) && (size == 0)) {

        contentType = MimeTypesUtil.getContentType(title);
      }

      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC) || (size > 0)) {

        String portletName = portletConfig.getPortletName();

        if (portletName.equals(DLPortletKeys.MEDIA_GALLERY_DISPLAY)) {
          PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

          DLPortletInstanceSettings dlPortletInstanceSettings =
              DLPortletInstanceSettings.getInstance(
                  themeDisplay.getLayout(), portletDisplay.getId());

          String[] mimeTypes = dlPortletInstanceSettings.getMimeTypes();

          if (Arrays.binarySearch(mimeTypes, contentType) < 0) {
            throw new FileMimeTypeException(contentType);
          }
        }
      }

      inputStream = uploadPortletRequest.getFileAsStream("file");

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(DLFileEntry.class.getName(), uploadPortletRequest);

      FileEntry fileEntry = null;

      if (cmd.equals(Constants.ADD) || cmd.equals(Constants.ADD_DYNAMIC)) {

        // Add file entry

        fileEntry =
            _dlAppService.addFileEntry(
                repositoryId,
                folderId,
                sourceFileName,
                contentType,
                title,
                description,
                changeLog,
                inputStream,
                size,
                serviceContext);

        if (cmd.equals(Constants.ADD_DYNAMIC)) {
          JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

          jsonObject.put("fileEntryId", fileEntry.getFileEntryId());

          JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
        }
      } else if (cmd.equals(Constants.UPDATE_AND_CHECKIN)) {

        // Update file entry and checkin

        fileEntry =
            _dlAppService.updateFileEntryAndCheckIn(
                fileEntryId,
                sourceFileName,
                contentType,
                title,
                description,
                changeLog,
                majorVersion,
                inputStream,
                size,
                serviceContext);
      } else {

        // Update file entry

        fileEntry =
            _dlAppService.updateFileEntry(
                fileEntryId,
                sourceFileName,
                contentType,
                title,
                description,
                changeLog,
                majorVersion,
                inputStream,
                size,
                serviceContext);
      }

      return fileEntry;
    } catch (Exception e) {
      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if (uploadException != null) {
        if (uploadException.isExceededLiferayFileItemSizeLimit()) {
          throw new LiferayFileItemException();
        } else if (uploadException.isExceededSizeLimit()) {
          throw new FileSizeException(uploadException.getCause());
        }
      }

      throw e;
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }
  protected void addTempFileEntry(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

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

    long folderId = ParamUtil.getLong(uploadPortletRequest, "folderId");
    String sourceFileName = uploadPortletRequest.getFileName("file");

    StringBundler sb = new StringBundler(5);

    sb.append(FileUtil.stripExtension(sourceFileName));
    sb.append(DL.TEMP_RANDOM_SUFFIX);
    sb.append(StringUtil.randomString());

    String extension = FileUtil.getExtension(sourceFileName);

    if (Validator.isNotNull(extension)) {
      sb.append(StringPool.PERIOD);
      sb.append(extension);
    }

    InputStream inputStream = null;

    try {
      inputStream = uploadPortletRequest.getFileAsStream("file");

      String contentType = uploadPortletRequest.getContentType("file");

      FileEntry fileEntry =
          _dlAppService.addTempFileEntry(
              themeDisplay.getScopeGroupId(),
              folderId,
              TEMP_FOLDER_NAME,
              sb.toString(),
              inputStream,
              contentType);

      JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

      jsonObject.put("groupId", fileEntry.getGroupId());
      jsonObject.put("name", fileEntry.getTitle());
      jsonObject.put("title", sourceFileName);
      jsonObject.put("uuid", fileEntry.getUuid());

      JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } catch (Exception e) {
      UploadException uploadException =
          (UploadException) actionRequest.getAttribute(WebKeys.UPLOAD_EXCEPTION);

      if ((uploadException != null)
          && (uploadException.getCause() instanceof FileUploadBase.IOFileUploadException)) {

        // Cancelled a temporary upload

      } else if ((uploadException != null) && uploadException.isExceededSizeLimit()) {

        throw new FileSizeException(uploadException.getCause());
      } else {
        throw e;
      }
    } finally {
      StreamUtil.cleanUp(inputStream);
    }
  }