#60555: Patch applied. BLD200507121800
authormmatula@netbeans.org
Tue, 28 Jun 2005 13:12:15 +0000
changeset 16983b0c677267ba
parent 1697 af8ef5422613
child 1699 1235c9a96f5f
#60555: Patch applied.
mdr/jmiutils/src/org/netbeans/lib/jmi/xmi/DefaultWriter.java
     1.1 --- a/mdr/jmiutils/src/org/netbeans/lib/jmi/xmi/DefaultWriter.java	Tue Jun 28 13:11:21 2005 +0000
     1.2 +++ b/mdr/jmiutils/src/org/netbeans/lib/jmi/xmi/DefaultWriter.java	Tue Jun 28 13:12:15 2005 +0000
     1.3 @@ -13,6 +13,7 @@
     1.4  package org.netbeans.lib.jmi.xmi;
     1.5  
     1.6  import java.io.*;
     1.7 +import java.nio.charset.*;
     1.8  import java.util.*;
     1.9  import java.net.URL;
    1.10  import org.xml.sax.*;
    1.11 @@ -23,7 +24,7 @@
    1.12  public class DefaultWriter extends DefaultHandler {
    1.13  
    1.14      private static final char QUOTE = '\'';
    1.15 -    private static final char EOL = '\n';
    1.16 +    private static final String EOL = System.getProperty("line.separator");
    1.17      private static final String INDENT = "  ";
    1.18      private static final int INDENT_LENGTH = INDENT.length ();
    1.19      /** An upper bound on the number of characters that can be printed to the output writer 
    1.20 @@ -35,7 +36,6 @@
    1.21      private static final String XMI_VERSION = "1.2";
    1.22      private static final String EXPORTER_NAME = "Netbeans XMI Writer";
    1.23      private static final String EXPORTER_VERSION = "1.0";
    1.24 -    private static final String DEFAULT_ENCODING = "ISO-8859-1";
    1.25      
    1.26      // variables ................................................................
    1.27              
    1.28 @@ -79,10 +79,24 @@
    1.29                  throw new SAXException (e);
    1.30              }
    1.31          }
    1.32 -        String enc = (encoding != null) ? encoding : DEFAULT_ENCODING;
    1.33 +        String enc = (encoding != null) ? encoding : canonicalNameFor(writer.getEncoding());
    1.34          write ("<?xml version = '1.0' encoding = '" + enc + "' ?>");
    1.35          writeln ();
    1.36      }
    1.37 +
    1.38 +    /**
    1.39 +     * Tries to convert the specified encoding name, which may be an historical
    1.40 +     * Java encoding name, to the equivalent canonical IANA registered charset
    1.41 +     * name.
    1.42 +     */
    1.43 +    private static String canonicalNameFor(String encoding) {
    1.44 +        try {
    1.45 +            encoding = Charset.forName(encoding).name();
    1.46 +        } catch (IllegalCharsetNameException e) {
    1.47 +        } catch (UnsupportedCharsetException e) {
    1.48 +        }
    1.49 +        return encoding;
    1.50 +    }
    1.51      
    1.52      // methods ..................................................................
    1.53       
    1.54 @@ -108,7 +122,7 @@
    1.55       */
    1.56      private void writeln () throws SAXException {
    1.57          try {
    1.58 -            writer.write ("\r\n");
    1.59 +            writer.write (EOL);
    1.60          } catch (IOException e) {
    1.61              throw new SAXException (e);
    1.62          }