Coverage Report - org.apache.tapestry.wml.WMLCharacterTranslatorSource
 
Classes in this File Line Coverage Branch Coverage Complexity
WMLCharacterTranslatorSource
0%
0/7
N/A
1
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 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  
 /**
 25  
  * The WML implementation of a character translator source. Returns a WML
 26  
  * translator that encodes everything that is non-safe. Some code borrowed from
 27  
  * WMLWriter (by David Solis)
 28  
  * 
 29  
  * @author mb
 30  
  * @since 4.0
 31  
  */
 32  0
 public class WMLCharacterTranslatorSource implements ICharacterTranslatorSource
 33  
 {
 34  
 
 35  
     private static final String SAFE_CHARACTERS = "01234567890"
 36  
             + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 37  
             + "\t\n\r !\"#%'()*+,-./:;=?@[\\]^_`{|}~";
 38  
 
 39  0
     private static final String[][] ENTITIES = { { "\"", """ },
 40  
             { "<", "&lt;" }, { ">", "&gt;" }, { "&", "&amp;" }, { "$", "$$" } };
 41  
 
 42  0
     private static final ICharacterMatcher SAFE_MATCHER = new AsciiCharacterMatcher(
 43  
             SAFE_CHARACTERS);
 44  0
     private static final ICharacterTranslator ENTITY_TRANSLATOR = new AsciiCharacterTranslator(
 45  
             ENTITIES);
 46  
 
 47  0
     private static final ICharacterTranslator WML_TRANSLATOR = new MarkupCharacterTranslator(
 48  
             true, SAFE_MATCHER, ENTITY_TRANSLATOR);
 49  
 
 50  
     /**
 51  
      * @see org.apache.tapestry.util.text.ICharacterTranslatorSource#getDefaultTranslator()
 52  
      */
 53  
     public ICharacterTranslator getDefaultTranslator()
 54  
     {
 55  0
         return WML_TRANSLATOR;
 56  
     }
 57  
 
 58  
     /**
 59  
      * @see org.apache.tapestry.util.text.ICharacterTranslatorSource#getTranslator(java.lang.String)
 60  
      */
 61  
     public ICharacterTranslator getTranslator(String encoding)
 62  
     {
 63  0
         return getDefaultTranslator();
 64  
     }
 65  
 }