| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.any23.cli; |
| 19 | |
|
| 20 | |
import org.apache.any23.vocab.RDFSchemaUtils; |
| 21 | |
import org.apache.commons.cli.CommandLine; |
| 22 | |
import org.apache.commons.cli.CommandLineParser; |
| 23 | |
import org.apache.commons.cli.HelpFormatter; |
| 24 | |
import org.apache.commons.cli.Option; |
| 25 | |
import org.apache.commons.cli.Options; |
| 26 | |
import org.apache.commons.cli.PosixParser; |
| 27 | |
|
| 28 | |
import java.io.BufferedOutputStream; |
| 29 | |
import java.io.IOException; |
| 30 | |
import java.util.Arrays; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
@ToolRunner.Description("Prints out the RDF Schema of the vocabularies used by Any23.") |
| 38 | 0 | public class VocabPrinter implements Tool { |
| 39 | |
|
| 40 | |
public static void main(String[] args) throws IOException { |
| 41 | 0 | System.exit( new VocabPrinter().run(args) ); |
| 42 | 0 | } |
| 43 | |
|
| 44 | |
public int run(String[] args) { |
| 45 | 0 | final CommandLineParser parser = new PosixParser(); |
| 46 | |
final CommandLine commandLine; |
| 47 | |
final RDFSchemaUtils.VocabularyFormat format; |
| 48 | |
try { |
| 49 | 0 | final Options options = new Options(); |
| 50 | 0 | options.addOption( |
| 51 | |
new Option("h", "help", false, "Print this help.") |
| 52 | |
); |
| 53 | 0 | options.addOption( |
| 54 | |
new Option( |
| 55 | |
"f", "format", |
| 56 | |
true, |
| 57 | |
"Vocabulary output format, supported values are: " + |
| 58 | |
Arrays.toString(RDFSchemaUtils.VocabularyFormat.values()) |
| 59 | |
) |
| 60 | |
); |
| 61 | 0 | commandLine = parser.parse(options, args); |
| 62 | 0 | if (commandLine.hasOption("h")) { |
| 63 | 0 | printHelp(options); |
| 64 | 0 | return 0; |
| 65 | |
} |
| 66 | |
try { |
| 67 | 0 | format = RDFSchemaUtils.VocabularyFormat.valueOf( |
| 68 | |
commandLine.getOptionValue("f", RDFSchemaUtils.VocabularyFormat.NQuads.name()) |
| 69 | |
); |
| 70 | 0 | } catch (IllegalArgumentException iae) { |
| 71 | 0 | throw new IllegalArgumentException("Unknown format [" + commandLine.getOptionValue("f") + "'"); |
| 72 | 0 | } |
| 73 | 0 | } catch (Exception e) { |
| 74 | 0 | e.printStackTrace(System.err); |
| 75 | 0 | return 1; |
| 76 | 0 | } |
| 77 | |
|
| 78 | 0 | final BufferedOutputStream bos = new BufferedOutputStream(System.out); |
| 79 | |
try { |
| 80 | 0 | RDFSchemaUtils.serializeVocabularies(format, System.out); |
| 81 | 0 | } catch (Exception e) { |
| 82 | 0 | e.printStackTrace(System.err); |
| 83 | 0 | return 1; |
| 84 | |
} finally { |
| 85 | 0 | try { |
| 86 | 0 | bos.flush(); |
| 87 | 0 | } catch (IOException ioe) { |
| 88 | 0 | ioe.printStackTrace(System.err); |
| 89 | 0 | } |
| 90 | 0 | System.out.println(); |
| 91 | 0 | } |
| 92 | 0 | return 0; |
| 93 | |
} |
| 94 | |
|
| 95 | |
private void printHelp(Options options) { |
| 96 | 0 | HelpFormatter formatter = new HelpFormatter(); |
| 97 | 0 | formatter.printHelp(this.getClass().getSimpleName(), options, true); |
| 98 | 0 | } |
| 99 | |
|
| 100 | |
} |