use of org.apache.jena.cmd.CmdException in project jena by apache.
the class shacl_parse method processModulesAndArgs.
@Override
protected void processModulesAndArgs() {
super.processModulesAndArgs();
if (super.hasArg(argOutput)) {
printCompact = false;
printRDF = false;
printText = false;
// Split values.
Function<String, Stream<String>> f = (x) -> {
String[] a = x.split(",");
return Arrays.stream(a);
};
List<String> values = StreamOps.toList(getValues(argOutput).stream().flatMap(f).map(s -> s.toLowerCase()));
printText = values.remove("text") || values.remove("t");
printCompact = values.remove("compact") || values.remove("c");
printRDF = values.remove("rdf") || values.remove("r");
if (values.remove("all") || values.remove("a")) {
printCompact = true;
printRDF = true;
printText = true;
}
if (!values.isEmpty())
throw new CmdException("Formats not recognized: " + values + " : Formats are 'text', 'compact', 'rdf' and 'all'");
} else {
printCompact = false;
printRDF = false;
printText = true;
}
if (super.contains(argSyntax)) {
String syntax = super.getValue(argSyntax);
Lang lang$ = RDFLanguages.nameToLang(syntax);
if (lang$ == null)
throw new CmdException("Can not detemine the syntax from '" + syntax + "'");
this.lang = lang$;
}
if (super.contains(argBase)) {
baseIRI = super.getValue(argBase);
try {
IRIx iri = IRIs.reference(baseIRI);
if (!iri.isAbsolute())
throw new CmdException("Base IRI not suitable for use as a base for RDF: " + baseIRI);
} catch (IRIException ex) {
throw new CmdException("Bad base IRI: " + baseIRI);
}
}
if (positionals.isEmpty())
// stdin
positionals.add("-");
}
use of org.apache.jena.cmd.CmdException in project jena by apache.
the class shex_parse method processModulesAndArgs.
@Override
protected void processModulesAndArgs() {
super.processModulesAndArgs();
if (super.positionals.size() == 0) {
System.err.println(getSummary());
System.exit(0);
}
if (super.hasArg(argOutput)) {
printCompact = false;
printRDF = false;
printText = false;
printJSON = false;
// Split values.
Function<String, Stream<String>> f = (x) -> {
String[] a = x.split(",");
return Arrays.stream(a);
};
List<String> values = StreamOps.toList(getValues(argOutput).stream().flatMap(f).map(s -> s.toLowerCase()));
printText = values.remove("text") || values.remove("t");
printCompact = values.remove("compact") || values.remove("c");
printRDF = values.remove("rdf") || values.remove("r");
printRDF = values.remove("json") || values.remove("j");
if (values.remove("all") || values.remove("a")) {
printCompact = true;
printRDF = true;
printText = true;
printJSON = true;
}
if (!values.isEmpty())
throw new CmdException("Formats not recognized: " + values + " : Formats are 'text', 'compact', 'json', 'rdf' and 'all'");
} else {
printCompact = false;
printRDF = false;
printJSON = true;
printText = true;
}
}
use of org.apache.jena.cmd.CmdException in project jena by apache.
the class CmdSub method exec.
protected void exec() {
Exec exec = dispatch.get(subCmd);
if (exec == null)
throw new CmdException("No subcommand: " + subCmd);
exec.exec(args);
}
use of org.apache.jena.cmd.CmdException in project jena by apache.
the class ModTDBDataset method createDataset.
@Override
public Dataset createDataset() {
if (inMemFile != null) {
Dataset ds = TDB2Factory.createDataset();
RDFDataMgr.read(ds, inMemFile);
return ds;
}
if (modAssembler.getAssemblerFile() != null) {
Dataset thing = null;
// (which may go wrong later if TDB2 directly is needed).
try {
thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), VocabTDB2.tDatasetTDB);
if (thing != null) {
DatasetGraph dsg = thing.asDatasetGraph();
if (!(dsg instanceof DatasetGraphSwitchable) && !(dsg instanceof DatasetGraphTDB))
Log.warn(this, "Unexpected: Not a TDB2 dataset for type DatasetTDB2");
}
if (thing == null)
// Should use assembler inheritance but how do we assert
// the subclass relationship in a program?
thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), DatasetAssemblerVocab.tDataset);
} catch (JenaException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Error creating", ex);
}
return thing;
}
if (modAssembler.getLocation() == null)
throw new CmdException("No assembler file nor location provided");
// No assembler - use location to find a database.
Dataset ds = TDB2Factory.connectDataset(modAssembler.getLocation());
return ds;
}
use of org.apache.jena.cmd.CmdException in project jena by apache.
the class CmdxIngestData method processModulesAndArgs.
@Override
protected void processModulesAndArgs() {
if (!super.contains(argLocation))
throw new CmdException("Required: --loc DIR");
// if ( !super.contains(argTriplesOut) ) throw new CmdException("Required: --triples FILE") ;
// if ( !super.contains(argQuadsOut) ) throw new CmdException("Required: --quads FILE") ;
super.processModulesAndArgs();
Location tmp = Location.create(tmpdir);
dataFileTriples = super.getValue(argTriplesOut);
if (dataFileTriples == null)
dataFileTriples = tmp.getPath("triples", "tmp");
dataFileQuads = super.getValue(argQuadsOut);
if (dataFileQuads == null)
dataFileQuads = tmp.getPath("quads", "tmp");
if (Objects.equals(dataFileTriples, dataFileQuads))
cmdError("Triples and Quads work files are the same");
if (filenames.isEmpty())
filenames = Arrays.asList("-");
// ---- Checking.
for (String filename : filenames) {
Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS);
if (lang == null)
// Does not happen due to default above.
cmdError("File suffix not recognized: " + filename);
if (!filename.equals("-") && !FileOps.exists(filename))
cmdError("File does not exist: " + filename);
}
}
Aggregations