1 |
| package photospace.meta.rdf; |
2 |
| |
3 |
| import java.io.*; |
4 |
| import org.apache.commons.logging.*; |
5 |
| import com.hp.hpl.jena.rdf.model.*; |
6 |
| |
7 |
| public class RdfTools |
8 |
| implements java.io.Serializable |
9 |
| { |
10 |
| private static final Log log = LogFactory.getLog(RdfTools.class); |
11 |
| |
12 |
| public static final String RDF_START = "<rdf:RDF"; |
13 |
| public static final String RDF_END = "</rdf:RDF>"; |
14 |
| |
15 |
0
| public static String getRdfString(String str)
|
16 |
| { |
17 |
0
| if (str == null) return null;
|
18 |
0
| int start = str.indexOf(RDF_START);
|
19 |
0
| int end = str.indexOf(RDF_END);
|
20 |
0
| if (start == -1) return null;
|
21 |
0
| if (end == -1) return null;
|
22 |
0
| if (end < start)
|
23 |
| { |
24 |
0
| log.warn(RDF_END + " is before " + RDF_START);
|
25 |
0
| return null;
|
26 |
| } |
27 |
0
| return str.substring(start, end + RDF_END.length());
|
28 |
| } |
29 |
| |
30 |
1
| public static String toString(Model model)
|
31 |
| { |
32 |
1
| ByteArrayOutputStream out = new ByteArrayOutputStream();
|
33 |
1
| model.write(out, "RDF/XML-ABBREV");
|
34 |
1
| return out.toString();
|
35 |
| } |
36 |
| |
37 |
| } |