01: package de.anomic.data.wiki;
02:
03: import java.io.BufferedReader;
04: import java.io.ByteArrayInputStream;
05: import java.io.IOException;
06: import java.io.InputStreamReader;
07: import java.io.StringReader;
08: import java.io.UnsupportedEncodingException;
09:
10: import de.anomic.plasma.plasmaSwitchboard;
11: import de.anomic.yacy.yacyCore;
12:
13: public abstract class abstractWikiParser implements wikiParser {
14:
15: private plasmaSwitchboard sb;
16:
17: public abstractWikiParser(plasmaSwitchboard sb) {
18: this .sb = sb;
19: }
20:
21: protected abstract String transform(BufferedReader reader,
22: int length, String publicAddress, plasmaSwitchboard sb)
23: throws IOException;
24:
25: public String transform(String content) {
26: return transform(content, this .sb);
27: }
28:
29: public String transform(String content, plasmaSwitchboard sb) {
30: try {
31: return transform(new BufferedReader(new StringReader(
32: content)), content.length(), yacyCore.seedDB
33: .mySeed().getPublicAddress(), sb);
34: } catch (IOException e) {
35: return "internal error: " + e.getMessage();
36: }
37: }
38:
39: public String transform(String content, String publicAddress) {
40: try {
41: return transform(new BufferedReader(new StringReader(
42: content)), content.length(), publicAddress, null);
43: } catch (IOException e) {
44: return "internal error: " + e.getMessage();
45: }
46: }
47:
48: public String transform(byte[] content)
49: throws UnsupportedEncodingException {
50: return transform(content, "UTF-8", this .sb);
51: }
52:
53: public String transform(byte[] content, String encoding)
54: throws UnsupportedEncodingException {
55: return transform(content, encoding, this .sb);
56: }
57:
58: public String transform(byte[] content, String encoding,
59: String publicAddress) throws UnsupportedEncodingException {
60: ByteArrayInputStream bais = new ByteArrayInputStream(content);
61: try {
62: return transform(new BufferedReader(new InputStreamReader(
63: bais, encoding)), content.length, publicAddress,
64: null);
65: } catch (IOException e) {
66: return "internal error: " + e.getMessage();
67: }
68: }
69:
70: public String transform(byte[] content, String encoding,
71: plasmaSwitchboard switchboard)
72: throws UnsupportedEncodingException {
73: ByteArrayInputStream bais = new ByteArrayInputStream(content);
74: try {
75: return transform(new BufferedReader(new InputStreamReader(
76: bais, encoding)), content.length, yacyCore.seedDB
77: .mySeed().getPublicAddress(), switchboard);
78: } catch (IOException e) {
79: return "internal error: " + e.getMessage();
80: }
81: }
82: }
|