public Object getContextValue(String activeProperty, String string) throws JsonLdError { throw new JsonLdError(Error.NOT_IMPLEMENTED, "getContextValue is only used by old code so far and thus isn't implemented"); }
public void setEmbed(String embed) throws JsonLdError { switch (embed) { case "@always": this.embed = Embed.ALWAYS; break; case "@never": this.embed = Embed.NEVER; break; case "@last": this.embed = Embed.LAST; break; case "@link": this.embed = Embed.LINK; break; default: throw new JsonLdError(JsonLdError.Error.INVALID_EMBED_VALUE); } }
public void setEmbed(String embed) throws JsonLdError { switch (embed) { case "@always": this.embed = Embed.ALWAYS; break; case "@never": this.embed = Embed.NEVER; break; case "@last": this.embed = Embed.LAST; break; case "@link": this.embed = Embed.LINK; break; default: throw new JsonLdError(JsonLdError.Error.INVALID_EMBED_VALUE); } }
public String expandIRI(String ns, String name) throws JsonLdError { if (namespaces.containsKey(ns)) { return namespaces.get(ns) + name; } else { throw new JsonLdError(JsonLdError.Error.PARSE_ERROR, "No prefix found for: " + ns + " {line: " + lineNumber + ", position:" + linePosition + "}"); } } }
private void validateIRI(State state, String iri) throws JsonLdError { if (!IRIREF_MINUS_CONTAINER.matcher(iri).matches()) { throw new JsonLdError(JsonLdError.Error.PARSE_ERROR, "Error while parsing Turtle; invalid IRI after escaping. {line: " + state.lineNumber + "position: " + state.linePosition + "}"); } }
@Override public RDFDataset parse(Object input) throws JsonLdError { if (input instanceof String) { return RDFDatasetUtils.parseNQuads((String) input); } else { throw new JsonLdError(JsonLdError.Error.INVALID_INPUT, "NQuad Parser expected string input."); } }
@Override public RDFDataset parse(Object input) throws JsonLdError { if (input instanceof String) { return parseNQuads((String) input); } else { throw new JsonLdError(JsonLdError.Error.INVALID_INPUT, "NQuad Parser expected string input."); } }
@Override public RDFDataset parse(Object input) throws JsonLdError { if (input instanceof String) { return RDFDatasetUtils.parseNQuads((String) input); } else { throw new JsonLdError(JsonLdError.Error.INVALID_INPUT, "NQuad Parser expected string input."); } }
private Embed getFrameEmbed(Map<String, Object> frame, Embed thedefault) throws JsonLdError { final Object value = getFrameValue(frame, JsonLdConsts.EMBED); if (value == null) { return thedefault; } if (value instanceof Boolean) { return (Boolean) value ? Embed.LAST : Embed.NEVER; } if (value instanceof Embed) { return (Embed) value; } if (value instanceof String) { switch ((String) value) { case "@always": return Embed.ALWAYS; case "@never": return Embed.NEVER; case "@last": return Embed.LAST; case "@link": return Embed.LINK; default: throw new JsonLdError(JsonLdError.Error.INVALID_EMBED_VALUE); } } throw new JsonLdError(JsonLdError.Error.INVALID_EMBED_VALUE); }
private Embed getFrameEmbed(Map<String, Object> frame, Embed thedefault) throws JsonLdError { final Object value = getFrameValue(frame, JsonLdConsts.EMBED); if (value == null) { return thedefault; } if (value instanceof Boolean) { return (Boolean) value ? Embed.LAST : Embed.NEVER; } if (value instanceof Embed) { return (Embed) value; } if (value instanceof String) { switch ((String) value) { case "@always": return Embed.ALWAYS; case "@never": return Embed.NEVER; case "@last": return Embed.LAST; case "@link": return Embed.LINK; default: throw new JsonLdError(JsonLdError.Error.INVALID_EMBED_VALUE); } } throw new JsonLdError(JsonLdError.Error.INVALID_EMBED_VALUE); }
@Override public RDFDataset parse(Object input) throws JsonLdError { if(input instanceof String){ JSONObject obj; try { obj = XML.toJSONObject((String) input); return parseXmlJson(obj); } catch (JSONException e) { throw new JsonLdError(JsonLdError.Error.INVALID_INPUT, "XML Parse Error: "+e.getMessage()); } } else { throw new JsonLdError(JsonLdError.Error.INVALID_INPUT, "RDF/XML Parser expected string input."); } }
throw new JsonLdError(JsonLdError.Error.SYNTAX_ERROR);
/** * Avoid resolving a document by instead using the given serialised * representation. * * @param url * The URL this document represents. * @param doc * The serialised document as a String * @return This object for fluent addition of other injected documents. * @throws JsonLdError * If loading of the document failed for any reason. */ public DocumentLoader addInjectedDoc(String url, String doc) throws JsonLdError { try { m_injectedDocs.put(url, JsonUtils.fromString(doc)); return this; } catch (final Exception e) { throw new JsonLdError(JsonLdError.Error.LOADING_INJECTED_CONTEXT_FAILED, url, e); } }
/** * Avoid resolving a document by instead using the given serialised * representation. * * @param url * The URL this document represents. * @param doc * The serialised document as a String * @return This object for fluent addition of other injected documents. * @throws JsonLdError * If loading of the document failed for any reason. */ public DocumentLoader addInjectedDoc(String url, String doc) throws JsonLdError { try { m_injectedDocs.put(url, JsonUtils.fromString(doc)); return this; } catch (final Exception e) { throw new JsonLdError(JsonLdError.Error.LOADING_INJECTED_CONTEXT_FAILED, url, e); } }
public void advanceLinePosition(int len) throws JsonLdError { if (len > 0) { linePosition += len; line = line.substring(len); } while (!"".equals(line)) { // clear any whitespace final Matcher match = Regex.COMMENT_OR_WS.matcher(line); if (match.find() && match.group(0).length() > 0) { final Matcher eoln = Regex.EOLN.matcher(match.group(0)); int end = 0; while (eoln.find()) { lineNumber += 1; end = eoln.end(); } linePosition = match.group(0).length() - end; line = line.substring(match.group(0).length()); } else { break; } } if ("".equals(line) && !endIsOK()) { throw new JsonLdError(JsonLdError.Error.PARSE_ERROR, "Error while parsing Turtle; unexpected end of input. {line: " + lineNumber + ", position:" + linePosition + "}"); } }
return new RemoteDocument(url, m_injectedDocs.get(url)); } catch (final Exception e) { throw new JsonLdError(JsonLdError.Error.LOADING_INJECTED_CONTEXT_FAILED, url, e); .getProperty(DocumentLoader.DISALLOW_REMOTE_CONTEXT_LOADING); if ("true".equalsIgnoreCase(disallowRemote)) { throw new JsonLdError(JsonLdError.Error.LOADING_REMOTE_CONTEXT_FAILED, "Remote context loading has been disallowed (url was " + url + ")"); return new RemoteDocument(url, JsonUtils.fromURL(new URL(url), getHttpClient())); } catch (final Exception e) { throw new JsonLdError(JsonLdError.Error.LOADING_REMOTE_CONTEXT_FAILED, url, e);
public RemoteDocument loadDocument(String url) throws JsonLdError { final RemoteDocument doc = new RemoteDocument(url, null); try { doc.setDocument(fromURL(new URL(url))); } catch (final Exception e) { new JsonLdError(JsonLdError.Error.LOADING_REMOTE_CONTEXT_FAILED, url); } return doc; }
@Override public RemoteDocument loadDocument(String url) throws JsonLdError { if (url == null) { throw new JsonLdError(JsonLdError.Error.LOADING_REMOTE_CONTEXT_FAILED, "URL was null"); } if (url.contains(":")) { // check if the url is relative to the test base if (url.startsWith(this.base)) { final String classpath = url.substring(this.base.length()); final ClassLoader cl = Thread.currentThread().getContextClassLoader(); final InputStream inputStream = cl .getResourceAsStream(TEST_DIR + "/" + classpath); try { return new RemoteDocument(url, JsonUtils.fromInputStream(inputStream)); } catch (final IOException e) { throw new JsonLdError(JsonLdError.Error.LOADING_DOCUMENT_FAILED, e); } } } // we can't load this remote document from the test suite throw new JsonLdError(JsonLdError.Error.NOT_IMPLEMENTED, "URL scheme was not recognised: " + url); }
@Override public RDFDataset parse(Object input) throws JsonLdError { final RDFDataset result = new RDFDataset(); // empty dataset if no input given if (input == null) { return result; } if (input instanceof ModelSet) { importModelSet(result, (ModelSet) input); } else if (input instanceof Model) { importModel(result, (Model) input); } else { throw new JsonLdError(Error.INVALID_INPUT, "RDF2Go parser expects a Model or ModelSet object as input"); } return result; }
/** * Supports "reverse injection" from an existing remote document. * <p> * Generally the document contents are already parsed JSON content, however this method will also accept * document contents represented as a string of JSON data. */ public Builder injectDocument(RemoteDocument document) { String url = document.getDocumentUrl(); if (document.getDocument() instanceof CharSequence) { // Avoid unnecessary JSON serialization return injectDocument(url, (CharSequence) document.getDocument()); } else { try { documentLoader.addInjectedDoc(url, JsonUtils.toString(document.getDocument())); return this; } catch (IOException e) { throw new JsonLdError(JsonLdError.Error.LOADING_INJECTED_CONTEXT_FAILED, url, e); } } }