You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.4 KiB
70 lines
2.4 KiB
15 years ago
|
// abstractWikiParser.java
|
||
|
// ---------
|
||
|
// part of YaCy
|
||
|
// (C) by Michael Peter Christen; mc@yacy.net
|
||
|
// first published on http://www.anomic.de
|
||
|
// Frankfurt, Germany, 2007
|
||
|
//
|
||
|
// $LastChangedDate$
|
||
|
// $LastChangedRevision$
|
||
|
// $LastChangedBy$
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or modify
|
||
|
// it under the terms of the GNU General Public License as published by
|
||
|
// the Free Software Foundation; either version 2 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
|
||
12 years ago
|
package net.yacy.data.wiki;
|
||
18 years ago
|
|
||
|
import java.io.BufferedReader;
|
||
|
import java.io.ByteArrayInputStream;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStreamReader;
|
||
|
import java.io.StringReader;
|
||
|
import java.io.UnsupportedEncodingException;
|
||
|
|
||
14 years ago
|
abstract class AbstractWikiParser implements WikiParser {
|
||
13 years ago
|
|
||
14 years ago
|
protected abstract String transform(String hostport, BufferedReader reader, int length) throws IOException;
|
||
18 years ago
|
|
||
13 years ago
|
@Override
|
||
14 years ago
|
public String transform(String hostport, final String content) {
|
||
18 years ago
|
try {
|
||
18 years ago
|
return transform(
|
||
14 years ago
|
hostport,
|
||
18 years ago
|
new BufferedReader(new StringReader(content)),
|
||
16 years ago
|
content.length());
|
||
17 years ago
|
} catch (final IOException e) {
|
||
18 years ago
|
return "internal error: " + e.getMessage();
|
||
|
}
|
||
|
}
|
||
13 years ago
|
|
||
|
@Override
|
||
14 years ago
|
public String transform(String hostport, final byte[] content) throws UnsupportedEncodingException {
|
||
|
return transform(hostport, content, "UTF-8");
|
||
18 years ago
|
}
|
||
13 years ago
|
|
||
|
@Override
|
||
|
public String transform(String hostport, final byte[] content, final String encoding) {
|
||
17 years ago
|
final ByteArrayInputStream bais = new ByteArrayInputStream(content);
|
||
18 years ago
|
try {
|
||
18 years ago
|
return transform(
|
||
14 years ago
|
hostport,
|
||
18 years ago
|
new BufferedReader(new InputStreamReader(bais, encoding)),
|
||
16 years ago
|
content.length);
|
||
17 years ago
|
} catch (final IOException e) {
|
||
18 years ago
|
return "internal error: " + e.getMessage();
|
||
|
}
|
||
|
}
|
||
13 years ago
|
|
||
18 years ago
|
}
|