Package org.openprovenance.prov.interop
Class InteropFramework
- java.lang.Object
-
- org.openprovenance.prov.interop.InteropFramework
-
- All Implemented Interfaces:
InteropMediaType
public class InteropFramework extends Object implements InteropMediaType
The interoperability framework for PROV, with utility methods to write and read documents to files and streams, according to media types, format (specified asInteropFramework.ProvFormat). The class also provides helper functions to support content negotiation.- Author:
- lavm, dtm
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInteropFramework.ProvFormatAn enumerated type for all the PROV serializations supported by ProvToolbox.static classInteropFramework.ProvFormatType
-
Field Summary
Fields Modifier and Type Field Description Hashtable<InteropFramework.ProvFormat,String>extensionMapHashtable<String,InteropFramework.ProvFormat>extensionRevMapHashtable<InteropFramework.ProvFormat,String>mimeTypeMapHashtable<String,InteropFramework.ProvFormat>mimeTypeRevMapHashtable<InteropFramework.ProvFormat,InteropFramework.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_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_PDF, MEDIA_APPLICATION_PROVENANCE_XML, MEDIA_APPLICATION_RDF_XML, MEDIA_APPLICATION_TRIG, MEDIA_APPLICATION_XML, MEDIA_IMAGE_JPEG, MEDIA_IMAGE_PNG, MEDIA_IMAGE_SVG_XML, 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 typeStringgetExtension(InteropFramework.ProvFormat format)Returns an extension for a given type of serialization of PROVList<Map<String,String>>getSupportedFormats()InteropFramework.ProvFormatgetTypeForFile(String filename)Get aInteropFramework.ProvFormatgiven the file's exetensionInteropFramework.ProvFormatgetTypeForFormat(String format)Get aInteropFramework.ProvFormatgiven a format stringList<javax.ws.rs.core.Variant>getVariants()Support for content negotiation, jax-rs style.voidinitializeExtensionMap(Hashtable<InteropFramework.ProvFormat,String> extensionMap, Hashtable<String,InteropFramework.ProvFormat> extensionRevMap)Initialization functionBooleanisInputFormat(InteropFramework.ProvFormat format)Determines whether this format received as argument is an input format.BooleanisOutputFormat(InteropFramework.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.static org.openprovenance.prov.model.ProvFactorynewXMLProvFactory()Creates a factory for the XML Java beans.voidprovn2html(String file, String file2)org.openprovenance.prov.model.DocumentreadDocument(InputStream is, InteropFramework.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, InteropFramework.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, InteropFramework.ProvFormat format)Reads a document from a file, using the format to decide which parser to read the file with.intrun()Top level entry point of this class, when called from the command line.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, InteropFramework.ProvFormat format, org.openprovenance.prov.model.Document document)Write aDocumentto output stream, according to specifiedInteropFramework.ProvFormatvoidwriteDocument(String filename, InteropFramework.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 extension
-
-
-
Field Detail
-
UNKNOWN
public static final String UNKNOWN
- See Also:
- Constant Field Values
-
extensionMap
public final Hashtable<InteropFramework.ProvFormat,String> extensionMap
-
extensionRevMap
public final Hashtable<String,InteropFramework.ProvFormat> extensionRevMap
-
mimeTypeMap
public final Hashtable<InteropFramework.ProvFormat,String> mimeTypeMap
-
mimeTypeRevMap
public final Hashtable<String,InteropFramework.ProvFormat> mimeTypeRevMap
-
provTypeMap
public final Hashtable<InteropFramework.ProvFormat,InteropFramework.ProvFormatType> provTypeMap
-
-
Constructor Detail
-
InteropFramework
public InteropFramework()
Default constructor for the ProvToolbox interoperability framework. It usesProvFactoryas 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
-
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(InteropFramework.ProvFormat format)
Returns an extension for a given type of serialization of PROV- Parameters:
format-InteropFramework.ProvFormatfor which file extension is sought- Returns:
- a String for the extension of a file containing such a serialization
-
getTypeForFile
public InteropFramework.ProvFormat getTypeForFile(String filename)
Get aInteropFramework.ProvFormatgiven the file's exetension- Parameters:
filename- the file for which theInteropFramework.ProvFormatis sought- Returns:
- a
InteropFramework.ProvFormat
-
getTypeForFormat
public InteropFramework.ProvFormat getTypeForFormat(String format)
Get aInteropFramework.ProvFormatgiven a format string- Parameters:
format- the format for which theInteropFramework.ProvFormatis sought- Returns:
- a
InteropFramework.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<InteropFramework.ProvFormat,String> extensionMap, Hashtable<String,InteropFramework.ProvFormat> extensionRevMap)
Initialization function- Parameters:
extensionMap- mapping ofInteropFramework.ProvFormatto extensionsextensionRevMap- reverse mapping of extensions toInteropFramework.ProvFormat
-
isInputFormat
public Boolean isInputFormat(InteropFramework.ProvFormat format)
Determines whether this format received as argument is an input format.- Parameters:
format- aInteropFramework.ProvFormat- Returns:
- true if format is an input format
-
isOutputFormat
public Boolean isOutputFormat(InteropFramework.ProvFormat format)
Determines whether this format received as argument is an output format.- Parameters:
format- aInteropFramework.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
-
newXMLProvFactory
public static org.openprovenance.prov.model.ProvFactory newXMLProvFactory()
Creates a factory for the XML Java beans.- Returns:
- a
ProvFactory
-
provn2html
public void provn2html(String file, String file2) throws IOException, JAXBException, org.antlr.runtime.RecognitionException
- Throws:
IOExceptionJAXBExceptionorg.antlr.runtime.RecognitionException
-
readDocument
public org.openprovenance.prov.model.Document readDocument(InputStream is, InteropFramework.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, InteropFramework.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, InteropFramework.ProvFormat format)
Reads 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
-
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, InteropFramework.ProvFormat format, org.openprovenance.prov.model.Document document)
Write aDocumentto output stream, according to specifiedInteropFramework.ProvFormat- Parameters:
os- anOutputStreamto write the Document toformat- aInteropFramework.ProvFormatdocument- aDocumentto serialize
-
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
-
writeDocument
public void writeDocument(String filename, InteropFramework.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
-
-