commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject cvs commit: jakarta-commons/lang/xdocs userguide.xml
Date Sat, 02 Oct 2004 01:46:30 GMT
bayard      2004/10/01 18:46:30

  Modified:    lang/src/test/org/apache/commons/lang LangTestSuite.java
               lang/xdocs userguide.xml
  Added:       lang/src/java/org/apache/commons/lang CharEncoding.java
               lang/src/test/org/apache/commons/lang CharEncodingTest.java
  Removed:     lang/src/java/org/apache/commons/lang CharacterEncoding.java
               lang/src/test/org/apache/commons/lang
                        CharacterEncodingTest.java
  Log:
  CharacterEncoding renamed to CharEncoding
  
  Revision  Changes    Path
  1.1                  jakarta-commons/lang/src/java/org/apache/commons/lang/CharEncoding.java
  
  Index: CharEncoding.java
  ===================================================================
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.lang;
  
  import java.io.UnsupportedEncodingException;
  
  /**
   * TODO: Accept/Reject for 2.1.
   * 
   * Character encoding names required of every implementation of the Java platform.
   * 
   * According to the Java documentation <a
   * href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character encoding names
   * </a>:
   * <p>
   * <cite>Every implementation of the Java platform is required to support the following
character encodings. Consult the
   * release documentation for your implementation to see if any other encodings are supported.
</cite>
   * </p>
   * 
   * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character encoding
   *          names </a>
   * @author Apache Software Foundation
   * @since 2.1
   * @version $Id: CharEncoding.java,v 1.1 2004/10/02 01:46:29 bayard Exp $
   */
  public class CharEncoding {
  
      /**
       * <p>
       * ISO Latin Alphabet #1, also known as ISO-LATIN-1.
       * </p>
       * <p>
       * Every implementation of the Java platform is required to support this character encoding.
       * </p>
       * 
       * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
       *          encoding names </a>
       */
      public static final String ISO_8859_1 = "ISO-8859-1";
  
      /**
       * <p>
       * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of
the Unicode character set.
       * </p>
       * <p>
       * Every implementation of the Java platform is required to support this character encoding.
       * </p>
       * 
       * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
       *          encoding names </a>
       */
      public static final String US_ASCII = "US-ASCII";
  
      /**
       * <p>
       * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial
byte-order mark (either
       * order accepted on input, big-endian used on output).
       * </p>
       * <p>
       * Every implementation of the Java platform is required to support this character encoding.
       * </p>
       * 
       * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
       *          encoding names </a>
       */
      public static final String UTF_16 = "UTF-16";
  
      /**
       * <p>
       * Sixteen-bit Unicode Transformation Format, big-endian byte order.
       * </p>
       * <p>
       * Every implementation of the Java platform is required to support this character encoding.
       * </p>
       * 
       * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
       *          encoding names </a>
       */
      public static final String UTF_16BE = "UTF-16BE";
  
      /**
       * <p>
       * Sixteen-bit Unicode Transformation Format, little-endian byte order.
       * </p>
       * <p>
       * Every implementation of the Java platform is required to support this character encoding.
       * </p>
       * 
       * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
       *          encoding names </a>
       */
      public static final String UTF_16LE = "UTF-16LE";
  
      /**
       * <p>
       * Eight-bit Unicode Transformation Format.
       * </p>
       * <p>
       * Every implementation of the Java platform is required to support this character encoding.
       * </p>
       * 
       * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
       *          encoding names </a>
       */
      public static final String UTF_8 = "UTF-8";
  
      /**
       * <p>
       * Returns whether the named charset is supported.
       * </p>
       * <p>
       * This is similar to <a
       * href="http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html#isSupported(java.lang.String)">java.nio.charset.Charset.isSupported(String)
       * </a>
       * </p>
       * 
       * @param name
       *                  The name of the requested charset; may be either a canonical name
or an alias
       * @return <code>true</code> if, and only if, support for the named charset
is available in the current Java virtual machine
       * 
       * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE
character
       *          encoding names </a>
       */
      public static boolean isSupported(String name) {
          if (name == null) {
              return false;
          }
          try {
              new String(ArrayUtils.EMPTY_BYTE_ARRAY, name);
          } catch (UnsupportedEncodingException e) {
              return false;
          }
          return true;
      }
  
  }
  
  
  1.29      +2 -1      jakarta-commons/lang/src/test/org/apache/commons/lang/LangTestSuite.java
  
  Index: LangTestSuite.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/LangTestSuite.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- LangTestSuite.java	5 Sep 2004 00:56:31 -0000	1.28
  +++ LangTestSuite.java	2 Oct 2004 01:46:30 -0000	1.29
  @@ -54,6 +54,7 @@
           suite.addTest(ArrayUtilsAddTest.suite());
           suite.addTest(BitFieldTest.suite());
           suite.addTest(BooleanUtilsTest.suite());
  +        suite.addTest(CharEncodingTest.suite());
           suite.addTest(CharRangeTest.suite());
           suite.addTest(CharSetTest.suite());
           suite.addTest(CharSetUtilsTest.suite());
  
  
  
  1.1                  jakarta-commons/lang/src/test/org/apache/commons/lang/CharEncodingTest.java
  
  Index: CharEncodingTest.java
  ===================================================================
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.commons.lang;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  /**
   * Tests CharEncoding.
   * 
   * @see CharEncoding
   * @author Gary D. Gregory
   * @version $Id: CharEncodingTest.java,v 1.1 2004/10/02 01:46:30 bayard Exp $
   */
  public class CharEncodingTest extends TestCase {
  
      public static void main(String[] args) {
          TestRunner.run(suite());
      }
  
      public static Test suite() {
          TestSuite suite = new TestSuite(CharEncodingTest.class);
          suite.setName("CharEncoding Tests");
          return suite;
      }
  
      private void assertSupportedEncoding(String name) {
          assertTrue("Encoding should be supported: " + name, CharEncoding.isSupported(name));
      }
  
      public void testMustBeSupportedJava1_3_1() {
          if (SystemUtils.isJavaVersionAtLeast(1.3f)) {
              this.assertSupportedEncoding(CharEncoding.ISO_8859_1);
              this.assertSupportedEncoding(CharEncoding.US_ASCII);
              this.assertSupportedEncoding(CharEncoding.UTF_16);
              this.assertSupportedEncoding(CharEncoding.UTF_16BE);
              this.assertSupportedEncoding(CharEncoding.UTF_16LE);
              this.assertSupportedEncoding(CharEncoding.UTF_8);
          } else {
              this.warn("Java 1.3 tests not run since the current version is " + SystemUtils.JAVA_VERSION);
          }
      }
  
      public void testNotSupported() {
          assertFalse(CharEncoding.isSupported(null));
          assertFalse(CharEncoding.isSupported(""));
          assertFalse(CharEncoding.isSupported(" "));
          assertFalse(CharEncoding.isSupported("\t\r\n"));
          assertFalse(CharEncoding.isSupported("DOESNOTEXIST"));
          assertFalse(CharEncoding.isSupported("this is not a valid encoding name"));
      }
  
      public void testWorksOnJava1_1_8() {
          //
          // In this test, I simply deleted the encodings from the 1.3.1 list.
          // The Javadoc do not specify which encodings are required.
          //
          if (SystemUtils.isJavaVersionAtLeast(1.1f)) {
              this.assertSupportedEncoding(CharEncoding.ISO_8859_1);
              this.assertSupportedEncoding(CharEncoding.US_ASCII);
              this.assertSupportedEncoding(CharEncoding.UTF_8);
          } else {
              this.warn("Java 1.1 tests not run since the current version is " + SystemUtils.JAVA_VERSION);
          }
      }
  
      public void testWorksOnJava1_2_2() {
          //
          // In this test, I simply deleted the encodings from the 1.3.1 list.
          // The Javadoc do not specify which encodings are required.
          //
          if (SystemUtils.isJavaVersionAtLeast(1.2f)) {
              this.assertSupportedEncoding(CharEncoding.ISO_8859_1);
              this.assertSupportedEncoding(CharEncoding.US_ASCII);
              this.assertSupportedEncoding(CharEncoding.UTF_8);
          } else {
              this.warn("Java 1.2 tests not run since the current version is " + SystemUtils.JAVA_VERSION);
          }
      }
  
      void warn(String msg) {
          System.err.println(msg);
      }
  }
  
  
  
  1.5       +2 -2      jakarta-commons/lang/xdocs/userguide.xml
  
  Index: userguide.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/xdocs/userguide.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- userguide.xml	6 Sep 2004 00:41:02 -0000	1.4
  +++ userguide.xml	2 Oct 2004 01:46:30 -0000	1.5
  @@ -44,9 +44,9 @@
        <p>CharRange and CharSet are both used internally by CharSetUtils, and will
probaby rarely be used. </p>
       </subsection>
   
  -    <subsection name="JVM interaction - SystemUtils, CharacterEncoding">
  +    <subsection name="JVM interaction - SystemUtils, CharEncoding">
        <p>SystemUtils is a simple little class which makes it easy to find out information
about which platform you are on. For some, this is a necessary evil. It was never something
I expected to use myself until I was trying to ensure that Commons Lang itself compiled under
JDK 1.2. Having pushed out a few JDK 1.3 bits that had slipped in (Collections.EMPTY_MAP is
a classic offender), I then found that one of the Unit Tests was dying mysteriously under
JDK 1.2, but ran fine under JDK 1.3. There was no obvious solution and I needed to move onwards,
so the simple solution was to wrap that particular test in a 'if(SystemUtils.isJavaVersionAtLeast(1.3f))
{', make a note and move on. </p>
  -     <p>The CharacterEncoding class is also used to interact with the Java environment
and may be used to see which character encodings are supported in a particular environment.
</p>
  +     <p>The CharEncoding class is also used to interact with the Java environment
and may be used to see which character encodings are supported in a particular environment.
</p>
       </subsection>
   
       <subsection name="Serialization - SerializationUtils, SerializationException">
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message