Clover coverage report - Code Coverage for tapestry release 3.1-alpha-1
Coverage timestamp: Mon Feb 21 2005 09:16:14 EST
file stats: LOC: 69   Methods: 2
NCLOC: 26   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
DefaultCharacterTranslatorSource.java 100% 100% 100% 100%
coverage
 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.util.text;
 16   
 
 17   
 import java.util.HashMap;
 18   
 import java.util.Map;
 19   
 
 20   
 /**
 21   
  * The default implementation of a character translator source.
 22   
  * Returns a standard HTML translator that encodes everything that is non-safe
 23   
  * or an HTML translator that encodes only non-safe ASCII symbols 
 24   
  * if the encoding is a unicode one. 
 25   
  * 
 26   
  * @author mb
 27   
  * @since 3.1
 28   
  */
 29   
 public class DefaultCharacterTranslatorSource implements ICharacterTranslatorSource
 30   
 {
 31   
     private static final ICharacterTranslator DEFAULT_TRANSLATOR = new MarkupCharacterTranslator();
 32   
     private static final ICharacterTranslator UNICODE_TRANSLATOR = new MarkupCharacterTranslator(false);
 33   
 
 34   
     private final static Map _translators;
 35   
     
 36   
     static {
 37  1
         _translators = new HashMap();
 38  1
         _translators.put("UTF-8", UNICODE_TRANSLATOR);
 39  1
         _translators.put("UTF-7", UNICODE_TRANSLATOR);
 40  1
         _translators.put("UTF-16", UNICODE_TRANSLATOR);
 41  1
         _translators.put("UTF-16BE", UNICODE_TRANSLATOR);
 42  1
         _translators.put("UTF-16LE", UNICODE_TRANSLATOR);
 43   
     }
 44   
     
 45   
     /**
 46   
      * Returns a translator that encodes all non-safe characters into their HTML equivalents.
 47   
      * 
 48   
      * @see org.apache.tapestry.util.text.ICharacterTranslatorSource#getDefaultTranslator()
 49   
      */
 50  4
     public ICharacterTranslator getDefaultTranslator() {
 51  4
         return DEFAULT_TRANSLATOR;
 52   
     }
 53   
 
 54   
     /**
 55   
      * If the encoding is a Unicode one, returns a translator that encodes only the 
 56   
      * non-safe ASCII characters and leaves the others untouched.
 57   
      * Otherwise, returns the default translator.
 58   
      * 
 59   
      * @see org.apache.tapestry.util.text.ICharacterTranslatorSource#getTranslator(java.lang.String)
 60   
      */
 61  455
     public ICharacterTranslator getTranslator(String encoding) {
 62  455
         ICharacterTranslator translator = (ICharacterTranslator) _translators.get(encoding.toUpperCase());
 63  455
         if (translator != null)
 64  451
             return translator;
 65  4
         return getDefaultTranslator();
 66   
     }
 67   
     
 68   
 }
 69