use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class ModStore method processArgs.
@Override
public void processArgs(CmdArgModule cmdLine) {
if (!cmdLine.contains(argDeclSDBdesc)) {
System.err.println("No store description");
throw new TerminationException(1);
}
String f = cmdLine.getArg(argDeclSDBdesc).getValue();
try {
storeDesc = StoreDesc.read(f);
if (storeDesc.getLayout() == null) {
System.err.println("No layout or unrecognized layout");
throw new TerminationException(1);
}
} catch (SDBException ex) {
System.err.println("Failed to read the store description");
System.err.println(ex.getMessage());
throw new TerminationException(1);
} catch (NotFoundException ex) {
System.err.println(f + " : Store description not found");
throw new TerminationException(1);
}
// Overrides.
if (cmdLine.contains(argDeclDbHost))
storeDesc.connDesc.setHost(cmdLine.getArg(argDeclDbHost).getValue());
if (cmdLine.contains(argDeclDbName))
storeDesc.connDesc.setName(cmdLine.getArg(argDeclDbName).getValue());
if (cmdLine.contains(argDeclDbType))
storeDesc.connDesc.setType(cmdLine.getArg(argDeclDbType).getValue());
if (cmdLine.contains(argDeclDbUser))
storeDesc.connDesc.setUser(cmdLine.getArg(argDeclDbUser).getValue());
if (cmdLine.contains(argDeclDbPassword))
storeDesc.connDesc.setPassword(cmdLine.getArg(argDeclDbPassword).getValue());
if (cmdLine.contains(argDeclMySQLEngine))
storeDesc.engineType = MySQLEngineType.convert(cmdLine.getArg(argDeclMySQLEngine).getValue());
if (cmdLine.contains(argDeclSAPStorage))
storeDesc.storageType = SAPStorageType.convert(cmdLine.getArg(argDeclSAPStorage).getValue());
if (cmdLine.contains(argDeclLayout)) {
String layoutName = cmdLine.getArg(argDeclLayout).getValue();
storeDesc.setLayout(LayoutType.fetch(layoutName));
if (storeDesc.getLayout() == null) {
System.err.println("Don't recognize layout name '" + layoutName + "'");
throw new TerminationException(2);
}
}
if (false) {
//System.out.println("URL = " + storeDesc.connDesc.URL);
System.out.println("Type = " + storeDesc.connDesc.getType());
System.out.println("Host = " + storeDesc.connDesc.getHost());
System.out.println("Database = " + storeDesc.connDesc.getName());
System.out.println("User = " + storeDesc.connDesc.getUser());
System.out.println("Password = " + storeDesc.connDesc.getPassword());
// if ( storeDesc.connDesc.getArgStr() != null )
// System.out.println("Args = " + storeDesc.connDesc.getArgStr());
System.out.println("Layout = " + storeDesc.getLayout().getName());
//System.out.println("Name = " + argModelName);
SDBConnection.logSQLExceptions = true;
SDBConnection.logSQLStatements = true;
}
if (cmdLine.contains(argDeclJdbcDriver)) {
String driverName = cmdLine.getArg(argDeclJdbcDriver).getValue();
storeDesc.connDesc.setDriver(driverName);
}
}
use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class ResultSetFactory method result.
/**
* Read in any kind of result kind (result set, boolean, graph)
*/
public static SPARQLResult result(String filenameOrURI, ResultsFormat format) {
if (format == null)
format = ResultsFormat.guessSyntax(filenameOrURI);
if (format == null) {
Log.warn(ResultSet.class, "Null format - defaulting to XML");
format = ResultsFormat.FMT_RS_XML;
}
if (format.equals(ResultsFormat.FMT_TEXT)) {
Log.error(ResultSet.class, "Can't read a text result set");
throw new ResultSetException("Can't read a text result set");
}
if (format.equals(ResultsFormat.FMT_RS_XML) || format.equals(ResultsFormat.FMT_RS_JSON) || format.equals(ResultsFormat.FMT_RS_TSV) || format.equals(ResultsFormat.FMT_RS_CSV)) {
InputStream in = null;
try {
in = FileManager.get().open(filenameOrURI);
if (in == null)
throw new NotFoundException(filenameOrURI);
} catch (NotFoundException ex) {
throw new NotFoundException("File not found: " + filenameOrURI);
}
SPARQLResult x = null;
if (format.equals(ResultsFormat.FMT_RS_JSON))
return JSONInput.make(in, GraphFactory.makeDefaultModel());
else if (format.equals(ResultsFormat.FMT_RS_XML))
return XMLInput.make(in, GraphFactory.makeDefaultModel());
else if (format.equals(ResultsFormat.FMT_RS_TSV)) {
ResultSet rs = TSVInput.fromTSV(in);
return new SPARQLResult(rs);
} else if (format.equals(ResultsFormat.FMT_RS_CSV)) {
ResultSet rs = CSVInput.fromCSV(in);
return new SPARQLResult(rs);
} else if (format.equals(ResultsFormat.FMT_RS_BIO)) {
ResultSet rs = BIOInput.fromBIO(in);
return new SPARQLResult(rs);
}
}
if (ResultsFormat.isRDFGraphSyntax(format)) {
Model model = FileManager.get().loadModel(filenameOrURI);
return new SPARQLResult(model);
}
Log.error(ResultSet.class, "Unknown result set syntax: " + format);
return null;
}
use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class ResultSetFactory method loadAsModel.
/**
* Load a result set (or any other model) from file or URL. Does not have to
* be a result set (e.g. CONSTRUCt results) but it does interpret the
* ResultSetFormat possibilities.
*
* @param model
* Load into this model (returned)
* @param filenameOrURI
* @param format
* @return Model
*/
public static Model loadAsModel(Model model, String filenameOrURI, ResultsFormat format) {
if (model == null)
model = GraphFactory.makeDefaultModel();
if (format == null)
format = ResultsFormat.guessSyntax(filenameOrURI);
if (format == null) {
Log.warn(ResultSet.class, "Null format - defaulting to XML");
format = ResultsFormat.FMT_RS_XML;
}
if (format.equals(ResultsFormat.FMT_TEXT)) {
Log.error(ResultSet.class, "Can't read a text result set");
throw new ResultSetException("Can't read a text result set");
}
if (format.equals(ResultsFormat.FMT_RS_XML) || format.equals(ResultsFormat.FMT_RS_JSON)) {
InputStream in = null;
try {
in = FileManager.get().open(filenameOrURI);
if (in == null)
throw new NotFoundException(filenameOrURI);
} catch (NotFoundException ex) {
throw new NotFoundException("File not found: " + filenameOrURI);
}
SPARQLResult x = null;
if (format.equals(ResultsFormat.FMT_RS_JSON))
x = JSONInput.make(in, GraphFactory.makeDefaultModel());
else
x = XMLInput.make(in, GraphFactory.makeDefaultModel());
if (x.isResultSet())
RDFOutput.encodeAsRDF(model, x.getResultSet());
else
RDFOutput.encodeAsRDF(model, x.getBooleanResult());
return model;
}
if (ResultsFormat.isRDFGraphSyntax(format))
return FileManager.get().readModel(model, filenameOrURI);
Log.error(ResultSet.class, "Unknown result set syntax: " + format);
return null;
}
use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class QueryFactory method read.
/**
* Read a query from a file.
*
* @param url URL (file: or http: or anything a FileManager can handle)
* @param streamManager Optional StreamManager
* @param baseURI BaseURI for the query
* @param langURI Query syntax
* @return A new query object
*/
public static Query read(String url, StreamManager streamManager, String baseURI, Syntax langURI) {
if (streamManager == null)
streamManager = StreamManager.get();
InputStream in = streamManager.open(url);
if (in == null)
throw new NotFoundException("Not found: " + url);
String qStr = IO.readWholeFileAsUTF8(streamManager.open(url));
if (baseURI == null)
baseURI = url;
if (langURI == null)
langURI = Syntax.guessFileSyntax(url);
return create(qStr, baseURI, langURI);
}
use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class StoreProtocol method pushFile.
/**
* Send a file. fileContentType takes precedence over this.contentType.
*/
protected static void pushFile(HttpClient httpClient, String endpoint, String file, String fileContentType, Map<String, String> httpHeaders, Push style) {
try {
Path path = Path.of(file);
if (fileContentType != null)
httpHeaders.put(HttpNames.hContentType, fileContentType);
BodyPublisher body = BodyPublishers.ofFile(path);
HttpLib.httpPushData(httpClient, style, endpoint, HttpLib.setHeaders(httpHeaders), body);
} catch (FileNotFoundException ex) {
throw new NotFoundException(file);
}
}
Aggregations