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) {
      if (_log.isDebugEnabled()) {
        _log.debug(pe, pe);
      }

      return HttpServletResponse.SC_FORBIDDEN;
    } 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);
    }
  }