Main program @param args
(String[] args)
| 61 | * @param args |
| 62 | */ |
| 63 | public static void main(String[] args) { |
| 64 | logger.info("-- START --"); |
| 65 | if (args.length < 2) { |
| 66 | logger.error("No input or output file"); |
| 67 | System.exit(-1); |
| 68 | } |
| 69 | |
| 70 | Optional<RDFFormat> fmtin = Rio.getParserFormatForFileName(args[0]); |
| 71 | if(!fmtin.isPresent()) { |
| 72 | logger.error("No parser for input {}", args[0]); |
| 73 | System.exit(-2); |
| 74 | } |
| 75 | |
| 76 | Optional<RDFFormat> fmtout = Rio.getWriterFormatForFileName(args[1]); |
| 77 | if(!fmtout.isPresent()) { |
| 78 | logger.error("No parser for output {}", args[1]); |
| 79 | System.exit(-3); |
| 80 | } |
| 81 | |
| 82 | int code = 0; |
| 83 | Repository repo = new SailRepository(new MemoryStore()); |
| 84 | |
| 85 | try (RepositoryConnection con = repo.getConnection()) { |
| 86 | con.add(new File(args[0]), "http://data.gov.be", fmtin.get()); |
| 87 | // Various namespace prefixes |
| 88 | con.setNamespace(DCAT.PREFIX, DCAT.NAMESPACE); |
| 89 | con.setNamespace(DCTERMS.PREFIX, DCTERMS.NAMESPACE); |
| 90 | con.setNamespace(FOAF.PREFIX, FOAF.NAMESPACE); |
| 91 | con.setNamespace("vcard", "http://www.w3.org/2006/vcard/ns#"); |
| 92 | con.setNamespace("locn", "http://www.w3.org/ns/locn#"); |
| 93 | |
| 94 | FileOutputStream fout = new FileOutputStream(new File(args[1])); |
| 95 | |
| 96 | RDFWriter writer; |
| 97 | if (fmtout.get().equals(RDFFormat.RDFXML)) { |
| 98 | writer = new RDFXMLPrettyWriterFactory().getWriter(fout); |
| 99 | } else { |
| 100 | writer = Rio.createWriter(fmtout.get(), fout); |
| 101 | } |
| 102 | |
| 103 | logger.info("Using writer {}", writer.getClass().getCanonicalName()); |
| 104 | |
| 105 | con.export(writer); |
| 106 | } catch (IOException ex) { |
| 107 | logger.error("Error converting", ex); |
| 108 | code = -1; |
| 109 | } |
| 110 | |
| 111 | repo.shutDown(); |
| 112 | |
| 113 | System.exit(code); |
| 114 | } |
| 115 | } |