|
26 | 26 |
|
27 | 27 | package java.util;
|
28 | 28 |
|
29 |
| -import com.google.j2objc.LibraryNotLinkedError; |
30 |
| -import com.google.j2objc.util.XmlLoader; |
31 | 29 | import java.io.BufferedWriter;
|
32 | 30 | import java.io.IOException;
|
33 |
| -import java.io.PrintStream; |
34 |
| -import java.io.PrintWriter; |
35 | 31 | import java.io.InputStream;
|
36 | 32 | import java.io.OutputStream;
|
37 | 33 | import java.io.OutputStreamWriter;
|
38 | 34 | import java.io.PrintStream;
|
39 | 35 | import java.io.PrintWriter;
|
40 | 36 | import java.io.Reader;
|
41 | 37 | import java.io.Writer;
|
42 |
| -import java.nio.charset.Charset; |
43 |
| -import java.nio.charset.IllegalCharsetNameException; |
44 |
| -import java.nio.charset.UnsupportedCharsetException; |
45 | 38 |
|
46 | 39 | // Android-removed: Dead native2ascii links.
|
47 | 40 | // These links are also gone in OpenJDK 9.
|
@@ -910,21 +903,16 @@ private void store0(BufferedWriter bw, String comments, boolean escUnicode)
|
910 | 903 | */
|
911 | 904 | public synchronized void loadFromXML(InputStream in)
|
912 | 905 | throws IOException, InvalidPropertiesFormatException {
|
913 |
| - XmlLoader loader = getXmlLoader(); |
914 |
| - if (loader == null) { |
915 |
| - throw new LibraryNotLinkedError( |
916 |
| - "XML support", "jre_xml", "ComGoogleJ2objcUtilPropertiesXmlLoader"); |
917 |
| - } |
918 |
| - loader.load(this, in); |
919 |
| - } |
920 |
| - |
921 |
| - private static XmlLoader getXmlLoader() { |
922 |
| - try { |
923 |
| - Class<?> loaderClass = Class.forName("com.google.j2objc.util.PropertiesXmlLoader"); |
924 |
| - return (XmlLoader) loaderClass.newInstance(); |
925 |
| - } catch (Exception e) { |
926 |
| - return null; |
927 |
| - } |
| 906 | + // Android-changed: Keep OpenJDK7u40's XmlUtils. |
| 907 | + // XmlSupport's system property based XmlPropertiesProvider |
| 908 | + // selection does not make sense on Android and has too many |
| 909 | + // dependencies on classes that are not available on Android. |
| 910 | + // |
| 911 | + // Objects.requireNonNull(in); |
| 912 | + // PropertiesDefaultHandler handler = new PropertiesDefaultHandler(); |
| 913 | + // handler.load(this, in); |
| 914 | + XMLUtils.load(this, Objects.requireNonNull(in)); |
| 915 | + in.close(); |
928 | 916 | }
|
929 | 917 |
|
930 | 918 | /**
|
@@ -994,72 +982,23 @@ public void storeToXML(OutputStream os, String comment)
|
994 | 982 | */
|
995 | 983 | public void storeToXML(OutputStream os, String comment, String encoding)
|
996 | 984 | throws IOException {
|
997 |
| - if (os == null) { |
998 |
| - throw new NullPointerException("os == null"); |
999 |
| - } else if (encoding == null) { |
1000 |
| - throw new NullPointerException("encoding == null"); |
1001 |
| - } |
1002 |
| - |
| 985 | + // Android-changed: Keep OpenJDK7u40's XmlUtils. |
| 986 | + // XmlSupport's system property based XmlPropertiesProvider |
| 987 | + // selection does not make sense on Android and has too many |
| 988 | + // dependencies on classes that are not available on Android. |
1003 | 989 | /*
|
1004 |
| - * We can write to XML file using encoding parameter but note that some |
1005 |
| - * aliases for encodings are not supported by the XML parser. Thus we |
1006 |
| - * have to know canonical name for encoding used to store data in XML |
1007 |
| - * since the XML parser must recognize encoding name used to store data. |
1008 |
| - */ |
| 990 | + Objects.requireNonNull(os); |
| 991 | + Objects.requireNonNull(encoding); |
1009 | 992 |
|
1010 |
| - String encodingCanonicalName; |
1011 | 993 | try {
|
1012 |
| - encodingCanonicalName = Charset.forName(encoding).name(); |
1013 |
| - } catch (IllegalCharsetNameException e) { |
1014 |
| - System.out.println("Warning: encoding name " + encoding |
1015 |
| - + " is illegal, using UTF-8 as default encoding"); |
1016 |
| - encodingCanonicalName = "UTF-8"; |
1017 |
| - } catch (UnsupportedCharsetException e) { |
1018 |
| - System.out.println("Warning: encoding " + encoding |
1019 |
| - + " is not supported, using UTF-8 as default encoding"); |
1020 |
| - encodingCanonicalName = "UTF-8"; |
1021 |
| - } |
1022 |
| - |
1023 |
| - PrintStream printStream = new PrintStream(os, false, |
1024 |
| - encodingCanonicalName); |
1025 |
| - |
1026 |
| - printStream.print("<?xml version=\"1.0\" encoding=\""); |
1027 |
| - printStream.print(encodingCanonicalName); |
1028 |
| - printStream.println("\"?>"); |
1029 |
| - |
1030 |
| - printStream.print("<!DOCTYPE properties SYSTEM \""); |
1031 |
| - printStream.print(PROP_DTD_NAME); |
1032 |
| - printStream.println("\">"); |
1033 |
| - |
1034 |
| - printStream.println("<properties>"); |
1035 |
| - |
1036 |
| - if (comment != null) { |
1037 |
| - printStream.print("<comment>"); |
1038 |
| - printStream.print(substitutePredefinedEntries(comment)); |
1039 |
| - printStream.println("</comment>"); |
| 994 | + Charset charset = Charset.forName(encoding); |
| 995 | + storeToXML(os, comment, charset); |
| 996 | + } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { |
| 997 | + throw new UnsupportedEncodingException(encoding); |
1040 | 998 | }
|
1041 |
| - |
1042 |
| - for (Map.Entry<Object, Object> entry : entrySet()) { |
1043 |
| - String keyValue = (String) entry.getKey(); |
1044 |
| - String entryValue = (String) entry.getValue(); |
1045 |
| - printStream.print("<entry key=\""); |
1046 |
| - printStream.print(substitutePredefinedEntries(keyValue)); |
1047 |
| - printStream.print("\">"); |
1048 |
| - printStream.print(substitutePredefinedEntries(entryValue)); |
1049 |
| - printStream.println("</entry>"); |
1050 |
| - } |
1051 |
| - printStream.println("</properties>"); |
1052 |
| - printStream.flush(); |
1053 |
| - } |
1054 |
| - |
1055 |
| - private String substitutePredefinedEntries(String s) { |
1056 |
| - // substitution for predefined character entities to use them safely in XML. |
1057 |
| - s = s.replaceAll("&", "&"); |
1058 |
| - s = s.replaceAll("<", "<"); |
1059 |
| - s = s.replaceAll(">", ">"); |
1060 |
| - s = s.replaceAll("'", "'"); |
1061 |
| - s = s.replaceAll("\"", """); |
1062 |
| - return s; |
| 999 | + */ |
| 1000 | + XMLUtils.save(this, Objects.requireNonNull(os), comment, |
| 1001 | + Objects.requireNonNull(encoding)); |
1063 | 1002 | }
|
1064 | 1003 |
|
1065 | 1004 | /**
|
|
0 commit comments