]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.export.core/src/org/simantics/export/core/intf/FormatClass.java
ImportPdfReader now implements Closeable
[simantics/platform.git] / bundles / org.simantics.export.core / src / org / simantics / export / core / intf / FormatClass.java
1 package org.simantics.export.core.intf;
2
3 import java.io.File;
4 import java.util.List;
5
6 import org.osgi.service.prefs.Preferences;
7 import org.simantics.databoard.binding.mutable.Variant;
8 import org.simantics.databoard.type.RecordType;
9 import org.simantics.export.core.ExportContext;
10 import org.simantics.export.core.error.ExportException;
11 import org.simantics.export.core.manager.Content;
12
13 /**
14  * Format class contains format related code.
15  *
16  * @author toni.kalajainen@semantum.fi
17  */
18 public interface FormatClass {
19         
20         /**
21          * Create a new file. Return a format specific writer object. 
22          * 
23          * @param context contextual data
24          * @param outputFile
25          * @param options
26          * @return writer 
27          * @throws ExportException
28          */
29         Object createFile( ExportContext context, File outputFile, Variant options ) throws ExportException;
30         
31         /**
32          * Open a file for reading.
33          * 
34          * @param context
35          * @param inputFile
36          * @param options
37          * @throws ExportException
38          */
39         Object openFile( ExportContext context, File inputFile, Variant options ) throws ExportException;
40         
41         /**
42          * Close a reader or writer object.
43          * 
44          * ExportException is thrown if flushing of the file fails. This is a signal that
45          * the file is corrupted. The file is closed in all cases how ever. 
46          * 
47          * @param context
48          * @param handle
49          * @throws ExportException 
50          */
51         void closeFile( ExportContext context, Object handle ) throws ExportException;
52
53         /**
54          * Add attachments to an open file handle. This method applies only to 
55          * container files.  
56          * 
57          * @param context
58          * @param handle
59          * @param attachements
60          * @throws ExportException
61          */
62         void addAttachment( ExportContext context, Object handle, List<Content> attachments ) throws ExportException;
63         
64         /**
65          * Get file format specific options.
66          * 
67          * @param context
68          * @return a record type describing options 
69          */
70         RecordType options( ExportContext context ) throws ExportException;
71         
72         /**
73          * Validate that the options are usable for export.
74          * 
75          * @param context
76          * @param options
77          * @return a list of errors
78          * @throws ExportException
79          */
80         List<String> validate( ExportContext context, Variant options ) throws ExportException;
81
82         /**
83          * Fill options with default values.
84          * 
85          * @param options
86          * @throws ExportException 
87          */
88         void fillDefaultPrefs( ExportContext context, Variant options ) throws ExportException;
89
90         /**
91          * Save format options to preferences node(s).
92          * 
93          * A preference value may or may not exist in the options object.
94          * 
95          * @param options
96          * @param contentScopeNode
97          * @param workbenchScopeNode
98          * @throws ExportException
99          */
100         void savePref( Variant options, Preferences contentScopeNode, Preferences workbenchScopeNode ) throws ExportException;
101         
102         /**
103          * Load format options from preferences node(s).
104          * 
105          * @param options
106          * @param contentScopeNode
107          * @param workbenchScopeNode
108          * @throws ExportException
109          */
110         void loadPref( Variant options, Preferences contentScopeNode, Preferences workbenchScopeNode ) throws ExportException;
111         
112 }