Пример #1
0
  public int moveSimpleResource(
      WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite)
      throws WebDAVException {

    try {
      String[] destinationArray = WebDAVUtil.getPathArray(destination, true);

      IGImage image = (IGImage) resource.getModel();

      long companyId = webDavRequest.getCompanyId();
      long groupId = WebDAVUtil.getGroupId(companyId, destinationArray);
      long parentFolderId = getParentFolderId(companyId, destinationArray);
      String name = WebDAVUtil.getResourceName(destinationArray);
      String description = image.getDescription();
      File file = null;
      String contentType = null;

      ServiceContext serviceContext = new ServiceContext();

      int status = HttpServletResponse.SC_CREATED;

      if (overwrite) {
        if (deleteResource(groupId, parentFolderId, name)) {
          status = HttpServletResponse.SC_NO_CONTENT;
        }
      }

      IGImageServiceUtil.updateImage(
          image.getImageId(),
          groupId,
          parentFolderId,
          name,
          description,
          file,
          contentType,
          serviceContext);

      return status;
    } catch (PrincipalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (DuplicateFileException dfe) {
      return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (DuplicateFolderNameException dfne) {
      return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
Пример #2
0
  public int putResource(WebDAVRequest webDavRequest) throws WebDAVException {
    File file = null;

    try {
      HttpServletRequest request = webDavRequest.getHttpServletRequest();

      String[] pathArray = webDavRequest.getPathArray();

      long companyId = webDavRequest.getCompanyId();
      long groupId = webDavRequest.getGroupId();
      long parentFolderId = getParentFolderId(companyId, pathArray);
      String name = WebDAVUtil.getResourceName(pathArray);
      String description = StringPool.BLANK;

      file = FileUtil.createTempFile(FileUtil.getExtension(name));

      FileUtil.write(file, request.getInputStream());

      String contentType = MimeTypesUtil.getContentType(name);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddCommunityPermissions(isAddCommunityPermissions(groupId));
      serviceContext.setAddGuestPermissions(true);

      try {
        IGImage image =
            IGImageServiceUtil.getImageByFolderIdAndNameWithExtension(
                groupId, parentFolderId, name);

        long imageId = image.getImageId();

        description = image.getDescription();

        String[] assetTagNames =
            AssetTagLocalServiceUtil.getTagNames(IGImage.class.getName(), imageId);

        serviceContext.setAssetTagNames(assetTagNames);

        IGImageServiceUtil.updateImage(
            imageId, groupId, parentFolderId, name, description, file, contentType, serviceContext);
      } catch (NoSuchImageException nsie) {
        IGImageServiceUtil.addImage(
            groupId, parentFolderId, name, description, file, contentType, serviceContext);
      }

      return HttpServletResponse.SC_CREATED;
    } catch (PrincipalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (PortalException pe) {
      if (_log.isWarnEnabled()) {
        _log.warn(pe, pe);
      }

      return HttpServletResponse.SC_CONFLICT;
    } catch (Exception e) {
      throw new WebDAVException(e);
    } finally {
      if (file != null) {
        file.delete();
      }
    }
  }