本文整理汇总了Java中org.openrdf.model.Namespace.getPrefix方法的典型用法代码示例。如果您正苦于以下问题:Java Namespace.getPrefix方法的具体用法?Java Namespace.getPrefix怎么用?Java Namespace.getPrefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.model.Namespace
的用法示例。
在下文中一共展示了Namespace.getPrefix方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findPrefix
import org.openrdf.model.Namespace; //导入方法依赖的package包/类
private String findPrefix(String ns, Model model) {
for (Namespace e : model.getNamespaces()) {
if (ns.equals(e.getName()) && e.getPrefix().length() > 0) {
return e.getPrefix();
}
}
if (resolvingPrefix) {
String prefix = NamespacePrefixService.getInstance().prefix(ns);
if (prefix != null && model.getNamespace(prefix) == null) {
model.setNamespace(prefix, ns);
return prefix;
}
}
return "ns" + Integer.toHexString(ns.hashCode());
}
示例2: getExportNamespacesResult
import org.openrdf.model.Namespace; //导入方法依赖的package包/类
/**
*
* @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);
}