public int deleteResource(WebDAVRequest webDavRequest) throws WebDAVException {

    try {
      Resource resource = getResource(webDavRequest);

      if (resource == null) {
        return HttpServletResponse.SC_NOT_FOUND;
      }

      Object model = resource.getModel();

      if (model instanceof IGFolder) {
        IGFolder folder = (IGFolder) model;

        IGFolderServiceUtil.deleteFolder(folder.getFolderId());
      } else {
        IGImage image = (IGImage) model;

        IGImageServiceUtil.deleteImage(image.getImageId());
      }

      return HttpServletResponse.SC_NO_CONTENT;
    } catch (PrincipalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
示例#2
0
  public static int deleteResource(
      WebDAVRequest webDAVRequest, String rootPath, String token, long classNameId)
      throws WebDAVException {

    try {
      Resource resource = getResource(webDAVRequest, rootPath, token, classNameId);

      if (resource == null) {
        return HttpServletResponse.SC_NOT_FOUND;
      }

      Object model = resource.getModel();

      if (model instanceof DDMStructure) {
        DDMStructure structure = (DDMStructure) model;

        DDMStructureServiceUtil.deleteStructure(structure.getStructureId());

        return HttpServletResponse.SC_NO_CONTENT;
      } else if (model instanceof DDMTemplate) {
        DDMTemplate template = (DDMTemplate) model;

        DDMTemplateServiceUtil.deleteTemplate(template.getTemplateId());

        return HttpServletResponse.SC_NO_CONTENT;
      } else {
        return HttpServletResponse.SC_FORBIDDEN;
      }
    } catch (PortalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
  public static Resource toResource(
      WebDAVRequest webDAVRequest, String type, String rootPath, boolean appendPath) {

    String parentPath = rootPath + webDAVRequest.getPath();

    String name = StringPool.BLANK;

    if (appendPath) {
      name = type;
    }

    Resource resource = new BaseResourceImpl(parentPath, name, type);

    resource.setModel(type);

    return resource;
  }
  public int copyCollectionResource(
      WebDAVRequest webDavRequest,
      Resource resource,
      String destination,
      boolean overwrite,
      long depth)
      throws WebDAVException {

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

      long companyId = webDavRequest.getCompanyId();

      long parentFolderId = IGFolderConstants.DEFAULT_PARENT_FOLDER_ID;

      try {
        parentFolderId = getParentFolderId(companyId, destinationArray);
      } catch (NoSuchFolderException nsfe) {
        return HttpServletResponse.SC_CONFLICT;
      }

      IGFolder folder = (IGFolder) resource.getModel();

      long groupId = WebDAVUtil.getGroupId(companyId, destination);
      String name = WebDAVUtil.getResourceName(destinationArray);
      String description = folder.getDescription();

      int status = HttpServletResponse.SC_CREATED;

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

      ServiceContext serviceContext = new ServiceContext();

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

      if (depth == 0) {
        IGFolderServiceUtil.addFolder(parentFolderId, name, description, serviceContext);
      } else {
        IGFolderServiceUtil.copyFolder(
            folder.getFolderId(), parentFolderId, name, description, serviceContext);
      }

      return status;
    } catch (DuplicateFolderNameException dfne) {
      return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (PrincipalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
  protected Resource toResource(WebDAVRequest webDavRequest, IGFolder folder, boolean appendPath) {

    String parentPath = getRootPath() + webDavRequest.getPath();
    String name = StringPool.BLANK;

    if (appendPath) {
      name = folder.getName();
    }

    Resource resource =
        new BaseResourceImpl(
            parentPath, name, folder.getName(), folder.getCreateDate(), folder.getModifiedDate());

    resource.setModel(folder);
    resource.setClassName(IGFolder.class.getName());
    resource.setPrimaryKey(folder.getPrimaryKey());

    return resource;
  }
  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);
    }
  }
  public static int putResource(
      WebDAVRequest webDAVRequest, String rootPath, String token, long classNameId)
      throws WebDAVException {

    try {
      Resource resource = getResource(webDAVRequest, rootPath, token, classNameId);

      if (resource == null) {
        return addResource(webDAVRequest, classNameId);
      }

      Object model = resource.getModel();

      if (model instanceof DDMStructure) {
        DDMStructure structure = (DDMStructure) model;

        HttpServletRequest request = webDAVRequest.getHttpServletRequest();

        String definition = StringUtil.read(request.getInputStream());

        DDMForm ddmForm = getDDMForm(definition);

        DDMFormLayout ddmFormLayout = DDMUtil.getDefaultDDMFormLayout(ddmForm);

        DDMStructureServiceUtil.updateStructure(
            structure.getGroupId(),
            structure.getParentStructureId(),
            structure.getClassNameId(),
            structure.getStructureKey(),
            structure.getNameMap(),
            structure.getDescriptionMap(),
            ddmForm,
            ddmFormLayout,
            new ServiceContext());

        return HttpServletResponse.SC_CREATED;
      } else if (model instanceof DDMTemplate) {
        DDMTemplate template = (DDMTemplate) model;

        HttpServletRequest request = webDAVRequest.getHttpServletRequest();

        String script = StringUtil.read(request.getInputStream());

        DDMTemplateServiceUtil.updateTemplate(
            template.getTemplateId(),
            template.getClassPK(),
            template.getNameMap(),
            template.getDescriptionMap(),
            template.getType(),
            template.getMode(),
            template.getLanguage(),
            script,
            template.isCacheable(),
            template.isSmallImage(),
            template.getSmallImageURL(),
            null,
            new ServiceContext());

        return HttpServletResponse.SC_CREATED;
      } else {
        return HttpServletResponse.SC_FORBIDDEN;
      }
    } catch (PortalException pe) {
      if (_log.isDebugEnabled()) {
        _log.debug(pe, pe);
      }

      return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
  public int copySimpleResource(
      WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite)
      throws WebDAVException {

    File file = null;

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

      long companyId = webDavRequest.getCompanyId();

      long parentFolderId = IGFolderConstants.DEFAULT_PARENT_FOLDER_ID;

      try {
        parentFolderId = getParentFolderId(companyId, destinationArray);
      } catch (NoSuchFolderException nsfe) {
        return HttpServletResponse.SC_CONFLICT;
      }

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

      long groupId = WebDAVUtil.getGroupId(companyId, destination);
      String name = WebDAVUtil.getResourceName(destinationArray);
      String description = image.getDescription();
      String contentType = MimeTypesUtil.getContentType(image.getNameWithExtension());

      file = FileUtil.createTempFile(image.getImageType());

      InputStream is = resource.getContentAsStream();

      FileUtil.write(file, is);

      ServiceContext serviceContext = new ServiceContext();

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

      int status = HttpServletResponse.SC_CREATED;

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

      IGImageServiceUtil.addImage(
          groupId, parentFolderId, name, description, file, contentType, serviceContext);

      return status;
    } catch (DuplicateFolderNameException dfne) {
      return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (DuplicateFileException dfe) {
      return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (PrincipalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
      throw new WebDAVException(e);
    } finally {
      if (file != null) {
        file.delete();
      }
    }
  }