예제 #1
0
 protected String getTitle(Resource feedScope, RequestContext requestContext) {
   String feedTitle = feedScope.getTitle();
   if (Path.ROOT.equals(feedScope.getURI())) {
     feedTitle = requestContext.getRepository().getId();
   }
   return feedTitle;
 }
예제 #2
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());
  }