1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package olr.rdf;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
24
25
26 public abstract class Tools
27 {
28 public static boolean isURI(String ID)
29 {
30 return ID.indexOf("://") >= 0 && getSeparatorPos(ID) >= 0;
31 }
32
33 public static String getNS(String URI)
34 {
35 int sep = getSeparatorPos(URI);
36 if(sep >= 0)
37 return URI.substring(0, sep + 1);
38 else
39 return "";
40 }
41
42 public static String getName(String URI)
43 {
44 return URI.substring(getSeparatorPos(URI) + 1);
45 }
46
47 private static int getSeparatorPos(String URI)
48 {
49 int sep = URI.lastIndexOf('#');
50 if(sep < 0)
51 {
52 sep = URI.lastIndexOf('/');
53 if(sep > 0 && URI.charAt(sep - 1) == '/')
54 sep = -1;
55 }
56 return sep;
57 }
58
59 public static String getURI(String ns, String name)
60 {
61 return String.valueOf(ns) + String.valueOf(name);
62 }
63
64 public static String correctURI(String URI)
65 {
66 if(URI == null)
67 return "";
68 else
69 return URI;
70 }
71
72 public static String URItoID(String URI)
73 {
74 return URI.replace('#', '*');
75 }
76
77 public static String IDtoURI(String ID)
78 {
79 return ID.replace('*', '#');
80 }
81
82 public static boolean isSameNS(String ns, String URI)
83 {
84 return ns.equals(getNS(URI));
85 }
86
87 public static List getSpecificObjects(Resource resource, String predicate)
88 {
89 List specObjects = new ArrayList();
90 Iterator it = resource.getAttributes().iterator();
91 do
92 {
93 if(!it.hasNext())
94 break;
95 Attribute attribute = (Attribute)it.next();
96 if(predicate.equals(attribute.getPredicate()))
97 specObjects.add(attribute.getObject());
98 } while(true);
99 return specObjects;
100 }
101
102 public static List getSpecificAttributes(Resource resource, String predicate)
103 {
104 List specAttributes = new ArrayList();
105 Iterator it = resource.getAttributes().iterator();
106 do
107 {
108 if(!it.hasNext())
109 break;
110 Attribute attribute = (Attribute)it.next();
111 if(predicate.equals(attribute.getPredicate()))
112 specAttributes.add(attribute);
113 } while(true);
114 return specAttributes;
115 }
116 }