Coverage Report - org.apache.tapestry.util.text.XmlCharacterTranslator
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlCharacterTranslator
0%
0/5
0%
0/18
6
 
 1  
 // Copyright Aug 4, 2006 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  
 package org.apache.tapestry.util.text;
 15  
 
 16  
 
 17  
 /**
 18  
  * Handles escaping of special characters as per the XML spec section 2.2.
 19  
  * 
 20  
  * @author lquijano
 21  
  */
 22  
 public final class XmlCharacterTranslator extends MarkupCharacterTranslator {
 23  
     
 24  
     /** Default constructor. */
 25  
     public XmlCharacterTranslator() {
 26  0
         super(true);
 27  0
     }
 28  
     
 29  
     /**
 30  
      * Translates the character.
 31  
      * 
 32  
      * <p>
 33  
      *  XML spec section 2.2
 34  
      *  Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] |
 35  
      *  [#xE000-#xFFFD] |
 36  
      *  [#x10000-#x10FFFF]
 37  
      *  any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
 38  
      *  </p>
 39  
      */
 40  
     public String translate(char ch) {
 41  0
         if (ch == 0x09 || ch == 0x0a || ch == 0x0d
 42  
                 || (ch >= 0x20 && ch <= 0xd7ff)
 43  
                 || (ch >= 0xe000 && ch <= 0xfffd)
 44  
                 || (ch >= 0x10000 && ch <= 0x10ffff)) {
 45  0
             return super.translate(ch);
 46  
         }
 47  
 
 48  0
         return "";
 49  
     }
 50  
 }