001 /**
002 *
003 * Copyright 2006 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 /*
018 * The Apache Software License, Version 1.1
019 *
020 *
021 * Copyright (c) 2000 The Apache Software Foundation. All rights
022 * reserved.
023 *
024 * Redistribution and use in source and binary forms, with or without
025 * modification, are permitted provided that the following conditions
026 * are met:
027 *
028 * 1. Redistributions of source code must retain the above copyright
029 * notice, this list of conditions and the following disclaimer.
030 *
031 * 2. Redistributions in binary form must reproduce the above copyright
032 * notice, this list of conditions and the following disclaimer in
033 * the documentation and/or other materials provided with the
034 * distribution.
035 *
036 * 3. The end-user documentation included with the redistribution,
037 * if any, must include the following acknowledgment:
038 * "This product includes software developed by the
039 * Apache Software Foundation (http://www.apache.org/)."
040 * Alternately, this acknowledgment may appear in the software itself,
041 * if and wherever such third-party acknowledgments normally appear.
042 *
043 * 4. The names "Xerces" and "Apache Software Foundation" must
044 * not be used to endorse or promote products derived from this
045 * software without prior written permission. For written
046 * permission, please contact apache@apache.org.
047 *
048 * 5. Products derived from this software may not be called "Apache",
049 * nor may "Apache" appear in their name, without prior written
050 * permission of the Apache Software Foundation.
051 *
052 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
053 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
054 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
055 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
056 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
057 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
058 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
059 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
060 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
061 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
062 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
063 * SUCH DAMAGE.
064 * ====================================================================
065 *
066 * This software consists of voluntary contributions made by many
067 * individuals on behalf of the Apache Software Foundation and was
068 * originally based on software copyright (c) 1999, International
069 * Business Machines, Inc., http://www.apache.org. For more
070 * information on the Apache Software Foundation, please see
071 * <http://www.apache.org/>.
072 */
073
074 /*
075 * This code has been borrowed from the Apache Xerces project. We're copying the code to
076 * keep from adding a dependency on Xerces in the Geronimo kernel.
077 */
078
079 package org.apache.geronimo.system.configuration;
080
081 import java.io.OutputStream;
082 import java.io.OutputStreamWriter;
083 import java.io.UnsupportedEncodingException;
084 import java.io.Writer;
085
086 /**
087 * This class represents an encoding.
088 *
089 * @version $Id: EncodingInfo.java 410741 2006-06-01 04:35:48Z jsisson $
090 */
091 public class EncodingInfo {
092
093 String name;
094 String javaName;
095 int lastPrintable;
096
097 /**
098 * Creates new <code>EncodingInfo</code> instance.
099 */
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 }