use of org.apache.jena.shared.PrefixMapping in project webofneeds by researchstudio-sat.
the class CommentUnrestrictedFacet method connectFromNeed.
@Override
public void connectFromNeed(Connection con, Model content, WonMessage wonMessage) throws NoSuchNeedException, IllegalMessageForNeedStateException, ConnectionAlreadyExistsException {
super.connectFromNeed(con, content, wonMessage);
/* send a connect back */
try {
// TODO: use new system
// needFacingConnectionClient.open(con, content, null);
Need need = needRepository.findOneByNeedURI(con.getNeedURI());
Model needContent = need.getDatatsetHolder().getDataset().getDefaultModel();
PrefixMapping prefixMapping = PrefixMapping.Factory.create();
// prefixMapping.setNsPrefix(SIOC.getURI(),"sioc");
needContent.withDefaultMappings(prefixMapping);
needContent.setNsPrefix("sioc", SIOC.getURI());
Resource post = needContent.createResource(con.getNeedURI().toString(), SIOC.POST);
Resource reply = needContent.createResource(con.getRemoteNeedURI().toString(), SIOC.POST);
needContent.add(needContent.createStatement(needContent.getResource(con.getNeedURI().toString()), SIOC.HAS_REPLY, needContent.getResource(con.getRemoteNeedURI().toString())));
// add WON node link
logger.debug("linked data:" + RdfUtils.toString(needContent));
need.getDatatsetHolder().getDataset().setDefaultModel(needContent);
needRepository.save(need);
// } catch (NoSuchConnectionException e) {
// e.printStackTrace();
// } catch (IllegalMessageForConnectionStateException e) {
// e.printStackTrace();
} catch (Exception e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
/* when connected change linked data*/
}
use of org.apache.jena.shared.PrefixMapping in project zeppelin by apache.
the class JenaInterpreter method query.
@Override
public InterpreterResult query(String query) {
LOGGER.info("SPARQL: Run Query '" + query + "' against " + serviceEndpoint);
try {
queryExecution = QueryExecutionFactory.sparqlService(serviceEndpoint, query);
PrefixMapping prefixMapping = queryExecution.getQuery().getPrefixMapping();
// execute query and get Results
ResultSet results = queryExecution.execSelect();
// transform ResultSet to TSV-String
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ResultSetFormatter.outputAsTSV(outputStream, results);
String tsv = new String(outputStream.toByteArray());
if (replaceURIs) {
LOGGER.info("SPARQL: Replacing URIs");
tsv = replaceURIs(tsv, prefixMapping);
}
if (removeDatatypes) {
LOGGER.info("SPARQL: Removing datatypes");
tsv = removeDatatypes(tsv);
}
return new InterpreterResult(InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TABLE, tsv);
} catch (QueryParseException e) {
LOGGER.error(e.toString());
return new InterpreterResult(InterpreterResult.Code.ERROR, "Error: " + e.getMessage());
} catch (QueryExceptionHTTP e) {
LOGGER.error(e.toString());
int responseCode = e.getResponseCode();
if (responseCode == HttpStatus.SC_UNAUTHORIZED) {
return new InterpreterResult(InterpreterResult.Code.ERROR, "Unauthorized.");
} else if (responseCode == HttpStatus.SC_NOT_FOUND) {
return new InterpreterResult(InterpreterResult.Code.ERROR, "Endpoint not found, please check endpoint in the configuration.");
} else {
return new InterpreterResult(InterpreterResult.Code.ERROR, "Error: " + e.getMessage());
}
} catch (ARQException e) {
return new InterpreterResult(InterpreterResult.Code.INCOMPLETE, "Query cancelled.");
}
}
use of org.apache.jena.shared.PrefixMapping in project jena by apache.
the class ParseHandlerResolver method declItem.
@Override
protected void declItem(ItemList list, Item item) {
if (list != declList)
// Deeper
return;
// Prefix - deeper than one.
boolean isBase = list.get(0).isSymbol(baseTag);
boolean isPrefix = list.get(0).isSymbol(prefixTag);
// Old state has already been saved.
if (isBase) {
if (!item.isNode())
throwException("(base ...): not an RDF node for the base.", item);
if (!item.getNode().isURI())
throwException("(base ...): not an IRI for the base.", item);
String newBase = item.getNode().getURI();
if (baseURI != null)
baseURI = baseURI.resolve(newBase);
else
baseURI = IRIs.resolveIRI(newBase);
// Remember first base seen
if (topBase == null)
topBase = newBase;
return;
}
if (isPrefix) {
PrefixMapping newPrefixes = new PrefixMappingImpl();
PrefixMapping itemMappings = BuilderPrefixMapping.build(item);
// Add exising, overwrite with new
newPrefixes.setNsPrefixes(prefixes);
newPrefixes.setNsPrefixes(itemMappings);
prefixes = newPrefixes;
// Remember first prefix mapping seen.
if (topMap == null)
topMap = itemMappings;
return;
}
throwException("Inconsistent: " + list.shortString(), list);
}
use of org.apache.jena.shared.PrefixMapping in project jena by apache.
the class WriterBasePrefix method printPrefix.
private static boolean printPrefix(IndentedWriter iWriter, Prologue prologue) {
PrefixMapping prefixMapping = prologue.getPrefixMapping();
if (prefixMapping != null) {
Map<String, String> m = prefixMapping.getNsPrefixMap();
if (!m.isEmpty()) {
int s = iWriter.getCol();
WriterLib.start(iWriter, Tags.tagPrefix, NoNL);
WriterLib.start(iWriter);
// Indent to this col.
int len = iWriter.getCurrentOffset();
iWriter.incIndent(len);
Iterator<String> iter = m.keySet().iterator();
boolean first = true;
for (; iter.hasNext(); ) {
if (!first)
iWriter.println();
first = false;
String prefix = iter.next();
String uri = prefixMapping.getNsPrefixURI(prefix);
// Base relative URI = but not prefix mappings!
uri = FmtUtils.stringForURI(uri, prologue.getBaseURI());
WriterLib.start(iWriter);
iWriter.print(prefix);
iWriter.print(": ");
iWriter.print(uri);
WriterLib.finish(iWriter);
}
iWriter.decIndent(len);
WriterLib.finish(iWriter);
iWriter.ensureStartOfLine();
return true;
}
}
return false;
}
use of org.apache.jena.shared.PrefixMapping in project jena by apache.
the class AbstractTestGraphOverDatasetGraph method graphDSG_prefixes_3.
@Test
public void graphDSG_prefixes_3() {
Graph g = makeDefaultGraph(baseDSG);
PrefixMapping pmap = g.getPrefixMapping();
assertNotNull(pmap);
}
Aggregations