66package core ;
77
88import application .MainController ;
9+ import customWriter .CustomRDFFormat ;
910import javafx .stage .FileChooser ;
1011import org .apache .commons .io .FileUtils ;
1112import org .apache .jena .datatypes .RDFDatatype ;
1920
2021import java .io .*;
2122import java .util .*;
23+ import java .util .zip .ZipOutputStream ;
2224
2325
2426public class RdfConvert {
@@ -63,7 +65,7 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
6365// filechooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Main RDF file", "*.rdf","*.xml", "*.ttl"));
6466// filechooser.setInitialDirectory(new File(MainController.prefs.get("LastWorkingFolder","")));
6567// File fileDet1=null;
66- List <File > fileDet1 = util .ModelFactory .filechoosercustom (true ,"Main RDF file" , List .of ("*.rdf" ,"*.xml" , "*.ttl" ));
68+ List <File > fileDet1 = util .ModelFactory .filechoosercustom (true ,"Main RDF file" , List .of ("*.rdf" ,"*.xml" , "*.ttl" ), "" );
6769// try {
6870// fileDet1 = filechooser.showOpenDialog(null);
6971// }catch (Exception e){
@@ -81,7 +83,7 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
8183// filechooser1.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Deviation RDF file", "*.rdf","*.xml", "*.ttl"));
8284// filechooser1.setInitialDirectory(new File(MainController.prefs.get("LastWorkingFolder","")));
8385// File fileDet2=null;
84- List <File > fileDet2 = util .ModelFactory .filechoosercustom (true ,"Deviation RDF file" , List .of ("*.rdf" ,"*.xml" , "*.ttl" ));
86+ List <File > fileDet2 = util .ModelFactory .filechoosercustom (true ,"Deviation RDF file" , List .of ("*.rdf" ,"*.xml" , "*.ttl" ), "" );
8587// try {
8688// fileDet2 = filechooser1.showOpenDialog(null);
8789// }catch (Exception e){
@@ -99,7 +101,7 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
99101// filechooser2.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Extended RDF file", "*.rdf","*.xml", "*.ttl"));
100102// filechooser2.setInitialDirectory(new File(MainController.prefs.get("LastWorkingFolder","")));
101103// File fileDet3=null;
102- List <File > fileDet3 = util .ModelFactory .filechoosercustom (true ,"Extended RDF file" , List .of ("*.rdf" ,"*.xml" , "*.ttl" ));
104+ List <File > fileDet3 = util .ModelFactory .filechoosercustom (true ,"Extended RDF file" , List .of ("*.rdf" ,"*.xml" , "*.ttl" ), "" );
103105// try {
104106// fileDet3 = filechooser2.showOpenDialog(null);
105107// }catch (Exception e){
@@ -197,7 +199,7 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
197199
198200 }else {
199201 // load all models
200- model = util .ModelFactory .modelLoad (modelFiles ,xmlBase ,rdfSourceFormat );
202+ model = util .ModelFactory .modelLoad (modelFiles ,xmlBase ,rdfSourceFormat , false );
201203 }
202204
203205
@@ -250,36 +252,103 @@ public static void rdfConversion(File file, List<File> files, String sourceForma
250252
251253 switch (targetFormat ) {
252254 case "RDF XML (.rdf or .xml)" :
255+
256+ //register custom format
257+ CustomRDFFormat .RegisterCustomFormatWriters ();
258+ String showXmlEncoding = "true" ; //saveProperties.get("showXmlEncoding").toString();
259+ boolean putHeaderOnTop = true ; //(boolean) saveProperties.get("putHeaderOnTop");
260+ String headerClassResource ="http://iec.ch/TC57/61970-552/ModelDescription/1#FullModel" ; //saveProperties.get("headerClassResource").toString();
261+ boolean useAboutRules = false ;//(boolean) saveProperties.get("useAboutRules"); //switch to trigger file chooser and adding the property
262+ boolean useEnumRules = false ;//(boolean) saveProperties.get("useEnumRules"); //switch to trigger special treatment when Enum is reference
263+
264+ Set <Resource > rdfAboutList = null ; //(Set<Resource>) saveProperties.get("rdfAboutList");
265+ Set <Resource > rdfEnumList = null ;//(Set<Resource>) saveProperties.get("rdfEnumList");
266+
253267 OutputStream outXML = fileSaveDialog ("Save RDF XML for: " +filename , "RDF XML" , "*.rdf" );
254- if (outXML !=null ) {
268+
269+ if (outXML != null ) {
255270 try {
256- Map <String , Object > properties = new HashMap <>();
257- properties .put ("showXmlDeclaration" , showXmlDeclaration );
258- properties .put ("showDoctypeDeclaration" , showDoctypeDeclaration );
259- //properties.put("blockRules", RDFSyntax.propertyAttr.toString()); //???? not sure
260- properties .put ("xmlbase" , xmlBase );
261- properties .put ("tab" , tab );
262- //properties.put("prettyTypes",new Resource[] {ResourceFactory.createResource("http://iec.ch/TC57/61970-552/ModelDescription/1#FullModel")});
263- properties .put ("relativeURIs" , relativeURIs );
264-
265-
266- // Put a properties object into the Context.
267- Context cxt = new Context ();
268- cxt .set (SysRIOT .sysRdfWriterProperties , properties );
269-
270- org .apache .jena .riot .RDFWriter .create ()
271- .base (xmlBase )
272- .format (rdfFormat )
273- .context (cxt )
274- .source (model )
275- .output (outXML );
276- if (inheritanceList ) {
277- fileSaveDialogInheritance (filename +"Inheritance" ,xmlBase );
271+ if (rdfFormat == CustomRDFFormat .RDFXML_CUSTOM_PLAIN_PRETTY || rdfFormat == CustomRDFFormat .RDFXML_CUSTOM_PLAIN ) {
272+ Map <String , Object > properties = new HashMap <>();
273+ properties .put ("showXmlDeclaration" , showXmlDeclaration );
274+ properties .put ("showDoctypeDeclaration" , showDoctypeDeclaration );
275+ properties .put ("showXmlEncoding" , showXmlEncoding ); // works only with the custom format
276+ //properties.put("blockRules", "daml:collection,parseTypeLiteralPropertyElt,"
277+ // +"parseTypeResourcePropertyElt,parseTypeCollectionPropertyElt"
278+ // +"sectionReification,sectionListExpand,idAttr,propertyAttr"); //???? not sure
279+ if (putHeaderOnTop ) {
280+ properties .put ("prettyTypes" , new Resource []{ResourceFactory .createResource (headerClassResource )});
281+ }
282+ properties .put ("xmlbase" , xmlBase );
283+ properties .put ("tab" , tab );
284+ properties .put ("relativeURIs" , relativeURIs );
285+
286+ if (useAboutRules ) {
287+ properties .put ("aboutRules" , rdfAboutList );
288+ }
289+
290+ if (useEnumRules ) {
291+ properties .put ("enumRules" , rdfEnumList );
292+ }
293+
294+ // Put a properties object into the Context.
295+ Context cxt = new Context ();
296+ cxt .set (SysRIOT .sysRdfWriterProperties , properties );
297+
298+ org .apache .jena .riot .RDFWriter .create ()
299+ .base (xmlBase )
300+ .format (rdfFormat )
301+ .context (cxt )
302+ .source (model )
303+ .output (outXML );
304+
305+ } else {
306+ try {
307+ Map <String , Object > properties = new HashMap <>();
308+ properties .put ("showXmlDeclaration" , showXmlDeclaration );
309+ properties .put ("showDoctypeDeclaration" , showDoctypeDeclaration );
310+ //properties.put("blockRules", RDFSyntax.propertyAttr.toString()); //???? not sure
311+ properties .put ("xmlbase" , xmlBase );
312+ properties .put ("tab" , tab );
313+ //properties.put("prettyTypes",new Resource[] {ResourceFactory.createResource("http://iec.ch/TC57/61970-552/ModelDescription/1#FullModel")});
314+ properties .put ("relativeURIs" , relativeURIs );
315+
316+
317+ // Put a properties object into the Context.
318+ Context cxt = new Context ();
319+ cxt .set (SysRIOT .sysRdfWriterProperties , properties );
320+
321+ org .apache .jena .riot .RDFWriter .create ()
322+ .base (xmlBase )
323+ .format (rdfFormat )
324+ .context (cxt )
325+ .source (model )
326+ .output (outXML );
327+ if (inheritanceList ) {
328+ fileSaveDialogInheritance (filename + "Inheritance" , xmlBase );
329+ }
330+ } finally {
331+ outXML .close ();
332+ }
278333 }
279334 } finally {
335+ outXML .flush ();
280336 outXML .close ();
337+
338+
281339 }
282340 }
341+
342+
343+
344+
345+
346+
347+
348+
349+
350+
351+
283352 break ;
284353
285354 case "RDF Turtle (.ttl)" :
0 commit comments