コード例 #1
0
  protected void validate(
      Map<Locale, String> nameMap,
      String xsl,
      boolean smallImage,
      String smallImageURL,
      File smallImageFile,
      byte[] smallImageBytes)
      throws PortalException, SystemException {

    if (nameMap.isEmpty()) {
      throw new TemplateNameException();
    } else if (Validator.isNull(xsl)) {
      throw new TemplateXslException();
    }

    String[] imageExtensions =
        PrefsPropsUtil.getStringArray(PropsKeys.JOURNAL_IMAGE_EXTENSIONS, StringPool.COMMA);

    if (smallImage
        && Validator.isNull(smallImageURL)
        && (smallImageFile != null)
        && (smallImageBytes != null)) {

      String smallImageName = smallImageFile.getName();

      if (smallImageName != null) {
        boolean validSmallImageExtension = false;

        for (int i = 0; i < imageExtensions.length; i++) {
          if (StringPool.STAR.equals(imageExtensions[i])
              || StringUtil.endsWith(smallImageName, imageExtensions[i])) {

            validSmallImageExtension = true;

            break;
          }
        }

        if (!validSmallImageExtension) {
          throw new TemplateSmallImageNameException(smallImageName);
        }
      }

      long smallImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.JOURNAL_IMAGE_SMALL_MAX_SIZE);

      if ((smallImageMaxSize > 0)
          && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) {

        throw new TemplateSmallImageSizeException();
      }
    }
  }
コード例 #2
0
  @Override
  public boolean isPreviewableSize(FileVersion fileVersion) {
    long fileEntryPreviewableProcessorMaxSize =
        PropsValues.DL_FILE_ENTRY_PREVIEWABLE_PROCESSOR_MAX_SIZE;

    try {
      fileEntryPreviewableProcessorMaxSize =
          PrefsPropsUtil.getLong(PropsKeys.DL_FILE_ENTRY_PREVIEWABLE_PROCESSOR_MAX_SIZE);
    } catch (Exception e) {
      _log.error(e, e);
    }

    if (fileEntryPreviewableProcessorMaxSize == 0) {
      return false;
    }

    if ((fileEntryPreviewableProcessorMaxSize > 0)
        && (fileVersion.getSize() > fileEntryPreviewableProcessorMaxSize)) {

      return false;
    }

    return true;
  }
コード例 #3
0
  protected void handleUploadException(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      String cmd,
      Exception e)
      throws Exception {

    if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

      SessionErrors.add(actionRequest, e.getClass(), e);
    } else if (e instanceof AntivirusScannerException
        || e instanceof DuplicateFileEntryException
        || e instanceof DuplicateFolderNameException
        || e instanceof FileExtensionException
        || e instanceof FileMimeTypeException
        || e instanceof FileNameException
        || e instanceof FileSizeException
        || e instanceof LiferayFileItemException
        || e instanceof NoSuchFolderException
        || e instanceof SourceFileNameException
        || e instanceof StorageFieldRequiredException) {

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

      if ((uploadException != null) && !cmd.equals(Constants.ADD_TEMP)) {
        String uploadExceptionRedirect =
            ParamUtil.getString(actionRequest, "uploadExceptionRedirect");

        sendRedirect(actionRequest, actionResponse, uploadExceptionRedirect);

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

        return;
      } else if (!cmd.equals(Constants.ADD_DYNAMIC)
          && !cmd.equals(Constants.ADD_MULTIPLE)
          && !cmd.equals(Constants.ADD_TEMP)) {

        if (e instanceof AntivirusScannerException) {
          SessionErrors.add(actionRequest, e.getClass(), e);
        } else {
          SessionErrors.add(actionRequest, e.getClass());
        }

        return;
      } else if (cmd.equals(Constants.ADD_TEMP)) {
        hideDefaultErrorMessage(actionRequest);
      }

      if (e instanceof AntivirusScannerException
          || e instanceof DuplicateFileEntryException
          || e instanceof FileExtensionException
          || e instanceof FileNameException
          || e instanceof FileSizeException) {

        HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

        response.setContentType(ContentTypes.TEXT_HTML);
        response.setStatus(HttpServletResponse.SC_OK);

        String errorMessage = StringPool.BLANK;
        int errorType = 0;

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

        if (e instanceof AntivirusScannerException) {
          AntivirusScannerException ase = (AntivirusScannerException) e;

          errorMessage = themeDisplay.translate(ase.getMessageKey());
          errorType = ServletResponseConstants.SC_FILE_ANTIVIRUS_EXCEPTION;
        }

        if (e instanceof DuplicateFileEntryException) {
          errorMessage = themeDisplay.translate("please-enter-a-unique-document-name");
          errorType = ServletResponseConstants.SC_DUPLICATE_FILE_EXCEPTION;
        } else if (e instanceof FileExtensionException) {
          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-extension-x",
                  StringUtil.merge(
                      getAllowedFileExtensions(portletConfig, actionRequest, actionResponse)));
          errorType = ServletResponseConstants.SC_FILE_EXTENSION_EXCEPTION;
        } else if (e instanceof FileNameException) {
          errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name");
          errorType = ServletResponseConstants.SC_FILE_NAME_EXCEPTION;
        } else if (e instanceof FileSizeException) {
          long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE);

          if (fileMaxSize == 0) {
            fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE);
          }

          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-file-size-no-larger" + "-than-x",
                  TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale()));

          errorType = ServletResponseConstants.SC_FILE_SIZE_EXCEPTION;
        }

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("message", errorMessage);
        jsonObject.put("status", errorType);

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
      }

      if (e instanceof AntivirusScannerException) {
        SessionErrors.add(actionRequest, e.getClass(), e);
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }
    } else if (e instanceof DuplicateLockException
        || e instanceof InvalidFileVersionException
        || e instanceof NoSuchFileEntryException
        || e instanceof PrincipalException) {

      if (e instanceof DuplicateLockException) {
        DuplicateLockException dle = (DuplicateLockException) e;

        SessionErrors.add(actionRequest, dle.getClass(), dle.getLock());
      } else {
        SessionErrors.add(actionRequest, e.getClass());
      }

      actionResponse.setRenderParameter("mvcPath", "/document_library/error.jsp");
    } else {
      Throwable cause = e.getCause();

      if (cause instanceof DuplicateFileEntryException) {
        SessionErrors.add(actionRequest, DuplicateFileEntryException.class);
      } else {
        throw e;
      }
    }
  }
