1 4 5 9 10 package org.openlaszlo.compiler; 11 import java.io.*; 12 import java.lang.*; 13 import java.util.*; 14 15 import org.apache.oro.text.regex.*; 19 20 25 26 class SolutionMessages { 27 28 static final Perl5Matcher sMatcher = new Perl5Matcher(); 29 static final Perl5Compiler compiler = new Perl5Compiler(); 30 static final Perl5Substitution sSubst = new Perl5Substitution(); 31 32 39 40 public static String regsub (String str, 41 String pattern, 42 String subst) { 43 return regsub(str, pattern, subst, Util.SUBSTITUTE_ALL); 44 } 45 46 54 55 public static String regsub (String str, String p, String s, int numSubs) { 56 try { 57 Pattern pattern = compiler.compile(p); 58 Perl5Substitution subst = new Perl5Substitution(s); 59 60 String result = Util.substitute(sMatcher, pattern, subst, str, numSubs); 61 return result; 62 } catch (MalformedPatternException e) { 63 throw new CompilationError(e); 64 } 65 } 66 67 72 73 public static boolean regexp (String input, String p) { 74 try { 75 Pattern pattern = compiler.compile(p); 76 return sMatcher.contains(input, pattern); 77 } catch (MalformedPatternException e) { 78 return false; 81 } 82 } 83 84 85 86 static final String PARSER = "PARSER"; 89 static final String VALIDATOR = "VALIDATOR"; 90 static final String VIEWCOMPILER = "VIEWCOMPILER"; 91 92 static final ArrayList errs = new ArrayList(); 93 94 static { 95 errs.add(new SolutionMessage(PARSER, 96 "The content of elements must consist of well-formed character data or markup", 98 "Look for stray or unmatched XML escape chars ( <, >, or & ) in your source code. When using '<' in a Script, XML requires wrapping the Script content with '<![CDATA[' and ']]>'. ")); 99 100 errs.add(new SolutionMessage(PARSER, 101 "entity name must immediately follow the '&' in the entity reference", 102 "Look for unescaped '&' characters in your source code.")); 103 104 errs.add(new SolutionMessage(VIEWCOMPILER, 105 "Was expecting one of: instanceof", 106 "The element and attribute names in .lzx files are case-sensitive; Look for a mistake in the upper/lower case spelling of attribute names, i.e., \"onClick\" instead of \"onclick\"")); 107 108 109 errs.add(new SolutionMessage(PARSER, 110 "\"\" is not a valid local name", 111 "Make sure that every <class> and <attribute> tag element contains a non-empty 'name' attribute, and each <method> element contains a non-empty 'name' or 'event' attribute.")); 112 113 errs.add(new SolutionMessage(PARSER, 114 "The root element is required in a well-formed document", 115 "Check for invalid UTF8 characters in your source file. LZX XML files may contain only legal UTF-8 character codes. If you see a character with an accent over it, it might be the problem.")); 116 117 errs.add(new SolutionMessage(PARSER, 118 "Content is not allowed in prolog", 119 "Some text editors may insert a Byte-Order Mark (the sequence of characters 0xEFBBBF) at the start of your source file without your knowledge. Please remove any non-whitespace characters before the start of the first '<' character.")); 120 121 errs.add(new SolutionMessage(PARSER, 122 "The reference to entity.*must end with the", 123 "Look for a misplaced or unescaped ampersand ('&') character in your source code.")); 124 125 126 errs.add(new SolutionMessage(VIEWCOMPILER, 127 "Lexical error. The source location is for the element that contains the erroneous script", 128 "Examine the compiler warnings for warnings about undefined class or attribute names." 129 )); 130 131 errs.add(new SolutionMessage(PARSER, 132 "Error in building", 133 "Check for invalid UTF8 characters in your source file. LZX XML files may contain only legal UTF-8 character codes. If you see a character with an accent over it, it might be the problem.")); 134 135 136 137 138 } 139 140 141 149 static String findSolution (String err, String type) { 150 for (int i = 0; i < errs.size(); i++) { 151 SolutionMessage msg = (SolutionMessage) errs.get(i); 152 if ((type == null || msg.errType.equals(type)) && regexp(err, msg.errMessage)) { 154 return msg.solution; 155 } 156 } 157 return ""; 158 } 159 160 161 static String findSolution (String err) { 162 return findSolution(err, null); 163 } 164 165 } 166 167 class SolutionMessage { 168 String errType; 169 String errMessage; 170 String solution; 171 172 SolutionMessage(String type, String err, String sol) { 173 errType = type; 174 errMessage = err; 175 solution = sol; 176 } 177 178 } 179 180 | Popular Tags |