Package org.openprovenance.prov.interop
Class InteropFramework
- java.lang.Object
-
- org.openprovenance.prov.interop.InteropFramework
-
- All Implemented Interfaces:
org.openprovenance.prov.interop.InteropMediaType,org.openprovenance.prov.model.ProvSerialiser
public class InteropFramework extends Object implements org.openprovenance.prov.interop.InteropMediaType, org.openprovenance.prov.model.ProvSerialiser
The interoperability framework for PROV, with utility methods to write and read documents to files and streams, according to media types, format (specified asFormats.ProvFormat). The class also provides helper functions to support content negotiation.- Author:
- lavm, dtm
-
-
Field Summary
Fields Modifier and Type Field Description static StringconfigFilestatic Stringconfigurationstatic org.openprovenance.prov.model.ProvFactorydefaultFactoryHashtable<org.openprovenance.prov.interop.Formats.ProvFormat,String>extensionMapHashtable<String,org.openprovenance.prov.interop.Formats.ProvFormat>extensionRevMapstatic StringfactoryClassHashtable<org.openprovenance.prov.interop.Formats.ProvFormat,String>mimeTypeMapHashtable<String,org.openprovenance.prov.interop.Formats.ProvFormat>mimeTypeRevMapHashtable<org.openprovenance.prov.interop.Formats.ProvFormat,org.openprovenance.prov.interop.Formats.ProvFormatType>provTypeMapstatic StringUNKNOWN-
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
-
-
Constructor Summary
Constructors Constructor Description InteropFramework()Default constructor for the ProvToolbox interoperability framework.InteropFramework(CommandLineArguments config, org.openprovenance.prov.model.ProvFactory pFactory)InteropFramework(org.openprovenance.prov.model.ProvFactory pFactory)
-
Method Summary
Modifier and Type Method Description StringbuildAcceptHeader()Create a list of mime types supported by ProvToolbox in view of constructing an Accept Header.URLConnectionconnectWithRedirect(URL theURL)A method to connect to a URL and follow redirects if any.StringconvertExtensionToMediaType(String extension)Maps an file extension to a Media typeMap<org.openprovenance.prov.interop.Formats.ProvFormat,DeserializerFunction>createDeserializerMap()Map<org.openprovenance.prov.interop.Formats.ProvFormat,DeserializerFunction>createLegacyDeserializerMap()Map<org.openprovenance.prov.interop.Formats.ProvFormat,SerializerFunction>createLegacySerializerMap()Map<org.openprovenance.prov.interop.Formats.ProvFormat,DeserializerFunction>createLightAndLegacyDeserializerMap()Map<org.openprovenance.prov.interop.Formats.ProvFormat,SerializerFunction>createLightAndLegacySerializerMap()Map<org.openprovenance.prov.interop.Formats.ProvFormat,SerializerFunction>createLightSerializerMap()Map<org.openprovenance.prov.interop.Formats.ProvFormat,SerializerFunction>createSerializerMap()org.openprovenance.prov.model.DocumentdeserialiseDocument(InputStream is, org.openprovenance.prov.interop.Formats.ProvFormat format)static org.openprovenance.prov.model.ProvFactorydynamicallyLoadFactory(String factory)static org.openprovenance.prov.model.ProvFactorygetDefaultFactory()StringgetExtension(org.openprovenance.prov.interop.Formats.ProvFormat format)Returns an extension for a given type of serialization of PROVstatic PropertiesgetPropertiesFromClasspath(String propFileName)List<Map<String,String>>getSupportedFormats()org.openprovenance.prov.interop.Formats.ProvFormatgetTypeForFile(String filename)Get aFormats.ProvFormatgiven the file's exetensionorg.openprovenance.prov.interop.Formats.ProvFormatgetTypeForFormat(String format)Get aFormats.ProvFormatgiven a format stringList<javax.ws.rs.core.Variant>getVariants()Support for content negotiation, jax-rs style.voidinitializeExtensionMap(Hashtable<org.openprovenance.prov.interop.Formats.ProvFormat,String> extensionMap, Hashtable<String,org.openprovenance.prov.interop.Formats.ProvFormat> extensionRevMap)Initialization functionBooleanisInputFormat(org.openprovenance.prov.interop.Formats.ProvFormat format)Determines whether this format received as argument is an input format.BooleanisOutputFormat(org.openprovenance.prov.interop.Formats.ProvFormat format)Determines whether this format received as argument is an output format.ObjectloadProvUnknownGraph(String filename)Experimental code, trying to load a document without knowing its serialization format.Collection<String>mediaTypes()org.openprovenance.prov.model.DocumentreadDocument(InputStream is, org.openprovenance.prov.interop.Formats.ProvFormat format, String baseuri)Reads a Document from an input stream, using the parser specified by the format argument.org.openprovenance.prov.model.DocumentreadDocument(InputStream is, org.openprovenance.prov.interop.Formats.ProvFormat format, org.openprovenance.prov.model.ProvFactory pFactory, String baseuri)Reads a Document from an input stream, using the parser specified by the format argument.org.openprovenance.prov.model.DocumentreadDocument(String url)Reads a document from a URL.org.openprovenance.prov.model.DocumentreadDocument(org.openprovenance.prov.interop.InteropFramework.ToRead something)org.openprovenance.prov.model.DocumentreadDocumentFromFile(String filename)Reads a document from a file, using the file extension to decide which parser to read the file with.org.openprovenance.prov.model.DocumentreadDocumentFromFile(String filename, org.openprovenance.prov.interop.Formats.ProvFormat format)Deprecated.Use instead deserialiseDocumentintrun()Top level entry point of this class, when called from the command line.voidserialiseDocument(OutputStream out, org.openprovenance.prov.model.Document document, boolean formatted)Serializes a document to a streamvoidserialiseDocument(OutputStream out, org.openprovenance.prov.model.Document document, String mediaType, boolean formatted)voidsetNamespaces(org.openprovenance.prov.model.Document doc)Initializes a Document's namespace.voidwriteDocument(OutputStream os, javax.ws.rs.core.MediaType mt, org.openprovenance.prov.model.Document document)Write aDocumentto output stream, according to specified Internet Media TypevoidwriteDocument(OutputStream os, org.openprovenance.prov.interop.Formats.ProvFormat format, org.openprovenance.prov.model.Document document)Write aDocumentto output stream, according to specifiedFormats.ProvFormatvoidwriteDocument(String filename, org.openprovenance.prov.interop.Formats.ProvFormat format, org.openprovenance.prov.model.Document document)Write aDocumentto file, serialized according to the file extensionvoidwriteDocument(String filename, org.openprovenance.prov.model.Document document)Write aDocumentto file, serialized according to the file extensionvoidwriteDocumentOLD(OutputStream os, org.openprovenance.prov.interop.Formats.ProvFormat format, org.openprovenance.prov.model.Document document)TO BE DELETED
-
-
-
Field Detail
-
configFile
public static final String configFile
- See Also:
- Constant Field Values
-
configuration
public static final String configuration
-
factoryClass
public static final String factoryClass
-
defaultFactory
public static final org.openprovenance.prov.model.ProvFactory defaultFactory
-
UNKNOWN
public static final String UNKNOWN
- See Also:
- Constant Field Values
-
extensionMap
public final Hashtable<org.openprovenance.prov.interop.Formats.ProvFormat,String> extensionMap
-
extensionRevMap
public final Hashtable<String,org.openprovenance.prov.interop.Formats.ProvFormat> extensionRevMap
-
mimeTypeMap
public final Hashtable<org.openprovenance.prov.interop.Formats.ProvFormat,String> mimeTypeMap
-
mimeTypeRevMap
public final Hashtable<String,org.openprovenance.prov.interop.Formats.ProvFormat> mimeTypeRevMap
-
provTypeMap
public final Hashtable<org.openprovenance.prov.interop.Formats.ProvFormat,org.openprovenance.prov.interop.Formats.ProvFormatType> provTypeMap
-
-
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
-
getPropertiesFromClasspath
public static Properties getPropertiesFromClasspath(String propFileName)
-
getDefaultFactory
public static org.openprovenance.prov.model.ProvFactory getDefaultFactory()
-
dynamicallyLoadFactory
public static org.openprovenance.prov.model.ProvFactory dynamicallyLoadFactory(String factory)
-
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.ProvFormatfor 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 aFormats.ProvFormatgiven the file's exetension- Parameters:
filename- the file for which theFormats.ProvFormatis sought- Returns:
- a
Formats.ProvFormat
-
getTypeForFormat
public org.openprovenance.prov.interop.Formats.ProvFormat getTypeForFormat(String format)
Get aFormats.ProvFormatgiven a format string- Parameters:
format- the format for which theFormats.ProvFormatis sought- Returns:
- a
Formats.ProvFormat
-
getVariants
public List<javax.ws.rs.core.Variant> getVariants()
Support for content negotiation, jax-rs style. Create a list of media type supported by the framework.- 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 ofFormats.ProvFormatto extensionsextensionRevMap- reverse mapping of extensions toFormats.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- aFormats.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- aFormats.ProvFormat- Returns:
- true if format is an output format
-
loadProvUnknownGraph
public Object loadProvUnknownGraph(String filename)
Experimental code, trying to load a document without knowing its serialization format. First parser that succeeds returns a results. Not a robust method!- Parameters:
filename- a file to load the provenance document from- Returns:
- a document
-
readDocument
public org.openprovenance.prov.model.Document readDocument(InputStream is, org.openprovenance.prov.interop.Formats.ProvFormat format, String baseuri)
Reads a Document from an input stream, using the parser specified by the format argument.- Parameters:
is- an input streamformat- one of the input formats supported by ProvToolboxbaseuri- a base uri for the input stream document- Returns:
- a Document
-
readDocument
public org.openprovenance.prov.model.Document readDocument(InputStream is, org.openprovenance.prov.interop.Formats.ProvFormat format, org.openprovenance.prov.model.ProvFactory pFactory, String baseuri)
Reads a Document from an input stream, using the parser specified by the format argument.- Parameters:
is- an input streamformat- one of the input formats supported by ProvToolboxpFactory- a provenance factory used to construct the Documentbaseuri- a base uri for the input stream document- Returns:
- a Document
-
readDocument
public org.openprovenance.prov.model.Document readDocument(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
-
readDocumentFromFile
public org.openprovenance.prov.model.Document readDocumentFromFile(String filename, org.openprovenance.prov.interop.Formats.ProvFormat format)
Deprecated.Use instead deserialiseDocumentReads a document from a file, using the format to decide which parser to read the file with.- Parameters:
filename- the file to read a document fromformat- the format of the file- Returns:
- a Document
-
serialiseDocument
public void serialiseDocument(OutputStream out, org.openprovenance.prov.model.Document document, boolean formatted)
Serializes a document to a stream- Specified by:
serialiseDocumentin interfaceorg.openprovenance.prov.model.ProvSerialiser- Parameters:
out- anOutputStreamdocument- aDocumentformatted- a boolean indicating whether the output should be pretty-printed
-
serialiseDocument
public void serialiseDocument(OutputStream out, org.openprovenance.prov.model.Document document, String mediaType, boolean formatted)
- Specified by:
serialiseDocumentin interfaceorg.openprovenance.prov.model.ProvSerialiser
-
deserialiseDocument
public org.openprovenance.prov.model.Document deserialiseDocument(InputStream is, org.openprovenance.prov.interop.Formats.ProvFormat format) throws IOException
- Throws:
IOException
-
mediaTypes
public Collection<String> mediaTypes()
- Specified by:
mediaTypesin interfaceorg.openprovenance.prov.model.ProvSerialiser
-
readDocument
public org.openprovenance.prov.model.Document readDocument(org.openprovenance.prov.interop.InteropFramework.ToRead something)
-
run
public int run()
Top level entry point of this class, when called from the command line.See method
CommandLineArguments.main(String[])
-
setNamespaces
public void setNamespaces(org.openprovenance.prov.model.Document doc)
Initializes a Document's namespace.
-
writeDocument
public void writeDocument(OutputStream os, javax.ws.rs.core.MediaType mt, org.openprovenance.prov.model.Document document)
Write aDocumentto output stream, according to specified Internet Media Type- Parameters:
os- anOutputStreamto write the Document tomt- aMediaTypedocument- aDocumentto serialize
-
writeDocument
public void writeDocument(OutputStream os, org.openprovenance.prov.interop.Formats.ProvFormat format, org.openprovenance.prov.model.Document document)
Write aDocumentto output stream, according to specifiedFormats.ProvFormat- Parameters:
os- anOutputStreamto write the Document toformat- aFormats.ProvFormatdocument- aDocumentto serialize
-
writeDocumentOLD
public void writeDocumentOLD(OutputStream os, org.openprovenance.prov.interop.Formats.ProvFormat format, org.openprovenance.prov.model.Document document)
TO BE DELETED
-
writeDocument
public void writeDocument(String filename, org.openprovenance.prov.model.Document document)
Write aDocumentto file, serialized according to the file extension- Parameters:
filename- path of the file to write the Document todocument- aDocumentto serialize
-
createLegacySerializerMap
public final Map<org.openprovenance.prov.interop.Formats.ProvFormat,SerializerFunction> createLegacySerializerMap()
-
createLightAndLegacySerializerMap
public final Map<org.openprovenance.prov.interop.Formats.ProvFormat,SerializerFunction> createLightAndLegacySerializerMap()
-
createLightSerializerMap
public final Map<org.openprovenance.prov.interop.Formats.ProvFormat,SerializerFunction> createLightSerializerMap()
-
createLightAndLegacyDeserializerMap
public final Map<org.openprovenance.prov.interop.Formats.ProvFormat,DeserializerFunction> createLightAndLegacyDeserializerMap()
-
createLegacyDeserializerMap
public final Map<org.openprovenance.prov.interop.Formats.ProvFormat,DeserializerFunction> createLegacyDeserializerMap()
-
createSerializerMap
public Map<org.openprovenance.prov.interop.Formats.ProvFormat,SerializerFunction> createSerializerMap()
-
createDeserializerMap
public Map<org.openprovenance.prov.interop.Formats.ProvFormat,DeserializerFunction> createDeserializerMap()
-
writeDocument
public void writeDocument(String filename, org.openprovenance.prov.interop.Formats.ProvFormat format, org.openprovenance.prov.model.Document document)
Write aDocumentto file, serialized according to the file extension- Parameters:
filename- path of the file to write the Document todocument- aDocumentto serialize
-
-