MCPcopy Create free account
hub / github.com/BaseXdb/basex / get

Method get

basex-api/src/main/java/org/basex/http/rest/RESTPut.java:32–81  ·  view source on GitHub ↗

Creates and returns a REST command. @param session REST session @return code @throws QueryException query exception @throws IOException I/O exception

(final RESTSession session)

Source from the content-addressed store, hash-verified

30 * @throws IOException I/O exception
31 */
32 public static RESTExec get(final RESTSession session) throws QueryException, IOException {
33 // create new database or update resource
34 final HTTPConnection conn = session.conn;
35 final String db = conn.db();
36 if(db.isEmpty()) throw HTTPStatus.NO_DATABASE_SPECIFIED.get();
37
38 RESTCmd.assignOptions(session);
39
40 final MainOptions options = conn.context.options;
41 final InputStream is = conn.request.getInputStream();
42 final MediaType mt = conn.mediaType();
43
44 // choose correct importer
45 boolean xml = true;
46 if(mt.isJSON()) {
47 final JsonParserOptions opts = new JsonParserOptions();
48 opts.assign(mt);
49 options.set(MainOptions.JSONPARSER, opts);
50 options.set(MainOptions.PARSER, MainParser.JSON);
51 } else if(mt.isCSV()) {
52 final CsvParserOptions opts = new CsvParserOptions();
53 opts.assign(mt);
54 options.set(MainOptions.CSVPARSER, opts);
55 options.set(MainOptions.PARSER, MainParser.CSV);
56 } else if(mt.is(MediaType.TEXT_HTML)) {
57 final HtmlOptions opts = new HtmlOptions();
58 opts.assign(mt);
59 options.set(MainOptions.HTMLPARSER, opts);
60 options.set(MainOptions.PARSER, MainParser.HTML);
61 } else if(!mt.is(MediaType.ALL_ALL) && !mt.isXml()) {
62 xml = false;
63 }
64
65 // store data as XML or binary resource, depending on content type
66 final String path = conn.dbpath();
67 if(path.isEmpty()) {
68 // do not OPEN database
69 session.clear();
70 if(xml) {
71 session.add(new CreateDB(db), is);
72 } else {
73 session.add(new CreateDB(db)).add(new BinaryPut(db), is);
74 }
75 } else if(xml) {
76 session.add(new Put(path), is);
77 } else {
78 session.add(new Delete(path)).add(new BinaryPut(path), is);
79 }
80 return new RESTExec(session, true);
81 }
82}

Callers 1

commandMethod · 0.95

Calls 14

dbMethod · 0.95
assignOptionsMethod · 0.95
mediaTypeMethod · 0.95
isJSONMethod · 0.95
isCSVMethod · 0.95
isMethod · 0.95
isXmlMethod · 0.95
dbpathMethod · 0.95
getMethod · 0.65
setMethod · 0.65
addMethod · 0.65
isEmptyMethod · 0.45

Tested by

no test coverage detected