0001: /* The following code was generated by JFlex 1.3.5 on 13-9-06 0:53 */
0002:
0003: package vqwiki.lex;
0004:
0005: /*
0006: * This class implements the MediaWiki syntax (http://meta.wikimedia.org/wiki/Help:Editing).
0007: * It will also escape any HTML tags that have not been specifically allowed to be
0008: * present.
0009: *
0010: * Currently supported syntax includes:
0011: *
0012: * Unordered lists: *
0013: * Ordered lists: #
0014: * Definition lists: ;:
0015: * Indents: :
0016: * Italics: ''
0017: * Bold: '''
0018: * h1 heading: =text=
0019: * h2 heading: ==text==
0020: * h3 level heading: ===text===
0021: * h4 level heading: ====text====
0022: * Breaking line: ----
0023: * Tables: {| |- ! | |}
0024: * <nowiki>
0025: * __NOTOC__
0026: *
0027: * Not yet implemented:
0028: *
0029: * <math>
0030: *
0031: * To do:
0032: *
0033: *
0034: * @author W. Ryan Holliday
0035: */
0036:
0037: import java.net.URLEncoder;
0038: import java.util.Hashtable;
0039: import java.util.Stack;
0040: import org.apache.log4j.Logger;
0041: import vqwiki.Environment;
0042: import vqwiki.WikiBase;
0043: import vqwiki.servlets.WikiServlet;
0044: import vqwiki.utils.JSPUtils;
0045:
0046: /**
0047: * This class is a scanner generated by
0048: * <a href="http://www.jflex.de/">JFlex</a> 1.3.5
0049: * on 13-9-06 0:53 from the specification file
0050: * <tt>file:/C:/SourceForge/VQWiki_2X/vqwiki-classic/jflex/mediawiki-syntax.jflex</tt>
0051: */
0052: public class MediaWikiSyntax implements vqwiki.lex.Lexer {
0053:
0054: /** This character denotes the end of file */
0055: final public static int YYEOF = -1;
0056:
0057: /** initial size of the lookahead buffer */
0058: final private static int YY_BUFFERSIZE = 16384;
0059:
0060: /** lexical states */
0061: final public static int NOWIKI = 14;
0062: final public static int LIST = 12;
0063: final public static int NORMAL = 2;
0064: final public static int TH = 8;
0065: final public static int TABLE = 4;
0066: final public static int YYINITIAL = 0;
0067: final public static int TD = 6;
0068: final public static int PRE = 16;
0069: final public static int TC = 10;
0070:
0071: /**
0072: * YY_LEXSTATE[l] is the state in the DFA for the lexical state l
0073: * YY_LEXSTATE[l+1] is the state in the DFA for the lexical state l
0074: * at the beginning of a line
0075: * l is of the form l = 2*k, k a non negative integer
0076: */
0077: private final static int YY_LEXSTATE[] = { 0, 0, 1, 2, 1, 3, 4, 3,
0078: 5, 6, 1, 3, 7, 8, 9, 9, 10, 10 };
0079:
0080: /**
0081: * Translates characters to character classes
0082: */
0083: final private static String yycmap_packed = "\11\0\1\61\1\2\1\0\1\3\1\1\22\0\1\21\1\46\1\0"
0084: + "\1\12\2\0\1\6\1\11\2\0\1\12\1\52\1\0\1\7\1\0"
0085: + "\1\20\12\0\1\60\1\12\1\4\1\10\1\5\2\0\1\34\1\25"
0086: + "\1\45\1\30\1\24\2\0\1\42\1\31\1\0\1\37\1\41\1\0"
0087: + "\1\35\1\27\1\22\1\0\1\23\1\33\1\44\1\40\1\32\4\0"
0088: + "\1\53\1\0\1\54\1\0\1\43\1\0\1\63\1\25\1\26\1\30"
0089: + "\1\66\1\65\1\0\1\55\1\16\1\0\1\17\1\64\1\62\1\13"
0090: + "\1\14\1\56\1\0\1\23\1\57\1\36\1\40\1\32\1\15\3\0"
0091: + "\1\47\1\50\1\51\uff82\0";
0092:
0093: /**
0094: * Translates characters to character classes
0095: */
0096: final private static char[] yycmap = yy_unpack_cmap(yycmap_packed);
0097:
0098: /**
0099: * Translates a state to a row index in the transition table
0100: */
0101: final private static int yy_rowMap[] = { 0, 55, 110, 165, 220, 275,
0102: 330, 385, 440, 495, 550, 0, 605, 0, 660, 0, 0, 715, 770,
0103: 825, 880, 935, 990, 1045, 1100, 1155, 1210, 1265, 1320,
0104: 1375, 1430, 1485, 1540, 1595, 1650, 0, 1650, 715, 1705,
0105: 770, 825, 880, 935, 990, 1760, 1815, 1870, 1925, 1980,
0106: 2035, 2090, 2145, 2200, 2255, 2310, 2365, 2420, 2475, 2530,
0107: 2585, 2640, 2695, 0, 2750, 2805, 2860, 2915, 2970, 3025,
0108: 3080, 3135, 3190, 3245, 0, 3300, 0, 0, 0, 0, 3355, 3410,
0109: 3465, 3520, 0, 3575, 3630, 3685, 3740, 3795, 3850, 3905,
0110: 3960, 0, 4015, 4070, 4125, 4180, 4235, 4290, 4345, 4400,
0111: 4455, 4510, 4565, 4620, 0, 4675, 0, 4730, 4785, 4840, 4895,
0112: 4950, 5005, 5060, 0, 5115, 5170, 5225, 0, 5280, 3245, 5335,
0113: 5390, 0, 5445, 5500, 5555, 0, 0, 5610, 5665, 5720, 5775,
0114: 5830, 5885, 5940, 5995, 6050, 6105, 0, 6160, 0, 6215, 6270,
0115: 6325, 6380, 6435, 6490, 6545, 0, 6600, 0, 6655, 6710, 0, 0,
0116: 6765, 6820, 6875, 6930, 6985, 7040, 7095, 0, 7150, 7205,
0117: 7260, 0, 7315, 7370, 7425, 7480, 7535, 7590, 7645, 7700,
0118: 7755, 0, 0, 7810, 0, 0, 0, 7865, 0, 7920, 7975, 8030, 0, 0,
0119: 8085, 8140, 8195, 4785, 0, 8250, 8305, 8360, 8415, 8470,
0120: 8525, 8580, 8635, 8690, 8745, 0, 8800, 8855, 0, 0, 8910, 0,
0121: 0, 8965, 9020, 9075, 9130, 9185, 9240, 0, 9295, 9350, 9405,
0122: 9460, 0, 9515, 0, 0, 9570, 9625, 9680, 0, 9735, 0, 9790,
0123: 9240, 9845, 9900, 9955, 10010, 0, 10065, 0, 0, 10120,
0124: 10175, 10230, 10285, 10340, 0, 0, 0, 10395, 10450, 0,
0125: 10505, 10560, 10615, 10670, 0, 10725, 10780, 10835, 0 };
0126:
0127: /**
0128: * The packed transition table of the DFA (part 0)
0129: */
0130: final private static String yy_packed0 = "\67\0\1\14\1\15\2\16\1\17\1\20\1\21\2\14"
0131: + "\1\22\7\14\1\16\21\14\1\23\7\14\1\24\1\14"
0132: + "\1\25\3\14\1\16\1\26\2\14\1\27\2\14\1\15"
0133: + "\2\16\1\17\1\20\1\21\1\30\1\31\1\22\1\32"
0134: + "\6\14\1\16\21\14\1\23\3\14\1\33\3\14\1\24"
0135: + "\1\14\1\25\2\14\1\32\1\16\1\26\2\14\1\27"
0136: + "\2\14\1\15\2\16\1\17\1\20\1\21\2\14\1\22"
0137: + "\1\32\6\14\1\16\21\14\1\23\2\14\1\34\1\33"
0138: + "\1\35\2\14\1\24\1\14\1\25\2\14\1\32\1\16"
0139: + "\1\26\2\14\1\27\2\14\1\15\2\16\1\17\1\20"
0140: + "\1\21\2\14\1\22\7\14\1\16\21\14\1\23\4\14"
0141: + "\1\36\2\14\1\24\1\14\1\25\3\14\1\16\1\26"
0142: + "\2\14\1\27\2\14\1\15\2\16\1\17\1\20\1\21"
0143: + "\2\14\1\22\7\14\1\16\21\14\1\23\2\14\1\37"
0144: + "\1\14\1\40\2\14\1\24\1\14\1\25\3\14\1\16"
0145: + "\1\26\2\14\1\27\2\14\1\15\2\16\1\17\1\20"
0146: + "\1\21\2\14\1\22\1\32\6\14\1\16\21\14\1\23"
0147: + "\2\14\1\41\1\33\1\42\2\14\1\24\1\14\1\25"
0148: + "\2\14\1\32\1\16\1\26\2\14\1\27\2\14\1\15"
0149: + "\2\16\1\43\1\20\1\21\2\14\1\22\7\14\1\16"
0150: + "\21\14\1\23\7\14\1\24\1\14\1\25\3\14\1\16"
0151: + "\1\26\2\14\1\27\1\14\1\44\1\15\1\16\1\44"
0152: + "\1\45\4\44\1\46\1\47\30\44\1\50\7\44\1\51"
0153: + "\1\44\1\52\2\44\1\47\1\44\1\53\2\44\1\54"
0154: + "\1\44\1\14\1\15\2\16\1\55\1\20\1\21\12\14"
0155: + "\1\16\37\14\1\16\6\14\1\15\2\16\1\56\1\20"
0156: + "\1\21\12\14\1\16\37\14\1\16\5\14\2\0\1\16"
0157: + "\77\0\1\57\2\0\1\60\1\0\1\61\1\62\1\63"
0158: + "\2\0\1\64\1\65\1\0\1\66\1\60\1\0\1\67"
0159: + "\2\0\1\70\1\0\1\71\3\0\1\70\1\65\1\72"
0160: + "\7\0\1\63\1\67\20\0\1\73\120\0\1\74\23\0"
0161: + "\53\75\1\76\1\77\12\75\36\0\1\100\113\0\1\101"
0162: + "\21\0\1\102\17\0\1\103\37\0\1\104\57\0\2\105"
0163: + "\1\0\5\105\1\106\56\105\12\0\1\32\45\0\1\32"
0164: + "\56\0\1\107\16\0\1\110\2\0\1\110\1\0\2\110"
0165: + "\1\0\36\110\3\0\16\110\1\111\2\112\1\111\1\112"
0166: + "\2\111\1\113\37\111\2\112\1\114\1\115\14\111\50\0"
0167: + "\1\116\64\0\1\117\70\0\1\117\16\0\1\110\2\0"
0168: + "\1\110\1\0\2\110\1\0\36\110\1\117\2\0\16\110"
0169: + "\1\111\2\112\1\111\1\112\2\111\1\113\37\111\1\112"
0170: + "\1\117\1\114\1\115\14\111\13\0\1\57\2\0\1\60"
0171: + "\1\0\1\61\1\62\1\63\2\0\1\64\1\65\1\0"
0172: + "\1\66\1\60\1\0\1\67\2\0\1\70\1\0\1\71"
0173: + "\3\0\1\70\1\65\10\0\1\63\1\67\21\0\1\47"
0174: + "\45\0\1\47\26\0\1\120\61\0\1\57\4\0\1\121"
0175: + "\1\122\61\0\1\123\57\0\1\124\13\0\1\60\63\0"
0176: + "\1\125\2\0\1\61\3\0\1\126\1\127\1\0\1\130"
0177: + "\1\125\1\0\1\131\2\0\1\132\1\0\1\133\3\0"
0178: + "\1\132\1\127\11\0\1\131\25\0\1\60\1\0\1\61"
0179: + "\1\62\1\63\2\0\1\64\1\65\1\0\1\66\1\60"
0180: + "\1\0\1\67\2\0\1\70\1\0\1\71\3\0\1\70"
0181: + "\1\65\10\0\1\63\1\67\32\0\1\134\50\0\1\135"
0182: + "\13\0\1\136\1\0\1\137\57\0\1\140\12\0\1\140"
0183: + "\55\0\1\141\12\0\1\141\57\0\1\142\13\0\1\143"
0184: + "\1\0\1\144\3\0\1\143\11\0\1\142\33\0\1\145"
0185: + "\4\0\1\146\3\0\1\147\1\0\1\150\3\0\1\151"
0186: + "\1\0\1\150\10\0\1\151\5\0\1\147\10\0\1\152"
0187: + "\13\0\1\71\54\0\1\153\70\0\1\154\112\0\1\155"
0188: + "\31\0\54\75\1\77\12\75\54\76\1\156\12\76\36\0"
0189: + "\1\157\46\0\1\160\134\0\1\161\60\0\1\162\17\0"
0190: + "\1\163\57\0\10\105\1\164\56\105\2\165\1\0\5\165"
0191: + "\1\166\56\165\1\107\1\167\1\170\64\107\1\110\2\0"
0192: + "\1\110\1\0\2\110\1\0\36\110\2\0\1\171\16\110"
0193: + "\1\172\2\0\45\172\1\173\16\172\1\113\1\174\1\175"
0194: + "\64\113\13\0\1\176\74\0\1\121\1\177\33\0\1\177"
0195: + "\30\0\1\121\1\122\62\0\1\200\56\0\1\201\13\0"
0196: + "\1\125\52\0\1\202\13\0\1\126\61\0\1\203\12\0"
0197: + "\1\203\55\0\1\204\12\0\1\204\57\0\1\205\13\0"
0198: + "\1\206\1\0\1\207\3\0\1\206\11\0\1\205\33\0"
0199: + "\1\210\4\0\1\211\3\0\1\212\1\0\1\213\3\0"
0200: + "\1\214\1\0\1\213\10\0\1\214\5\0\1\212\10\0"
0201: + "\1\215\13\0\1\133\71\0\1\216\41\0\1\216\5\0"
0202: + "\1\135\13\0\1\136\52\0\1\217\12\0\1\220\1\137"
0203: + "\75\0\1\221\70\0\1\222\70\0\1\223\26\0\1\223"
0204: + "\26\0\1\224\65\0\1\225\2\0\1\226\30\0\1\225"
0205: + "\15\0\1\227\13\0\1\230\52\0\1\231\13\0\1\232"
0206: + "\72\0\1\233\46\0\1\234\13\0\1\150\52\0\1\235"
0207: + "\13\0\1\151\54\0\1\236\106\0\1\237\37\0\54\240"
0208: + "\1\241\12\240\56\0\1\242\74\0\1\243\70\0\1\162"
0209: + "\60\0\1\244\15\0\1\245\57\0\10\165\1\246\56\165"
0210: + "\2\247\1\0\5\247\1\250\56\247\2\0\1\170\64\0"
0211: + "\50\251\1\0\16\251\50\112\1\0\16\112\2\0\1\175"
0212: + "\100\0\1\252\75\0\1\253\61\0\1\254\100\0\1\255"
0213: + "\70\0\1\256\70\0\1\257\26\0\1\257\26\0\1\260"
0214: + "\65\0\1\261\2\0\1\262\30\0\1\261\15\0\1\263"
0215: + "\13\0\1\210\52\0\1\264\13\0\1\211\72\0\1\265"
0216: + "\46\0\1\266\13\0\1\213\52\0\1\267\13\0\1\214"
0217: + "\52\0\1\270\13\0\1\216\52\0\1\217\13\0\1\220"
0218: + "\71\0\1\271\41\0\1\271\5\0\1\272\13\0\1\273"
0219: + "\60\0\1\274\21\0\1\274\47\0\1\275\12\0\1\275"
0220: + "\42\0\1\276\13\0\1\225\52\0\1\277\13\0\1\226"
0221: + "\45\0\5\230\1\227\12\230\1\0\46\230\5\232\1\231"
0222: + "\12\232\1\0\46\232\41\0\1\300\22\0\1\300\2\0"
0223: + "\7\236\1\301\57\236\44\0\1\302\22\0\54\240\1\303"
0224: + "\12\240\54\0\1\304\71\0\1\162\1\244\44\0\1\305"
0225: + "\50\0\1\306\46\0\10\165\1\307\56\165\10\247\1\310"
0226: + "\56\247\2\311\1\0\5\311\1\312\56\311\15\0\1\313"
0227: + "\75\0\1\314\41\0\1\314\17\0\1\315\73\0\1\316"
0228: + "\41\0\1\316\5\0\1\317\13\0\1\256\60\0\1\320"
0229: + "\21\0\1\320\47\0\1\321\12\0\1\321\42\0\1\322"
0230: + "\13\0\1\261\52\0\1\323\13\0\1\262\106\0\1\324"
0231: + "\22\0\1\324\7\0\1\325\13\0\1\271\45\0\5\273"
0232: + "\1\272\12\273\1\0\46\273\5\0\1\326\13\0\1\327"
0233: + "\64\0\1\330\17\0\1\330\53\0\1\331\41\0\1\331"
0234: + "\7\236\1\332\57\236\27\0\1\333\53\0\1\162\72\0"
0235: + "\1\334\56\0\1\335\56\0\10\247\1\336\56\247\10\311"
0236: + "\1\337\56\311\2\340\1\0\5\340\1\0\56\340\16\0"
0237: + "\1\341\55\0\1\342\13\0\1\314\63\0\1\343\55\0"
0238: + "\1\344\13\0\1\316\52\0\1\345\13\0\1\320\64\0"
0239: + "\1\346\17\0\1\346\53\0\1\347\41\0\1\347\5\327"
0240: + "\1\326\12\327\1\0\46\327\24\0\1\350\41\0\1\350"
0241: + "\5\0\1\351\13\0\1\352\45\0\5\236\1\353\1\236"
0242: + "\1\332\57\236\45\0\1\354\21\0\1\355\2\0\16\355"
0243: + "\1\0\37\355\1\0\5\355\10\247\1\356\56\247\10\311"
0244: + "\1\357\56\311\10\340\1\360\56\340\17\0\1\361\54\0"
0245: + "\1\362\105\0\1\363\41\0\1\363\5\0\1\364\13\0"
0246: + "\1\347\52\0\1\365\13\0\1\350\45\0\5\352\1\351"
0247: + "\12\352\1\0\46\352\43\0\1\366\33\0\1\367\56\0"
0248: + "\10\311\1\370\56\311\10\340\1\371\56\340\16\0\1\372"
0249: + "\55\0\1\373\13\0\1\363\110\0\1\374\33\0\1\375"
0250: + "\56\0\10\311\1\376\56\311\10\340\1\377\56\340\5\0"
0251: + "\1\u0100\71\0\1\u0101\56\0\10\340\1\u0102\56\340\10\0"
0252: + "\1\u0103\56\0\10\340\1\u0104\56\340\10\0\1\u0105\66\0"
0253: + "\1\u0106\66\0\1\u0107\66\0\1\u0108\66\0\1\u0109\56\0";
0254:
0255: /**
0256: * The transition table of the DFA
0257: */
0258: final private static int yytrans[] = yy_unpack();
0259:
0260: /* error codes */
0261: final private static int YY_UNKNOWN_ERROR = 0;
0262: final private static int YY_ILLEGAL_STATE = 1;
0263: final private static int YY_NO_MATCH = 2;
0264: final private static int YY_PUSHBACK_2BIG = 3;
0265:
0266: /* error messages for the codes above */
0267: final private static String YY_ERROR_MSG[] = {
0268: "Unkown internal scanner error",
0269: "Internal error: unknown state",
0270: "Error: could not match input",
0271: "Error: pushback value was too large" };
0272:
0273: /**
0274: * YY_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
0275: */
0276: private final static byte YY_ATTRIBUTE[] = { 8, 0, 0, 0, 0, 0, 0,
0277: 0, 0, 0, 0, 9, 1, 9, 1, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0278: 1, 1, 1, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
0279: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 9, 0, 0, 0, 0,
0280: 0, 0, 0, 0, 0, 1, 9, 0, 9, 9, 9, 9, 0, 0, 0, 0, 9, 0, 0, 0,
0281: 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0,
0282: 9, 0, 1, 0, 0, 0, 0, 0, 9, 0, 0, 1, 9, 0, 0, 0, 1, 9, 0, 0,
0283: 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 9, 0, 0, 0, 0,
0284: 0, 0, 0, 9, 0, 9, 0, 0, 9, 9, 0, 0, 0, 1, 0, 0, 0, 9, 0, 0,
0285: 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 9, 9, 9, 0, 9, 0,
0286: 0, 0, 9, 9, 0, 0, 0, 0, 9, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 9,
0287: 0, 0, 9, 9, 0, 9, 9, 0, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 9, 0,
0288: 9, 9, 0, 0, 0, 9, 0, 9, 0, 1, 1, 0, 0, 0, 9, 0, 9, 9, 0, 1,
0289: 0, 0, 0, 9, 9, 9, 1, 0, 9, 1, 0, 1, 1, 9, 1, 1, 1, 9 };
0290:
0291: /** the input device */
0292: private java.io.Reader yy_reader;
0293:
0294: /** the current state of the DFA */
0295: private int yy_state;
0296:
0297: /** the current lexical state */
0298: private int yy_lexical_state = YYINITIAL;
0299:
0300: /** this buffer contains the current text to be matched and is
0301: the source of the yytext() string */
0302: private char yy_buffer[] = new char[YY_BUFFERSIZE];
0303:
0304: /** the textposition at the last accepting state */
0305: private int yy_markedPos;
0306:
0307: /** the textposition at the last state to be included in yytext */
0308: private int yy_pushbackPos;
0309:
0310: /** the current text position in the buffer */
0311: private int yy_currentPos;
0312:
0313: /** startRead marks the beginning of the yytext() string in the buffer */
0314: private int yy_startRead;
0315:
0316: /** endRead marks the last character in the buffer, that has been read
0317: from input */
0318: private int yy_endRead;
0319:
0320: /** number of newlines encountered up to the start of the matched text */
0321: private int yyline;
0322:
0323: /** the number of characters up to the start of the matched text */
0324: private int yychar;
0325:
0326: /**
0327: * the number of characters from the last newline up to the start of the
0328: * matched text
0329: */
0330: private int yycolumn;
0331:
0332: /**
0333: * yy_atBOL == true <=> the scanner is currently at the beginning of a line
0334: */
0335: private boolean yy_atBOL = true;
0336:
0337: /** yy_atEOF == true <=> the scanner is at the EOF */
0338: private boolean yy_atEOF;
0339:
0340: /* user code: */
0341: protected static Logger logger = Logger
0342: .getLogger(MediaWikiSyntax.class.getName());
0343: /** Member variable used to keep track of the state history for the lexer. */
0344: protected Stack states = new Stack();
0345: protected String virtualWiki;
0346: protected MakeTableOfContents toc = new MakeTableOfContents();
0347: protected boolean allowHtml = false;
0348: protected boolean wikibold = false;
0349: protected boolean wikiitalic = false;
0350: protected boolean nowiki = false;
0351: protected Stack listOpenStack = new Stack();
0352: protected Stack listCloseStack = new Stack();
0353: protected static Hashtable listOpenHash = new Hashtable();
0354: protected static Hashtable listCloseHash = new Hashtable();
0355: protected static Hashtable listItemOpenHash = new Hashtable();
0356:
0357: static {
0358: listOpenHash.put("*", "<ul>");
0359: listOpenHash.put("#", "<ol>");
0360: listOpenHash.put(":", "<dl>");
0361: listOpenHash.put(";", "<dl>");
0362: listItemOpenHash.put("*", "<li>");
0363: listItemOpenHash.put("#", "<li>");
0364: listItemOpenHash.put(":", "<dd>");
0365: listItemOpenHash.put(";", "<dt>");
0366: listCloseHash.put("<ul>", "</ul>");
0367: listCloseHash.put("<ol>", "</ol>");
0368: listCloseHash.put("<dl>", "</dl>");
0369: listCloseHash.put("<li>", "</li>");
0370: listCloseHash.put("<dd>", "</dd>");
0371: listCloseHash.put("<dt>", "</dt>");
0372: }
0373:
0374: /**
0375: *
0376: */
0377: protected boolean allowHtml() {
0378: return (allowHtml && yystate() != PRE && yystate() != NOWIKI);
0379: }
0380:
0381: /**
0382: * Begin a new state and store the old state onto the stack.
0383: */
0384: protected void beginState(int state) {
0385: // store current state
0386: Integer current = new Integer(yystate());
0387: states.push(current);
0388: // switch to new state
0389: yybegin(state);
0390: }
0391:
0392: /**
0393: *
0394: */
0395: protected String closeList() {
0396: StringBuffer output = new StringBuffer();
0397: while (listOpenStack.size() > 0) {
0398: listOpenStack.pop();
0399: output.append(listCloseStack.pop());
0400: }
0401: return output.toString();
0402: }
0403:
0404: /**
0405: *
0406: */
0407: protected String closeTable(int currentState) {
0408: String output = "";
0409: if (yystate() == TC)
0410: output = "</caption>";
0411: if (yystate() == TH)
0412: output = "</th>";
0413: if (yystate() == TD)
0414: output = "</td>";
0415: if ((yystate() == TC || yystate() == TH || yystate() == TD)
0416: && yystate() != currentState)
0417: endState();
0418: return output;
0419: }
0420:
0421: /**
0422: * End processing of a state and switch to the previous state.
0423: */
0424: protected void endState() {
0425: // revert to previous state
0426: int next = ((Integer) states.pop()).intValue();
0427: yybegin(next);
0428: }
0429:
0430: /**
0431: *
0432: */
0433: protected String listItem(String text) {
0434: text = text.trim();
0435: StringBuffer output = new StringBuffer();
0436: // build a stack of html tags based on current values passed to lexer
0437: Stack currentOpenStack = new Stack();
0438: for (int i = 0; i < text.length(); i++) {
0439: String tag = "" + text.charAt(i);
0440: String listOpenTag = (String) listOpenHash.get(tag);
0441: String listItemOpenTag = (String) listItemOpenHash.get(tag);
0442: if (listOpenTag == null || listItemOpenTag == null) {
0443: logger.error("Unknown list tag " + tag);
0444: continue;
0445: }
0446: currentOpenStack.push(listOpenTag);
0447: currentOpenStack.push(listItemOpenTag);
0448: }
0449: // if list was previously open to a greater depth, close the old list
0450: while (listOpenStack.size() > currentOpenStack.size()) {
0451: listOpenStack.pop();
0452: output.append(listCloseStack.pop());
0453: }
0454: // if continuing the same list, process normally
0455: if (currentOpenStack.equals(listOpenStack)) {
0456: // get last tag in current stack
0457: String currentOpenTag = (String) currentOpenStack
0458: .elementAt(currentOpenStack.size() - 1);
0459: String listOpenTag = (String) listOpenStack
0460: .elementAt(listOpenStack.size() - 1);
0461: String closeTag = (String) listCloseHash.get(listOpenTag);
0462: output.append(closeTag);
0463: output.append(currentOpenTag);
0464: return output.toString();
0465: }
0466: // look for differences in the old list stack and the new list stack
0467: int pos = 0;
0468: while (pos < listOpenStack.size()) {
0469: if (!listOpenStack.elementAt(pos).equals(
0470: currentOpenStack.elementAt(pos))) {
0471: break;
0472: }
0473: pos++;
0474: }
0475: // if any differences found process them
0476: while (listOpenStack.size() > pos) {
0477: listOpenStack.pop();
0478: output.append(listCloseStack.pop());
0479: }
0480: // continue processing differences
0481: for (int i = pos; i < currentOpenStack.size(); i++) {
0482: String currentOpenTag = (String) currentOpenStack
0483: .elementAt(i);
0484: String currentCloseTag = (String) listCloseHash
0485: .get(currentOpenTag);
0486: listOpenStack.push(currentOpenTag);
0487: listCloseStack.push(currentCloseTag);
0488: output.append(currentOpenTag);
0489: }
0490: return output.toString();
0491: }
0492:
0493: /**
0494: *
0495: */
0496: protected String updateToc(String name, String text, int level) {
0497: String output = "";
0498: if (this .toc.getStatus() == MakeTableOfContents.STATUS_TOC_UNINITIALIZED) {
0499: output = MakeTableOfContents.TOC_INSERT_TAG;
0500: }
0501: this .toc.addEntry(name, text, level);
0502: return output;
0503: }
0504:
0505: /**
0506: *
0507: */
0508: public void setVirtualWiki(String vWiki) {
0509: this .virtualWiki = vWiki;
0510: }
0511:
0512: /**
0513: *
0514: */
0515: public void setTOC(MakeTableOfContents toc) {
0516: this .toc = toc;
0517: }
0518:
0519: /**
0520: * Creates a new scanner
0521: * There is also a java.io.InputStream version of this constructor.
0522: *
0523: * @param in the java.io.Reader to read input from.
0524: */
0525: public MediaWikiSyntax(java.io.Reader in) {
0526: allowHtml = Environment.getInstance().getAllowHTML();
0527: yybegin(NORMAL);
0528: states.add(new Integer(yystate()));
0529: this .yy_reader = in;
0530: }
0531:
0532: /**
0533: * Creates a new scanner.
0534: * There is also java.io.Reader version of this constructor.
0535: *
0536: * @param in the java.io.Inputstream to read input from.
0537: */
0538: public MediaWikiSyntax(java.io.InputStream in) {
0539: this (new java.io.InputStreamReader(in));
0540: }
0541:
0542: /**
0543: * Unpacks the split, compressed DFA transition table.
0544: *
0545: * @return the unpacked transition table
0546: */
0547: private static int[] yy_unpack() {
0548: int[] trans = new int[10890];
0549: int offset = 0;
0550: offset = yy_unpack(yy_packed0, offset, trans);
0551: return trans;
0552: }
0553:
0554: /**
0555: * Unpacks the compressed DFA transition table.
0556: *
0557: * @param packed the packed transition table
0558: * @return the index of the last entry
0559: */
0560: private static int yy_unpack(String packed, int offset, int[] trans) {
0561: int i = 0; /* index in packed string */
0562: int j = offset; /* index in unpacked array */
0563: int l = packed.length();
0564: while (i < l) {
0565: int count = packed.charAt(i++);
0566: int value = packed.charAt(i++);
0567: value--;
0568: do
0569: trans[j++] = value;
0570: while (--count > 0);
0571: }
0572: return j;
0573: }
0574:
0575: /**
0576: * Unpacks the compressed character translation table.
0577: *
0578: * @param packed the packed character translation table
0579: * @return the unpacked character translation table
0580: */
0581: private static char[] yy_unpack_cmap(String packed) {
0582: char[] map = new char[0x10000];
0583: int i = 0; /* index in packed string */
0584: int j = 0; /* index in unpacked array */
0585: while (i < 168) {
0586: int count = packed.charAt(i++);
0587: char value = packed.charAt(i++);
0588: do
0589: map[j++] = value;
0590: while (--count > 0);
0591: }
0592: return map;
0593: }
0594:
0595: /**
0596: * Refills the input buffer.
0597: *
0598: * @return <code>false</code>, iff there was new input.
0599: *
0600: * @exception IOException if any I/O-Error occurs
0601: */
0602: private boolean yy_refill() throws java.io.IOException {
0603:
0604: /* first: make room (if you can) */
0605: if (yy_startRead > 0) {
0606: System.arraycopy(yy_buffer, yy_startRead, yy_buffer, 0,
0607: yy_endRead - yy_startRead);
0608:
0609: /* translate stored positions */
0610: yy_endRead -= yy_startRead;
0611: yy_currentPos -= yy_startRead;
0612: yy_markedPos -= yy_startRead;
0613: yy_pushbackPos -= yy_startRead;
0614: yy_startRead = 0;
0615: }
0616:
0617: /* is the buffer big enough? */
0618: if (yy_currentPos >= yy_buffer.length) {
0619: /* if not: blow it up */
0620: char newBuffer[] = new char[yy_currentPos * 2];
0621: System.arraycopy(yy_buffer, 0, newBuffer, 0,
0622: yy_buffer.length);
0623: yy_buffer = newBuffer;
0624: }
0625:
0626: /* finally: fill the buffer with new input */
0627: int numRead = yy_reader.read(yy_buffer, yy_endRead,
0628: yy_buffer.length - yy_endRead);
0629:
0630: if (numRead < 0) {
0631: return true;
0632: } else {
0633: yy_endRead += numRead;
0634: return false;
0635: }
0636: }
0637:
0638: /**
0639: * Closes the input stream.
0640: */
0641: final public void yyclose() throws java.io.IOException {
0642: yy_atEOF = true; /* indicate end of file */
0643: yy_endRead = yy_startRead; /* invalidate buffer */
0644:
0645: if (yy_reader != null)
0646: yy_reader.close();
0647: }
0648:
0649: /**
0650: * Closes the current stream, and resets the
0651: * scanner to read from a new input stream.
0652: *
0653: * All internal variables are reset, the old input stream
0654: * <b>cannot</b> be reused (internal buffer is discarded and lost).
0655: * Lexical state is set to <tt>YY_INITIAL</tt>.
0656: *
0657: * @param reader the new input stream
0658: */
0659: final public void yyreset(java.io.Reader reader)
0660: throws java.io.IOException {
0661: yyclose();
0662: yy_reader = reader;
0663: yy_atBOL = true;
0664: yy_atEOF = false;
0665: yy_endRead = yy_startRead = 0;
0666: yy_currentPos = yy_markedPos = yy_pushbackPos = 0;
0667: yyline = yychar = yycolumn = 0;
0668: yy_lexical_state = YYINITIAL;
0669: }
0670:
0671: /**
0672: * Returns the current lexical state.
0673: */
0674: final public int yystate() {
0675: return yy_lexical_state;
0676: }
0677:
0678: /**
0679: * Enters a new lexical state
0680: *
0681: * @param newState the new lexical state
0682: */
0683: final public void yybegin(int newState) {
0684: yy_lexical_state = newState;
0685: }
0686:
0687: /**
0688: * Returns the text matched by the current regular expression.
0689: */
0690: final public String yytext() {
0691: return new String(yy_buffer, yy_startRead, yy_markedPos
0692: - yy_startRead);
0693: }
0694:
0695: /**
0696: * Returns the character at position <tt>pos</tt> from the
0697: * matched text.
0698: *
0699: * It is equivalent to yytext().charAt(pos), but faster
0700: *
0701: * @param pos the position of the character to fetch.
0702: * A value from 0 to yylength()-1.
0703: *
0704: * @return the character at position pos
0705: */
0706: final public char yycharat(int pos) {
0707: return yy_buffer[yy_startRead + pos];
0708: }
0709:
0710: /**
0711: * Returns the length of the matched text region.
0712: */
0713: final public int yylength() {
0714: return yy_markedPos - yy_startRead;
0715: }
0716:
0717: /**
0718: * Reports an error that occured while scanning.
0719: *
0720: * In a wellformed scanner (no or only correct usage of
0721: * yypushback(int) and a match-all fallback rule) this method
0722: * will only be called with things that "Can't Possibly Happen".
0723: * If this method is called, something is seriously wrong
0724: * (e.g. a JFlex bug producing a faulty scanner etc.).
0725: *
0726: * Usual syntax/scanner level error handling should be done
0727: * in error fallback rules.
0728: *
0729: * @param errorCode the code of the errormessage to display
0730: */
0731: private void yy_ScanError(int errorCode) {
0732: String message;
0733: try {
0734: message = YY_ERROR_MSG[errorCode];
0735: } catch (ArrayIndexOutOfBoundsException e) {
0736: message = YY_ERROR_MSG[YY_UNKNOWN_ERROR];
0737: }
0738:
0739: throw new Error(message);
0740: }
0741:
0742: /**
0743: * Pushes the specified amount of characters back into the input stream.
0744: *
0745: * They will be read again by then next call of the scanning method
0746: *
0747: * @param number the number of characters to be read again.
0748: * This number must not be greater than yylength()!
0749: */
0750: private void yypushback(int number) {
0751: if (number > yylength())
0752: yy_ScanError(YY_PUSHBACK_2BIG);
0753:
0754: yy_markedPos -= number;
0755: }
0756:
0757: /**
0758: * Resumes scanning until the next regular expression is matched,
0759: * the end of input is encountered or an I/O-Error occurs.
0760: *
0761: * @return the next token
0762: * @exception IOException if any I/O-Error occurs
0763: */
0764: public String yylex() throws java.io.IOException {
0765: int yy_input;
0766: int yy_action;
0767:
0768: // cached fields:
0769: int yy_currentPos_l;
0770: int yy_startRead_l;
0771: int yy_markedPos_l;
0772: int yy_endRead_l = yy_endRead;
0773: char[] yy_buffer_l = yy_buffer;
0774: char[] yycmap_l = yycmap;
0775:
0776: int[] yytrans_l = yytrans;
0777: int[] yy_rowMap_l = yy_rowMap;
0778: byte[] yy_attr_l = YY_ATTRIBUTE;
0779:
0780: while (true) {
0781: yy_markedPos_l = yy_markedPos;
0782:
0783: if (yy_markedPos_l > yy_startRead) {
0784: switch (yy_buffer_l[yy_markedPos_l - 1]) {
0785: case '\n':
0786: case '\u000B':
0787: case '\u000C':
0788: case '\u0085':
0789: case '\u2028':
0790: case '\u2029':
0791: yy_atBOL = true;
0792: break;
0793: case '\r':
0794: if (yy_markedPos_l < yy_endRead_l)
0795: yy_atBOL = yy_buffer_l[yy_markedPos_l] != '\n';
0796: else if (yy_atEOF)
0797: yy_atBOL = false;
0798: else {
0799: boolean eof = yy_refill();
0800: yy_markedPos_l = yy_markedPos;
0801: yy_buffer_l = yy_buffer;
0802: if (eof)
0803: yy_atBOL = false;
0804: else
0805: yy_atBOL = yy_buffer_l[yy_markedPos_l] != '\n';
0806: }
0807: break;
0808: default:
0809: yy_atBOL = false;
0810: }
0811: }
0812: yy_action = -1;
0813:
0814: yy_startRead_l = yy_currentPos_l = yy_currentPos = yy_startRead = yy_markedPos_l;
0815:
0816: if (yy_atBOL)
0817: yy_state = YY_LEXSTATE[yy_lexical_state + 1];
0818: else
0819: yy_state = YY_LEXSTATE[yy_lexical_state];
0820:
0821: yy_forAction: {
0822: while (true) {
0823:
0824: if (yy_currentPos_l < yy_endRead_l)
0825: yy_input = yy_buffer_l[yy_currentPos_l++];
0826: else if (yy_atEOF) {
0827: yy_input = YYEOF;
0828: break yy_forAction;
0829: } else {
0830: // store back cached positions
0831: yy_currentPos = yy_currentPos_l;
0832: yy_markedPos = yy_markedPos_l;
0833: boolean eof = yy_refill();
0834: // get translated positions and possibly new buffer
0835: yy_currentPos_l = yy_currentPos;
0836: yy_markedPos_l = yy_markedPos;
0837: yy_buffer_l = yy_buffer;
0838: yy_endRead_l = yy_endRead;
0839: if (eof) {
0840: yy_input = YYEOF;
0841: break yy_forAction;
0842: } else {
0843: yy_input = yy_buffer_l[yy_currentPos_l++];
0844: }
0845: }
0846: int yy_next = yytrans_l[yy_rowMap_l[yy_state]
0847: + yycmap_l[yy_input]];
0848: if (yy_next == -1)
0849: break yy_forAction;
0850: yy_state = yy_next;
0851:
0852: int yy_attributes = yy_attr_l[yy_state];
0853: if ((yy_attributes & 1) == 1) {
0854: yy_action = yy_state;
0855: yy_markedPos_l = yy_currentPos_l;
0856: if ((yy_attributes & 8) == 8)
0857: break yy_forAction;
0858: }
0859:
0860: }
0861: }
0862:
0863: // store back cached position
0864: yy_markedPos = yy_markedPos_l;
0865:
0866: switch (yy_action) {
0867:
0868: case 115: {
0869: logger
0870: .debug("h1: " + yytext() + " (" + yystate()
0871: + ")");
0872: String tagText = yytext().substring(1,
0873: yytext().indexOf("=", 1)).trim();
0874: String tagName = JSPUtils.encodeURL(tagText);
0875: String output = updateToc(tagName, tagText, 1);
0876: return output + "<a name=\"" + tagName + "\"></a><h1>"
0877: + tagText + "</h1>";
0878: }
0879: case 266:
0880: break;
0881: case 259:
0882: case 261:
0883: case 262:
0884: case 263:
0885: case 264: {
0886: logger
0887: .debug("h5: " + yytext() + " (" + yystate()
0888: + ")");
0889: String tagText = yytext().substring(5,
0890: yytext().indexOf("=====", 5)).trim();
0891: String tagName = JSPUtils.encodeURL(tagText);
0892: String output = updateToc(tagName, tagText, 5);
0893: return output + "<a name=\"" + tagName + "\"></a><h5>"
0894: + tagText + "</h5>";
0895: }
0896: case 267:
0897: break;
0898: case 253:
0899: case 256:
0900: case 258:
0901: case 260: {
0902: logger
0903: .debug("h4: " + yytext() + " (" + yystate()
0904: + ")");
0905: String tagText = yytext().substring(4,
0906: yytext().indexOf("====", 4)).trim();
0907: String tagName = JSPUtils.encodeURL(tagText);
0908: String output = updateToc(tagName, tagText, 4);
0909: return output + "<a name=\"" + tagName + "\"></a><h4>"
0910: + tagText + "</h4>";
0911: }
0912: case 268:
0913: break;
0914: case 83: {
0915: logger.debug("htmlitalicstart: " + yytext() + " ("
0916: + yystate() + ")");
0917: return (allowHtml()) ? "<i>" : MediaWikiUtil
0918: .escapeHtml(yytext());
0919: }
0920: case 269:
0921: break;
0922: case 140: {
0923: logger.debug("htmlunderlineend: " + yytext() + " ("
0924: + yystate() + ")");
0925: return (allowHtml()) ? "</u>" : MediaWikiUtil
0926: .escapeHtml(yytext());
0927: }
0928: case 270:
0929: break;
0930: case 15: {
0931: logger.debug("htmltagclose: " + yytext() + " ("
0932: + yystate() + ")");
0933: // if html not allowed, escape it
0934: return (allowHtml()) ? yytext() : ">";
0935: }
0936: case 271:
0937: break;
0938: case 164: {
0939: logger
0940: .debug("hr: " + yytext() + " (" + yystate()
0941: + ")");
0942: return "<hr />\n";
0943: }
0944: case 272:
0945: break;
0946: case 160:
0947: case 195: {
0948: logger.debug("wikilink: " + yytext() + " (" + yystate()
0949: + ")");
0950: return MediaWikiUtil.buildWikiLink(yytext(),
0951: virtualWiki);
0952: }
0953: case 273:
0954: break;
0955: case 77: {
0956: logger.debug("tablecells: " + yytext() + " ("
0957: + yystate() + ")");
0958: return "</td><td>";
0959: }
0960: case 274:
0961: break;
0962: case 11:
0963: case 17:
0964: case 18:
0965: case 19:
0966: case 20:
0967: case 21:
0968: case 22:
0969: case 23:
0970: case 24:
0971: case 26:
0972: case 28:
0973: case 29:
0974: case 30:
0975: case 31:
0976: case 33: {
0977: logger.debug("default: " + yytext() + " (" + yystate()
0978: + ")");
0979: return yytext();
0980: }
0981: case 275:
0982: break;
0983: case 78: {
0984: logger.debug("tableheadings: " + yytext() + " ("
0985: + yystate() + ")");
0986: return "</th><th>";
0987: }
0988: case 276:
0989: break;
0990: case 38: {
0991: logger.debug("list item: " + yytext() + " ("
0992: + yystate() + ")");
0993: // process list item
0994: return listItem(yytext());
0995: }
0996: case 277:
0997: break;
0998: case 105: {
0999: logger.debug("htmlunderlinestart: " + yytext() + " ("
1000: + yystate() + ")");
1001: return (allowHtml()) ? "<u>" : MediaWikiUtil
1002: .escapeHtml(yytext());
1003: }
1004: case 278:
1005: break;
1006: case 255: {
1007: logger.debug("nowikiend: " + yytext() + " ("
1008: + yystate() + ")");
1009: endState();
1010: return "";
1011: }
1012: case 279:
1013: break;
1014: case 250: {
1015: logger.debug("htmlstrikeend: " + yytext() + " ("
1016: + yystate() + ")");
1017: return (allowHtml()) ? "</strike>" : MediaWikiUtil
1018: .escapeHtml(yytext());
1019: }
1020: case 280:
1021: break;
1022: case 243: {
1023: logger.debug("htmltableend: " + yytext() + " ("
1024: + yystate() + ")");
1025: return (allowHtml()) ? "</table>" : MediaWikiUtil
1026: .escapeHtml(yytext());
1027: }
1028: case 281:
1029: break;
1030: case 237:
1031: case 246:
1032: case 252: {
1033: logger
1034: .debug("h3: " + yytext() + " (" + yystate()
1035: + ")");
1036: String tagText = yytext().substring(3,
1037: yytext().indexOf("===", 3)).trim();
1038: String tagName = JSPUtils.encodeURL(tagText);
1039: String output = updateToc(tagName, tagText, 3);
1040: return output + "<a name=\"" + tagName + "\"></a><h3>"
1041: + tagText + "</h3>";
1042: }
1043: case 282:
1044: break;
1045: case 236: {
1046: logger.debug("htmllinkraw: " + yytext() + " ("
1047: + yystate() + ")");
1048: return MediaWikiUtil.buildHtmlLinkRaw(yytext());
1049: }
1050: case 283:
1051: break;
1052: case 228: {
1053: logger.debug("htmlspanend: " + yytext() + " ("
1054: + yystate() + ")");
1055: return (allowHtml()) ? "</span>" : MediaWikiUtil
1056: .escapeHtml(yytext());
1057: }
1058: case 284:
1059: break;
1060: case 227: {
1061: logger.debug("htmlcodeend: " + yytext() + " ("
1062: + yystate() + ")");
1063: return (allowHtml()) ? "</code>" : MediaWikiUtil
1064: .escapeHtml(yytext());
1065: }
1066: case 285:
1067: break;
1068: case 210: {
1069: logger.debug("htmlsubend: " + yytext() + " ("
1070: + yystate() + ")");
1071: return (allowHtml()) ? "</sub>" : MediaWikiUtil
1072: .escapeHtml(yytext());
1073: }
1074: case 286:
1075: break;
1076: case 209: {
1077: logger.debug("htmlsupend: " + yytext() + " ("
1078: + yystate() + ")");
1079: return (allowHtml()) ? "</sup>" : MediaWikiUtil
1080: .escapeHtml(yytext());
1081: }
1082: case 287:
1083: break;
1084: case 206: {
1085: logger.debug("htmldivend: " + yytext() + " ("
1086: + yystate() + ")");
1087: return (allowHtml()) ? "</div>" : MediaWikiUtil
1088: .escapeHtml(yytext());
1089: }
1090: case 288:
1091: break;
1092: case 198:
1093: case 220: {
1094: logger
1095: .debug("h2: " + yytext() + " (" + yystate()
1096: + ")");
1097: String tagText = yytext().substring(2,
1098: yytext().indexOf("==", 2)).trim();
1099: String tagName = JSPUtils.encodeURL(tagText);
1100: String output = updateToc(tagName, tagText, 2);
1101: return output + "<a name=\"" + tagName + "\"></a><h2>"
1102: + tagText + "</h2>";
1103: }
1104: case 289:
1105: break;
1106: case 185: {
1107: logger.debug("htmldivstart: " + yytext() + " ("
1108: + yystate() + ")");
1109: return (allowHtml()) ? yytext() : MediaWikiUtil
1110: .escapeHtml(yytext());
1111: }
1112: case 290:
1113: break;
1114: case 182: {
1115: logger.debug("htmlthend: " + yytext() + " ("
1116: + yystate() + ")");
1117: return (allowHtml()) ? "</th>" : MediaWikiUtil
1118: .escapeHtml(yytext());
1119: }
1120: case 291:
1121: break;
1122: case 181: {
1123: logger.debug("htmlttend: " + yytext() + " ("
1124: + yystate() + ")");
1125: return (allowHtml()) ? "</tt>" : MediaWikiUtil
1126: .escapeHtml(yytext());
1127: }
1128: case 292:
1129: break;
1130: case 62:
1131: case 109: {
1132: logger.debug("htmllink: " + yytext() + " (" + yystate()
1133: + ")");
1134: return MediaWikiUtil.buildHtmlLink(yytext());
1135: }
1136: case 293:
1137: break;
1138: case 58: {
1139: logger.debug("italic: " + yytext() + " (" + yystate()
1140: + ")");
1141: wikiitalic = !wikiitalic;
1142: return (wikiitalic) ? "<i>" : "</i>";
1143: }
1144: case 294:
1145: break;
1146: case 12:
1147: case 13: {
1148: logger.debug("{whitespace}: " + yytext() + " ("
1149: + yystate() + ")");
1150: return yytext();
1151: }
1152: case 295:
1153: break;
1154: case 14:
1155: case 34:
1156: case 44:
1157: case 45: {
1158: logger.debug("htmltagopen: " + yytext() + " ("
1159: + yystate() + ")");
1160: // if html not allowed, escape it
1161: return (allowHtml()) ? yytext() : "<";
1162: }
1163: case 296:
1164: break;
1165: case 16: {
1166: logger.debug("htmltagopen: " + yytext() + " ("
1167: + yystate() + ")");
1168: // if html not allowed, escape it
1169: return (allowHtml()) ? yytext() : "&";
1170: }
1171: case 297:
1172: break;
1173: case 107: {
1174: logger.debug("bold: " + yytext() + " (" + yystate()
1175: + ")");
1176: wikibold = !wikibold;
1177: return (wikibold) ? "<b>" : "</b>";
1178: }
1179: case 298:
1180: break;
1181: case 142: {
1182: logger.debug("htmlbreak: " + yytext() + " ("
1183: + yystate() + ")");
1184: return (allowHtml()) ? "<br />" : MediaWikiUtil
1185: .escapeHtml(yytext());
1186: }
1187: case 299:
1188: break;
1189: case 150: {
1190: logger.debug("htmltrstart: " + yytext() + " ("
1191: + yystate() + ")");
1192: return (allowHtml()) ? yytext() : MediaWikiUtil
1193: .escapeHtml(yytext());
1194: }
1195: case 300:
1196: break;
1197: case 152: {
1198: logger.debug("htmltdstart: " + yytext() + " ("
1199: + yystate() + ")");
1200: return (allowHtml()) ? yytext() : MediaWikiUtil
1201: .escapeHtml(yytext());
1202: }
1203: case 301:
1204: break;
1205: case 156: {
1206: logger.debug("htmlthstart: " + yytext() + " ("
1207: + yystate() + ")");
1208: return (allowHtml()) ? yytext() : MediaWikiUtil
1209: .escapeHtml(yytext());
1210: }
1211: case 302:
1212: break;
1213: case 178: {
1214: logger.debug("htmltrend: " + yytext() + " ("
1215: + yystate() + ")");
1216: return (allowHtml()) ? "</tr>" : MediaWikiUtil
1217: .escapeHtml(yytext());
1218: }
1219: case 303:
1220: break;
1221: case 179: {
1222: logger.debug("htmltdend: " + yytext() + " ("
1223: + yystate() + ")");
1224: return (allowHtml()) ? "</td>" : MediaWikiUtil
1225: .escapeHtml(yytext());
1226: }
1227: case 304:
1228: break;
1229: case 234: {
1230: logger.debug("htmlcomment: " + yytext() + " ("
1231: + yystate() + ")");
1232: // remove comment
1233: return "";
1234: }
1235: case 305:
1236: break;
1237: case 251: {
1238: logger.debug("notoc: " + yytext() + " (" + yystate()
1239: + ")");
1240: this .toc.setStatus(MakeTableOfContents.STATUS_NO_TOC);
1241: return "";
1242: }
1243: case 306:
1244: break;
1245: case 241: {
1246: logger.debug("nowikistart: " + yytext() + " ("
1247: + yystate() + ")");
1248: beginState(NOWIKI);
1249: return "";
1250: }
1251: case 307:
1252: break;
1253: case 123:
1254: case 124: {
1255: logger.debug("tablerow: " + yytext() + " (" + yystate()
1256: + ")");
1257: StringBuffer output = new StringBuffer();
1258: // if a column was already open, close it
1259: output.append(closeTable(TABLE));
1260: output.append("</tr>");
1261: if (yytext().length() > 2) {
1262: output.append("<tr ").append(
1263: yytext().substring(2).trim()).append(">");
1264: } else {
1265: output.append("<tr>");
1266: }
1267: return output.toString();
1268: }
1269: case 308:
1270: break;
1271: case 75: {
1272: logger.debug("tableend: " + yytext() + " (" + yystate()
1273: + ")");
1274: StringBuffer output = new StringBuffer();
1275: // if a column was already open, close it
1276: output.append(closeTable(TABLE));
1277: // end TABLE state
1278: endState();
1279: output.append("</tr></table>\n");
1280: return output.toString();
1281: }
1282: case 309:
1283: break;
1284: case 25: {
1285: logger.debug("start of list: " + yytext() + " ("
1286: + yystate() + ")");
1287: // switch to list processing mode
1288: beginState(LIST);
1289: yypushback(yylength());
1290: return "";
1291: }
1292: case 310:
1293: break;
1294: case 72:
1295: case 73: {
1296: logger.debug("tablecell: " + yytext() + " ("
1297: + yystate() + ")");
1298: StringBuffer output = new StringBuffer();
1299: // if a column was already open, close it
1300: output.append(closeTable(TD));
1301: if (yystate() != TD)
1302: beginState(TD);
1303: if (yytext().length() > 2) {
1304: int start = 1;
1305: int end = yytext().indexOf("|", start + 1);
1306: output.append("<td ").append(
1307: yytext().substring(start, end).trim())
1308: .append(">");
1309: } else {
1310: output.append("<td>");
1311: }
1312: // extra character matched by both regular expressions so push it back
1313: yypushback(1);
1314: return output.toString();
1315: }
1316: case 311:
1317: break;
1318: case 27:
1319: case 32:
1320: case 168: {
1321: logger.debug("tableheading: " + yytext() + " ("
1322: + yystate() + ")");
1323: StringBuffer output = new StringBuffer();
1324: // if a column was already open, close it
1325: output.append(closeTable(TH));
1326: if (yystate() != TH)
1327: beginState(TH);
1328: if (yytext().length() > 1) {
1329: int start = 1;
1330: int end = yytext().indexOf("|", start + 1);
1331: output.append("<th ").append(
1332: yytext().substring(start, end).trim())
1333: .append(">");
1334: // extra character matched by regular expression so push it back
1335: yypushback(1);
1336: } else {
1337: output.append("<th>");
1338: }
1339: return output.toString();
1340: }
1341: case 312:
1342: break;
1343: case 183: {
1344: logger.debug("htmlprestart: " + yytext() + " ("
1345: + yystate() + ")");
1346: if (allowHtml) {
1347: beginState(PRE);
1348: return "<pre>";
1349: }
1350: return "<pre>";
1351: }
1352: case 313:
1353: break;
1354: case 92: {
1355: logger.debug("htmlboldstart: " + yytext() + " ("
1356: + yystate() + ")");
1357: return (allowHtml()) ? "<b>" : MediaWikiUtil
1358: .escapeHtml(yytext());
1359: }
1360: case 314:
1361: break;
1362: case 128: {
1363: logger.debug("htmlitalicend: " + yytext() + " ("
1364: + yystate() + ")");
1365: return (allowHtml()) ? "</i>" : MediaWikiUtil
1366: .escapeHtml(yytext());
1367: }
1368: case 315:
1369: break;
1370: case 244: {
1371: logger.debug("htmlstrikestart: " + yytext() + " ("
1372: + yystate() + ")");
1373: return (allowHtml()) ? "<strike>" : MediaWikiUtil
1374: .escapeHtml(yytext());
1375: }
1376: case 316:
1377: break;
1378: case 232: {
1379: logger.debug("htmltablestart: " + yytext() + " ("
1380: + yystate() + ")");
1381: return (allowHtml()) ? yytext() : MediaWikiUtil
1382: .escapeHtml(yytext());
1383: }
1384: case 317:
1385: break;
1386: case 213: {
1387: logger.debug("htmlspanstart: " + yytext() + " ("
1388: + yystate() + ")");
1389: return (allowHtml()) ? yytext() : MediaWikiUtil
1390: .escapeHtml(yytext());
1391: }
1392: case 318:
1393: break;
1394: case 212: {
1395: logger.debug("htmlcodestart: " + yytext() + " ("
1396: + yystate() + ")");
1397: return (allowHtml()) ? "<code>" : MediaWikiUtil
1398: .escapeHtml(yytext());
1399: }
1400: case 319:
1401: break;
1402: case 190: {
1403: logger.debug("htmlsubstart: " + yytext() + " ("
1404: + yystate() + ")");
1405: return (allowHtml()) ? "<sub>" : MediaWikiUtil
1406: .escapeHtml(yytext());
1407: }
1408: case 320:
1409: break;
1410: case 189: {
1411: logger.debug("htmlsupstart: " + yytext() + " ("
1412: + yystate() + ")");
1413: return (allowHtml()) ? "<sup>" : MediaWikiUtil
1414: .escapeHtml(yytext());
1415: }
1416: case 321:
1417: break;
1418: case 76: {
1419: logger.debug("tablecaption: " + yytext() + " ("
1420: + yystate() + ")");
1421: StringBuffer output = new StringBuffer();
1422: output.append(closeTable(TC));
1423: beginState(TC);
1424: output.append("<caption>");
1425: return output.toString();
1426: }
1427: case 322:
1428: break;
1429: case 129: {
1430: logger.debug("htmlboldend: " + yytext() + " ("
1431: + yystate() + ")");
1432: return (allowHtml()) ? "</b>" : MediaWikiUtil
1433: .escapeHtml(yytext());
1434: }
1435: case 323:
1436: break;
1437: case 155: {
1438: logger.debug("htmlttstart: " + yytext() + " ("
1439: + yystate() + ")");
1440: return (allowHtml()) ? "<tt>" : MediaWikiUtil
1441: .escapeHtml(yytext());
1442: }
1443: case 324:
1444: break;
1445: case 118:
1446: case 119: {
1447: logger.debug("tablestart: " + yytext() + " ("
1448: + yystate() + ")");
1449: beginState(TABLE);
1450: return "<table " + yytext().substring(2).trim()
1451: + "><tr>";
1452: }
1453: case 325:
1454: break;
1455: case 225: {
1456: logger.debug("htmlpreend: " + yytext() + " ("
1457: + yystate() + ")");
1458: // state only changes to pre if allowHTML is true, so no need to check here
1459: endState();
1460: return "</pre>";
1461: }
1462: case 326:
1463: break;
1464: case 35:
1465: case 36:
1466: case 37:
1467: case 39:
1468: case 40:
1469: case 41:
1470: case 42:
1471: case 43: {
1472: logger.debug("end of list: " + yytext() + " ("
1473: + yystate() + ")");
1474: // end of list, switch back to normal processing mode
1475: endState();
1476: yypushback(yylength());
1477: return closeList();
1478: }
1479: case 327:
1480: break;
1481: default:
1482: if (yy_input == YYEOF && yy_startRead == yy_currentPos) {
1483: yy_atEOF = true;
1484: {
1485: StringBuffer output = new StringBuffer();
1486: if (wikibold) {
1487: wikibold = false;
1488: output.append("</b>");
1489: }
1490: if (wikiitalic) {
1491: wikiitalic = false;
1492: output.append("</i>");
1493: }
1494: // close any open list tags
1495: output.append(closeList());
1496: // close any open tables
1497: if (yystate() == TD) {
1498: output.append("</td>");
1499: endState();
1500: }
1501: if (yystate() == TH) {
1502: output.append("</th>");
1503: endState();
1504: }
1505: if (yystate() == TC) {
1506: output.append("</caption>");
1507: endState();
1508: }
1509: if (yystate() == TABLE) {
1510: output.append("</td>");
1511: endState();
1512: }
1513: return (output.length() == 0) ? null : output
1514: .toString();
1515: }
1516: } else {
1517: yy_ScanError(YY_NO_MATCH);
1518: }
1519: }
1520: }
1521: }
1522:
1523: }
|