GeoPubby  Version 0.1.0.0
URIPrefixer Class Reference

Helper class that splits URIs into prefix and local name according to a Jena PrefixMapping. More...

Collaboration diagram for URIPrefixer:

Public Member Functions

 URIPrefixer (String uri, PrefixMapping prefixes)
 
 URIPrefixer (Resource resource, PrefixMapping prefixes)
 
boolean hasPrefix ()
 
String getPrefix ()
 
String getLocalName ()
 
String toTurtle ()
 

Private Attributes

final Resource resource
 
final String prefix
 
final String localName
 

Detailed Description

Helper class that splits URIs into prefix and local name according to a Jena PrefixMapping.

Constructor & Destructor Documentation

◆ URIPrefixer() [1/2]

URIPrefixer ( String  uri,
PrefixMapping  prefixes 
)
20  {
21  this(ResourceFactory.createResource(uri), prefixes);
22  }

◆ URIPrefixer() [2/2]

URIPrefixer ( Resource  resource,
PrefixMapping  prefixes 
)
24  {
25  this.resource = resource;
26  String uri = resource.getURI();
27  Iterator<String> it = prefixes.getNsPrefixMap().keySet().iterator();
28  while (it.hasNext() && uri != null) {
29  String entryPrefix = it.next();
30  String entryURI = prefixes.getNsPrefixURI(entryPrefix);
31  if (uri.startsWith(entryURI)) {
32  prefix = entryPrefix;
33  localName = uri.substring(entryURI.length());
34  return;
35  }
36  }
37  prefix = null;
38  localName = null;
39  }
final String localName
Definition: URIPrefixer.java:18
final Resource resource
Definition: URIPrefixer.java:16
final String prefix
Definition: URIPrefixer.java:17

References URIPrefixer.localName, URIPrefixer.prefix, and URIPrefixer.resource.

Member Function Documentation

◆ getLocalName()

String getLocalName ( )
49  {
50  if (resource.isAnon()) return null;
51  if (localName == null) {
52  Matcher matcher = Pattern.compile("([^#/:?]+)[#/:?]*$").matcher(resource.getURI());
53  if (matcher.find()) {
54  return matcher.group(1);
55  }
56  return ""; // Only happens if the URI contains only excluded chars
57  }
58  return localName;
59  }

References URIPrefixer.localName, and URIPrefixer.resource.

Referenced by ResourceDescription.Value.getDatatypeLabel(), ResourceDescription.ResourceProperty.getLocalName(), ResourceDescription.Value.getLocalName(), ResourceDescription.getTitle(), and URIPrefixer.toTurtle().

◆ getPrefix()

◆ hasPrefix()

◆ toTurtle()

String toTurtle ( )
61  {
62  if (resource.isAnon()) return "[]";
63  if (hasPrefix()) {
64  return getPrefix() + ":" + getLocalName();
65  }
66  return "<" + resource.getURI() + ">";
67  }
String getPrefix()
Definition: URIPrefixer.java:45
String getLocalName()
Definition: URIPrefixer.java:49
boolean hasPrefix()
Definition: URIPrefixer.java:41

References URIPrefixer.getLocalName(), URIPrefixer.getPrefix(), URIPrefixer.hasPrefix(), and URIPrefixer.resource.

Referenced by ResourceDescription.Value.getDatatypeLabel().

Member Data Documentation

◆ localName

final String localName
private

◆ prefix

final String prefix
private

◆ resource

final Resource resource
private