1 15 package org.apache.tapestry.wml; 16 17 import org.apache.tapestry.util.text.AsciiCharacterMatcher; 18 import org.apache.tapestry.util.text.AsciiCharacterTranslator; 19 import org.apache.tapestry.util.text.ICharacterMatcher; 20 import org.apache.tapestry.util.text.ICharacterTranslator; 21 import org.apache.tapestry.util.text.ICharacterTranslatorSource; 22 import org.apache.tapestry.util.text.MarkupCharacterTranslator; 23 24 33 public class WMLCharacterTranslatorSource implements ICharacterTranslatorSource 34 { 35 private static final String SAFE_CHARACTERS = 36 "01234567890" 37 + "abcdefghijklmnopqrstuvwxyz" 38 + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 39 + "\t\n\r !\"#%'()*+,-./:;=?@[\\]^_`{|}~"; 40 41 private static final String [][] ENTITIES = { 42 { "\"", """ }, 43 { "<", "<" }, 44 { ">", ">" }, 45 { "&", "&" }, 46 { "$", "$$" } 47 }; 48 49 private static final ICharacterMatcher SAFE_MATCHER = new AsciiCharacterMatcher(SAFE_CHARACTERS); 50 private static final ICharacterTranslator ENTITY_TRANSLATOR = new AsciiCharacterTranslator(ENTITIES); 51 52 private static final ICharacterTranslator WML_TRANSLATOR = new MarkupCharacterTranslator(true, SAFE_MATCHER, ENTITY_TRANSLATOR); 53 54 57 public ICharacterTranslator getDefaultTranslator() { 58 return WML_TRANSLATOR; 59 } 60 61 64 public ICharacterTranslator getTranslator(String encoding) { 65 return getDefaultTranslator(); 66 } 67 } 68 | Popular Tags |