1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.any23.filter; |
19 | |
|
20 | |
import org.apache.any23.extractor.ExtractionContext; |
21 | |
import org.apache.any23.extractor.rdfa.RDFaExtractor; |
22 | |
import org.apache.any23.vocab.XHTML; |
23 | |
import org.apache.any23.writer.TripleHandler; |
24 | |
import org.apache.any23.writer.TripleHandlerException; |
25 | |
import org.openrdf.model.Resource; |
26 | |
import org.openrdf.model.URI; |
27 | |
import org.openrdf.model.Value; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class IgnoreAccidentalRDFa implements TripleHandler { |
37 | |
|
38 | 0 | private static final XHTML vXHTML = XHTML.getInstance(); |
39 | |
|
40 | |
private final ExtractionContextBlocker blocker; |
41 | |
|
42 | |
private final boolean alwaysSuppressCSSTriples; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | 0 | public IgnoreAccidentalRDFa(TripleHandler wrapped, boolean alwaysSuppressCSSTriples) { |
54 | 0 | this.blocker = new ExtractionContextBlocker(wrapped); |
55 | 0 | this.alwaysSuppressCSSTriples = alwaysSuppressCSSTriples; |
56 | 0 | } |
57 | |
public IgnoreAccidentalRDFa(TripleHandler wrapped) { |
58 | 0 | this(wrapped, false); |
59 | 0 | } |
60 | |
|
61 | |
public void startDocument(URI documentURI) throws TripleHandlerException { |
62 | 0 | blocker.startDocument(documentURI); |
63 | 0 | } |
64 | |
|
65 | |
public void openContext(ExtractionContext context) throws TripleHandlerException { |
66 | 0 | blocker.openContext(context); |
67 | 0 | if (isRDFaContext(context)) { |
68 | 0 | blocker.blockContext(context); |
69 | |
} |
70 | 0 | } |
71 | |
|
72 | |
public void receiveTriple(Resource s, URI p, Value o, URI g, ExtractionContext context) |
73 | |
throws TripleHandlerException { |
74 | |
|
75 | 0 | if(alwaysSuppressCSSTriples && p.stringValue().equals(vXHTML.stylesheet.stringValue())) { |
76 | 0 | return; |
77 | |
} |
78 | 0 | if (isRDFaContext(context)) { |
79 | 0 | blocker.unblockContext(context); |
80 | |
} |
81 | 0 | blocker.receiveTriple(s, p, o, g, context); |
82 | 0 | } |
83 | |
|
84 | |
public void receiveNamespace(String prefix, String uri, ExtractionContext context) |
85 | |
throws TripleHandlerException { |
86 | 0 | blocker.receiveNamespace(prefix, uri, context); |
87 | 0 | } |
88 | |
|
89 | |
public void closeContext(ExtractionContext context) { |
90 | 0 | blocker.closeContext(context); |
91 | 0 | } |
92 | |
|
93 | |
public void close() throws TripleHandlerException { |
94 | 0 | blocker.close(); |
95 | 0 | } |
96 | |
|
97 | |
private boolean isRDFaContext(ExtractionContext context) { |
98 | 0 | return context.getExtractorName().equals(RDFaExtractor.NAME); |
99 | |
} |
100 | |
|
101 | |
public void endDocument(URI documentURI) throws TripleHandlerException { |
102 | 0 | blocker.endDocument(documentURI); |
103 | 0 | } |
104 | |
|
105 | |
public void setContentLength(long contentLength) { |
106 | |
|
107 | 0 | } |
108 | |
} |