public void setGlobalContext(JSONObject context, ContextIdentifier contextId) { if (context.has("@context")) { if (contextId != null) { location = contextId.getLocation(); } JSONObject c = context.getJSONObject("@context"); this.context = c; @SuppressWarnings("rawtypes") Iterator itr = c.keys(); while (itr.hasNext()) { String key = itr.next().toString(); try { if (c.get(key).toString().equals("@id")) { atId = key; } if (c.get(key).toString().equals("@type")) { atType = key; } if (c.getJSONObject(key).has("@id")) { contextInverseAtIdMapping.put(c.getJSONObject(key).getString("@id"), key); } if (c.getJSONObject(key).has("@container") && c.getJSONObject(key).get("@container").equals("@set")) { contextInverseAtContainerMapping.put(key, true); } }catch(Exception e) { } } } }
private void initializeWriter(R2RMLMappingIdentifier id, ContextIdentifier contextId, List<KR2RMLRDFWriter> writers) { JSONObject contextObj = new JSONObject(); if (contextId != null) { try { JSONTokener token = new JSONTokener(contextId.getLocation().openStream()); contextObj = new JSONObject(token); }catch(Exception e) { } } for (KR2RMLRDFWriter writer : writers) { if (writer instanceof JSONKR2RMLRDFWriter) { JSONKR2RMLRDFWriter t = (JSONKR2RMLRDFWriter)writer; t.setGlobalContext(contextObj, contextId); } writer.setR2RMLMappingIdentifier(id); } }
public JSONObject loadContext(ContextIdentifier id) throws IOException { if (contextCache.containsKey(id.getName())) { return contextCache.get(id.getName()); } InputStream jsonStream; if(id.getContent() != null) jsonStream = IOUtils.toInputStream(id.getContent(), "utf-8"); else jsonStream = id.getLocation().openStream(); JSONTokener token = new JSONTokener(new InputStreamReader(jsonStream)); JSONObject obj = new JSONObject(token); this.contextCache.put(id.getName(), obj); return obj; }