Class DefaultMediaPackageSerializerImpl

java.lang.Object
org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl
All Implemented Interfaces:
MediaPackageSerializer

public class DefaultMediaPackageSerializerImpl extends Object implements MediaPackageSerializer
Default implementation of a MediaPackageSerializer that is able to deal with relative urls in manifest.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected URL
    Optional package root file
    static final int
    It's very likely that this should be the first serializer when encoding an URI, therefore choose a high ranking
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new package serializer that will work completely transparent, therefore resolving urls by simply returning them as is.
    Creates a new package serializer that enables the resolution of relative urls from the manifest by taking packageRoot as the root directory.
    Creates a new package serializer that enables the resolution of relative urls from the manifest by taking packageRoot as the root url.
  • Method Summary

    Modifier and Type
    Method
    Description
    This serializer implementation tries to cope with relative urls.
    This serializer implementation tries to cope with relative urls.
    Returns the package root that is used determine and resolve relative paths.
    int
    Identifies the serializer ranking number.
    void
    setPackageRoot(URL packageRoot)
    Sets the package root.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • packageRoot

      protected URL packageRoot
      Optional package root file
    • RANKING

      public static final int RANKING
      It's very likely that this should be the first serializer when encoding an URI, therefore choose a high ranking
      See Also:
  • Constructor Details

    • DefaultMediaPackageSerializerImpl

      public DefaultMediaPackageSerializerImpl()
      Creates a new package serializer that will work completely transparent, therefore resolving urls by simply returning them as is.
    • DefaultMediaPackageSerializerImpl

      public DefaultMediaPackageSerializerImpl(URL packageRoot)
      Creates a new package serializer that enables the resolution of relative urls from the manifest by taking packageRoot as the root url.
      Parameters:
      packageRoot - the root url
    • DefaultMediaPackageSerializerImpl

      public DefaultMediaPackageSerializerImpl(File packageRoot) throws MalformedURLException
      Creates a new package serializer that enables the resolution of relative urls from the manifest by taking packageRoot as the root directory.
      Parameters:
      packageRoot - the root url
      Throws:
      MalformedURLException - if the file cannot be converted to a url
  • Method Details

    • getPackageRoot

      public URL getPackageRoot()
      Returns the package root that is used determine and resolve relative paths. Note that the package root may be null.
      Returns:
      the packageRoot
    • setPackageRoot

      public void setPackageRoot(URL packageRoot)
      Sets the package root.
      Parameters:
      packageRoot - the packageRoot to set
      See Also:
    • encodeURI

      public URI encodeURI(URI uri) throws URISyntaxException
      This serializer implementation tries to cope with relative urls. Should the root url be set to any value other than null, the serializer will try to convert element urls to relative paths if possible. .
      Specified by:
      encodeURI in interface MediaPackageSerializer
      Parameters:
      uri - the url to encode
      Returns:
      the encoded path
      Throws:
      URISyntaxException - if the resulting URI contains syntax errors
      See Also:
    • decodeURI

      public URI decodeURI(URI uri) throws URISyntaxException
      This serializer implementation tries to cope with relative urls. Should the path start with neither a protocol nor a path separator, the packageRoot is used to create the url relative to the root url that was passed in the constructor.

      Note that for absolute paths without a protocol, the file:// protocol is assumed.

      Specified by:
      decodeURI in interface MediaPackageSerializer
      Parameters:
      uri - the original path from the manifest
      Returns:
      the resolved url
      Throws:
      URISyntaxException - if the path cannot be converted into a url
      URISyntaxException - if the resulting URI contains syntax errors
      See Also:
    • getRanking

      public int getRanking()
      Description copied from interface: MediaPackageSerializer
      Identifies the serializer ranking number. The ranking is respected when multiple serializers are chained. When encoding an URI, the serializer with the highest ranking is used first. If an URI needs to be decoded, the ranking is used in the opposite direction.
      Specified by:
      getRanking in interface MediaPackageSerializer
      Returns:
      The service ranking number.