/** * Check whether the {@link Resource} is used in any statement. * Checks if the provided {@link Resource} is used as * <ol> * <li>subject * <li>context * <li>object * <li>predicate (if the resource is a {@link URI}) * </ol> * @param conn {@link ResourceConnection} to check on * @param rsc the {@link Resource} to check * @return true if the {@link Resource} is ever used in a {@link Statement} */ public static boolean isUsed(RepositoryConnection conn, Resource rsc) { if (isSubject(conn, rsc) || isContext(conn, rsc) || isObject(conn, rsc)) return true; return rsc instanceof URI && isPredicate(conn, (URI) rsc); }
/** * List all outgoing edges from this resource to other resources. Shortcut for listOutgoing(null). * Just for the given space * * @return all outgoing edges from this resource */ public static Iterable<? extends Statement> listOutgoing(RepositoryConnection con, Resource r, URI context) throws RepositoryException { return listOutgoing(con, r,null,context); }
/** * List all resources of a specific type in the KiWi system. * * @param type the type of the resources to list * @return */ public static Iterable<Resource> listResources(final RepositoryConnection con, Resource type) { return listResources(con,type,null); }
public static String getWeakETag(RepositoryConnection conn, String resource) throws RepositoryException { if (resource.startsWith("http://")) { return getWeakETag(conn, ResourceUtils.getUriResource(conn, resource)); } else { return getWeakETag(conn, ResourceUtils.getAnonResource(conn, resource)); } }
if (UriUtil.validate(resource)) { try { if (ResourceUtils.isSubject(conn, resource)) { //tests if a resource is used as subject r = ResourceUtils.getUriResource(conn, resource); r = ResourceUtils.getAnonResource(conn, resource); } catch (Exception e) { log.error("Error retrieving the blank node <{}>: {}", resource, e.getMessage()); response.getMetadata().add(LAST_MODIFIED, ResourceUtils.getLastModified(conn, r)); response.getMetadata().add(ETAG, "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\""); return response;
r = ResourceUtils.getUriResource(conn, resource); } else { r = ResourceUtils.getAnonResource(conn, resource); if (r == null || !ResourceUtils.isUsed(conn, r)) { throw new HttpErrorException(Status.NOT_FOUND, resource, "the requested resource could not be found in Marmotta right now, but may be available again in the future", ImmutableMap.of(ACCEPT, mimetype)); .lastModified(ResourceUtils.getLastModified(conn, r)); response.header(ETAG, "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");
public static String getETag(RepositoryConnection conn, String uri) throws RepositoryException { URI resource = ResourceUtils.getUriResource(conn, uri); return getETag(conn, resource); }
con.begin(); for (String rsc_uri : context) { if (!ResourceUtils.isSubject(con, rsc_uri)) { continue; for (Value cP : cPos) { if (cP instanceof URI || cP instanceof BNode) { for (Statement t : listOutgoing(con, (Resource) cP)) { pathCandidates.add(t.getPredicate());
List<String> resources = ImmutableList.copyOf( Iterables.transform( ResourceUtils.listResources(connection), new Function<Resource, String>() { @Override ResourceUtils.removeResource(connection, connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier")); connection.commit(); ResourceUtils.listSubjects(connection), new Function<Resource, String>() { @Override
/** * Check whether the uri is ever used as subject. * @param conn connection with the repository * @param uri uri of the resource to check * @return true if the uri is ever used as subject. */ public static boolean isSubject(RepositoryConnection conn, String uri) { return isSubject(conn, conn.getValueFactory().createURI(uri)); }
/** * Return the label of this resource in the language provided as parameter * <p/> * If no label is available for the given language, returns the identifier. * * @param context the space of the label * @return */ public static String getLabel(RepositoryConnection con, Resource r, URI context) throws RepositoryException { return getLabel(con, r, null,context); }
/** * Remove a property from the RepositoryConnection con, Resource. Just for the given space!!! * * @param propLabel the property label in SeRQL syntax to remove * @return true if the property existed and was removed */ public static boolean removeProperty(RepositoryConnection con, Resource r, String propLabel, URI context) throws RepositoryException { return removeProperty(con,r,propLabel, null, context); }
try { conn.begin(); Resource resource = ResourceUtils.getUriResource(conn, URLDecoder.decode(uri, "utf-8")); if (resource != null) { ResourceUtils.removeResource(conn, resource); return Response.ok().build(); } else
ps.println("</head><body>"); ps.printf("<h1>Inspect %s</h1>%n<div>ShortName: %s<span class='%s'>%<s</span></div>%n", rsc.stringValue(), getLabel(conn,rsc), ""); Date created = ResourceUtils.getCreated(conn, rsc); if(created != null) { ps.printf("<div>Created: <span>%tF %<tT</span> by <span>%s</span></div>%n", created, createInspectLink(conn, null, null, "")); ps.printf("<div>Last Modified: <span>%tF %<tT</span></div>%n", ResourceUtils.getLastModified(conn, rsc)); return Response.ok() .header(HttpHeaders.CONTENT_TYPE, "text/html;charset=" + CHARSET) .header(HttpHeaders.LAST_MODIFIED, ResourceUtils.getLastModified(conn, rsc)) .entity(os.toString(CHARSET)).build();
/** * Check whenever the uri actually exists. * Existence of a URI (Resource) is bound to the existence of a * Statement referencing the Resource, so this method simply delegates to {@link #isUsed(RepositoryConnection, Resource)}. * * @param conn connection with the repository * @param uri uri of the resource to check * @return resource exists or not * @deprecated the name of this method is missleading. use {@link #isUsed(RepositoryConnection, Resource)}. */ @Deprecated public static boolean existsResource(RepositoryConnection conn, String uri) { return isUsed(conn, conn.getValueFactory().createURI(uri)); }
/** * Generic method to query for literal values related to this resource with the property * identified by "propLabel" (SeRQL/SPARQL short or long notation) and the given locale. * context define the knowledgespace in which this operation is. For the given context. * * @param propLabel label of the property; either RDF short form (e.g. "foaf:mbox") or long * form (e.g. <http://xmlns.com/foaf/0.1/mbox>) * @param loc * @param context context in which this property will set * @return */ public static <T> void setProperty(RepositoryConnection con, Resource r, String propLabel, String propValue, Locale loc, URI context) throws RepositoryException { if(propValue != null) { Resource[] contexts; if(context != null) { contexts = new Resource[] { context }; } else { contexts = new Resource[0]; } // remove previous property setting removeProperty(con,r,propLabel,loc,context); String prop_uri = resolvePropLabel(con, propLabel); // then set the new property value Literal value = con.getValueFactory().createLiteral(propValue, loc != null ? loc.getLanguage().toLowerCase() : null); URI prop = con.getValueFactory().createURI(prop_uri); con.add(r, prop, value, contexts); } else { removeProperty(con,r, propLabel,loc,context); } }
/** * Check whether the uri is ever used as context. * @param conn connection with the repository * @param uri uri of the resource to check * @return true if the uri is ever used as context. */ public static boolean isContext(RepositoryConnection conn, String uri) { return isContext(conn, conn.getValueFactory().createURI(uri)); }
/** * List resources with the given prefix * * @param prefix the prefix */ public static Iterable<URI> listResourcesByPrefix(final RepositoryConnection con, String prefix) { return listResourcesByPrefix(con,prefix,0,0); }
if (UriUtil.validate(resource)) { try { if (ResourceUtils.isSubject(conn, resource)) { //tests if a resource is used as subject r = ResourceUtils.getUriResource(conn, resource); r = ResourceUtils.getAnonResource(conn, resource); } catch (Exception e) { log.error("Error retrieving the blank node <{}>: {}", resource, e.getMessage()); response.getMetadata().add(LAST_MODIFIED, ResourceUtils.getLastModified(conn, r)); response.getMetadata().add(ETAG, "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\""); return response;
r = ResourceUtils.getUriResource(conn, resource); } else { r = ResourceUtils.getAnonResource(conn, resource); if (r == null || !ResourceUtils.isUsed(conn, r)) { throw new HttpErrorException(Status.NOT_FOUND, resource, "the requested resource could not be found in Marmotta right now, but may be available again in the future", ImmutableMap.of(ACCEPT, mimetype)); .lastModified(ResourceUtils.getLastModified(conn, r)); response.header(ETAG, "W/\"" + ETagGenerator.getWeakETag(conn, r) + "\"");