|
|
@ -1,4 +1,4 @@
|
|
|
|
// wikiParser.java
|
|
|
|
// knwikiParser.java
|
|
|
|
// ---------
|
|
|
|
// ---------
|
|
|
|
// part of YaCy
|
|
|
|
// part of YaCy
|
|
|
|
// (C) by Michael Peter Christen; mc@yacy.net
|
|
|
|
// (C) by Michael Peter Christen; mc@yacy.net
|
|
|
@ -8,9 +8,9 @@
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// This file is contributed by Franz Brausze
|
|
|
|
// This file is contributed by Franz Brausze
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// $LastChangedDate: $
|
|
|
|
// $LastChangedDate$
|
|
|
|
// $LastChangedRevision: $
|
|
|
|
// $LastChangedRevision$
|
|
|
|
// $LastChangedBy: $
|
|
|
|
// $LastChangedBy$
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// 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
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
@ -145,46 +145,41 @@ public class knwikiParser implements wikiParser {
|
|
|
|
private String parseUnescaped(String text) {
|
|
|
|
private String parseUnescaped(String text) {
|
|
|
|
Token st;
|
|
|
|
Token st;
|
|
|
|
Matcher m;
|
|
|
|
Matcher m;
|
|
|
|
StringBuffer sb;
|
|
|
|
StringBuffer stringBuffer;
|
|
|
|
for (int i=0; i<tokens.length; i++) {
|
|
|
|
for (int i=0; i<tokens.length; i++) {
|
|
|
|
st = tokens[i];
|
|
|
|
st = tokens[i];
|
|
|
|
for (int j=0; j<st.getRegex().length; j++) {
|
|
|
|
for (int j=0; j<st.getRegex().length; j++) {
|
|
|
|
m = st.getRegex()[j].matcher(text);
|
|
|
|
m = st.getRegex()[j].matcher(text);
|
|
|
|
sb = new StringBuffer();
|
|
|
|
stringBuffer = new StringBuffer();
|
|
|
|
while (m.find()) try {
|
|
|
|
while (m.find()) try {
|
|
|
|
//System.out.print("found " + st.getClass().getSimpleName() + ": " +
|
|
|
|
|
|
|
|
// m.group().replaceAll("\n", "\\\\n").replaceAll("\t", " ") + ", ");
|
|
|
|
|
|
|
|
if (!st.setText(m.group(), j)) {
|
|
|
|
if (!st.setText(m.group(), j)) {
|
|
|
|
// System.out.println("not usable");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
//} else {
|
|
|
|
|
|
|
|
// System.out.println("usable");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m.appendReplacement(sb, (st.getMarkup() == null) ? m.group() : st.getMarkup());
|
|
|
|
m.appendReplacement(stringBuffer, (st.getMarkup() == null) ? m.group() : st.getMarkup());
|
|
|
|
} catch (final wikiParserException e) {
|
|
|
|
} catch (final wikiParserException e) {
|
|
|
|
m.appendReplacement(sb, st.getText());
|
|
|
|
m.appendReplacement(stringBuffer, st.getText());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
text = new String(m.appendTail(sb));
|
|
|
|
text = new String(m.appendTail(stringBuffer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return text.replaceAll("----", "<hr />");
|
|
|
|
return text.replaceAll("----", "<hr />");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String replaceBRs(final String text) {
|
|
|
|
private String replaceBRs(final String text) {
|
|
|
|
final StringBuilder sb = new StringBuilder(text.length());
|
|
|
|
final StringBuilder stringBuffer = new StringBuilder(text.length());
|
|
|
|
final String[] tt = text.split("\n");
|
|
|
|
final String[] tt = text.split("\n");
|
|
|
|
boolean replace;
|
|
|
|
boolean replace;
|
|
|
|
for (int i=0, j; i<tt.length; i++) {
|
|
|
|
for (int i=0, j; i<tt.length; i++) {
|
|
|
|
replace = true;
|
|
|
|
replace = true;
|
|
|
|
for (j=0; j<BEs.length; j++)
|
|
|
|
for (j=0; j<BEs.length; j++)
|
|
|
|
if (tt[i].endsWith(BEs[j] + ">")) { replace = false; break; }
|
|
|
|
if (tt[i].endsWith(BEs[j] + ">")) { replace = false; break; }
|
|
|
|
sb.append(tt[i]);
|
|
|
|
stringBuffer.append(tt[i]);
|
|
|
|
if (i < tt.length - 1) {
|
|
|
|
if (i < tt.length - 1) {
|
|
|
|
if (replace) sb.append("<br />");
|
|
|
|
if (replace) stringBuffer.append("<br />");
|
|
|
|
sb.append("\n");
|
|
|
|
stringBuffer.append("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new String(sb);
|
|
|
|
return new String(stringBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class Text {
|
|
|
|
private static class Text {
|
|
|
@ -200,25 +195,35 @@ public class knwikiParser implements wikiParser {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String setText(final String text) {
|
|
|
|
public String setText(final String text) {
|
|
|
|
if (this.nl)
|
|
|
|
if (this.nl) {
|
|
|
|
this.text = text.substring(escapeNewLine.length());
|
|
|
|
this.text = text.substring(escapeNewLine.length());
|
|
|
|
else
|
|
|
|
} else {
|
|
|
|
this.text = text;
|
|
|
|
this.text = text;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.text;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getTextPlain() {
|
|
|
|
return this.text;
|
|
|
|
return this.text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getTextPlain() { return this.text; }
|
|
|
|
|
|
|
|
public String getText() {
|
|
|
|
public String getText() {
|
|
|
|
if (this.nl)
|
|
|
|
if (this.nl) {
|
|
|
|
return escapeNewLine + this.text;
|
|
|
|
return escapeNewLine + this.text;
|
|
|
|
|
|
|
|
}
|
|
|
|
return this.text;
|
|
|
|
return this.text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String toString() { return this.text; }
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
|
|
|
|
return this.text;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Text[] split2Texts(final String text, final String escapeBegin, final String escapeEnd) {
|
|
|
|
static Text[] split2Texts(final String text, final String escapeBegin, final String escapeEnd) {
|
|
|
|
|
|
|
|
|
|
|
|
if (text == null) return null;
|
|
|
|
if (text == null) return null;
|
|
|
|
if (text.length() < 2) return new Text[] { new Text(text, false, true) };
|
|
|
|
|
|
|
|
|
|
|
|
if (text.length() < 2) return new Text[] {new Text(text, false, true) };
|
|
|
|
|
|
|
|
|
|
|
|
final int startLen = escapeBegin.length();
|
|
|
|
final int startLen = escapeBegin.length();
|
|
|
|
final int endLen = escapeEnd.length();
|
|
|
|
final int endLen = escapeEnd.length();
|
|
|
@ -245,8 +250,9 @@ public class knwikiParser implements wikiParser {
|
|
|
|
|
|
|
|
|
|
|
|
static String mergeTexts(final Text[] texts) {
|
|
|
|
static String mergeTexts(final Text[] texts) {
|
|
|
|
final StringBuilder sb = new StringBuilder(2000);
|
|
|
|
final StringBuilder sb = new StringBuilder(2000);
|
|
|
|
for (int n=0; n < texts.length; n++)
|
|
|
|
for (int n=0; n < texts.length; n++) {
|
|
|
|
sb.append(texts[n].getTextPlain());
|
|
|
|
sb.append(texts[n].getTextPlain());
|
|
|
|
|
|
|
|
}
|
|
|
|
return new String(sb);
|
|
|
|
return new String(sb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|