public UpdateClause parse(InputStream in) throws IOException { return parse(in, "UTF-8"); }
private List<UID> from() throws IOException { return collectUIDs(FROM); }
private UpdateClause drop() throws IOException { // DROP [ SILENT ] GRAPH <uri> String token = collectWhileIn(SILENT); skipWhitespace(); skipWhileIn(GRAPH); skipWhitespace(); UID uid = uri(); return new UpdateClause(prefixes, UpdateClause.Type.DROP, uid, !token.isEmpty()); }
private String block() throws IOException { expect(BLOCK_START); String rv = collectWhileNotIn(BLOCK_END).trim(); expect(BLOCK_END); return rv; }
public UpdateClause parse(InputStream in, String charset) throws IOException { try { this.in = new PushbackReader(new InputStreamReader(in, charset), 1); init(); while (nextChar().in(P)) { skipWhileIn(PREFIX, WS); String prefix = collectWhileIn(WORD); skipWhileIn(COLON, WS); UID ns = uri(); prefixes.put(prefix, ns.getId()); skipWhileIn(WS); pushback(); String start = collectWhileIn(ALPHA); skipWhitespace(); if (start.equals("CLEAR")) { return clear(); } else if (start.equals("CREATE")) { return create(); } else if (start.equals("DELETE")) { return delete(); } else if (start.equals("DROP")) { return drop(); } else if (start.equals("INSERT")) { return insert(); } else if (start.equals("LOAD")) { return load(); } else if (start.equals("MODIFY")) { return modify(); } else {
private UpdateClause insert() throws IOException { // INSERT DATA [ INTO <uri> ]* { triples } // INSERT [ INTO <uri> ]* { template } [ WHERE { pattern } ] String token = collectWhileIn(DATA, INTO); UpdateClause insert = new UpdateClause(prefixes, UpdateClause.Type.INSERT); if (token.equals("DATA")) { insert.addInto(into()); insert.setTemplate(block()); } else { if (token.equals("INTO")) { skipWhitespace(); insert.addInto(uri()); insert.addInto(into()); skipWhitespace(); } insert.setTemplate(block()); skipWhileIn(WS); if (nextChar().in(WHERE)) { skipWhileIn(WS, WHERE); insert.setPattern(block()); } } return insert; }
private UpdateClause modify() throws IOException { // MODIFY [ <uri> ]* DELETE { template } INSERT { template } [ WHERE { // pattern } ] UpdateClause modify = new UpdateClause(prefixes, UpdateClause.Type.MODIFY); nextChar(); while (in(LT)) { pushback(); modify.addInto(uri()); skipWhitespace(); nextChar(); } skipWhileIn(DELETE, WS); modify.setDelete(block()); skipWhileIn(INSERT, WS); modify.setInsert(block()); skipWhitespace(); nextChar(); if (ch > -1 && ch < 65535) { // FIXME skipWhileIn(WHERE, WS); modify.setPattern(block()); } return modify; }
private UpdateClause delete() throws IOException { // DELETE DATA [ FROM <uri> ]* { triples } // DELETE [ FROM <uri> ]* { template } [ WHERE { pattern } ] String token = collectWhileIn(DATA, FROM); UpdateClause delete = new UpdateClause(prefixes, UpdateClause.Type.DELETE); if (token.equals("DATA")) { delete.addFrom(from()); delete.setTemplate(block()); } else { if (token.equals("FROM")) { skipWhitespace(); delete.addFrom(uri()); delete.addFrom(from()); skipWhitespace(); } delete.setTemplate(block()); skipWhileIn(WS, WHERE); delete.setPattern(block()); } return delete; }
public SPARQLUpdateClause(RDFConnection connection, String clause) { try { this.connection = connection; this.clause = new SPARQLUpdateParser().parse(clause); } catch (IOException e) { throw new RepositoryException(e); } }
private List<UID> collectUIDs(CharSet cs) throws IOException { List<UID> uids = new ArrayList<UID>(); String token = null; do { skipWhitespace(); token = collectWhileIn(cs); skipWhitespace(); if (!token.isEmpty()) { UID uid = uri(); uids.add(uid); } } while (!token.isEmpty()); return uids; }
private UpdateClause parse(String string) throws IOException { return new SPARQLUpdateParser().parse(string); }
private UID uri() throws IOException { expect(LT); UID rv = new UID(collectWhileNotIn(WS, GT)); expect(GT); return rv; }
private UpdateClause create() throws IOException { // CREATE [ SILENT ] GRAPH <uri> String token = collectWhileIn(SILENT); skipWhitespace(); skipWhileIn(GRAPH); skipWhitespace(); UID uid = uri(); return new UpdateClause(prefixes, UpdateClause.Type.CREATE, uid, !token.isEmpty()); }
public UpdateClause parse(String str) throws IOException { return parse(new ByteArrayInputStream(str.getBytes("UTF-8")), "UTF-8"); }
private List<UID> into() throws IOException { return collectUIDs(INTO); }