import java.io.BufferedInputStream;\r
import java.io.DataInput;\r
import java.io.DataInputStream;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
import java.io.InputStream;\r
+import java.nio.file.Files;\r
+import java.nio.file.Path;\r
+import java.nio.file.Paths;\r
\r
import org.simantics.databoard.binding.Binding;\r
import org.simantics.databoard.binding.mutable.Variant;\r
import org.simantics.databoard.container.DataContainers;\r
import org.simantics.graph.representation.TransferableGraph1;\r
\r
+/**\r
+ * @author Antti Villberg\r
+ * @since 1.24.0\r
+ */\r
public class FixExportedOntology {\r
\r
- public static void main(String[] args) throws Exception {\r
- \r
-// File input = new File("E:/work/workspace/apros-head/fi.semantum.simupedia.feature/rootfiles/sharedlibraries/SimupediaStandardLibrary-1.3-trunk.sharedLibrary");\r
- File input = new File("E:/work/workspace/apros-head/fi.semantum.simupedia.feature/rootfiles/sharedlibraries/AprosSimupedia-1.3-trunk.sharedLibrary");\r
- File output = new File(input.getParentFile(), input.getName() + ".fixed");\r
- InputStream is = new FileInputStream(input);\r
+ static void convertExportedSharedOntologyIntoBundleOntology(Path input, Path output) throws Exception {\r
+ System.out.format("Converting exported shared ontology%n\t" + input.toString() + "%nto bundle-compatible ontology%n\t" + output.toString());\r
+ try (InputStream is = new BufferedInputStream(Files.newInputStream(input), 128*1024)) {\r
+ DataInput dis = new DataInputStream(is);\r
+ org.simantics.databoard.container.DataContainer container = \r
+ DataContainers.readFile(dis); \r
+ Binding binding = TransferableGraph1.BINDING;\r
+ TransferableGraph1 graph = (TransferableGraph1)container.content.getValue(binding);\r
+ GraphRefactoringUtils.fixOntologyExport(graph);\r
\r
- is = new BufferedInputStream(is, 128*1024);\r
- \r
- DataInput dis = new DataInputStream(is);\r
- org.simantics.databoard.container.DataContainer container = \r
- DataContainers.readFile(dis); \r
- Binding binding = TransferableGraph1.BINDING;\r
- TransferableGraph1 graph = (TransferableGraph1)container.content.getValue(binding);\r
- GraphRefactoringUtils.fixOntologyExport(graph);\r
+ DataContainers.writeFile(output.toFile(), new DataContainer(\r
+ container.format, container.version,\r
+ container.metadata, new Variant(TransferableGraph1.BINDING, graph)));\r
+ }\r
+ }\r
\r
- DataContainers.writeFile(output, new DataContainer(\r
- container.format, container.version,\r
- container.metadata, new Variant(TransferableGraph1.BINDING, graph)));\r
- \r
+ public static void main(String[] args) throws Exception {\r
+ if (args.length < 1) {\r
+ System.out.println("Required arguments: <input .sharedOntology file> [<output .tg file>]");\r
+ } else if (args.length < 2) {\r
+ Path input = Paths.get(args[0]);\r
+ Path output = input.getParent().resolve(input.getName(input.getNameCount()-1) + ".fixed");\r
+ convertExportedSharedOntologyIntoBundleOntology(input, output);\r
+ } else {\r
+ convertExportedSharedOntologyIntoBundleOntology(Paths.get(args[0]), Paths.get(args[1]));\r
+ }\r
}\r
- \r
\r
}\r