| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.any23.extractor.rdfa; |
| 19 | |
|
| 20 | |
import org.apache.any23.extractor.ExtractionContext; |
| 21 | |
import org.apache.any23.extractor.ExtractionException; |
| 22 | |
import org.apache.any23.extractor.ExtractionParameters; |
| 23 | |
import org.apache.any23.extractor.ExtractionResult; |
| 24 | |
import org.apache.any23.extractor.Extractor; |
| 25 | |
import org.apache.any23.extractor.ExtractorDescription; |
| 26 | |
import org.apache.any23.extractor.ExtractorFactory; |
| 27 | |
import org.apache.any23.extractor.SimpleExtractorFactory; |
| 28 | |
import org.w3c.dom.Document; |
| 29 | |
|
| 30 | |
import java.io.IOException; |
| 31 | |
import java.net.URL; |
| 32 | |
import java.util.Arrays; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | 0 | public class RDFa11Extractor implements Extractor.TagSoupDOMExtractor { |
| 41 | |
|
| 42 | |
public final static String NAME = "html-rdfa11"; |
| 43 | |
|
| 44 | 0 | public final static ExtractorFactory<RDFa11Extractor> factory = |
| 45 | |
SimpleExtractorFactory.create( |
| 46 | |
NAME, |
| 47 | |
null, |
| 48 | |
Arrays.asList("text/html;q=0.3", "application/xhtml+xml;q=0.3"), |
| 49 | |
"example-rdfa11.html", |
| 50 | |
RDFa11Extractor.class |
| 51 | |
); |
| 52 | |
|
| 53 | |
private final RDFa11Parser parser; |
| 54 | |
|
| 55 | |
private boolean verifyDataType; |
| 56 | |
|
| 57 | |
private boolean stopAtFirstError; |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | 0 | public RDFa11Extractor(boolean verifyDataType, boolean stopAtFirstError) { |
| 68 | 0 | this.parser = new RDFa11Parser(); |
| 69 | 0 | this.verifyDataType = verifyDataType; |
| 70 | 0 | this.stopAtFirstError = stopAtFirstError; |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public RDFa11Extractor() { |
| 77 | 0 | this(false, false); |
| 78 | 0 | } |
| 79 | |
|
| 80 | |
public boolean isVerifyDataType() { |
| 81 | 0 | return verifyDataType; |
| 82 | |
} |
| 83 | |
|
| 84 | |
public void setVerifyDataType(boolean verifyDataType) { |
| 85 | 0 | this.verifyDataType = verifyDataType; |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
public boolean isStopAtFirstError() { |
| 89 | 0 | return stopAtFirstError; |
| 90 | |
} |
| 91 | |
|
| 92 | |
public void setStopAtFirstError(boolean stopAtFirstError) { |
| 93 | 0 | this.stopAtFirstError = stopAtFirstError; |
| 94 | 0 | } |
| 95 | |
|
| 96 | |
public void run( |
| 97 | |
ExtractionParameters extractionParameters, |
| 98 | |
ExtractionContext extractionContext, |
| 99 | |
Document in, |
| 100 | |
ExtractionResult out |
| 101 | |
) throws IOException, ExtractionException { |
| 102 | |
try { |
| 103 | 0 | parser.processDocument( new URL(extractionContext.getDocumentURI().toString() ), in, out ); |
| 104 | 0 | } catch (RDFa11ParserException rpe) { |
| 105 | 0 | throw new ExtractionException("Error while performing extraction.", rpe); |
| 106 | 0 | } |
| 107 | 0 | } |
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
public ExtractorDescription getDescription() { |
| 113 | 0 | return factory; |
| 114 | |
} |
| 115 | |
|
| 116 | |
} |