Improved rendering
[phpeclipse.git] / archive / org.plog4u.wiki / src / org / plog4u / wiki / filter / WikipediaFilter.java
index dc7f3ef..af37725 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>");
@@ -778,95 +701,95 @@ public class WikipediaFilter extends FilterSupport implements CacheFilter, IWiki
     result.append("</a></span>");
   }
 
-  public static void handleSnipLink(StringBuffer result, RenderEngine wikiEngine, String name) {
-    if (name != null) {
-      int index = name.indexOf("http://");
-      // Configuration probably wrote [http://radeox.org] instead of http://radeox.org
-      if (index != -1) {
-        createExternalLink(result, wikiEngine, name.substring(index));
-        // show error
-        // fResult.append("<div class=\"error\">Do not surround URLs with [...].</div>");
-      } else {
-        // trim the name and unescape it
-        name = Encoder.unescape(name.trim());
-        //                Is there an alias like [alias|link] ?
-        int pipeIndex = name.indexOf('|');
-        String alias = "";
-        if (-1 != pipeIndex) {
-          alias = name.substring(0, pipeIndex);
-          name = name.substring(pipeIndex + 1);
-        }
-
-        int hashIndex = name.lastIndexOf('#');
-
-        String hash = "";
-        if (-1 != hashIndex && hashIndex != name.length() - 1) {
-          hash = name.substring(hashIndex + 1);
-          name = name.substring(0, hashIndex);
-        }
-
-        int colonIndex = name.indexOf(':');
-        // typed link ?
-        if (-1 != colonIndex) {
-          // for now throw away the fType information
-          name = name.substring(colonIndex + 1);
-        }
-
-        int atIndex = name.lastIndexOf('@');
-        // InterWiki link ?
-        if (-1 != atIndex) {
-          String extSpace = name.substring(atIndex + 1);
-          // known extarnal space ?
-          InterWiki interWiki = InterWiki.getInstance();
-          if (interWiki.contains(extSpace)) {
-            name = name.substring(0, atIndex);
-            Writer writer = new StringBufferWriter(result);
-            try {
-              if (-1 != hashIndex) {
-                interWiki.expand(writer, extSpace, name, hash);
-              } else {
-                interWiki.expand(writer, extSpace, name, "");
-              }
-            } catch (IOException e) {
-//              log.debug("InterWiki " + extSpace + " not found.");
-            }
-          } else {
-            result.append("&#91;<span class=\"error\">");
-            result.append(name);
-            result.append("?</span>&#93;");
-          }
-        } else {
-          // internal link
-          if (wikiEngine != null && wikiEngine instanceof WikiRenderEngine) {
-            if (((WikiRenderEngine) wikiEngine).exists(name)) {
-              String view = name;
-              if (-1 != pipeIndex) {
-                view = alias;
-              }
-              // Do not add hash if an alias was given
-              if (-1 != hashIndex) {
-                ((WikiRenderEngine) wikiEngine).appendLink(result, name, view, hash);
-              } else {
-                ((WikiRenderEngine) wikiEngine).appendLink(result, name, view);
-              }
-            } else if (((WikiRenderEngine) wikiEngine).showCreate()) {
-              ((WikiRenderEngine) wikiEngine).appendCreateLink(result, name, name);
-              // links with "create" are not cacheable because
-              // a missing wiki could be created
-              // TODO is this ok?
-              //  fContext.getRenderContext().setCacheable(false);
-            } else {
-              // cannot display/create wiki, so just display the text
-              result.append(name);
-            }
-          } else {
-            // cannot display/create wiki, so just display the text
-            result.append(name);
-          }
-        }
-      }
-    }
-  }
+//  public static void handleSnipLink(StringBuffer result, RenderEngine wikiEngine, String name) {
+//    if (name != null) {
+//      int index = name.indexOf("http://");
+//      // Configuration probably wrote [http://radeox.org] instead of http://radeox.org
+//      if (index != -1) {
+//        createExternalLink(result, wikiEngine, name.substring(index));
+//        // show error
+//        // fResult.append("<div class=\"error\">Do not surround URLs with [...].</div>");
+//      } else {
+//        // trim the name and unescape it
+//        name = Encoder.unescape(name.trim());
+//        //                Is there an alias like [alias|link] ?
+//        int pipeIndex = name.indexOf('|');
+//        String alias = "";
+//        if (-1 != pipeIndex) {
+//          alias = name.substring(0, pipeIndex);
+//          name = name.substring(pipeIndex + 1);
+//        }
+//
+//        int hashIndex = name.lastIndexOf('#');
+//
+//        String hash = "";
+//        if (-1 != hashIndex && hashIndex != name.length() - 1) {
+//          hash = name.substring(hashIndex + 1);
+//          name = name.substring(0, hashIndex);
+//        }
+//
+//        int colonIndex = name.indexOf(':');
+//        // typed link ?
+//        if (-1 != colonIndex) {
+//          // for now throw away the fType information
+//          name = name.substring(colonIndex + 1);
+//        }
+//
+//        int atIndex = name.lastIndexOf('@');
+//        // InterWiki link ?
+//        if (-1 != atIndex) {
+//          String extSpace = name.substring(atIndex + 1);
+//          // known extarnal space ?
+//          InterWiki interWiki = InterWiki.getInstance();
+//          if (interWiki.contains(extSpace)) {
+//            name = name.substring(0, atIndex);
+//            Writer writer = new StringBufferWriter(result);
+//            try {
+//              if (-1 != hashIndex) {
+//                interWiki.expand(writer, extSpace, name, hash);
+//              } else {
+//                interWiki.expand(writer, extSpace, name, "");
+//              }
+//            } catch (IOException e) {
+////              log.debug("InterWiki " + extSpace + " not found.");
+//            }
+//          } else {
+//            result.append("&#91;<span class=\"error\">");
+//            result.append(name);
+//            result.append("?</span>&#93;");
+//          }
+//        } else {
+//          // internal link
+//          if (wikiEngine != null && wikiEngine instanceof WikiRenderEngine) {
+//            if (((WikiRenderEngine) wikiEngine).exists(name)) {
+//              String view = name;
+//              if (-1 != pipeIndex) {
+//                view = alias;
+//              }
+//              // Do not add hash if an alias was given
+//              if (-1 != hashIndex) {
+//                ((WikiRenderEngine) wikiEngine).appendLink(result, name, view, hash);
+//              } else {
+//                ((WikiRenderEngine) wikiEngine).appendLink(result, name, view);
+//              }
+//            } else if (((WikiRenderEngine) wikiEngine).showCreate()) {
+//              ((WikiRenderEngine) wikiEngine).appendCreateLink(result, name, name);
+//              // links with "create" are not cacheable because
+//              // a missing wiki could be created
+//              // TODO is this ok?
+//              //  fContext.getRenderContext().setCacheable(false);
+//            } else {
+//              // cannot display/create wiki, so just display the text
+//              result.append(name);
+//            }
+//          } else {
+//            // cannot display/create wiki, so just display the text
+//            result.append(name);
+//          }
+//        }
+//      }
+//    }
+//  }
 
   public static void handleWikipediaLink(StringBuffer result, RenderEngine wikiEngine, String name, String suffix) {
     if (name != null) {