Пример #1
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);
    }
  }
Пример #2
0
  @Override
  public boolean evaluate(Property property, PropertyEvaluationContext ctx)
      throws PropertyEvaluationException {
    Type evalType = ctx.getEvaluationType();

    if (evalType == Type.Create) {
      if (ctx.isCollection()) {
        property.setStringValue(X_VORTEX_COLLECTION);
        return true;
      }
      // Unless proeprty has been preset to some controlled or desired value,
      // take a guess based on name:
      if (!property.isValueInitialized()) {
        String guessedContentType = MimeHelper.map(ctx.getNewResource().getName());
        property.setStringValue(guessedContentType);
      }
    }
    if (this.contentPeekRegexps == null) {
      return true;
    }

    if (evalType == Type.Create || evalType == Type.ContentChange) {
      // Initial guess:
      String resourceContentType = ctx.getOriginalResource().getContentType();
      if (resourceContentType == null
          || resourceContentType.isEmpty()
          || "application/octet-stream".equals(resourceContentType)) {
        resourceContentType = MimeHelper.map(ctx.getNewResource().getName());
        property.setStringValue(resourceContentType);
      }

      if (this.contentPeekRegexps.containsKey(resourceContentType)) {
        try {
          // Peek in content:
          InputStream inputStream = ctx.getContent().getContentInputStream();
          byte[] buffer = StreamUtil.readInputStream(inputStream, this.regexpChunkSize);
          String chunk = new String(buffer, this.peekCharacterEncoding.name());
          Map<Pattern, String> mapping = this.contentPeekRegexps.get(resourceContentType);
          for (Pattern pattern : mapping.keySet()) {
            Matcher m = pattern.matcher(chunk);
            boolean match = m.find();
            if (match) {
              // XXX: temporary hack:
              if ("application/json".equals(mapping.get(pattern))) {
                try {
                  ctx.getContent().getContentRepresentation(Json.MapContainer.class);
                  property.setStringValue(mapping.get(pattern));
                  return true;
                } catch (Exception e) {
                }
              }
            }
          }
        } catch (Throwable t) {
        }
      }
    }
    return true;
  }
Пример #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 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);
    }
  }