コード例 #4
0
  protected String getAddMultipleFileEntriesErrorMessage(
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      Exception e)
      throws Exception {

    String errorMessage = null;

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

    if (e instanceof AntivirusScannerException) {
      AntivirusScannerException ase = (AntivirusScannerException) e;

      errorMessage = themeDisplay.translate(ase.getMessageKey());
    } else if (e instanceof AssetCategoryException) {
      AssetCategoryException ace = (AssetCategoryException) e;

      AssetVocabulary assetVocabulary = ace.getVocabulary();

      String vocabularyTitle = StringPool.BLANK;

      if (assetVocabulary != null) {
        vocabularyTitle = assetVocabulary.getTitle(themeDisplay.getLocale());
      }

      if (ace.getType() == AssetCategoryException.AT_LEAST_ONE_CATEGORY) {
        errorMessage =
            themeDisplay.translate("please-select-at-least-one-category-for-x", vocabularyTitle);
      } else if (ace.getType() == AssetCategoryException.TOO_MANY_CATEGORIES) {

        errorMessage =
            themeDisplay.translate(
                "you-cannot-select-more-than-one-category-for-x", vocabularyTitle);
      }
    } else if (e instanceof DuplicateFileEntryException) {
      errorMessage =
          themeDisplay.translate(
              "the-folder-you-selected-already-has-an-entry-with-this-name."
                  + "-please-select-a-different-folder");
    } else if (e instanceof FileExtensionException) {
      errorMessage =
          themeDisplay.translate(
              "please-enter-a-file-with-a-valid-extension-x",
              StringUtil.merge(
                  getAllowedFileExtensions(portletConfig, actionRequest, actionResponse)));
    } else if (e instanceof FileNameException) {
      errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-name");
    } else if (e instanceof FileSizeException) {
      long fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.DL_FILE_MAX_SIZE);

      if (fileMaxSize == 0) {
        fileMaxSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE);
      }

      errorMessage =
          themeDisplay.translate(
              "please-enter-a-file-with-a-valid-file-size-no-larger-than-x",
              TextFormatter.formatStorageSize(fileMaxSize, themeDisplay.getLocale()));
    } else if (e instanceof InvalidFileEntryTypeException) {
      errorMessage =
          themeDisplay.translate("the-document-type-you-selected-is-not-valid-for-this-folder");
    } else {
      errorMessage =
          themeDisplay.translate("an-unexpected-error-occurred-while-saving-your-document");
    }

    return errorMessage;
  }
