*) added <s>...</s> tag to WikiCode -> works just as the HTML equivalent

*) code changes (PMD) without functional changes

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7193 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
low012 15 years ago
parent a83186ac7d
commit afa708d552

@ -45,9 +45,10 @@ import net.yacy.kelondro.order.NaturalOrder;
public class wikiBoard { public class wikiBoard {
public static final int keyLength = 64; public static final int keyLength = 64;
private static final String dateFormat = "yyyyMMddHHmmss"; private static final String DATE_FORMAT = "yyyyMMddHHmmss";
private static final String ANONYMOUS = "anonymous";
protected static final SimpleDateFormat SimpleFormatter = new SimpleDateFormat(dateFormat, Locale.US); protected static final SimpleDateFormat SimpleFormatter = new SimpleDateFormat(DATE_FORMAT, Locale.US);
static { static {
SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT")); SimpleFormatter.setTimeZone(TimeZone.getTimeZone("GMT"));
@ -66,7 +67,7 @@ public class wikiBoard {
new File(bkppath.getParent()).mkdirs(); new File(bkppath.getParent()).mkdirs();
if (bkpbase == null) { if (bkpbase == null) {
//bkpbase = new MapView(BLOBTree.toHeap(bkppath, true, true, keyLength + dateFormat.length(), recordSize, '_', NaturalOrder.naturalOrder, bkppathNew), 500, '_'); //bkpbase = new MapView(BLOBTree.toHeap(bkppath, true, true, keyLength + dateFormat.length(), recordSize, '_', NaturalOrder.naturalOrder, bkppathNew), 500, '_');
bkpbase = new MapHeap(bkppath, keyLength + dateFormat.length(), NaturalOrder.naturalOrder, 1024 * 64, 500, '_'); bkpbase = new MapHeap(bkppath, keyLength + DATE_FORMAT.length(), NaturalOrder.naturalOrder, 1024 * 64, 500, '_');
} }
} }
@ -94,17 +95,11 @@ public class wikiBoard {
} }
private static String normalize(final String key) { private static String normalize(final String key) {
if (key == null) return "null"; return (key != null) ? key.trim().toLowerCase() : "null";
return key.trim().toLowerCase();
} }
public static String webalize(String key) { public static String webalize(final String key) {
if (key == null) return "null"; return (key != null) ? normalize(key).replaceAll(" ", "%20") : "null";
key = key.trim().toLowerCase();
int p;
while ((p = key.indexOf(" ")) >= 0)
key = key.substring(0, p) + "%20" + key.substring(p +1);
return key;
} }
public static String guessAuthor(final String ip) { public static String guessAuthor(final String ip) {
@ -122,6 +117,7 @@ public class wikiBoard {
} }
public class entry { public class entry {
private static final String ANONYMOUS = "anonymous";
String key; String key;
Map<String, String> record; Map<String, String> record;
@ -129,18 +125,27 @@ public class wikiBoard {
public entry(final String subject, String author, String ip, String reason, final byte[] page) throws IOException { public entry(final String subject, String author, String ip, String reason, final byte[] page) throws IOException {
record = new HashMap<String, String>(); record = new HashMap<String, String>();
key = subject; key = subject;
if (key.length() > keyLength) key = key.substring(0, keyLength); if (key.length() > keyLength) {
key = key.substring(0, keyLength);
}
record.put("date", dateString()); record.put("date", dateString());
if ((author == null) || (author.length() == 0)) author = "anonymous"; if ((author == null) || (author.length() == 0)) {
author = ANONYMOUS;
}
record.put("author", Base64Order.enhancedCoder.encode(author.getBytes("UTF-8"))); record.put("author", Base64Order.enhancedCoder.encode(author.getBytes("UTF-8")));
if ((ip == null) || (ip.length() == 0)) ip = ""; if ((ip == null) || (ip.length() == 0)) {
ip = "";
}
record.put("ip", ip); record.put("ip", ip);
if ((reason == null) || (reason.length() == 0)) reason = ""; if ((reason == null) || (reason.length() == 0)) {
reason = "";
}
record.put("reason", Base64Order.enhancedCoder.encode(reason.getBytes("UTF-8"))); record.put("reason", Base64Order.enhancedCoder.encode(reason.getBytes("UTF-8")));
if (page == null) if (page == null) {
record.put("page", ""); record.put("page", "");
else } else {
record.put("page", Base64Order.enhancedCoder.encode(page)); record.put("page", Base64Order.enhancedCoder.encode(page));
}
authors.put(ip, author); authors.put(ip, author);
//System.out.println("DEBUG: setting author " + author + " for ip = " + ip + ", authors = " + authors.toString()); //System.out.println("DEBUG: setting author " + author + " for ip = " + ip + ", authors = " + authors.toString());
} }
@ -171,26 +176,26 @@ public class wikiBoard {
public String author() { public String author() {
final String a = record.get("author"); final String a = record.get("author");
if (a == null) return "anonymous"; final byte[] b;
final byte[] b = Base64Order.enhancedCoder.decode(a); return (a != null && (b = Base64Order.enhancedCoder.decode(a)) != null) ? new String(b) : ANONYMOUS;
if (b == null) return "anonymous";
return new String(b);
} }
public String reason() { public String reason() {
final String r = record.get("reason"); final String r = record.get("reason");
if (r == null) return ""; if (r == null) {
return "";
}
final byte[] b = Base64Order.enhancedCoder.decode(r); final byte[] b = Base64Order.enhancedCoder.decode(r);
if (b == null) return "unknown"; if (b == null) {
return "unknown";
}
return new String(b); return new String(b);
} }
public byte[] page() { public byte[] page() {
final String m = record.get("page"); final String m = record.get("page");
if (m == null) return new byte[0]; final byte[] b;
final byte[] b = Base64Order.enhancedCoder.decode(m); return (m != null && (b = Base64Order.enhancedCoder.decode(m)) != null) ? b : new byte[0];
if (b == null) return "".getBytes();
return b;
} }
void setAncestorDate(final Date date) { void setAncestorDate(final Date date) {
@ -223,8 +228,7 @@ public class wikiBoard {
public entry getAncestor() { public entry getAncestor() {
final Date ancDate = getAncestorDate(); final Date ancDate = getAncestorDate();
if (ancDate == null) return null; return (ancDate == null) ? null : read(key + dateString(ancDate), bkpbase);
return read(key + dateString(ancDate), bkpbase);
} }
void setChild(final String subject) { void setChild(final String subject) {
@ -233,28 +237,24 @@ public class wikiBoard {
private String getChildName() { private String getChildName() {
final String c = record.get("child"); final String c = record.get("child");
if (c == null) return null; final byte[] subject;
final byte[] subject = Base64Order.enhancedCoder.decode(c); return (c != null && (subject = Base64Order.enhancedCoder.decode(c)) != null) ? new String(subject) : null;
if (subject == null) return null;
return new String(subject);
} }
public boolean hasChild() { public boolean hasChild() {
final String c = record.get("child"); final String c = record.get("child");
if (c == null) return false; return (c != null && Base64Order.enhancedCoder.decode(c) != null) ? true : false;
final byte[] subject = Base64Order.enhancedCoder.decode(c);
return (subject != null);
} }
public entry getChild() { public entry getChild() {
final String childName = getChildName(); final String childName = getChildName();
if (childName == null) return null; return (childName == null) ? null : read(childName, datbase);
return read(childName, datbase);
} }
} }
public String write(final entry page) { public String write(final entry page) {
// writes a new page and returns key // writes a new page and returns key
String ret = null;
try { try {
// first load the old page // first load the old page
final entry oldEntry = read(page.key); final entry oldEntry = read(page.key);
@ -269,11 +269,11 @@ public class wikiBoard {
bkpbase.insert((page.key + dateString(oldDate)).getBytes(), oldEntry.record); bkpbase.insert((page.key + dateString(oldDate)).getBytes(), oldEntry.record);
// write the new page // write the new page
datbase.insert(page.key.getBytes(), page.record); datbase.insert(page.key.getBytes(), page.record);
return page.key; ret = page.key;
} catch (final Exception e) { } catch (final Exception e) {
Log.logException(e); Log.logException(e);
return null;
} }
return ret;
} }
public entry read(final String key) { public entry read(final String key) {
@ -281,19 +281,20 @@ public class wikiBoard {
} }
entry read(String key, final MapHeap base) { entry read(String key, final MapHeap base) {
entry ret = null;
try { try {
key = normalize(key); key = normalize(key);
if (key.length() > keyLength) key = key.substring(0, keyLength); if (key.length() > keyLength) {
key = key.substring(0, keyLength);
}
final Map<String, String> record = base.get(key.getBytes()); final Map<String, String> record = base.get(key.getBytes());
if (record == null) return newEntry(key, "anonymous", "127.0.0.1", "New Page", "".getBytes()); ret = (record == null) ? newEntry(key, ANONYMOUS, "127.0.0.1", "New Page", "".getBytes()) : new entry(key, record);
return new entry(key, record);
} catch (final IOException e) { } catch (final IOException e) {
Log.logException(e); Log.logException(e);
return null;
} catch (RowSpaceExceededException e) { } catch (RowSpaceExceededException e) {
Log.logException(e); Log.logException(e);
return null;
} }
return ret;
} }
public entry readBkp(final String key) { public entry readBkp(final String key) {

@ -41,44 +41,49 @@ import de.anomic.server.serverCore;
* @author Alexander Schier [AS], Franz Brausze [FB], Marc Nause [MN] * @author Alexander Schier [AS], Franz Brausze [FB], Marc Nause [MN]
*/ */
public class wikiCode extends abstractWikiParser implements wikiParser { public class wikiCode extends abstractWikiParser implements wikiParser {
public static final String WIKI_EMPHASIZE_1 = "\'\'";
public static final String WIKI_EMPHASIZE_2 = "\'\'\'";
private static final String ASTERISK = "*"; private static final String ASTERISK = "*";
private static final String CLOSE_DEFINITION_DESCRIPTION = "</dd>"; private static final String EMPTY = "";
private static final String CLOSE_DEFINITION_ITEM = "</dt>"; private static final String PIPE_ESCAPED = "&#124;";
private static final String CLOSE_DEFINITION_LIST = "</dl>"; private static final String REGEX_NOT_CHAR_NUM_OR_UNDERSCORE = "[^a-zA-Z0-9_]";
private static final char ONE = '1';
private static final char THREE = '3'; private static final String HTML_OPEN_DEFINITION_DESCRIPTION = "<dd>";
private static final char TWO = '2'; private static final String HTML_CLOSE_DEFINITION_DESCRIPTION = "</dd>";
private static final String HTML_OPEN_DEFINITION_ITEM = "<dt>";
private static final String HTML_CLOSE_DEFINITION_ITEM = "</dt>";
private static final String HTML_OPEN_DEFINITION_LIST = "<dl>";
private static final String HTML_CLOSE_DEFINITION_LIST = "</dl>";
private static final String HTML_OPEN_UNORDERED_LIST = "<ul>";
private static final String HTML_CLOSE_UNORDERED_LIST = "</ul>";
private static final String HTML_CLOSE_BLOCKQUOTE = "</blockquote>";
private static final String HTML_CLOSE_LIST_ELEMENT = "</li>";
private static final String HTML_CLOSE_ORDERED_LIST = "</ol>";
private static final String HTML_OPEN_BLOCKQUOTE = "<blockquote>";
private static final String HTML_OPEN_LIST_ELEMENT = "<li>";
private static final String HTML_OPEN_ORDERED_LIST = "<ol>";
private static final String WIKI_CLOSE_LINK = "]]";
private static final String WIKI_OPEN_LINK = "[[";
private static final String WIKI_CLOSE_EXTERNAL_LINK = "]"; private static final String WIKI_CLOSE_EXTERNAL_LINK = "]";
private static final String WIKI_CLOSE_PRE_ESCAPED = "&lt;/pre&gt;"; private static final String WIKI_CLOSE_PRE_ESCAPED = "&lt;/pre&gt;";
private static final String CLOSE_UNORDERED_LIST = "</ul>"; private static final String WIKI_OPEN_STRIKE = "&lt;s&gt;";
private static final String WIKI_CLOSE_STRIKE = "&lt;/s&gt;";
private static final String WIKI_EMPHASIZE_1 = "\'\'";
private static final String WIKI_EMPHASIZE_2 = "\'\'\'";
private static final String WIKI_EMPHASIZE_3 = "\'\'\'\'\'"; private static final String WIKI_EMPHASIZE_3 = "\'\'\'\'\'";
private static final char WIKI_FORMATTED = ' ';
private static final String WIKI_HEADLINE_TAG_1 = "=="; private static final String WIKI_HEADLINE_TAG_1 = "==";
private static final String WIKI_HEADLINE_TAG_2 = "==="; private static final String WIKI_HEADLINE_TAG_2 = "===";
private static final String WIKI_HEADLINE_TAG_3 = "===="; private static final String WIKI_HEADLINE_TAG_3 = "====";
private static final String OPEN_DEFINITION_DESCRIPTION = "<dd>";
private static final String OPEN_DEFINITION_ITEM = "<dt>";
private static final String WIKI_HR_LINE = "----"; private static final String WIKI_HR_LINE = "----";
private static final String WIKI_IMAGE = "Image:"; private static final String WIKI_IMAGE = "Image:";
private static final char WIKI_INDENTION = ':';
private static final String WIKI_OPEN_EXTERNAL_LINK = "["; private static final String WIKI_OPEN_EXTERNAL_LINK = "[";
private static final String WIKI_OPEN_PRE_ESCAPED = "&lt;pre&gt;"; private static final String WIKI_OPEN_PRE_ESCAPED = "&lt;pre&gt;";
private static final String OPEN_UNORDERED_LIST = "<ul>";
private static final String EMPTY = ""; private static final char ONE = '1';
private static final String CLOSE_BLOCKQUOTE = "</blockquote>"; private static final char THREE = '3';
private static final String CLOSE_LIST_ELEMENT = "</li>"; private static final char TWO = '2';
private static final String CLOSE_ORDERED_LIST = "</ol>"; private static final char WIKI_FORMATTED = ' ';
private static final String REGEX_NOT_CHAR_NUM_OR_UNDERSCORE = "[^a-zA-Z0-9_]"; private static final char WIKI_INDENTION = ':';
private static final String OPEN_BLOCKQUOTE = "<blockquote>";
private static final String OPEN_DEFINITION_LIST = "<dl>";
private static final String OPEN_LIST_ELEMENT = "<li>";
private static final String OPEN_ORDERED_LIST = "<ol>";
private static final String PIPE_ESCAPED = "&#124;";
private static final String WIKI_CLOSE_LINK = "]]";
private static final String WIKI_OPEN_LINK = "[[";
private static final int LEN_WIKI_CLOSE_PRE_ESCAPED = WIKI_CLOSE_PRE_ESCAPED.length(); private static final int LEN_WIKI_CLOSE_PRE_ESCAPED = WIKI_CLOSE_PRE_ESCAPED.length();
private static final int LEN_WIKI_OPEN_PRE_ESCAPED = WIKI_OPEN_PRE_ESCAPED.length(); private static final int LEN_WIKI_OPEN_PRE_ESCAPED = WIKI_OPEN_PRE_ESCAPED.length();
private static final int LEN_WIKI_OPEN_LINK = WIKI_OPEN_LINK.length(); private static final int LEN_WIKI_OPEN_LINK = WIKI_OPEN_LINK.length();
@ -292,21 +297,21 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
//# sorted Lists contributed by [AS] //# sorted Lists contributed by [AS]
//## Sublist //## Sublist
if (line.startsWith(numberedListLevel + "#")) { //more # if (line.startsWith(numberedListLevel + "#")) { //more #
line = OPEN_ORDERED_LIST + serverCore.CRLF_STRING line = HTML_OPEN_ORDERED_LIST + serverCore.CRLF_STRING
+ OPEN_LIST_ELEMENT + HTML_OPEN_LIST_ELEMENT
+ line.substring(numberedListLevel.length() + 1, line.length()) + line.substring(numberedListLevel.length() + 1, line.length())
+ CLOSE_LIST_ELEMENT; + HTML_CLOSE_LIST_ELEMENT;
numberedListLevel += "#"; numberedListLevel += "#";
} else if (numberedListLevel.length() > 0 && line.startsWith(numberedListLevel)) { //equal number of # } else if (numberedListLevel.length() > 0 && line.startsWith(numberedListLevel)) { //equal number of #
line = OPEN_LIST_ELEMENT line = HTML_OPEN_LIST_ELEMENT
+ line.substring(numberedListLevel.length(), line.length()) + line.substring(numberedListLevel.length(), line.length())
+ CLOSE_LIST_ELEMENT; + HTML_CLOSE_LIST_ELEMENT;
} else if (numberedListLevel.length() > 0) { //less # } else if (numberedListLevel.length() > 0) { //less #
int i = numberedListLevel.length(); int i = numberedListLevel.length();
String tmp = EMPTY; String tmp = EMPTY;
while (!line.startsWith(numberedListLevel.substring(0, i))) { while (!line.startsWith(numberedListLevel.substring(0, i))) {
tmp += CLOSE_ORDERED_LIST; tmp += HTML_CLOSE_ORDERED_LIST;
i--; i--;
} }
numberedListLevel = numberedListLevel.substring(0, i); numberedListLevel = numberedListLevel.substring(0, i);
@ -315,9 +320,9 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
if (numberedListLevel.length() > 0) { if (numberedListLevel.length() > 0) {
line = tmp line = tmp
+ OPEN_LIST_ELEMENT + HTML_OPEN_LIST_ELEMENT
+ line.substring(positionOfOpeningTag, positionOfClosingTag) + line.substring(positionOfOpeningTag, positionOfClosingTag)
+ CLOSE_LIST_ELEMENT; + HTML_CLOSE_LIST_ELEMENT;
} else { } else {
line = tmp + line.substring(positionOfOpeningTag, positionOfClosingTag); line = tmp + line.substring(positionOfOpeningTag, positionOfClosingTag);
} }
@ -337,21 +342,21 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
if (!noList) { //lists only get processed if not forbidden (see code for [= and <pre>). [MN] if (!noList) { //lists only get processed if not forbidden (see code for [= and <pre>). [MN]
//contributed by [AS] //contributed by [AS]
if (line.startsWith(unorderedListLevel + ASTERISK)) { //more stars if (line.startsWith(unorderedListLevel + ASTERISK)) { //more stars
line = OPEN_UNORDERED_LIST + serverCore.CRLF_STRING line = HTML_OPEN_UNORDERED_LIST + serverCore.CRLF_STRING
+ OPEN_LIST_ELEMENT + HTML_OPEN_LIST_ELEMENT
+ line.substring(unorderedListLevel.length() + 1, line.length()) + line.substring(unorderedListLevel.length() + 1, line.length())
+ CLOSE_LIST_ELEMENT; + HTML_CLOSE_LIST_ELEMENT;
unorderedListLevel += ASTERISK; unorderedListLevel += ASTERISK;
} else if (unorderedListLevel.length() > 0 && line.startsWith(unorderedListLevel)) { //equal number of stars } else if (unorderedListLevel.length() > 0 && line.startsWith(unorderedListLevel)) { //equal number of stars
line = OPEN_LIST_ELEMENT line = HTML_OPEN_LIST_ELEMENT
+ line.substring(unorderedListLevel.length(), line.length()) + line.substring(unorderedListLevel.length(), line.length())
+ CLOSE_LIST_ELEMENT; + HTML_CLOSE_LIST_ELEMENT;
} else if (unorderedListLevel.length() > 0) { //less stars } else if (unorderedListLevel.length() > 0) { //less stars
int i = unorderedListLevel.length(); int i = unorderedListLevel.length();
String tmp = EMPTY; String tmp = EMPTY;
while (unorderedListLevel.length() >= i && !line.startsWith(unorderedListLevel.substring(0, i))) { while (unorderedListLevel.length() >= i && !line.startsWith(unorderedListLevel.substring(0, i))) {
tmp += CLOSE_UNORDERED_LIST; tmp += HTML_CLOSE_UNORDERED_LIST;
i--; i--;
} }
int positionOfOpeningTag = unorderedListLevel.length(); int positionOfOpeningTag = unorderedListLevel.length();
@ -363,9 +368,9 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
if (unorderedListLevel.length() > 0) { if (unorderedListLevel.length() > 0) {
line = tmp line = tmp
+ OPEN_LIST_ELEMENT + HTML_OPEN_LIST_ELEMENT
+ line.substring(positionOfOpeningTag, positionOfClosingTag) + line.substring(positionOfOpeningTag, positionOfClosingTag)
+ CLOSE_LIST_ELEMENT; + HTML_CLOSE_LIST_ELEMENT;
} else { } else {
line = tmp + line.substring(positionOfOpeningTag, positionOfClosingTag); line = tmp + line.substring(positionOfOpeningTag, positionOfClosingTag);
} }
@ -393,11 +398,11 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) { if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) {
definitionItem = copyOfLine.substring(0, positionOfOpeningTag); definitionItem = copyOfLine.substring(0, positionOfOpeningTag);
definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1); definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1);
line = OPEN_DEFINITION_LIST + line = HTML_OPEN_DEFINITION_LIST +
OPEN_DEFINITION_ITEM + HTML_OPEN_DEFINITION_ITEM +
definitionItem + definitionItem +
CLOSE_DEFINITION_ITEM + HTML_CLOSE_DEFINITION_ITEM +
OPEN_DEFINITION_DESCRIPTION + HTML_OPEN_DEFINITION_DESCRIPTION +
definitionDescription; definitionDescription;
processingDefList = true; processingDefList = true;
} }
@ -411,10 +416,10 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) { if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) {
definitionItem = copyOfLine.substring(0, positionOfOpeningTag); definitionItem = copyOfLine.substring(0, positionOfOpeningTag);
definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1); definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1);
line = OPEN_DEFINITION_ITEM + line = HTML_OPEN_DEFINITION_ITEM +
definitionItem + definitionItem +
CLOSE_DEFINITION_ITEM + HTML_CLOSE_DEFINITION_ITEM +
OPEN_DEFINITION_DESCRIPTION + HTML_OPEN_DEFINITION_DESCRIPTION +
definitionDescription; definitionDescription;
processingDefList = true; processingDefList = true;
} }
@ -424,7 +429,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
int i = defListLevel.length(); int i = defListLevel.length();
String tmp = EMPTY; String tmp = EMPTY;
while (!line.startsWith(defListLevel.substring(0, i))) { while (!line.startsWith(defListLevel.substring(0, i))) {
tmp = CLOSE_DEFINITION_DESCRIPTION + CLOSE_DEFINITION_LIST; tmp = HTML_CLOSE_DEFINITION_DESCRIPTION + HTML_CLOSE_DEFINITION_LIST;
i--; i--;
} }
defListLevel = defListLevel.substring(0, i); defListLevel = defListLevel.substring(0, i);
@ -435,7 +440,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) { if ((positionOfOpeningTag = copyOfLine.indexOf(":")) > 0) {
definitionItem = copyOfLine.substring(0, positionOfOpeningTag); definitionItem = copyOfLine.substring(0, positionOfOpeningTag);
definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1); definitionDescription = copyOfLine.substring(positionOfOpeningTag + 1);
line = tmp + OPEN_DEFINITION_ITEM + definitionItem + CLOSE_DEFINITION_ITEM + OPEN_DEFINITION_DESCRIPTION + definitionDescription; line = tmp + HTML_OPEN_DEFINITION_ITEM + definitionItem + HTML_CLOSE_DEFINITION_ITEM + HTML_OPEN_DEFINITION_DESCRIPTION + definitionDescription;
processingDefList = true; processingDefList = true;
} }
} else { } else {
@ -588,7 +593,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
//taking care of indented lines //taking care of indented lines
while (line.substring(preindented, positionOfOpeningTag).charAt(0) == WIKI_INDENTION) { while (line.substring(preindented, positionOfOpeningTag).charAt(0) == WIKI_INDENTION) {
preindented++; preindented++;
openBlockQuoteTags.append(OPEN_BLOCKQUOTE); openBlockQuoteTags.append(HTML_OPEN_BLOCKQUOTE);
} }
line = processLineOfWikiCode(line.substring(preindented, positionOfOpeningTag).replaceAll("!pre!", "!pre!!") + "!pre!txt!"); line = processLineOfWikiCode(line.substring(preindented, positionOfOpeningTag).replaceAll("!pre!", "!pre!!") + "!pre!txt!");
line = openBlockQuoteTags + line.replaceAll("!pre!txt!", preformattedText); line = openBlockQuoteTags + line.replaceAll("!pre!txt!", preformattedText);
@ -602,7 +607,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
preformattedText = preformattedText.replaceAll("!pre!", "!pre!!"); preformattedText = preformattedText.replaceAll("!pre!", "!pre!!");
//taking care of indented lines //taking care of indented lines
while (preindented > 0) { while (preindented > 0) {
endBlockQuoteTags.append(CLOSE_BLOCKQUOTE); endBlockQuoteTags.append(HTML_CLOSE_BLOCKQUOTE);
preindented--; preindented--;
} }
line = processLineOfWikiCode("!pre!txt!" + line.substring(positionOfOpeningTag + LEN_WIKI_CLOSE_PRE_ESCAPED).replaceAll("!pre!", "!pre!!")); line = processLineOfWikiCode("!pre!txt!" + line.substring(positionOfOpeningTag + LEN_WIKI_CLOSE_PRE_ESCAPED).replaceAll("!pre!", "!pre!!"));
@ -706,7 +711,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
directory.append("\" class=\"WikiTOC\">"); directory.append("\" class=\"WikiTOC\">");
directory.append(element); directory.append(element);
directory.append("</a><br />\n"); directory.append("</a><br />\n");
} }
anchorext = EMPTY; anchorext = EMPTY;
} }
directory.append("</div></td></tr></table>\n"); directory.append("</div></td></tr></table>\n");
@ -728,16 +733,22 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
*/ */
//[MN] //[MN]
private String pairReplace(String input, final String pat, final String repl1, final String repl2) { private String pairReplace(String input, final String pat, final String repl1, final String repl2) {
return pairReplace(input, pat, pat, repl1, repl2);
}
private String pairReplace(String input, final String pat1, final String pat2,
final String repl1, final String repl2) {
String direlem = null; //string to keep headlines until they get added to List dirElements String direlem = null; //string to keep headlines until they get added to List dirElements
int firstPosition; int firstPosition;
final int secondPosition; final int secondPosition;
final int strLen = pat.length(); final int pat1Len = pat1.length();
final int pat2Len = pat2.length();
//replace pattern if a pair of the pattern can be found in the line //replace pattern if a pair of the pattern can be found in the line
if (((firstPosition = input.indexOf(pat)) >= 0) && ((secondPosition = input.indexOf(pat, firstPosition + strLen)) >= 0)) { if (((firstPosition = input.indexOf(pat1)) >= 0) && ((secondPosition = input.indexOf(pat2, firstPosition + pat1Len)) >= 0)) {
//extra treatment for headlines //extra treatment for headlines
if (Arrays.binarySearch(HEADLINE_TAGS, pat) >= 0) { if (Arrays.binarySearch(HEADLINE_TAGS, pat1) >= 0) {
//add anchor and create headline //add anchor and create headline
direlem = input.substring(firstPosition + strLen, secondPosition); direlem = input.substring(firstPosition + pat1Len, secondPosition);
if (direlem != null) { if (direlem != null) {
//counting double headlines //counting double headlines
int doubles = 0; int doubles = 0;
@ -755,21 +766,21 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
anchor = anchor + "_" + (doubles + 1); anchor = anchor + "_" + (doubles + 1);
} }
input = input.substring(0, firstPosition) + "<a name=\"" + anchor + "\"></a>" + repl1 input = input.substring(0, firstPosition) + "<a name=\"" + anchor + "\"></a>" + repl1
+ direlem + repl2 + input.substring(secondPosition + strLen); + direlem + repl2 + input.substring(secondPosition + pat2Len);
//add headlines to list of headlines (so TOC can be created) //add headlines to list of headlines (so TOC can be created)
if (Arrays.binarySearch(HEADLINE_TAGS, pat) >= 0) { if (Arrays.binarySearch(HEADLINE_TAGS, pat1) >= 0) {
tableOfContentElements.add((pat.length() - 1) + direlem); tableOfContentElements.add((pat1Len - 1) + direlem);
} }
} }
} else { } else {
input = input.substring(0, firstPosition) + repl1 input = input.substring(0, firstPosition) + repl1
+ (input.substring(firstPosition + strLen, secondPosition)) + repl2 + (input.substring(firstPosition + pat1Len, secondPosition)) + repl2
+ input.substring(secondPosition + strLen); + input.substring(secondPosition + pat2Len);
} }
} }
//recursion if another pair of the pattern can still be found in the line //recursion if another pair of the pattern can still be found in the line
if (((firstPosition = input.indexOf(pat)) >= 0) && (input.indexOf(pat, firstPosition + strLen) >= 0)) { if (((firstPosition = input.indexOf(pat1)) >= 0) && (input.indexOf(pat2, firstPosition + pat1Len) >= 0)) {
input = pairReplace(input, pat, repl1, repl2); input = pairReplace(input, pat1, pat2, repl1, repl2);
} }
return input; return input;
} }
@ -806,8 +817,8 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
final StringBuilder head = new StringBuilder(); final StringBuilder head = new StringBuilder();
final StringBuilder tail = new StringBuilder(); final StringBuilder tail = new StringBuilder();
while (line.length() > 0 && line.charAt(0) == WIKI_INDENTION) { while (line.length() > 0 && line.charAt(0) == WIKI_INDENTION) {
head.append(OPEN_BLOCKQUOTE); head.append(HTML_OPEN_BLOCKQUOTE);
tail.append(CLOSE_BLOCKQUOTE); tail.append(HTML_CLOSE_BLOCKQUOTE);
line = line.substring(1); line = line.substring(1);
} }
line = head + line + tail; line = head + line + tail;
@ -823,6 +834,8 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
line = pairReplace(line, WIKI_EMPHASIZE_2, "<b>", "</b>"); line = pairReplace(line, WIKI_EMPHASIZE_2, "<b>", "</b>");
line = pairReplace(line, WIKI_EMPHASIZE_1, "<i>", "</i>"); line = pairReplace(line, WIKI_EMPHASIZE_1, "<i>", "</i>");
line = pairReplace(line, WIKI_OPEN_STRIKE, WIKI_CLOSE_STRIKE, "<s>", "</s>");
line = processUnorderedList(line); line = processUnorderedList(line);
line = processOrderedList(line); line = processOrderedList(line);
line = processDefinitionList(line); line = processDefinitionList(line);
@ -834,7 +847,7 @@ public class wikiCode extends abstractWikiParser implements wikiParser {
if (!processingPreformattedText) { if (!processingPreformattedText) {
replacedHtmlAlready = false; replacedHtmlAlready = false;
} }
if (!(line.endsWith(CLOSE_LIST_ELEMENT) || processingDefList || escape || processingPreformattedText || processingTable || processingCell)) { if (!(line.endsWith(HTML_CLOSE_LIST_ELEMENT) || processingDefList || escape || processingPreformattedText || processingTable || processingCell)) {
line += "<br />"; line += "<br />";
} }
return line; return line;

Loading…
Cancel
Save