1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.any23.writer; |
19 | |
|
20 | |
import org.apache.any23.extractor.ExtractionContext; |
21 | |
import org.openrdf.model.Resource; |
22 | |
import org.openrdf.model.URI; |
23 | |
import org.openrdf.model.Value; |
24 | |
|
25 | |
import java.io.OutputStream; |
26 | |
import java.io.PrintStream; |
27 | |
import java.util.ArrayList; |
28 | |
import java.util.List; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
@Writer(identifier = "uri", mimeType = "text/plain") |
37 | |
public class URIListWriter implements FormatWriter { |
38 | |
|
39 | |
private List<Resource> resources; |
40 | |
|
41 | |
private PrintStream printStream; |
42 | |
|
43 | |
private ExtractionContext extractionContext; |
44 | |
|
45 | |
private long contentLength; |
46 | |
|
47 | 0 | public URIListWriter(OutputStream outputStream) { |
48 | 0 | this.resources = new ArrayList<Resource>(); |
49 | 0 | this.printStream = new PrintStream(outputStream); |
50 | 0 | } |
51 | |
|
52 | 0 | public void startDocument(URI documentURI) throws TripleHandlerException {} |
53 | |
|
54 | |
public void openContext(ExtractionContext context) throws TripleHandlerException { |
55 | 0 | this.extractionContext = context; |
56 | 0 | } |
57 | |
|
58 | |
public void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context) |
59 | |
throws TripleHandlerException { |
60 | 0 | if(!this.resources.contains(s)) { |
61 | 0 | this.resources.add(s); |
62 | 0 | this.printStream.println(s.stringValue()); |
63 | |
} |
64 | 0 | if(o instanceof Resource && !this.resources.contains(o)) { |
65 | 0 | this.resources.add((Resource) o); |
66 | 0 | this.printStream.println(o.stringValue()); |
67 | |
} |
68 | 0 | } |
69 | |
|
70 | |
public void receiveNamespace(String prefix, String uri, ExtractionContext context) |
71 | |
throws TripleHandlerException { |
72 | 0 | } |
73 | |
|
74 | |
public void closeContext(ExtractionContext context) throws TripleHandlerException { |
75 | 0 | } |
76 | |
|
77 | |
public void endDocument(URI documentURI) throws TripleHandlerException { |
78 | 0 | } |
79 | |
|
80 | |
public void setContentLength(long contentLength) { |
81 | 0 | this.contentLength = contentLength; |
82 | 0 | } |
83 | |
|
84 | |
public void close() throws TripleHandlerException { |
85 | 0 | this.printStream.close(); |
86 | 0 | } |
87 | |
|
88 | |
@Override |
89 | |
public boolean isAnnotated() { |
90 | 0 | return false; |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public void setAnnotated(boolean f) { |
95 | |
|
96 | 0 | } |
97 | |
} |