コード例 #5
0
  protected void validate(
      long companyId,
      long itemId,
      String sku,
      String name,
      boolean smallImage,
      String smallImageURL,
      File smallImageFile,
      byte[] smallImageBytes,
      boolean mediumImage,
      String mediumImageURL,
      File mediumImageFile,
      byte[] mediumImageBytes,
      boolean largeImage,
      String largeImageURL,
      File largeImageFile,
      byte[] largeImageBytes)
      throws PortalException, SystemException {

    if (Validator.isNull(sku)) {
      throw new ItemSKUException();
    }

    ShoppingItem item = shoppingItemPersistence.fetchByC_S(companyId, sku);

    if (item != null) {
      if (itemId > 0) {
        if (item.getItemId() != itemId) {
          throw new DuplicateItemSKUException();
        }
      } else {
        throw new DuplicateItemSKUException();
      }
    }

    if (Validator.isNull(name)) {
      throw new ItemNameException();
    }

    String[] imageExtensions =
        PrefsPropsUtil.getStringArray(PropsKeys.SHOPPING_IMAGE_EXTENSIONS, StringPool.COMMA);

    // Small image

    if (smallImage
        && Validator.isNull(smallImageURL)
        && (smallImageFile != null)
        && (smallImageBytes != null)) {

      String smallImageName = smallImageFile.getName();

      if (smallImageName != null) {
        boolean validSmallImageExtension = false;

        for (int i = 0; i < imageExtensions.length; i++) {
          if (StringPool.STAR.equals(imageExtensions[i])
              || StringUtil.endsWith(smallImageName, imageExtensions[i])) {

            validSmallImageExtension = true;

            break;
          }
        }

        if (!validSmallImageExtension) {
          throw new ItemSmallImageNameException(smallImageName);
        }
      }

      long smallImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE);

      if ((smallImageMaxSize > 0)
          && ((smallImageBytes == null) || (smallImageBytes.length > smallImageMaxSize))) {

        throw new ItemSmallImageSizeException();
      }
    }

    // Medium image

    if (mediumImage
        && Validator.isNull(mediumImageURL)
        && (mediumImageFile != null)
        && (mediumImageBytes != null)) {

      String mediumImageName = mediumImageFile.getName();

      if (mediumImageName != null) {
        boolean validMediumImageExtension = false;

        for (int i = 0; i < imageExtensions.length; i++) {
          if (StringPool.STAR.equals(imageExtensions[i])
              || StringUtil.endsWith(mediumImageName, imageExtensions[i])) {

            validMediumImageExtension = true;

            break;
          }
        }

        if (!validMediumImageExtension) {
          throw new ItemMediumImageNameException(mediumImageName);
        }
      }

      long mediumImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE);

      if ((mediumImageMaxSize > 0)
          && ((mediumImageBytes == null) || (mediumImageBytes.length > mediumImageMaxSize))) {

        throw new ItemMediumImageSizeException();
      }
    }

    // Large image

    if (!largeImage
        || Validator.isNotNull(largeImageURL)
        || (largeImageFile == null)
        || (largeImageBytes == null)) {

      return;
    }

    String largeImageName = largeImageFile.getName();

    if (largeImageName != null) {
      boolean validLargeImageExtension = false;

      for (int i = 0; i < imageExtensions.length; i++) {
        if (StringPool.STAR.equals(imageExtensions[i])
            || StringUtil.endsWith(largeImageName, imageExtensions[i])) {

          validLargeImageExtension = true;

          break;
        }
      }

      if (!validLargeImageExtension) {
        throw new ItemLargeImageNameException(largeImageName);
      }
    }

    long largeImageMaxSize = PrefsPropsUtil.getLong(PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE);

    if ((largeImageMaxSize > 0)
        && ((largeImageBytes == null) || (largeImageBytes.length > largeImageMaxSize))) {

      throw new ItemLargeImageSizeException();
    }
  }
コード例 #6
0
  protected void handleUploadException(
      ActionRequest actionRequest,
      ActionResponse actionResponse,
      String cmd,
      long maxFileSize,
      Exception e)
      throws Exception {

    if (e instanceof PrincipalException) {
      SessionErrors.add(actionRequest, e.getClass());

      setForward(actionRequest, "portal.error");
    } else if (e instanceof AntivirusScannerException
        || e instanceof FileExtensionException
        || e instanceof FileSizeException
        || e instanceof ImageTypeException
        || e instanceof NoSuchFileException
        || e instanceof UploadException) {

      if (cmd.equals(Constants.ADD_TEMP)) {
        hideDefaultErrorMessage(actionRequest);

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

        String errorMessage = StringPool.BLANK;

        if (e instanceof AntivirusScannerException) {
          AntivirusScannerException ase = (AntivirusScannerException) e;

          errorMessage = themeDisplay.translate(ase.getMessageKey());
        } else if (e instanceof FileExtensionException) {
          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-extension-x",
                  StringUtil.merge(PropsValues.DL_FILE_EXTENSIONS, StringPool.COMMA));
        } else if (e instanceof FileSizeException) {
          if (maxFileSize == 0) {
            maxFileSize = PrefsPropsUtil.getLong(PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE);
          }

          errorMessage =
              themeDisplay.translate(
                  "please-enter-a-file-with-a-valid-file-size-no" + "-larger-than-x",
                  TextFormatter.formatStorageSize(maxFileSize, themeDisplay.getLocale()));
        } else if (e instanceof ImageTypeException) {
          errorMessage = themeDisplay.translate("please-enter-a-file-with-a-valid-file-type");
        } else if (e instanceof NoSuchFileException || e instanceof UploadException) {

          errorMessage =
              themeDisplay.translate("an-unexpected-error-occurred-while-uploading" + "-your-file");
        }

        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("errorMessage", errorMessage);

        writeJSON(actionRequest, actionResponse, jsonObject);
      } else {
        SessionErrors.add(actionRequest, e.getClass(), e);
      }
    } else {
      throw e;
    }
  }