Search in sources :

Example 26 with CmdException

use of org.apache.jena.cmd.CmdException in project jena by apache.

the class tdbdump method exec.

@Override
protected void exec() {
    DatasetGraph dsg = super.getDatasetGraphTDB();
    // Prefer stream over fully pretty output formats.
    RDFFormat fmt = modLangOutput.getOutputStreamFormat();
    // if ( fmt != null && StreamRDFWriter.registered(fmt) )
    if (fmt == null)
        fmt = modLangOutput.getOutputFormatted();
    if (fmt == null)
        // Default.
        fmt = RDFFormat.NQUADS;
    if (!RDFLanguages.isQuads(fmt.getLang()))
        throw new CmdException("Databases can be dumped only in quad formats (e.g. Trig, N-Quads), not " + fmt.getLang());
    RDFDataMgr.write(System.out, dsg, fmt);
}
Also used : CmdException(org.apache.jena.cmd.CmdException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) RDFFormat(org.apache.jena.riot.RDFFormat)

Example 27 with CmdException

use of org.apache.jena.cmd.CmdException in project jena by apache.

the class tdbdump method exec.

@Override
protected void exec() {
    DatasetGraph dsg = getDatasetGraph();
    // Prefer stream over fully pretty output formats.
    RDFFormat fmt = modLangOutput.getOutputStreamFormat();
    // if ( fmt != null && StreamRDFWriter.registered(fmt) )
    if (fmt == null)
        fmt = modLangOutput.getOutputFormatted();
    if (fmt == null)
        // Default.
        fmt = RDFFormat.NQUADS;
    if (!RDFLanguages.isQuads(fmt.getLang()))
        throw new CmdException("Databases can be dumped only in quad formats (e.g. Trig, N-Quads), not " + fmt.getLang());
    RDFFormat fmtFinal = fmt;
    Txn.executeRead(dsg, () -> RDFDataMgr.write(System.out, dsg, fmtFinal));
}
Also used : CmdException(org.apache.jena.cmd.CmdException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) RDFFormat(org.apache.jena.riot.RDFFormat)

Example 28 with CmdException

use of org.apache.jena.cmd.CmdException in project jena by apache.

the class CmdNodeTableBuilder 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") ;
    locationString = super.getValue(argLocation);
    location = Location.create(locationString);
    dataFileTriples = super.getValue(argTriplesOut);
    if (dataFileTriples == null)
        dataFileTriples = location.getPath("triples", "tmp");
    dataFileQuads = super.getValue(argQuadsOut);
    if (dataFileQuads == null)
        dataFileQuads = location.getPath("quads", "tmp");
    if (Objects.equals(dataFileTriples, dataFileQuads))
        cmdError("Triples and Quads work files are the same");
    if (super.contains(argNoStats))
        collectStats = false;
    // datafiles  = getPositionalOrStdin() ;
    datafiles = getPositional();
    if (datafiles.isEmpty())
        datafiles = Arrays.asList("-");
    // ---- Checking.
    for (String filename : datafiles) {
        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)

Example 29 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 = TDBFactory.createDataset();
        RDFDataMgr.read(ds, inMemFile);
        return ds;
    }
    if (modAssembler.getAssemblerFile() != null) {
        Dataset thing = null;
        // Two variants: plain dataset with a TDB graph or a TDB dataset.
        try {
            thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), VocabTDB.tDatasetTDB);
            if (thing != null && !(thing.asDatasetGraph() instanceof DatasetGraphTransaction))
                Log.warn(this, "Unexpected: Not a TDB dataset for type DatasetTDB");
            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 = TDBFactory.createDataset(modAssembler.getLocation());
    return ds;
}
Also used : JenaException(org.apache.jena.shared.JenaException) CmdException(org.apache.jena.cmd.CmdException) ModDataset(arq.cmdline.ModDataset) DatasetGraphTransaction(org.apache.jena.tdb.transaction.DatasetGraphTransaction) CmdException(org.apache.jena.cmd.CmdException) JenaException(org.apache.jena.shared.JenaException)

Example 30 with CmdException

use of org.apache.jena.cmd.CmdException in project jena by apache.

the class tdbloader method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    super.processModulesAndArgs();
    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$;
    }
}
Also used : CmdException(org.apache.jena.cmd.CmdException) Lang(org.apache.jena.riot.Lang)

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