Small code clean up
authoraxelcl <axelcl>
Sun, 13 Feb 2005 18:22:28 +0000 (18:22 +0000)
committeraxelcl <axelcl>
Sun, 13 Feb 2005 18:22:28 +0000 (18:22 +0000)
archive/org.plog4u.wiki/src/META-INF/services/org.radeox.filter.Filter
archive/org.plog4u.wiki/src/org/plog4u/wiki/filter/FilterUtil.java
archive/org.plog4u.wiki/src/org/plog4u/wiki/filter/WikipediaFilter.java
archive/org.plog4u.wiki/src/org/plog4u/wiki/filter/WikipediaParser.java
archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/HMathMacro.java [deleted file]
archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/LinkMacro.java [deleted file]
archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/MacroListMacro.java [deleted file]
archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/QuoteMacro.java [deleted file]

index 82f22c4..921ae29 100644 (file)
@@ -1,4 +1,3 @@
 org.plog4u.wiki.filter.WikipediaFilter\r
-#org.radeox.filter.BoldFilter\r
-#org.radeox.filter.ItalicFilter\r
+\r
  
\ No newline at end of file
index 8fbe0ed..db2733a 100644 (file)
@@ -1,9 +1,7 @@
 package org.plog4u.wiki.filter;
 
-import java.util.List;
-import java.io.IOException;
-import java.io.Writer;
 import java.util.Arrays;
