@Override public RemoteDocument loadDocument(String url) throws JsonLdError { return new RemoteDocument("http://nonexisting.example.com/context", context); } };
/** * 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); } } }
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; }
try { final RemoteDocument tmp = opts.getDocumentLoader().loadDocument((String) input); input = tmp.getDocument();
try { final RemoteDocument tmp = opts.getDocumentLoader().loadDocument((String) input); input = tmp.getDocument();
@Test public void loadDocumentSchemaOrgDirect() throws Exception { final RemoteDocument document = documentLoader .loadDocument("http://schema.org/docs/jsonldcontext.json"); final Object context = document.getDocument(); assertTrue(context instanceof Map); assertFalse(((Map<?, ?>) context).isEmpty()); }
if (m_injectedDocs.containsKey(url)) { try { return new RemoteDocument(url, m_injectedDocs.get(url)); } catch (final Exception e) { throw new JsonLdError(JsonLdError.Error.LOADING_INJECTED_CONTEXT_FAILED, url, e); 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);
@Test public void loadDocumentWf4ever() throws Exception { final RemoteDocument document = documentLoader .loadDocument("http://purl.org/wf4ever/ro-bundle/context.json"); final Object context = document.getDocument(); assertTrue(context instanceof Map); assertFalse(((Map<?, ?>) context).isEmpty()); }
if (m_injectedDocs.containsKey(url)) { try { return new RemoteDocument(url, m_injectedDocs.get(url)); } catch (final Exception e) { throw new JsonLdError(JsonLdError.Error.LOADING_INJECTED_CONTEXT_FAILED, url, e); 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);
@Test public void loadDocumentSchemaOrg() throws Exception { final RemoteDocument document = documentLoader.loadDocument("http://schema.org/"); final Object context = document.getDocument(); assertTrue(context instanceof Map); assertFalse(((Map<?, ?>) context).isEmpty()); }
@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); }
final Object remoteContext = rd.getDocument(); if (!(remoteContext instanceof Map) || !((Map<String, Object>) remoteContext) .containsKey(JsonLdConsts.CONTEXT)) {
final Object remoteContext = rd.getDocument(); if (!(remoteContext instanceof Map) || !((Map<String, Object>) remoteContext) .containsKey(JsonLdConsts.CONTEXT)) {