At the end I decide to take a shortcut that also might help explain what I want:
|private URI rdfLiteralToUri(String literal) { int xsdIndex = literal.lastIndexOf("^^"); if (xsdIndex == -1) { throw new IllegalArgumentException("Not valid literal format"); } String uriStr = literal.substring(0, xsdIndex); String type = literal.substring(xsdIndex + 2, literal.length()); if (!XSDDatatype.XSDanyURI.getURI().equals(type)) { throw new IllegalArgumentException("Not valid literal type"); } return URI.create(uriStr); } | On 11/01/2017 16:42, George News wrote: > On 11/01/2017 16:25, Chris Dollin wrote: >> On 11/01/17 14:55, George News wrote: >>> Hi, >>> >>> I have this literal: >>> http://hola^^http://www.w3.org/2001/XMSchema#anyURI >> What do you mean by "have"? A String value, a Literal >> value, or what? > I want to get http://hola as a String or as a URI. Better as a URI, but > only if it is conforming with the type linked. > > >>> And I want to create a URI from it. Is there any way to do so? >> And do you want an actual URI object or just its spelling? >> >> Because you can get the spelling of the URI using getLexicalForm. > Literal a = (Literal) > ResourceFactory.createTypedLiteral("http://hola^^http://www.w3.org/2001/XMSchema#anyURI", > XSDDatatype.XSDanyURI); > System.out.println(a.getDatatype()); > System.out.println(a.getLexicalForm()); > System.out.println(a.getDatatypeURI()); > System.out.println(a.getString()); > > Output: > Datatype[http://www.w3.org/2001/XMLSchema#anyURI -> class java.net.URI] > http://hola^^http://www.w3.org/2001/XMSchema#anyURI > http://www.w3.org/2001/XMLSchema#anyURI > http://hola^^http://www.w3.org/2001/XMSchema#anyURI > > > None of them returns "http://hola" which is the actual URI. > >> Chris >>