You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2002/07/17 23:30:12 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/msg XMLMessages.properties

neilg       2002/07/17 14:30:12

  Modified:    java/src/org/apache/xerces/impl XMLEntityManager.java
                        XMLErrorReporter.java
               java/src/org/apache/xerces/impl/io ASCIIReader.java
                        UTF8Reader.java
               java/src/org/apache/xerces/impl/msg XMLMessages.properties
  Log:
  localize some exception message produced by our custom reader classes.
  
  Revision  Changes    Path
  1.33      +3 -3      xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java
  
  Index: XMLEntityManager.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLEntityManager.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- XMLEntityManager.java	27 Jun 2002 21:23:08 -0000	1.32
  +++ XMLEntityManager.java	17 Jul 2002 21:30:11 -0000	1.33
  @@ -1361,13 +1361,13 @@
               if (DEBUG_ENCODINGS) {
                   System.out.println("$$$ creating UTF8Reader");
               }
  -            return new UTF8Reader(inputStream, fBufferSize);
  +            return new UTF8Reader(inputStream, fBufferSize, fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), fErrorReporter.getLocale() );
           }
           if (ENCODING.equals("US-ASCII")) {
               if (DEBUG_ENCODINGS) {
                   System.out.println("$$$ creating ASCIIReader");
               }
  -            return new ASCIIReader(inputStream, fBufferSize);
  +            return new ASCIIReader(inputStream, fBufferSize, fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN), fErrorReporter.getLocale());
           }
           if(ENCODING.equals("ISO-10646-UCS-4")) {
               if(isBigEndian != null) {
  
  
  
  1.9       +10 -1     xml-xerces/java/src/org/apache/xerces/impl/XMLErrorReporter.java
  
  Index: XMLErrorReporter.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLErrorReporter.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- XMLErrorReporter.java	27 Jun 2002 21:23:08 -0000	1.8
  +++ XMLErrorReporter.java	17 Jul 2002 21:30:11 -0000	1.9
  @@ -232,6 +232,15 @@
       } // setLocale(Locale)
   
       /**
  +     * Gets the current locale.
  +     * 
  +     * @return the current Locale
  +     */
  +    public Locale getLocale() {
  +        return fLocale ;
  +    } // getLocale():  Locale
  +
  +    /**
        * Sets the document locator.
        *
        * @param locator The locator.
  
  
  
  1.4       +25 -8     xml-xerces/java/src/org/apache/xerces/impl/io/ASCIIReader.java
  
  Index: ASCIIReader.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/io/ASCIIReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ASCIIReader.java	29 Jan 2002 01:15:13 -0000	1.3
  +++ ASCIIReader.java	17 Jul 2002 21:30:12 -0000	1.4
  @@ -60,6 +60,8 @@
   import java.io.InputStream;
   import java.io.IOException;
   import java.io.Reader;
  +import java.util.Locale;
  +import org.apache.xerces.util.MessageFormatter;
   
   /**
    * A simple ASCII byte reader. This is an optimized reader for reading
  @@ -89,6 +91,13 @@
       /** Byte buffer. */
       protected byte[] fBuffer;
   
  +    // message formatter; used to produce localized
  +    // exception messages
  +    private MessageFormatter fFormatter = null;
  +
  +    //Locale to use for messages
  +    private Locale fLocale = null;
  +
       //
       // Constructors
       //
  @@ -98,10 +107,13 @@
        * using the default buffer size.
        *
        * @param inputStream The input stream.
  +     * @param messageFormatter  the MessageFormatter to use to message reporting.
  +     * @param locale    the Locale for which messages are to be reported
        */
  -    public ASCIIReader(InputStream inputStream) {
  -        this(inputStream, DEFAULT_BUFFER_SIZE);
  -    } // <init>(InputStream)
  +    public ASCIIReader(InputStream inputStream, MessageFormatter messageFormatter,
  +            Locale locale) {
  +        this(inputStream, DEFAULT_BUFFER_SIZE, messageFormatter, locale);
  +    } // <init>(InputStream, MessageFormatter, Locale)
   
       /** 
        * Constructs an ASCII reader from the specified input stream 
  @@ -109,11 +121,16 @@
        *
        * @param inputStream The input stream.
        * @param size        The initial buffer size.
  +     * @param messageFormatter  the MessageFormatter to use to message reporting.
  +     * @param locale    the Locale for which messages are to be reported
        */
  -    public ASCIIReader(InputStream inputStream, int size) {
  +    public ASCIIReader(InputStream inputStream, int size,
  +            MessageFormatter messageFormatter, Locale locale) {
           fInputStream = inputStream;
           fBuffer = new byte[size];
  -    } // <init>(InputStream,int)
  +        fFormatter = messageFormatter;
  +        fLocale = locale;
  +    } // <init>(InputStream,int, MessageFormatter, Locale)
   
       //
       // Reader methods
  @@ -135,7 +152,7 @@
       public int read() throws IOException {
           int b0 = fInputStream.read();
           if (b0 > 0x80) {
  -            throw new IOException("character not 7-bit ASCII");
  +            throw new IOException(fFormatter.formatMessage(fLocale, "InvalidASCII", new Object [] {Integer.toString(b0)}));
           }
           return b0;
       } // read():int
  @@ -162,7 +179,7 @@
           for (int i = 0; i < count; i++) {
               int b0 = fBuffer[i];
               if (b0 > 0x80) {
  -                throw new IOException("character not 7-bit ASCII");
  +                throw new IOException(fFormatter.formatMessage(fLocale, "InvalidASCII", new Object [] {Integer.toString(b0)}));
               }
               ch[offset + i] = (char)b0;
           }
  
  
  
  1.4       +34 -30    xml-xerces/java/src/org/apache/xerces/impl/io/UTF8Reader.java
  
  Index: UTF8Reader.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/io/UTF8Reader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UTF8Reader.java	29 Jan 2002 01:15:13 -0000	1.3
  +++ UTF8Reader.java	17 Jul 2002 21:30:12 -0000	1.4
  @@ -62,6 +62,9 @@
   import java.io.Reader;
   import java.io.UTFDataFormatException;
   
  +import java.util.Locale;
  +import org.apache.xerces.util.MessageFormatter;
  +
   /**
    * @author Andy Clark, IBM
    *
  @@ -98,31 +101,46 @@
       /** Surrogate character. */
       private int fSurrogate = -1;
   
  +    // message formatter; used to produce localized
  +    // exception messages
  +    private MessageFormatter fFormatter = null;
  +
  +    //Locale to use for messages
  +    private Locale fLocale = null;
  +
       //
       // Constructors
       //
   
       /** 
        * Constructs a UTF-8 reader from the specified input stream 
  -     * using the default buffer size.
  +     * using the default buffer size and the given MessageFormatter.
        *
        * @param inputStream The input stream.
  +     * @param messageFormatter  given MessageFormatter
  +     * @param locale    Locale to use for messages
        */
  -    public UTF8Reader(InputStream inputStream) {
  -        this(inputStream, DEFAULT_BUFFER_SIZE);
  -    } // <init>(InputStream)
  +    public UTF8Reader(InputStream inputStream, MessageFormatter messageFormatter,
  +            Locale locale) {
  +        this(inputStream, DEFAULT_BUFFER_SIZE, messageFormatter, locale);
  +    } // <init>(InputStream, MessageFormatter)
   
       /** 
  -     * Constructs a UTF-8 reader from the specified input stream 
  -     * and buffer size.
  +     * Constructs a UTF-8 reader from the specified input stream, 
  +     * buffer size and MessageFormatter.
        *
        * @param inputStream The input stream.
        * @param size        The initial buffer size.
  +     * @param messageFormatter  the formatter for localizing/formatting errors.
  +     * @param locale    the Locale to use for messages
        */
  -    public UTF8Reader(InputStream inputStream, int size) {
  +    public UTF8Reader(InputStream inputStream, int size,
  +            MessageFormatter messageFormatter, Locale locale) {
           fInputStream = inputStream;
           fBuffer = new byte[size];
  -    } // <init>(InputStream,int)
  +        fFormatter = messageFormatter;
  +        fLocale = locale;
  +    } // <init>(InputStream,int, MessageFormatter)
   
       //
       // Reader methods
  @@ -609,7 +627,7 @@
        *                          or if some other I/O error occurs
        */
       public void mark(int readAheadLimit) throws IOException {
  -	    throw new IOException("mark not supported");
  +	    throw new IOException(fFormatter.formatMessage(fLocale, "OperationNotSupported", new Object[]{"mark()", "UTF-8"}));
       } // mark(int)
   
       /**
  @@ -649,14 +667,8 @@
       private void expectedByte(int position, int count)
           throws UTFDataFormatException {
   
  -        StringBuffer str = new StringBuffer();
  -        str.append("expected byte ");
  -        str.append(position);
  -        str.append(" of ");
  -        str.append(count);
  -        str.append("-byte UTF-8 sequence");
  -
  -        String message = str.toString();
  +        String message = fFormatter.formatMessage(fLocale, "ExpectedByte",
  +                new Object[] {Integer.toString(position), Integer.toString(count)});
           throw new UTFDataFormatException(message);
   
       } // expectedByte(int,int,int)
  @@ -665,16 +677,8 @@
       private void invalidByte(int position, int count, int c) 
           throws UTFDataFormatException {
   
  -        StringBuffer str = new StringBuffer();
  -        str.append("invalid byte ");
  -        str.append(position);
  -        str.append(" of ");
  -        str.append(count);
  -        str.append("-byte UTF-8 sequence (0x");
  -        str.append(Integer.toHexString(c));
  -        str.append(')');
  -
  -        String message = str.toString();
  +        String message = fFormatter.formatMessage(fLocale, "InvalidByte", 
  +                new Object [] {Integer.toString(position), Integer.toString(count)});
           throw new UTFDataFormatException(message);
   
       } // invalidByte(int,int,int,int)
  @@ -684,9 +688,9 @@
           
           StringBuffer str = new StringBuffer();
           str.append("high surrogate bits in UTF-8 sequence must not exceed 0x10 but found 0x");
  -        str.append(Integer.toHexString(uuuuu));
   
  -        String message = str.toString();
  +        String message = fFormatter.formatMessage(fLocale, "InvalidHighSurrogate", 
  +                new Object[] {Integer.toHexString(uuuuu)});
           throw new UTFDataFormatException(message);
   
       } // invalidSurrogate(int)
  
  
  
  1.12      +5 -0      xml-xerces/java/src/org/apache/xerces/impl/msg/XMLMessages.properties
  
  Index: XMLMessages.properties
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/msg/XMLMessages.properties,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XMLMessages.properties	28 Jun 2002 17:36:36 -0000	1.11
  +++ XMLMessages.properties	17 Jul 2002 21:30:12 -0000	1.12
  @@ -112,6 +112,11 @@
   # 4.3.3 Character Encoding in Entities
           EncodingDeclInvalid = Invalid encoding name \"{0}\".
           EncodingByteOrderUnsupported = Given byte order for encoding \"{0}\" is not supported.
  +        InvalidByte = Invalid byte {0} of {1}-byte UTF-8 sequence.
  +        ExpectedByte = Expected byte {0} of {1}-byte UTF-8 sequence.  
  +        InvalidHighSurrogate = High surrogate bits in UTF-8 sequence must not exceed 0x10 but found 0x{0}.
  +        OperationNotSupported = Operation \"{0}\" not supported by {1} reader.
  +        InvalidASCII = Byte \"{0}\" not 7-bit ASCII.
           
   # DTD Messages
   # 2.2 Characters
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org