Esempio n. 1
0
  @Override
  public ModelAndView generateFeed(HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    RequestContext requestContext = RequestContext.getRequestContext();
    Path uri = requestContext.getResourceURI();
    String token = requestContext.getSecurityToken();
    Resource feedScope = requestContext.getRepository().retrieve(token, uri, true);

    Map<String, Object> feedContent = new HashMap<String, Object>();

    // Title, link and description are required by spec
    feedContent.put("title", getTitle(feedScope, requestContext));
    feedContent.put("link", request.getRequestURL().toString());
    Property introductionProp = feedScope.getProperty(introductionPropDef);
    String description =
        introductionProp != null
            ? introductionProp.getFormattedValue(HtmlValueFormatter.FLATTENED_FORMAT, null)
            : "";
    feedContent.put("description", description);

    // Optional elements
    feedContent.put("atomLink", requestContext.getRequestURL().toString());

    if (!StringUtils.isBlank(feedLogoPath)) {
      feedContent.put("feedLogoPath", feedLogoPath);
    }

    feedContent.put("feedItems", getFeedEntries(feedScope));

    Map<String, Object> model = new HashMap<String, Object>();
    model.put("feedContent", feedContent);

    return new ModelAndView(viewName, model);
  }
Esempio n. 2
0
 protected String getTitle(Resource feedScope, RequestContext requestContext) {
   String feedTitle = feedScope.getTitle();
   if (Path.ROOT.equals(feedScope.getURI())) {
     feedTitle = requestContext.getRepository().getId();
   }
   return feedTitle;
 }
Esempio n. 3
0
  /**
   * Provided model data:
   *
   * <ul>
   *   <li><code>mediaResource</code> - if media reference points to a local resource, then the
   *       {@link Resource} will be provided under this key if it could be retrieved from the
   *       repository.
   *   <li><code>media</code> - a {@link URL} instance pointing to the media.
   *   <li>TODO complete me
   * </ul>
   *
   * @param model model to add data to
   * @param mediaRef the media resource URI as a string
   * @param height height of inserted video
   * @param width width of inserted video
   * @param autoplay whether to setup player to start automatically or not.
   * @param contentType
   * @param streamType
   * @param poster
   * @param showDL
   * @throws AuthorizationException
   */
  public void addMediaPlayer(
      Map<String, Object> model,
      String mediaRef,
      String height,
      String width,
      String autoplay,
      String contentType,
      String streamType,
      String poster,
      String showDL) {

    if (URL.isEncoded(mediaRef)) {
      mediaRef = urlDecodeMediaRef(mediaRef);
    }

    Resource mediaResource = null;
    try {
      mediaResource = getLocalResource(mediaRef);
    } catch (AuthorizationException e) {
      return; // not able to read local resource - abort
    } catch (AuthenticationException e) {
      return; // not able to read local resource - abort
    } catch (Exception e) {
      // ignore
    }

    if (mediaResource != null) {
      model.put("mediaResource", mediaResource);
    }

    if ((height != null && !"".equals(height)) && (width != null && !"".equals(width))) {
      model.put("height", height);
      model.put("width", width);
    }

    if (autoplay != null && !autoplay.isEmpty()) model.put("autoplay", autoplay);

    if (streamType != null && !streamType.isEmpty()) model.put("streamType", streamType);

    model.put("showDL", showDL != null && showDL.equalsIgnoreCase("true") ? "true" : "false");

    if (poster != null && !poster.isEmpty()) model.put("poster", poster);
    else addPosterUrl(mediaResource, model);

    if (contentType != null && !contentType.isEmpty()) {
      model.put("contentType", contentType);
    } else if (mediaResource != null) {
      model.put("contentType", mediaResource.getContentType());
    } else {
      model.put("contentType", MimeHelper.map(mediaRef));
    }
    model.put("extension", MimeHelper.findExtension(mediaRef));
    model.put("nanoTime", System.nanoTime());

    if (mediaResource != null) {
      addMediaUrl(mediaResource, model);
    } else {
      addMediaUrl(mediaRef, model);
    }
  }
 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);
 }
Esempio n. 6
0
  /**
   * Provided model data:
   *
   * <ul>
   *   <li><code>mediaResource</code> - if media reference points to a local resource, then the
   *       {@link Resource} will be provided under this key if it could successfully be retrieved
   *       from the repository.
   *   <li><code>media</code> - a {@link URL} instance pointing to the media.
   *   <li>TODO complete me
   * </ul>
   *
   * @param model MVC model
   * @param mediaRef media reference/link as string
   */
  public void addMediaPlayer(Map<String, Object> model, String mediaRef) {

    if (URL.isEncoded(mediaRef)) {
      mediaRef = urlDecodeMediaRef(mediaRef);
    }

    Resource mediaResource = null;
    try {
      mediaResource = getLocalResource(mediaRef);
    } catch (AuthorizationException e) {
      return; // not able to read local resource - abort
    } catch (AuthenticationException e) {
      return; // not able to read local resource - abort
    } catch (Exception e) {
      // ignore
    }

    if (mediaResource != null) {
      model.put("mediaResource", mediaResource);
    }

    addPosterUrl(mediaResource, model);
    model.put("extension", MimeHelper.findExtension(mediaRef));

    if (mediaResource != null) {
      model.put("contentType", mediaResource.getContentType());
    } else {
      model.put("contentType", MimeHelper.map(mediaRef));
    }

    model.put("nanoTime", System.nanoTime());

    if (mediaResource != null) {
      addMediaUrl(mediaResource, model);
    } else {
      addMediaUrl(mediaRef, model);
    }
  }
Esempio n. 7
0
  private void addPosterUrl(Resource mediaResource, Map<String, Object> model) {
    if (mediaResource == null) return;
    URL poster = null;
    Property posterImageProp = mediaResource.getProperty(posterImagePropDef);
    Property thumbnail = mediaResource.getProperty(thumbnailPropDef);
    if (posterImageProp != null) {
      poster = createUrl(posterImageProp.getStringValue());
    } else if (thumbnail != null) {
      poster = thumbnailService.constructURL(mediaResource);
      // Work-around for SelectiveProtocolManager URL post-processing which sets
      // URL protocol to "http" for open resources, but this causes mixed-mode
      // in secure page context, since this URL points to an inline element (image).
      if (RequestContext.exists()) {
        if (RequestContext.getRequestContext().getServletRequest().isSecure()) {
          poster.setProtocol("https");
        }
      }
    }

    if (poster != null) {
      model.put("poster", poster);
    }
  }
Esempio n. 8
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());
  }