1 21 package au.id.jericho.lib.html; 22 23 import java.util.*; 24 25 38 public final class Config { 39 private Config() {} 40 41 51 public static String ColumnMultipleValueSeparator=","; 52 53 60 public static String ColumnValueTrue=Boolean.toString(true); 61 62 67 public static String ColumnValueFalse=null; 68 69 76 public static CompatibilityMode CurrentCompatibilityMode=CompatibilityMode.IE; 77 78 92 public static boolean IsApostropheEncoded=false; 93 94 98 static final boolean IncludeServerTagsInElementHierarchy=false; 99 100 117 static class UnterminatedCharacterReferenceSettings { 118 public volatile int characterEntityReferenceMaxCodePoint; 120 public volatile int decimalCharacterReferenceMaxCodePoint; 121 public volatile int hexadecimalCharacterReferenceMaxCodePoint; 122 123 public static UnterminatedCharacterReferenceSettings ACCEPT_ALL=new UnterminatedCharacterReferenceSettings(CompatibilityMode.CODE_POINTS_ALL,CompatibilityMode.CODE_POINTS_ALL,CompatibilityMode.CODE_POINTS_ALL); 124 125 public UnterminatedCharacterReferenceSettings() { 126 this(CompatibilityMode.CODE_POINTS_NONE,CompatibilityMode.CODE_POINTS_NONE,CompatibilityMode.CODE_POINTS_NONE); 127 } 128 129 public UnterminatedCharacterReferenceSettings(final int characterEntityReferenceMaxCodePoint, final int decimalCharacterReferenceMaxCodePoint, final int hexadecimalCharacterReferenceMaxCodePoint) { 130 this.characterEntityReferenceMaxCodePoint=characterEntityReferenceMaxCodePoint; 131 this.decimalCharacterReferenceMaxCodePoint=decimalCharacterReferenceMaxCodePoint; 132 this.hexadecimalCharacterReferenceMaxCodePoint=hexadecimalCharacterReferenceMaxCodePoint; 133 } 134 135 public String toString() { 136 return "\n Character entity reference: "+getDescription(characterEntityReferenceMaxCodePoint) 137 +"\n Decimal character reference: "+getDescription(decimalCharacterReferenceMaxCodePoint) 138 +"\n Haxadecimal character reference: "+getDescription(hexadecimalCharacterReferenceMaxCodePoint); 139 } 140 141 private String getDescription(final int codePoint) { 142 if (codePoint==CompatibilityMode.CODE_POINTS_NONE) return "None"; 143 if (codePoint==CompatibilityMode.CODE_POINTS_ALL) return "All"; 144 return "0x"+Integer.toString(codePoint,16); 145 } 146 } 147 148 164 public static final class CompatibilityMode { 165 private String name; 166 private volatile boolean formFieldNameCaseInsensitive; 167 volatile UnterminatedCharacterReferenceSettings unterminatedCharacterReferenceSettingsInsideAttributeValue; 168 volatile UnterminatedCharacterReferenceSettings unterminatedCharacterReferenceSettingsOutsideAttributeValue; 169 170 179 public static final int CODE_POINTS_ALL=CharacterReference.MAX_CODE_POINT; 180 181 190 public static final int CODE_POINTS_NONE=CharacterReference.INVALID_CODE_POINT; 191 192 204 public static final CompatibilityMode IE=new CompatibilityMode("IE",true, 205 new UnterminatedCharacterReferenceSettings(0xFF, CODE_POINTS_ALL, CODE_POINTS_ALL), new UnterminatedCharacterReferenceSettings(0xFF, CODE_POINTS_ALL, CODE_POINTS_NONE) ); 208 209 223 public static final CompatibilityMode MOZILLA=new CompatibilityMode("Mozilla",false, 224 new UnterminatedCharacterReferenceSettings(0xFF, CODE_POINTS_ALL, CODE_POINTS_ALL), new UnterminatedCharacterReferenceSettings(CODE_POINTS_ALL, CODE_POINTS_ALL, CODE_POINTS_ALL) ); 227 228 240 public static final CompatibilityMode OPERA=new CompatibilityMode("Opera",true, 241 new UnterminatedCharacterReferenceSettings(0x3E, CODE_POINTS_ALL, CODE_POINTS_ALL), new UnterminatedCharacterReferenceSettings(CODE_POINTS_ALL, CODE_POINTS_ALL, CODE_POINTS_ALL) ); 244 245 257 public static final CompatibilityMode XHTML=new CompatibilityMode("XHTML"); 258 259 267 public CompatibilityMode(final String name) { 268 this(name,false,new UnterminatedCharacterReferenceSettings(),new UnterminatedCharacterReferenceSettings()); 269 } 270 271 private CompatibilityMode(final String name, final boolean formFieldNameCaseInsensitive, final UnterminatedCharacterReferenceSettings unterminatedCharacterReferenceSettingsInsideAttributeValue, final UnterminatedCharacterReferenceSettings unterminatedCharacterReferenceSettingsOutsideAttributeValue) { 272 this.name=name; 273 this.formFieldNameCaseInsensitive=formFieldNameCaseInsensitive; 274 this.unterminatedCharacterReferenceSettingsInsideAttributeValue=unterminatedCharacterReferenceSettingsInsideAttributeValue; 275 this.unterminatedCharacterReferenceSettingsOutsideAttributeValue=unterminatedCharacterReferenceSettingsOutsideAttributeValue; 276 } 277 278 282 public String getName() { 283 return name; 284 } 285 286 299 public boolean isFormFieldNameCaseInsensitive() { 300 return formFieldNameCaseInsensitive; 301 } 302 303 310 public void setFormFieldNameCaseInsensitive(final boolean value) { 311 formFieldNameCaseInsensitive=value; 312 } 313 314 339 public int getUnterminatedCharacterEntityReferenceMaxCodePoint(final boolean insideAttributeValue) { 340 return getUnterminatedCharacterReferenceSettings(insideAttributeValue).characterEntityReferenceMaxCodePoint; 341 } 342 343 352 public void setUnterminatedCharacterEntityReferenceMaxCodePoint(final boolean insideAttributeValue, final int maxCodePoint) { 353 getUnterminatedCharacterReferenceSettings(insideAttributeValue).characterEntityReferenceMaxCodePoint=maxCodePoint; 354 } 355 356 379 public int getUnterminatedDecimalCharacterReferenceMaxCodePoint(final boolean insideAttributeValue) { 380 return getUnterminatedCharacterReferenceSettings(insideAttributeValue).decimalCharacterReferenceMaxCodePoint; 381 } 382 383 392 public void setUnterminatedDecimalCharacterReferenceMaxCodePoint(final boolean insideAttributeValue, final int maxCodePoint) { 393 getUnterminatedCharacterReferenceSettings(insideAttributeValue).decimalCharacterReferenceMaxCodePoint=maxCodePoint; 394 } 395 396 419 public int getUnterminatedHexadecimalCharacterReferenceMaxCodePoint(final boolean insideAttributeValue) { 420 return getUnterminatedCharacterReferenceSettings(insideAttributeValue).hexadecimalCharacterReferenceMaxCodePoint; 421 } 422 423 432 public void setUnterminatedHexadecimalCharacterReferenceMaxCodePoint(final boolean insideAttributeValue, final int maxCodePoint) { 433 getUnterminatedCharacterReferenceSettings(insideAttributeValue).hexadecimalCharacterReferenceMaxCodePoint=maxCodePoint; 434 } 435 436 440 public String getDebugInfo() { 441 return "Form field name case insensitive: "+formFieldNameCaseInsensitive 442 +"\nMaximum codepoints in unterminated character references:" 443 +"\n Inside attribute values:" 444 +unterminatedCharacterReferenceSettingsInsideAttributeValue 445 +"\n Outside attribute values:" 446 +unterminatedCharacterReferenceSettingsOutsideAttributeValue; 447 } 448 449 453 public String toString() { 454 return getName(); 455 } 456 457 UnterminatedCharacterReferenceSettings getUnterminatedCharacterReferenceSettings(final boolean insideAttributeValue) { 458 return insideAttributeValue ? unterminatedCharacterReferenceSettingsInsideAttributeValue : unterminatedCharacterReferenceSettingsOutsideAttributeValue; 459 } 460 } 461 } 462 | Popular Tags |