Esempio n. 1
0
  private Resource getLocalResource(String resourceRef) throws Exception {
    if (resourceRef != null && resourceRef.startsWith("/")) {
      RequestContext requestContext = RequestContext.getRequestContext();
      Repository repository = requestContext.getRepository();
      String token = requestContext.getSecurityToken();
      return repository.retrieve(token, Path.fromString(resourceRef), true);
    }

    return null;
  }
 public void removePropertyValue(PropertyTypeDefinition propDef) throws Exception {
   RequestContext requestContext = RequestContext.getRequestContext();
   Repository repository = requestContext.getRepository();
   String token = SecurityContext.getSecurityContext().getToken();
   Path uri = requestContext.getResourceURI();
   Resource resource = repository.retrieve(token, uri, true);
   if (resource.getProperty(propDef) != null) {
     resource.removeProperty(propDef);
     repository.store(token, resource);
   }
 }
 public void setPropertyDateValue(PropertyTypeDefinition datePropDef, Date date) throws Exception {
   RequestContext requestContext = RequestContext.getRequestContext();
   Repository repository = requestContext.getRepository();
   String token = SecurityContext.getSecurityContext().getToken();
   Path uri = requestContext.getResourceURI();
   Resource resource = repository.retrieve(token, uri, true);
   Property dateProp = resource.getProperty(datePropDef);
   if (dateProp == null) {
     dateProp = datePropDef.createProperty();
     resource.addProperty(dateProp);
   }
   dateProp.setDateValue(date);
   repository.store(token, resource);
 }
  protected Object formBackingObject(HttpServletRequest request) throws Exception {

    RequestContext requestContext = RequestContext.getRequestContext();
    Repository repository = requestContext.getRepository();
    Path uri = requestContext.getResourceURI();
    String token = requestContext.getSecurityToken();
    Resource resource = repository.retrieve(token, uri, false);

    Service service = requestContext.getService();
    String submitURL = service.constructLink(resource, requestContext.getPrincipal());

    EditPublishingCommand command = new EditPublishingCommand(submitURL);
    command.setResource(resource);

    return command;
  }
Esempio n. 5
0
  @Override
  protected ModelAndView onSubmit(Object command) throws Exception {
    ResourceEditWrapper wrapper = (ResourceEditWrapper) command;
    Resource resource = wrapper.getResource();
    RequestContext requestContext = RequestContext.getRequestContext();
    Principal principal = requestContext.getPrincipal();
    Repository repository = requestContext.getRepository();
    String token = requestContext.getSecurityToken();

    if (wrapper.hasErrors()) {
      Map<String, Object> model = getModelProperties(command, resource, principal, repository);
      return new ModelAndView(getFormView(), model);
    }

    if (!wrapper.isSave() && !wrapper.isSaveCopy() && !wrapper.isView()) {
      this.resourceManager.unlock();
      return new ModelAndView(getSuccessView(), new HashMap<String, Object>());
    }

    Property imageHeightProp = heightPropDef.createProperty();
    imageHeightProp.setIntValue(wrapper.getNewHeight());
    resource.addProperty(imageHeightProp);

    Property imageWidthProp = widthPropDef.createProperty();
    imageWidthProp.setIntValue(wrapper.getNewWidth());
    resource.addProperty(imageWidthProp);

    InputStream is =
        saveImageHelper.getEditedImageInputStream(
            resource,
            repository,
            token,
            resource.getURI(),
            wrapper.getCropX(),
            wrapper.getCropY(),
            wrapper.getCropWidth(),
            wrapper.getCropHeight(),
            wrapper.getNewWidth(),
            wrapper.getNewHeight());

    if (wrapper.isSaveCopy()) {
      Path destUri =
          copyHelper.copyResource(
              resource.getURI(), resource.getURI(), repository, token, resource, is);
      this.resourceManager.unlock();
      return new ModelAndView(new RedirectView(this.editService.constructURL(destUri).toString()));
    }

    repository.store(token, resource);
    if (is != null) {
      repository.storeContent(token, wrapper.getURI(), is);
    }

    if (!wrapper.isView()) {
      Map<String, Object> model = getModelProperties(command, resource, principal, repository);
      wrapper.setSave(false);
      model = addImageEditorServices(model, resource, principal);
      return new ModelAndView(getFormView(), model);
    }

    this.resourceManager.unlock();
    return new ModelAndView(getSuccessView());
  }