+import java.util.List;
 
 public class FilterUtil {
   public static String getImageRoot() {
index dc7f3ef..0645fb9 100644 (file)
@@ -28,9 +28,6 @@ import org.radeox.macro.parameter.MacroParameter;
 import org.radeox.util.Encoder;
 import org.radeox.util.StringBufferWriter;
 
-//import org.snipsnap.app.Application;
-//import org.snipsnap.fUser.Configuration;
-//import org.snipsnap.app.Application;
 
 /**
  * Parse the input and transform it for the most used wiki patterns
@@ -54,80 +51,6 @@ public class WikipediaFilter extends FilterSupport implements CacheFilter, IWiki
 
   
   
-//  public static class ListToken extends Token {
-//    int fLevel;
-//
-//    public ListToken(int token, int level) {
-//      super(token);
-//      fLevel = level;
-//    }
-//
-//    public int getLevel() {
-//      return fLevel;
-//    }
-//  }
-//
-//  public static class OpenTagToken extends Token {
-//    private String fTagName;
-//    private String fOpenTag;
-//
-//    public OpenTagToken(int token, String name, String openTag) {
-//      super(token);
-//      fTagName = name;
-//      fOpenTag = openTag;
-//
-//    }
-//
-//    public String getTagName() {
-//      return fTagName;
-//    }
-//
-//    public String getOpenTag() {
-//      return fOpenTag;
-//    }
-//
-//    public void setTagName(String name) {
-//      fTagName = name;
-//    }
-//
-//    public void setOpenTag(String openTag) {
-//      fOpenTag = openTag;
-//    }
-//  }
-//
-//  public static class SpecialTagToken extends OpenTagToken {
-//    public SpecialTagToken(int token, String name, String openTag) {
-//      super(token, name, openTag);
-//    }
-//  }
-//
-//  public static class CloseTagToken extends Token {
-//    private String fTagName;
-//    private String fCloseTag;
-//
-//    public CloseTagToken(int token, String name, String closeTag) {
-//      super(token);
-//      fTagName = name;
-//      fCloseTag = closeTag;
-//    }
-//
-//    public String getTagName() {
-//      return fTagName;
-//    }
-//
-//    public String getCloseTag() {
-//      return fCloseTag;
-//    }
-//
-//    public void setTagName(String name) {
-//      fTagName = name;
-//    }
-//
-//    public void setCloseTag(String closeTag) {
-//      fCloseTag = closeTag;
-//    }
-//
-//  }
   final static String HEADER_STRINGS[] = { "=", "==", "===", "====", "=====", "======" };
 
   final static int TokenNotFound = -2;
@@ -241,8 +164,8 @@ public class WikipediaFilter extends FilterSupport implements CacheFilter, IWiki
   final static AbstractTag STRONG = new AbstractTag(TokenSTRONG);
   final static AbstractTag EM = new AbstractTag(TokenEM);
 
-  final static AbstractTag HTML_BR_OPEN = new SpecialTagToken(TokenHTML_BR_OPEN, "br", "<br/>");
-  final static AbstractTag HTML_HR_OPEN = new SpecialTagToken(TokenHTML_HR_OPEN, "hr", "<hr/>");
+  final static AbstractTag HTML_BR_OPEN = new SpecialTagToken(TokenHTML_BR_OPEN, "br", "<br />");
+  final static AbstractTag HTML_HR_OPEN = new SpecialTagToken(TokenHTML_HR_OPEN, "hr", "<hr />");
 
   final static AbstractTag HTML_EM_CLOSE = new CloseTagToken(TokenHTML_EM_CLOSE, "em", "</i>");
   final static AbstractTag HTML_EM_OPEN = new OpenTagToken(TokenHTML_EM_OPEN, "em", "<i>");
index 5383fb7..2e04285 100644 (file)
@@ -103,7 +103,6 @@ public class WikipediaParser {
 
   //  private String fSrcPath;
   //  private String fBinPath;
-
   public WikipediaParser(MacroRepository macros, String stringSource, StringBuffer result, FilterContext context, int recursionLevel) {
     fContext = context;
     fWikiEngine = context.getRenderContext().getRenderEngine();
@@ -182,7 +181,7 @@ public class WikipediaParser {
           } else {
             lastIndex++;
           }
-          fResultBuffer.append("&#60;");
+          fResultBuffer.append("&lt;");
           break;
         case '>': // special html escape character
           if (lastIndex < (currentIndex - 1)) {
@@ -191,7 +190,7 @@ public class WikipediaParser {
           } else {
             lastIndex++;
           }
-          fResultBuffer.append("&#62;");
+          fResultBuffer.append("&gt;");
           break;
         case '&': // special html escape character
           if (lastIndex < (currentIndex - 1)) {
@@ -370,6 +369,7 @@ public class WikipediaParser {
       char closeCharacter;
       char nextCharacter;
       if (getNextChar('/')) {
+        // end tag detected
         currentHtmlPosition++;
         // closing tag
         int r = readUntilCharOrEOL('>');
@@ -405,24 +405,26 @@ public class WikipediaParser {
         }
 
       } else {
-        // opening tag
+        // start tag
         String tokenString;
         int tagNameStart = fCurrentPosition;
         int tokenLength = 0;
-        while (Character.isJavaIdentifierStart(fSource[fCurrentPosition++])) {
+        while (Character.isJavaIdentifierStart(fSource[fCurrentPosition])) {
+          fCurrentPosition++;
           tokenLength++;
         }
         try {
-          tokenString = new String(fSource, tagNameStart, fCurrentPosition - tagNameStart - 1); //tagTokenizer.nextToken();
+          tokenString = new String(fSource, tagNameStart, fCurrentPosition - tagNameStart); //tagTokenizer.nextToken();
+
           OpenTagToken token = (OpenTagToken) WikipediaFilter.OPEN_TAGS.get(tokenString);
           if (token == null) {
             return WikipediaFilter.TokenNotFound;
           }
           copyWhite(fWhiteStart, fWhiteStartPosition, (fCurrentPosition - tagNameStart) + 1);
           fWhiteStart = false;
-
           if (token instanceof SpecialTagToken) {
-            fResultBuffer.append(token.getOpenTag());
+            // for <br> <br/> <br /> <hr> <hr/>
+
             while (Character.isWhitespace(fSource[fCurrentPosition])) {
               fCurrentPosition++;
             }
@@ -431,17 +433,21 @@ public class WikipediaParser {
             }
             if (fSource[fCurrentPosition] == '>') {
               fCurrentPosition++;
+              fWhiteStartPosition = fCurrentPosition;
+              // insert the special tag :
+              fResultBuffer.append(token.getOpenTag());
+              return WikipediaFilter.TokenIgnore;
             }
+
           } else if (token instanceof OpenTagToken) {
             fResultBuffer.append("<");
             fResultBuffer.append(token.getTagName());
             fTokenStack.push(token);
             fCurrentPosition = token.scan(fResultBuffer, fSource, fCurrentPosition - 1);
             fResultBuffer.append(">");
+            return WikipediaFilter.TokenIgnore;
           }
-
-          //                                   System.out.println(fResultBuffer);
-          return WikipediaFilter.TokenIgnore;
+          return WikipediaFilter.TokenNotFound;
         } catch (NoSuchElementException e) {
           return WikipediaFilter.TokenNotFound;
         }
@@ -701,9 +707,9 @@ public class WikipediaParser {
               int index = head.indexOf(": ");
               if (index > 0) {
                 fResultBuffer.append("<dl><dt>");
-                fResultBuffer.append(head.substring(0,index));
+                fResultBuffer.append(head.substring(0, index));
                 fResultBuffer.append("</dt><dd>");
-                fResultBuffer.append(head.substring(index+2));
+                fResultBuffer.append(head.substring(index + 2));
                 fResultBuffer.append("</dd></dl>");
               } else {
                 fResultBuffer.append("<dl><dt>");
@@ -716,79 +722,6 @@ public class WikipediaParser {
             continue;
           }
           break;
-        //                             case '\\': // special characters follow
-        //                                     copyWhite(fWhiteStart, fWhiteStartPosition, 1);
-        //                                     fWhiteStart = false;
-        //                                     try {
-        //                                             fCurrentCharacter = fSource[fCurrentPosition++];
-        //                                             switch (fCurrentCharacter) {
-        //                                             case '\\': // newline
-        //                                                     if ((fCurrentCharacter = fSource[fCurrentPosition++]) == '\\') {
-        //                                                             fResultBuffer.append(Encoder
-        //                                                                             .toEntity(fCurrentCharacter));
-        //                                                             break;
-        //                                                     } else {
-        //                                                             fResultBuffer.append("<br />");
-        //                                                             break;
-        //                                                     }
-        //                                             default:
-        //                                                     fResultBuffer.append(Encoder
-        //                                                                     .toEntity(fCurrentCharacter));
-        //                                             }
-        //                                     } catch (IndexOutOfBoundsException e) {
-        //
-        //                                     }
-        //                                     continue;
-        //          case '$' : // detect tex math
-        //            copyWhite(fWhiteStart, fWhiteStartPosition, 1);
-        //            fWhiteStart = false;
-        //            startOfIndent = false;
-        //            int startMathPosition = fCurrentPosition;
-        //            if (getNextChar('$')) {
-        //              startMathPosition = fCurrentPosition;
-        //              copyWhite(fWhiteStart, fWhiteStartPosition, 2);
-        //              fWhiteStart = false;
-        //              if (readUntilString("$$")) {
-        //                String mathContent = new String(fSource, startMathPosition,
-        // fCurrentPosition - startMathPosition - 2);
-        //                if (mathContent != null) {
-        //                  handleTeXMath(mathContent, false);
-        //                  continue;
-        //                }
-        //              }
-        //            } else {
-        //              if (readUntilChar('$')) {
-        //                String mathContent = new String(fSource, startMathPosition,
-        // fCurrentPosition - startMathPosition - 1);
-        //                if (mathContent != null) {
-        //                  handleTeXMath(mathContent, true);
-        //                  continue;
-        //                }
-        //              }
-        //            }
-        //            break;
-        case '{':
-          // detect macros
-          copyWhite(fWhiteStart, fWhiteStartPosition, 1);
-          fWhiteStart = false;
-          //              boolean scanBody = true;
-          int startMacroPosition = fCurrentPosition;
-          if (getNextChar('|') && handleWikipediaTable()) { // Wikipedia
-            // table
-            // syntax
-            continue;
-          } else {
-            if (readUntilChar('}')) {
-              String macroStartTag;
-
-              macroStartTag = new String(fSource, startMacroPosition, fCurrentPosition - startMacroPosition - 1);
-              if (macroStartTag != null) {
-                createMacro(startMacroPosition, macroStartTag);
-                continue;
-              }
-            }
-          }
-          break;
         case '[':
           int startLinkPosition = fCurrentPosition;
           if (getNextChar('[')) { // wikipedia link style
@@ -830,56 +763,6 @@ public class WikipediaParser {
             }
           }
           break;
-        //                             case '1': // heading filter ?
-        //                                     int temp1Position = checkWhitespaces(fWhiteStartPosition,
-        //                                                     fCurrentPosition - 2);
-        //                                     if (temp1Position >= 0) {
-        //                                             copyWhite(fWhiteStart, fWhiteStartPosition, 1);
-        //                                             fWhiteStart = false;
-        //                                             int simpleHeader = getNextChar(' ', '.');
-        //                                             if (simpleHeader < 0) {
-        //                                                     if (getNextChar('1')) {
-        //                                                             fCurrentPosition--;
-        //                                                             if (getList('1', "<ol>", "</ol>")) {
-        //                                                                     continue;
-        //                                                             }
-        //                                                     }
-        //                                                     break;
-        //                                             }
-        //                                             if (simpleHeader == 1 && !getNextChar('1')) {
-        //                                                     fCurrentPosition--;
-        //                                                     if (getList('1', "<ol>", "</ol>")) {
-        //                                                             continue;
-        //                                                     }
-        //                                                     break;
-        //                                             }
-        //                                             temp1Position = fCurrentPosition;
-        //                                             if (simpleHeader >= 0 && readUntilChar('\n')) {
-        //                                                     String heading = new String(fSource, temp1Position,
-        //                                                                     fCurrentPosition - temp1Position - 1);
-        //                                                     if (heading != null) {
-        //                                                             fResultBuffer.append("<h3 class=\"heading-");
-        //                                                             if (simpleHeader == 1) {
-        //                                                                     fResultBuffer.append("1");
-        //                                                             } else {
-        //                                                                     fResultBuffer.append("1-1");
-        //                                                             }
-        //                                                             fResultBuffer.append("\">");
-        //                                                             // System.out.println(heading);
-        //                                                             fResultBuffer
-        //                                                                             .append(WikipediaFilter
-        //                                                                                             .filterParser(
-        //                                                                                                             heading,
-        //                                                                                                             fContext,
-        //                                                                                                             WikipediaFilter.DUMMY_CACHED_PAGE,
-        //                                                                                                             fMacros,
-        //                                                                                                             fRecursionLevel));
-        //                                                             fResultBuffer.append("</h3>");
-        //                                                             continue;
-        //                                                     }
-        //                                             }
-        //                                     }
-        //                                     break;
         case '*': // <ul> list
         case '#': // <ol> list
           if (isStartOfLine()) {
@@ -891,92 +774,6 @@ public class WikipediaParser {
             }
           }
           break;
-        //        case '#': // <ol> list
-        //          if (fCurrentPosition >= 2) {
-        //            char beforeChar = fSource[fCurrentPosition - 2];
-        //            if (beforeChar == '\n' || beforeChar == '\r') {
-        //
-        //              int levelHash = getNumberOfChar('#') + 1;
-        //
-        //              int tempHashPosition = checkWhitespaces(fWhiteStartPosition, fCurrentPosition - 1 - levelHash);
-        //              if (tempHashPosition >= 0) {
-        //                copyWhite(fWhiteStart, fWhiteStartPosition, levelHash);
-        //                fWhiteStart = false;
-        //                AbstractTag tok = (AbstractTag) fTokenStack.peek();
-        //                if (tok instanceof ListToken) {
-        //                  ListToken listToken = (ListToken) tok;
-        //                  int topLevel = listToken.getLevel();
-        //                  if (listToken.getToken() == WikipediaFilter.TokenLIST_OL_START) {
-        //                    if (levelHash > topLevel) {
-        //                      fTokenStack.push(new ListToken(WikipediaFilter.TokenLIST_OL_START, topLevel + 1));
-        //                      fResultBuffer.append("<ol><li>");
-        //                    } else if (levelHash < topLevel) {
-        //                      fTokenStack.pop();
-        //                      fResultBuffer.append("</li></ol></li><li>");
-        //                    } else {
-        //                      fResultBuffer.append("</li><li>");
-        //                    }
-        //                  } else {
-        //                    fTokenStack.push(new ListToken(WikipediaFilter.TokenLIST_OL_START, levelHash));
-        //                    fResultBuffer.append("<ol><li>");
-        //                  }
-        //                } else {
-        //                  fTokenStack.push(new ListToken(WikipediaFilter.TokenLIST_OL_START, 1));
-        //                  fResultBuffer.append("\n<ol><li>");
-        //                }
-        //                continue;
-        //              }
-        //            }
-        //            // }
-        //          }
-        //          break;
-
-        //                             case 'i': // <ol> list
-        //                                     if (getList('i', "<ol class=\"roman\">", "</ol>")) {
-        //                                             continue;
-        //                                     }
-        //                                     break;
-        //                             case 'I': // <ol> list
-        //                                     if (getList('i', "<ol class=\"ROMAN\">", "</ol>")) {
-        //                                             continue;
-        //                                     }
-        //                                     break;
-        //            case 'a' : // <ol> list
-        //              if (getList('a', "<ol class=\"alpha\">", "</ol>")) {
-        //                continue;
-        //              }
-        //              break;
-        //            case 'A' : // <ol> list
-        //              if (getList('A', "<ol class=\"ALPHA\">", "</ol>")) {
-        //                continue;
-        //              }
-        //              break;
-        //            case 'g' : // <ol> list
-        //              if (getList('g', "<ol class=\"greek\">", "</ol>")) {
-        //                continue;
-        //              }
-        //              break;
-        //            case 'H' : // <ol> list
-        //              if (getList('H', "<ol class=\"HIRAGANA\">", "</ol>")) {
-        //                continue;
-        //              }
-        //              break;
-        //            case 'k' : // <ol> list
-        //              if (getList('k', "<ol class=\"katakana\">", "</ol>")) {
-        //                continue;
-        //              }
-        //              break;
-        //            case 'K' : // <ol> list
-        //              if (getList('K', "<ol class=\"KATAKANA\">", "</ol>")) {
-        //                continue;
-        //              }
-        //              break;
-        //            case 'j' : // <ol> list
-        //              if (getList('j', "<ol class=\"HEBREW\">", "</ol>")) {
-        //                continue;
-        //              }
-        //              break;
-
         case '\'':
           if (getNextChar('\'')) {
             if (getNextChar('\'')) {
@@ -989,20 +786,6 @@ public class WikipediaParser {
             return WikipediaFilter.TokenEM;
           }
           break;
-        //                             case '_':
-        //                                     if (getNextChar('_')) {
-        //                                             copyWhite(fWhiteStart, fWhiteStartPosition, 2);
-        //                                             fWhiteStart = false;
-        //                                             return WikipediaFilter.TokenBOLD;
-        //                                     }
-        //                                     break;
-        //                             case '~':
-        //                                     if (getNextChar('~')) {
-        //                                             copyWhite(fWhiteStart, fWhiteStartPosition, 2);
-        //                                             fWhiteStart = false;
-        //                                             return WikipediaFilter.TokenITALIC;
-        //                                     }
-        //                                     break;
         case '-':
           int tempCurrPosition = fCurrentPosition;
           try {
@@ -1022,60 +805,6 @@ public class WikipediaParser {
           } catch (IndexOutOfBoundsException e) {
 
           }
-
-          //                                   int levelMinus = getNumberOfChar('-') + 1;
-          //                                   if (getNextChar(' ')) {
-          //                                           int tempPosition = checkWhitespaces(
-          //                                                           fWhiteStartPosition, fCurrentPosition - 2
-          //                                                                           - levelMinus);
-          //                                           if (tempPosition >= 0) {
-          //                                                   copyWhite(fWhiteStart, fWhiteStartPosition,
-          //                                                                   1 + levelMinus);
-          //                                                   fWhiteStart = false;
-          //                                                   AbstractTag tok = (AbstractTag) fTokenStack.peek();
-          //                                                   if (tok instanceof ListToken) {
-          //                                                           ListToken listToken = (ListToken) tok;
-          //                                                           int topLevel = listToken.getLevel();
-          //                                                           if (listToken.getToken() ==
-          // WikipediaFilter.TokenLIST_UL_START) {
-          //                                                                   if (levelMinus > topLevel) {
-          //                                                                           fTokenStack
-          //                                                                                           .push(new ListToken(
-          //                                                                                                           WikipediaFilter.TokenLIST_UL_START,
-          //                                                                                                           topLevel + 1));
-          //                                                                           fResultBuffer
-          //                                                                                           .append("<ul class=\"minus\"><li>");
-          //                                                                   } else if (levelMinus < topLevel) {
-          //                                                                           fTokenStack.pop();
-          //                                                                           fResultBuffer
-          //                                                                                           .append("</li></ul></li><li>");
-          //                                                                   } else {
-          //                                                                           fResultBuffer.append("</li><li>");
-          //                                                                   }
-          //                                                           } else {
-          //                                                                   fTokenStack
-          //                                                                                   .push(new ListToken(
-          //                                                                                                   WikipediaFilter.TokenLIST_UL_START,
-          //                                                                                                   levelMinus));
-          //                                                                   fResultBuffer
-          //                                                                                   .append("<ul class=\"minus\"><li>");
-          //                                                           }
-          //                                                   } else {
-          //                                                           fTokenStack
-          //                                                                           .push(new ListToken(
-          //                                                                                           WikipediaFilter.TokenLIST_UL_START,
-          //                                                                                           1));
-          //                                                           fResultBuffer
-          //                                                                           .append("\n<ul class=\"minus\"><li>");
-          //                                                   }
-          //                                                   continue;
-          //                                           }
-          //                                   }
-          //                                   if (levelMinus == 2) {
-          //                                           copyWhite(fWhiteStart, fWhiteStartPosition, 2);
-          //                                           fWhiteStart = false;
-          //                                           return WikipediaFilter.TokenSTRIKETHROUGH;
-          //                                   }
           break;
         case 'h': // http(s)://
           int urlStartPosition = fCurrentPosition;
@@ -1174,6 +903,27 @@ public class WikipediaParser {
             }
           }
           break;
+        case '{':
+          // detect macros
+          copyWhite(fWhiteStart, fWhiteStartPosition, 1);
+          fWhiteStart = false;
+          int startMacroPosition = fCurrentPosition;
+          if (getNextChar('|') && handleWikipediaTable()) { // Wikipedia
+            // table
+            // syntax
+            continue;
+          } else {
+            if (readUntilChar('}')) {
+              String macroStartTag;
+
+              macroStartTag = new String(fSource, startMacroPosition, fCurrentPosition - startMacroPosition - 1);
+              if (macroStartTag != null) {
+                createMacro(startMacroPosition, macroStartTag);
+                continue;
+              }
+            }
+          }
+          break;
         case '<':
           int htmlStartPosition = fCurrentPosition;
           try {
@@ -1198,32 +948,6 @@ public class WikipediaParser {
                 }
               }
               break;
-            //                case 'm' : // math
-            //                  String mathString =
-            // fStringSource.substring(fCurrentPosition - 1,
-            // fCurrentPosition + 5);
-
-            //                  if (mathString.equals("<math>")) {
-            //                    fCurrentPosition += 5;
-            //                    if (readUntilString("</math>")) {
-            //                      String mathContent = new String(fSource,
-            // htmlStartPosition + 5, fCurrentPosition -
-            // htmlStartPosition - 12);
-            //                      if (mathContent != null) {
-            //                        copyWhite(fWhiteStart, fWhiteStartPosition,
-            // fCurrentPosition - htmlStartPosition + 1);
-            //                        fWhiteStart = false;
-            //                        if (startOfIndent) {
-            //                          startOfIndent = false;
-            //                          handleTeXMath(mathContent, false);
-            //                        } else {
-            //                          handleTeXMath(mathContent, true);
-            //                        }
-            //                        continue;
-            //                      }
-            //                    }
-            //                  }
-            //                  break;
             case 'n': // nowiki
               String nowikiString = fStringSource.substring(fCurrentPosition - 1, fCurrentPosition + 7);
 
@@ -1242,7 +966,7 @@ public class WikipediaParser {
               break;
             }
           } catch (IndexOutOfBoundsException e) {
-
+            // do nothing
           }
           startOfIndent = false;
           fCurrentPosition = htmlStartPosition;
@@ -2627,11 +2351,13 @@ public class WikipediaParser {
 
     if (fResultBufferHeader != null) {
       int tocStart = fResultBufferHeader.length();
-      fResultBufferHeader.append("<table id=\"toc\" border=\"0\"><tr><th>Table of contents</th></tr><tr><td>");
-      fResultBufferHeader.append("<ol>");
-      createToC(fTableOfContent);
-      fResultBufferHeader.append("</ol>");
-      fResultBufferHeader.append("</td></tr></table><hr/>");
+      if (isToC(fTableOfContent) > 3) {
+        fResultBufferHeader.append("<table id=\"toc\" border=\"0\"><tr><th>Table of contents</th></tr><tr><td>");
+        fResultBufferHeader.append("<ol>");
+        createToC(fTableOfContent);
+        fResultBufferHeader.append("</ol>");
+        fResultBufferHeader.append("</td></tr></table><hr/>");
+      }
 
       fResultBufferHeader.append(fResultBuffer);
       fResultBuffer = fResultBufferHeader;
@@ -2640,6 +2366,28 @@ public class WikipediaParser {
     }
   }
 
+  /**
+   * count the number of wiki headers in this document
+   * 
+   * @param toc
+   * @return
+   */
+  private int isToC(ArrayList toc) {
+
+    if (toc.size() == 1 && (toc.get(0) instanceof ArrayList)) {
+      return isToC((ArrayList) toc.get(0));
+    }
+    int result = 0;
+    for (int i = 0; i < toc.size(); i++) {
+      if (toc.get(i) instanceof ArrayList) {
+        result += isToC((ArrayList) toc.get(i));
+      } else {
+        result++;
+      }
+    }
+    return result;
+  }
+
   private void createToC(ArrayList toc) {
     if (toc.size() == 1 && (toc.get(0) instanceof ArrayList)) {
       createToC((ArrayList) toc.get(0));
diff --git a/archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/HMathMacro.java b/archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/HMathMacro.java
deleted file mode 100644 (file)
index daa5e2a..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.plog4u.wiki.macro;
-
-
-import org.plog4u.wiki.filter.INoParserBodyFilterMacro;
-import org.radeox.macro.BaseMacro;
-public abstract class HMathMacro extends BaseMacro implements INoParserBodyFilterMacro {
-
-}
diff --git a/archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/LinkMacro.java b/archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/LinkMacro.java
deleted file mode 100644 (file)
index e3e08c0..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * This file is part of "SnipSnap Radeox Rendering Engine".
- *
- * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
- * All Rights Reserved.
- *
- * Please visit http://radeox.org/ for updates and contact.
- *
- * --LICENSE NOTICE--
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * --LICENSE NOTICE--
- */
-package org.plog4u.wiki.macro;
-
-import java.io.IOException;
-import java.io.Writer;
-
-
-import org.plog4u.wiki.filter.ICachableMacro;
-import org.radeox.api.engine.ImageRenderEngine;
-import org.radeox.api.engine.RenderEngine;
-import org.radeox.api.engine.context.RenderContext;
-import org.radeox.macro.BaseLocaleMacro;
-import org.radeox.macro.parameter.MacroParameter;
-import org.radeox.util.Encoder;
-
-/*
- * Macro for displaying external links with a name. The normal UrlFilter
- * takes the url as a name.
- *
- * @author stephan
- * @team sonicteam
- */
-
-public class LinkMacro extends BaseLocaleMacro implements ICachableMacro {
-  public String getLocaleKey() {
-    return "macro.link";
-  }
-
-  public void execute(Writer writer, MacroParameter params)
-      throws IllegalArgumentException, IOException {
-
-    RenderContext context = params.getContext();
-    RenderEngine engine = context.getRenderEngine();
-
-    String text = params.get("text", 0);
-    String url = params.get("url", 1);
-    String img = params.get("img", 2);
-
-    // check for single url argument (text == url)
-    if(params.getLength() == 1) {
-      url = text;
-      text = Encoder.toEntity(text.charAt(0)) + Encoder.escape(text.substring(1));
-    }
-
-    if (url != null && text != null) {
-      writer.write("<span class=\"nobr\">");
-      if (!"none".equals(img) && engine instanceof ImageRenderEngine) {
-        writer.write(((ImageRenderEngine) engine).getExternalImageLink());
-      }
-      writer.write("<a href=\"");
-      writer.write(Encoder.escape(url));
-      writer.write("\">");
-      writer.write(text);
-      writer.write("</a></span>");
-    } else {
-      throw new IllegalArgumentException("link needs a name and a url as argument");
-    }
-    return;
-  }
-}
diff --git a/archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/MacroListMacro.java b/archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/MacroListMacro.java
deleted file mode 100644 (file)
index 593b9e2..0000000
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * This file is part of "SnipSnap Radeox Rendering Engine".
- * 
- * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel All Rights Reserved.
- * 
- * Please visit http://radeox.org/ for updates and contact.
- * 
- * --LICENSE NOTICE-- This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
- * General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any
- * later version.
- * 
- * This library 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 Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free
- * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA --LICENSE NOTICE--
- */
-package org.plog4u.wiki.macro;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-
-import org.plog4u.wiki.filter.ICachableMacro;
-import org.plog4u.wiki.filter.IRenderResultMacro;
-import org.radeox.macro.BaseLocaleMacro;
-import org.radeox.macro.Macro;
-import org.radeox.macro.MacroRepository;
-import org.radeox.macro.parameter.MacroParameter;
-
-/*
- * MacroListMacro displays a list of all known macros of the EngineManager with their name, parameters and a description.
- * 
- * @author Matthias L. Jugel
- * 
- */
-
-public class MacroListMacro extends BaseLocaleMacro implements IRenderResultMacro, ICachableMacro {
-  public String getLocaleKey() {
-    return "macro.macrolist";
-  }
-
-  public void execute(Writer writer, MacroParameter params) throws IllegalArgumentException, IOException {
-    if (params.getLength() == 0) {
-      appendTo(writer);
-    } else {
-      throw new IllegalArgumentException("MacroListMacro: number of arguments does not match");
-    }
-  }
-
-  public Writer appendTo(Writer writer) throws IOException {
-    List macroList = MacroRepository.getInstance().getPlugins();
-    Collections.sort(macroList);
-    Iterator iterator = macroList.iterator();
-    writer.write("{table}\n");
-    writer.write("Macro|Description|Parameters\n");
-    while (iterator.hasNext()) {
-      Macro macro = (Macro) iterator.next();
-      writer.write(macro.getName());
-      writer.write("|");
-      writer.write(macro.getDescription());
-      writer.write("|");
-      String[] params = macro.getParamDescription();
-      if (params.length == 0) {
-        writer.write("none");
-      } else {
-        for (int i = 0; i < params.length; i++) {
-          String description = params[i];
-          if (description.startsWith("?")) {
-            writer.write(description.substring(1));
-            writer.write(" (optional)");
-          } else {
-            writer.write(params[i]);
-          }
-          writer.write("\\\\");
-        }
-      }
-      writer.write("\n");
-    }
-    writer.write("{table}");
-    return writer;
-  }
-
-}
diff --git a/archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/QuoteMacro.java b/archive/org.plog4u.wiki/src/org/plog4u/wiki/macro/QuoteMacro.java
deleted file mode 100644 (file)
index 4d3158d..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * This file is part of "SnipSnap Radeox Rendering Engine".
- *
- * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
- * All Rights Reserved.
- *
- * Please visit http://radeox.org/ for updates and contact.
- *
- * --LICENSE NOTICE--
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * --LICENSE NOTICE--
- */
-
-package org.plog4u.wiki.macro;
-
-import java.io.IOException;
-import java.io.Writer;
-
-
-//import org.apache.commons.logging.Log;
-//import org.apache.commons.logging.LogFactory;
-import org.plog4u.wiki.filter.ICachableMacro;
-import org.plog4u.wiki.filter.INoParserBodyFilterMacro;
-import org.radeox.macro.LocalePreserved;
-import org.radeox.macro.parameter.MacroParameter;
-
-/*
- * Macro to display quotations from other sources. The
- * output is wrapped usually in <blockquote> to look like
- * a quotation.
- *
- * @author stephan
- * @team sonicteam
- */
-
-public class QuoteMacro extends LocalePreserved implements INoParserBodyFilterMacro, ICachableMacro {
-//  private static Log log = LogFactory.getLog(QuoteMacro.class);
-
-  private String[] paramDescription =
-      {"?1: source",
-       "?2: displayed description, default is Source"};
-
-  public String[] getParamDescription() {
-    return paramDescription;
-  }
-
-  public QuoteMacro() {
-  }
-
-  public String getLocaleKey() {
-    return "macro.quote";
-  }
-  public void execute(Writer writer, MacroParameter params)
-      throws IllegalArgumentException, IOException {
-
-    writer.write("<blockquote>");
-    writer.write(params.getContent());
-    String source = "Source"; // i18n
-    if (params.getLength() == 2) {
-      source = params.get(1);
-    }
-    // if more than one was present, we
-    // should show a description for the link
-    if (params.getLength() > 0) {
-      writer.write("<a href=\""+params.get(0)+"\">");
-      writer.write(source);
-      writer.write("</a>");
-    }
-    writer.write("</blockquote>");
-    return;
-  }
-}