Search in sources :

Example 1 with CmdException

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("-");
}
Also used : PrintStream(java.io.PrintStream) Arrays(java.util.Arrays) LogCtl(org.apache.jena.atlas.logging.LogCtl) IRIException(org.apache.jena.irix.IRIException) IRIx(org.apache.jena.irix.IRIx) CmdException(org.apache.jena.cmd.CmdException) ShaclcParseException(org.apache.jena.shacl.compact.reader.ShaclcParseException) Function(java.util.function.Function) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) Graph(org.apache.jena.graph.Graph) ArgDecl(org.apache.jena.cmd.ArgDecl) ShLib(org.apache.jena.shacl.lib.ShLib) List(java.util.List) ShaclException(org.apache.jena.shacl.ShaclException) Stream(java.util.stream.Stream) StreamOps(org.apache.jena.atlas.lib.StreamOps) org.apache.jena.riot(org.apache.jena.riot) CmdGeneral(org.apache.jena.cmd.CmdGeneral) ShaclcWriter(org.apache.jena.shacl.compact.ShaclcWriter) ShaclParseException(org.apache.jena.shacl.parser.ShaclParseException) IRIs(org.apache.jena.irix.IRIs) Shapes(org.apache.jena.shacl.Shapes) JenaSystem(org.apache.jena.sys.JenaSystem) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) IRIException(org.apache.jena.irix.IRIException) CmdException(org.apache.jena.cmd.CmdException) PrintStream(java.io.PrintStream) Stream(java.util.stream.Stream) IRIx(org.apache.jena.irix.IRIx)

Example 2 with CmdException

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;
    }
}
Also used : PrintStream(java.io.PrintStream) Arrays(java.util.Arrays) LogCtl(org.apache.jena.atlas.logging.LogCtl) RiotException(org.apache.jena.riot.RiotException) CmdException(org.apache.jena.cmd.CmdException) ShexParseException(org.apache.jena.shex.parser.ShexParseException) Function(java.util.function.Function) ArgDecl(org.apache.jena.cmd.ArgDecl) List(java.util.List) Stream(java.util.stream.Stream) Shex(org.apache.jena.shex.Shex) StreamOps(org.apache.jena.atlas.lib.StreamOps) ShexSchema(org.apache.jena.shex.ShexSchema) CmdGeneral(org.apache.jena.cmd.CmdGeneral) FileOps(org.apache.jena.atlas.lib.FileOps) JenaSystem(org.apache.jena.sys.JenaSystem) CmdException(org.apache.jena.cmd.CmdException) PrintStream(java.io.PrintStream) Stream(java.util.stream.Stream)

Example 3 with CmdException

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);
}
Also used : CmdException(org.apache.jena.cmd.CmdException)

Example 4 with CmdException

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;
}
Also used : JenaException(org.apache.jena.shared.JenaException) CmdException(org.apache.jena.cmd.CmdException) ModDataset(arq.cmdline.ModDataset) DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) CmdException(org.apache.jena.cmd.CmdException) JenaException(org.apache.jena.shared.JenaException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 5 with CmdException

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);
    }
}
Also used : CmdException(org.apache.jena.cmd.CmdException) Lang(org.apache.jena.riot.Lang) Location(org.apache.jena.dboe.base.file.Location)

Aggregations

CmdException (org.apache.jena.cmd.CmdException)35 Lang (org.apache.jena.riot.Lang)8 JenaException (org.apache.jena.shared.JenaException)5 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)4 RiotException (org.apache.jena.riot.RiotException)4 ArgDecl (org.apache.jena.cmd.ArgDecl)3 Graph (org.apache.jena.graph.Graph)3 Node (org.apache.jena.graph.Node)3 ModDataset (arq.cmdline.ModDataset)2 PrintStream (java.io.PrintStream)2 Arrays (java.util.Arrays)2 List (java.util.List)2 Function (java.util.function.Function)2 Stream (java.util.stream.Stream)2 StreamOps (org.apache.jena.atlas.lib.StreamOps)2 LogCtl (org.apache.jena.atlas.logging.LogCtl)2 CmdGeneral (org.apache.jena.cmd.CmdGeneral)2 TerminationException (org.apache.jena.cmd.TerminationException)2 DataAccessPoint (org.apache.jena.fuseki.server.DataAccessPoint)2