Java Code Examples for org.openrdf.repository.RepositoryConnection#getNamespaces()
The following examples show how to use
org.openrdf.repository.RepositoryConnection#getNamespaces() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TripleStoreBlazegraph.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
@Override public List<PrefixNamespace> getNamespaces() { List<PrefixNamespace> namespaces = new ArrayList<>(); RepositoryConnection cnx = null; try { cnx = repo.getConnection(); RepositoryResult<Namespace> ns = cnx.getNamespaces(); while (ns.hasNext()) { Namespace namespace = ns.next(); namespaces.add(new PrefixNamespace(namespace.getPrefix(), namespace.getName())); } } catch (RepositoryException x) { throw new TripleStoreException("Getting namespaces", x); } finally { closeConnection(cnx, "Getting namespaces"); } return namespaces; }
Example 2
Source File: TripleStoreBlazegraph.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
private static void copyNamespaces(RepositoryConnection source, RepositoryConnection target) { try { RepositoryResult<Namespace> ns = source.getNamespaces(); for (Namespace namespace : Iterations.asList(ns)) { target.setNamespace(namespace.getPrefix(), namespace.getName()); } } catch (RepositoryException e) { LOG.error("Copying Namespaces : {}", e.getMessage()); } }
Example 3
Source File: RDFModelParser.java From ldp4j with Apache License 2.0 | 5 votes |
private Namespaces getNamespaces(RepositoryConnection connection) throws RepositoryException { Namespaces ns = new Namespaces(); RepositoryResult<Namespace> rr = null; try { rr=connection.getNamespaces(); while(rr.hasNext()) { Namespace n=rr.next(); ns.addPrefix(n.getPrefix(), n.getName()); } } finally { closeQuietly(rr,"Could not close results after retrieving namespaces"); } return ns; }
Example 4
Source File: TripleStoreBlazegraph.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
private static void copyNamespacesToModel(RepositoryConnection conn, Model m) throws RepositoryException { RepositoryResult<Namespace> ns = conn.getNamespaces(); while (ns.hasNext()) { m.setNamespace(ns.next()); } }
Example 5
Source File: NamespacesHandler.java From cumulusrdf with Apache License 2.0 | 4 votes |
/** * * @param repository the Repository object * @param request the HttpServletRequest object * @param response the HttpServletResponse oject * @return QueryResultView object include the namespaces * @throws ClientHTTPException throws when errors in the request * @throws ServerHTTPException throws when errors in the Repository * @throws RepositoryException throws when errors in closing the RepositoryConnection */ private ModelAndView getExportNamespacesResult(final Repository repository, final HttpServletRequest request, final HttpServletResponse response) throws ClientHTTPException, ServerHTTPException, RepositoryException { final boolean headersOnly = METHOD_HEAD.equals(request.getMethod()); Map<String, Object> model = new HashMap<String, Object>(); if (!headersOnly) { List<String> columnNames = Arrays.asList("prefix", "namespace"); List<BindingSet> namespaces = new ArrayList<BindingSet>(); RepositoryConnection repositoryCon = repository.getConnection(); synchronized (repositoryCon) { try { CloseableIteration<? extends Namespace, RepositoryException> iter = repositoryCon.getNamespaces(); try { while (iter.hasNext()) { Namespace ns = iter.next(); Literal prefix = new LiteralImpl(ns.getPrefix()); Literal namespace = new LiteralImpl(ns.getName()); BindingSet bindingSet = new ListBindingSet(columnNames, prefix, namespace); namespaces.add(bindingSet); } } finally { iter.close(); } } catch (RepositoryException e) { throw new ServerHTTPException("Repository error: " + e.getMessage(), e); } } model.put(QueryResultView.QUERY_RESULT_KEY, new TupleQueryResultImpl(columnNames, namespaces)); repositoryCon.close(); } TupleQueryResultWriterFactory factory = ProtocolUtil.getAcceptableService(request, response, TupleQueryResultWriterRegistry.getInstance()); model.put(QueryResultView.FILENAME_HINT_KEY, "namespaces"); model.put(QueryResultView.HEADERS_ONLY, headersOnly); model.put(QueryResultView.FACTORY_KEY, factory); return new ModelAndView(TupleQueryResultView.getInstance(), model); }