Search in sources :

Example 6 with CmdException

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

the class shex_validate method exec.

@Override
protected void exec() {
    ShexSchema shapes;
    try {
        shapes = Shex.readSchema(shapesfile);
    } catch (ShexException ex) {
        System.err.println("Failed to read shapes: " + ex.getMessage());
        throw new CmdException();
    }
    Graph dataGraph;
    try {
        dataGraph = load(datafile, "data file");
    } catch (RiotException ex) {
        throw new CmdException("Failed to data: " + ex.getMessage());
    }
    if (mapfile != null) {
        ShexMap map;
        try {
            map = Shex.readShapeMap(mapfile);
        } catch (ShexException ex) {
            throw new CmdException("Failed to read shapes map: " + ex.getMessage());
        }
        ShexReport report = ShexValidator.get().validate(dataGraph, shapes, map);
        ShexLib.printReport(output, report);
        return;
    }
    // Or --shapeURI
    ShexShape startShape = shapes.getStart();
    if (startShape == null)
        throw new CmdException("Start node required for URI-validation");
    String targetURIstr = dataGraph.getPrefixMapping().expandPrefix(targetNode);
    Node focus = NodeFactory.createURI(targetURIstr);
    // if ( isVerbose() )
    // ValidationContext.VERBOSE = true;
    // ValidationReport report = ( node != null )
    // ? ShaclValidator.get().validate(shapesGraph, dataGraph, node)
    // : ShaclValidator.get().validate(shapesGraph, dataGraph);
    ShexReport report = ShexValidator.get().validate(dataGraph, shapes, startShape, focus);
    ShexLib.printReport(output, report);
}
Also used : Graph(org.apache.jena.graph.Graph) RiotException(org.apache.jena.riot.RiotException) CmdException(org.apache.jena.cmd.CmdException) Node(org.apache.jena.graph.Node)

Example 7 with CmdException

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

the class shex_validate method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    super.processModulesAndArgs();
    datafile = super.getValue(argData);
    shapesfile = super.getValue(argShapes);
    // No -- arguments, use act on single file of shapes and data.
    if (datafile == null && shapesfile == null) {
        if (positionals.size() == 1) {
            datafile = positionals.get(0);
            shapesfile = positionals.get(0);
        }
    }
    if (datafile == null)
        throw new CmdException("Usage: " + getSummary());
    if (shapesfile == null)
        shapesfile = datafile;
    textOutput = super.hasArg(argOutputText);
    if (contains(argTargetNode))
        targetNode = getValue(argTargetNode);
    if (contains(argShapeMap))
        mapfile = getValue(argShapeMap);
    if (targetNode != null && mapfile != null)
        throw new CmdException("Only one of target node and map file");
    if (targetNode == null && mapfile == null)
        throw new CmdException("One of target node and map file required");
}
Also used : CmdException(org.apache.jena.cmd.CmdException)

Example 8 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 9 with CmdException

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

the class ModTDBAssembler method processArgs.

@Override
public void processArgs(CmdArgModule cmdLine) {
    int count = 0;
    modLocation.processArgs(cmdLine);
    super.processArgs(cmdLine);
    if (super.getAssemblerFile() != null)
        count++;
    if (modLocation.getLocation() != null)
        count++;
    if (count == 0) {
        useDefaultAssemblerFile = true;
    // throw new CmdException("No assembler file and no location") ;
    }
    if (count > 1)
        throw new CmdException("Only one of an assembler file and a location");
}
Also used : CmdException(org.apache.jena.cmd.CmdException)

Example 10 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 (contains(argLoader)) {
        String loadername = getValue(argLoader).toLowerCase();
        if (loadername.matches("basic.*"))
            loader = LoaderEnum.Basic;
        else if (loadername.matches("phas.*"))
            loader = LoaderEnum.Phased;
        else if (loadername.matches("seq.*"))
            loader = LoaderEnum.Sequential;
        else if (loadername.matches("para.*"))
            loader = LoaderEnum.Parallel;
        else if (loadername.matches("light"))
            loader = LoaderEnum.Light;
        else
            throw new CmdException("Unrecognized value for --loader: " + loadername);
    }
    if (super.contains(argStats)) {
        if (!hasValueOfTrue(argStats) && !hasValueOfFalse(argStats))
            throw new CmdException("Not a boolean value: " + getValue(argStats));
        generateStats = super.hasValueOfTrue(argStats);
    }
    if (super.graphName != null)
        lang = Lang.NTRIPLES;
    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