Class InteropFramework

  • All Implemented Interfaces:
    org.openprovenance.prov.interop.Framework, org.openprovenance.prov.interop.InteropMediaType, org.openprovenance.prov.model.ProvDocumentWriter

    public class InteropFramework
    extends Object
    implements org.openprovenance.prov.interop.InteropMediaType, org.openprovenance.prov.model.ProvDocumentWriter, org.openprovenance.prov.interop.Framework
    The interoperability framework for PROV, with utility methods to write and read documents to files and streams, according to media types, format (specified as Formats.ProvFormat). The class also provides helper functions to support content negotiation.
    Author:
    lavm, dtm
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String configFile  
      static String configuration  
      static org.openprovenance.prov.model.ProvFactory defaultFactory  
      Hashtable<String,​org.openprovenance.prov.interop.Formats.ProvFormat> extensionRevMap  
      static String factoryClass  
      Hashtable<String,​org.openprovenance.prov.interop.Formats.ProvFormat> mimeTypeRevMap  
      static String UNKNOWN  
      • Fields inherited from interface org.openprovenance.prov.interop.InteropMediaType

        ALL_PROV_INPUT_MEDIA_TYPES, ALL_PROV_OUTPUT_MEDIA_TYPES, EXTENSION_DOT, EXTENSION_JPEG, EXTENSION_JPG, EXTENSION_JSON, EXTENSION_JSONLD, EXTENSION_PDF, EXTENSION_PNG, EXTENSION_PROVN, EXTENSION_PROVX, EXTENSION_RDF, EXTENSION_SVG, EXTENSION_TRIG, EXTENSION_TTL, EXTENSION_XML, MEDIA_APPLICATION_FORM_URLENCODED, MEDIA_APPLICATION_JSON, MEDIA_APPLICATION_JSONLD, MEDIA_APPLICATION_PDF, MEDIA_APPLICATION_PROVENANCE_XML, MEDIA_APPLICATION_RDF_XML, MEDIA_APPLICATION_SQL, MEDIA_APPLICATION_TRIG, MEDIA_APPLICATION_XML, MEDIA_IMAGE_JPEG, MEDIA_IMAGE_PNG, MEDIA_IMAGE_SVG_XML, MEDIA_TEXT_CSV, MEDIA_TEXT_HTML, MEDIA_TEXT_PLAIN, MEDIA_TEXT_PROVENANCE_NOTATION, MEDIA_TEXT_TURTLE, MEDIA_TEXT_VND_GRAPHVIZ, MEDIA_TEXT_XML
    • Field Detail

      • configuration

        public static final String configuration
      • factoryClass

        public static final String factoryClass
      • defaultFactory

        public static final org.openprovenance.prov.model.ProvFactory defaultFactory
      • extensionRevMap

        public final Hashtable<String,​org.openprovenance.prov.interop.Formats.ProvFormat> extensionRevMap
      • mimeTypeRevMap

        public final Hashtable<String,​org.openprovenance.prov.interop.Formats.ProvFormat> mimeTypeRevMap
    • Constructor Detail

      • InteropFramework

        public InteropFramework()
        Default constructor for the ProvToolbox interoperability framework. It uses the factory declared in the configuration file as its default factory.
      • InteropFramework

        public InteropFramework​(org.openprovenance.prov.model.ProvFactory pFactory)
      • InteropFramework

        public InteropFramework​(CommandLineArguments config,
                                org.openprovenance.prov.model.ProvFactory pFactory)
    • Method Detail

      • getDefaultFactory

        public static org.openprovenance.prov.model.ProvFactory getDefaultFactory()
      • getFactory

        public org.openprovenance.prov.model.ProvFactory getFactory()
        Specified by:
        getFactory in interface org.openprovenance.prov.interop.Framework
      • buildAcceptHeader

        public String buildAcceptHeader()
        Create a list of mime types supported by ProvToolbox in view of constructing an Accept Header.
        Returns:
        a string representing the mime types.
      • connectWithRedirect

        public URLConnection connectWithRedirect​(URL theURL)
                                          throws IOException
        A method to connect to a URL and follow redirects if any.
        Parameters:
        theURL - a URL to connect to
        Returns:
        a URLConnection
        Throws:
        IOException - if connection cannot be opened and no response is received.
      • convertExtensionToMediaType

        public String convertExtensionToMediaType​(String extension)
        Maps an file extension to a Media type
        Parameters:
        extension - the extension of a file containing a serialization of PROV
        Returns:
        a String for the Internet Media type corresponding to a file with this extension
      • getExtension

        public String getExtension​(org.openprovenance.prov.interop.Formats.ProvFormat format)
        Returns an extension for a given type of serialization of PROV
        Parameters:
        format - Formats.ProvFormat for which file extension is sought
        Returns:
        a String for the extension of a file containing such a serialization
      • getTypeForFile

        public org.openprovenance.prov.interop.Formats.ProvFormat getTypeForFile​(String filename)
        Get a Formats.ProvFormat given the file's exetension
        Parameters:
        filename - the file for which the Formats.ProvFormat is sought
        Returns:
        a Formats.ProvFormat
      • getTypeForFormat

        public org.openprovenance.prov.interop.Formats.ProvFormat getTypeForFormat​(String format)
        Get a Formats.ProvFormat given a format string
        Parameters:
        format - the format for which the Formats.ProvFormat is sought
        Returns:
        a Formats.ProvFormat
      • getVariants

        public List<jakarta.ws.rs.core.Variant> getVariants()
        Support for content negotiation, jax-rs style. Create a list of media type supported by the framework.
        Returns:
        a list of Variant
        See Also:
        Content Negotiation
      • initializeExtensionMap

        public void initializeExtensionMap​(Hashtable<org.openprovenance.prov.interop.Formats.ProvFormat,​String> extensionMap,
                                           Hashtable<String,​org.openprovenance.prov.interop.Formats.ProvFormat> extensionRevMap)
        Initialization function
        Parameters:
        extensionMap - mapping of Formats.ProvFormat to extensions
        extensionRevMap - reverse mapping of extensions to Formats.ProvFormat
      • isInputFormat

        public Boolean isInputFormat​(org.openprovenance.prov.interop.Formats.ProvFormat format)
        Determines whether this format received as argument is an input format.
        Parameters:
        format - a Formats.ProvFormat
        Returns:
        true if format is an input format
      • isOutputFormat

        public Boolean isOutputFormat​(org.openprovenance.prov.interop.Formats.ProvFormat format)
        Determines whether this format received as argument is an output format.
        Parameters:
        format - a Formats.ProvFormat
        Returns:
        true if format is an output format
      • setMaxStringLength

        public void setMaxStringLength​(Integer maxStringLength)
      • writeDocument

        public void writeDocument​(String filename,
                                  org.openprovenance.prov.model.Document document)
        Write a Document to file, serialized according to the file extension. If extension is not known, throws an exception.
        Parameters:
        filename - path of the file to write the Document to
        document - a Document to serialize
        Throws:
        InteropException - if the extension of the file is not known
      • writeDocument

        public void writeDocument​(String filename,
                                  org.openprovenance.prov.model.Document document,
                                  org.openprovenance.prov.interop.Formats.ProvFormat format)
        Write a Document to file, serialized according to format Formats.ProvFormat
        Parameters:
        filename - path of the file to write the Document to
        document - a Document to serialize
        format - a Formats.ProvFormat to serialize the document to
      • writeDocument

        public void writeDocument​(OutputStream os,
                                  org.openprovenance.prov.model.Document document,
                                  org.openprovenance.prov.interop.Formats.ProvFormat format)
        Write a Document to output stream, according to specified Formats.ProvFormat
        Specified by:
        writeDocument in interface org.openprovenance.prov.interop.Framework
        Parameters:
        os - an OutputStream to write the Document to
        document - a Document to serialize
        format - a Formats.ProvFormat
      • writeDocument

        public void writeDocument​(OutputStream out,
                                  org.openprovenance.prov.model.Document document,
                                  String mediaType,
                                  boolean formatted)
        Specified by:
        writeDocument in interface org.openprovenance.prov.model.ProvDocumentWriter
      • mediaTypes

        public Collection<String> mediaTypes()
        Specified by:
        mediaTypes in interface org.openprovenance.prov.model.ProvDocumentWriter
      • getExtensionMap

        public Hashtable<org.openprovenance.prov.interop.Formats.ProvFormat,​String> getExtensionMap()
      • getMimeTypeMap

        public Hashtable<org.openprovenance.prov.interop.Formats.ProvFormat,​String> getMimeTypeMap()
      • getMimeTypeRevMap

        public Hashtable<String,​org.openprovenance.prov.interop.Formats.ProvFormat> getMimeTypeRevMap()
      • getDeserializerMap

        public Map<org.openprovenance.prov.interop.Formats.ProvFormat,​DeserializerFunction> getDeserializerMap()
      • getDeserializerMap2

        public Map<org.openprovenance.prov.interop.Formats.ProvFormat,​DeserializerFunction2> getDeserializerMap2()
      • readDocument

        public org.openprovenance.prov.model.Document readDocument​(InputStream is,
                                                                   org.openprovenance.prov.interop.Formats.ProvFormat format)
                                                            throws IOException
        Reads a document from an input stream, using the specified format. Uses configuration's dateTimeOption and timeZone.
        Parameters:
        is - an InputStream
        format - a Formats.ProvFormat
        Returns:
        a Document
        Throws:
        IOException - if the input stream cannot be read
      • readDocument

        public org.openprovenance.prov.model.Document readDocument​(InputStream is,
                                                                   org.openprovenance.prov.interop.Formats.ProvFormat format,
                                                                   org.openprovenance.prov.model.DateTimeOption dateTimeOption,
                                                                   TimeZone timeZone)
                                                            throws IOException
        Reads a document from an input stream, using the specified format.
        Parameters:
        is - an InputStream
        format - a Formats.ProvFormat
        dateTimeOption - a DateTimeOption
        timeZone - a TimeZone
        Returns:
        a Document
        Throws:
        IOException - if the input stream cannot be read
      • readDocumentFromFile

        public org.openprovenance.prov.model.Document readDocumentFromFile​(String filename,
                                                                           org.openprovenance.prov.model.DateTimeOption dateTimeOption,
                                                                           TimeZone timeZone)
        Reads a document from a file, using the filename extension as an indicator of the serialization type.
        Parameters:
        filename - a file to load the provenance document from
        dateTimeOption - a DateTimeOption
        timeZone - a TimeZone
        Returns:
        a Document
        Throws:
        InteropException - if the file extension is not known or file cannot be read
      • readDocumentFromFileWithUnknownType

        public org.openprovenance.prov.model.Document readDocumentFromFileWithUnknownType​(String filename)
        Read a document without knowing its serialization format. First parser that succeeds returns a result.
        Parameters:
        filename - a file to load the provenance document from
        Returns:
        a Document
      • readDocumentFromFileWithUnknownType

        public org.openprovenance.prov.model.Document readDocumentFromFileWithUnknownType​(String filename,
                                                                                          org.openprovenance.prov.model.DateTimeOption dateTimeOption,
                                                                                          TimeZone timeZone)
        Read a document without knowing its serialization format. First parser that succeeds returns a result.
        Parameters:
        filename - a file to load the provenance document from
        dateTimeOption - a DateTimeOption
        timeZone - a TimeZone
        Returns:
        a Document
      • readDocumentFromURL

        public org.openprovenance.prov.model.Document readDocumentFromURL​(String url)
        Reads a document from a URL. Uses the Content-type header field to determine the mime-type of the resource, and therefore the parser to read the document.
        Parameters:
        url - a URL
        Returns:
        a Document
      • readDocumentFromFile

        public org.openprovenance.prov.model.Document readDocumentFromFile​(String filename)
        Reads a document from a file, using the file extension to decide which parser to read the file with.
        Parameters:
        filename - the file to read a document from
        Returns:
        a Document