1 /** 2 * 3 * Copyright 2006 The Apache Software Foundation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 /* 18 * The Apache Software License, Version 1.1 19 * 20 * 21 * Copyright (c) 2000 The Apache Software Foundation. All rights 22 * reserved. 23 * 24 * Redistribution and use in source and binary forms, with or without 25 * modification, are permitted provided that the following conditions 26 * are met: 27 * 28 * 1. Redistributions of source code must retain the above copyright 29 * notice, this list of conditions and the following disclaimer. 30 * 31 * 2. Redistributions in binary form must reproduce the above copyright 32 * notice, this list of conditions and the following disclaimer in 33 * the documentation and/or other materials provided with the 34 * distribution. 35 * 36 * 3. The end-user documentation included with the redistribution, 37 * if any, must include the following acknowledgment: 38 * "This product includes software developed by the 39 * Apache Software Foundation (http://www.apache.org/)." 40 * Alternately, this acknowledgment may appear in the software itself, 41 * if and wherever such third-party acknowledgments normally appear. 42 * 43 * 4. The names "Xerces" and "Apache Software Foundation" must 44 * not be used to endorse or promote products derived from this 45 * software without prior written permission. For written 46 * permission, please contact apache@apache.org. 47 * 48 * 5. Products derived from this software may not be called "Apache", 49 * nor may "Apache" appear in their name, without prior written 50 * permission of the Apache Software Foundation. 51 * 52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 53 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 54 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 55 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 56 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 59 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 60 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 61 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 62 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * SUCH DAMAGE. 64 * ==================================================================== 65 * 66 * This software consists of voluntary contributions made by many 67 * individuals on behalf of the Apache Software Foundation and was 68 * originally based on software copyright (c) 1999, International 69 * Business Machines, Inc., http://www.apache.org. For more 70 * information on the Apache Software Foundation, please see 71 * <http://www.apache.org/>. 72 */ 73 74 /* 75 * This code has been borrowed from the Apache Xerces project. We're copying the code to 76 * keep from adding a dependency on Xerces in the Geronimo kernel. 77 */ 78 79 package org.apache.geronimo.system.configuration; 80 81 import java.io.OutputStream; 82 import java.io.OutputStreamWriter; 83 import java.io.UnsupportedEncodingException; 84 import java.io.Writer; 85 86 /** 87 * This class represents an encoding. 88 * 89 * @version $Id: EncodingInfo.java 410741 2006-06-01 04:35:48Z jsisson $ 90 */ 91 public class EncodingInfo { 92 93 String name; 94 String javaName; 95 int lastPrintable; 96 97 /** 98 * Creates new <code>EncodingInfo</code> instance. 99 */ 100 public EncodingInfo(String mimeName, String javaName, int lastPrintable) { 101 this.name = mimeName; 102 this.javaName = javaName == null ? mimeName : javaName; 103 this.lastPrintable = lastPrintable; 104 } 105 106 /** 107 * Creates new <code>EncodingInfo</code> instance. 108 */ 109 public EncodingInfo(String mimeName, int lastPrintable) { 110 this(mimeName, mimeName, lastPrintable); 111 } 112 113 /** 114 * Returns a MIME charset name of this encoding. 115 */ 116 public String getName() { 117 return this.name; 118 } 119 120 /** 121 * Returns a writer for this encoding based on 122 * an output stream. 123 * 124 * @return A suitable writer 125 * @exception UnsupportedEncodingException There is no convertor 126 * to support this encoding 127 */ 128 public Writer getWriter(OutputStream output) 129 throws UnsupportedEncodingException { 130 if (this.javaName == null) 131 return new OutputStreamWriter(output); 132 return new OutputStreamWriter(output, this.javaName); 133 } 134 /** 135 * Checks whether the specified character is printable or not. 136 * 137 * @param ch a code point (0-0x10ffff) 138 */ 139 public boolean isPrintable(int ch) { 140 return ch <= this.lastPrintable; 141 } 142 }