jdk/src/share/classes/java/util/prefs/XmlSupport.java
changeset 11274 7e7196757acd
parent 5506 202f599c92aa
child 14014 da3648e13e67
equal deleted inserted replaced
11139:db0c2ff5e1ea 11274:7e7196757acd
   104         Element xmlRoot =  (Element)
   104         Element xmlRoot =  (Element)
   105         preferences.appendChild(doc.createElement("root"));
   105         preferences.appendChild(doc.createElement("root"));
   106         xmlRoot.setAttribute("type", (p.isUserNode() ? "user" : "system"));
   106         xmlRoot.setAttribute("type", (p.isUserNode() ? "user" : "system"));
   107 
   107 
   108         // Get bottom-up list of nodes from p to root, excluding root
   108         // Get bottom-up list of nodes from p to root, excluding root
   109         List ancestors = new ArrayList();
   109         List<Preferences> ancestors = new ArrayList<>();
   110 
   110 
   111         for (Preferences kid = p, dad = kid.parent(); dad != null;
   111         for (Preferences kid = p, dad = kid.parent(); dad != null;
   112                                    kid = dad, dad = kid.parent()) {
   112                                    kid = dad, dad = kid.parent()) {
   113             ancestors.add(kid);
   113             ancestors.add(kid);
   114         }
   114         }
   115         Element e = xmlRoot;
   115         Element e = xmlRoot;
   116         for (int i=ancestors.size()-1; i >= 0; i--) {
   116         for (int i=ancestors.size()-1; i >= 0; i--) {
   117             e.appendChild(doc.createElement("map"));
   117             e.appendChild(doc.createElement("map"));
   118             e = (Element) e.appendChild(doc.createElement("node"));
   118             e = (Element) e.appendChild(doc.createElement("node"));
   119             e.setAttribute("name", ((Preferences)ancestors.get(i)).name());
   119             e.setAttribute("name", ancestors.get(i).name());
   120         }
   120         }
   121         putPreferencesInXml(e, doc, p, subTree);
   121         putPreferencesInXml(e, doc, p, subTree);
   122 
   122 
   123         writeDoc(doc, os);
   123         writeDoc(doc, os);
   124     }
   124     }
   337      * as the internal (undocumented) format for FileSystemPrefs.
   337      * as the internal (undocumented) format for FileSystemPrefs.
   338      *
   338      *
   339      * @throws IOException if writing to the specified output stream
   339      * @throws IOException if writing to the specified output stream
   340      *         results in an <tt>IOException</tt>.
   340      *         results in an <tt>IOException</tt>.
   341      */
   341      */
   342     static void exportMap(OutputStream os, Map map) throws IOException {
   342     static void exportMap(OutputStream os, Map<String, String> map) throws IOException {
   343         Document doc = createPrefsDoc("map");
   343         Document doc = createPrefsDoc("map");
   344         Element xmlMap = doc.getDocumentElement( ) ;
   344         Element xmlMap = doc.getDocumentElement( ) ;
   345         xmlMap.setAttribute("MAP_XML_VERSION", MAP_XML_VERSION);
   345         xmlMap.setAttribute("MAP_XML_VERSION", MAP_XML_VERSION);
   346 
   346 
   347         for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) {
   347         for (Iterator<Map.Entry<String, String>> i = map.entrySet().iterator(); i.hasNext(); ) {
   348             Map.Entry e = (Map.Entry) i.next();
   348             Map.Entry<String, String> e = i.next();
   349             Element xe = (Element)
   349             Element xe = (Element)
   350                 xmlMap.appendChild(doc.createElement("entry"));
   350                 xmlMap.appendChild(doc.createElement("entry"));
   351             xe.setAttribute("key",   (String) e.getKey());
   351             xe.setAttribute("key",   e.getKey());
   352             xe.setAttribute("value", (String) e.getValue());
   352             xe.setAttribute("value", e.getValue());
   353         }
   353         }
   354 
   354 
   355         writeDoc(doc, os);
   355         writeDoc(doc, os);
   356     }
   356     }
   357 
   357 
   366      * @throws IOException if reading from the specified output stream
   366      * @throws IOException if reading from the specified output stream
   367      *         results in an <tt>IOException</tt>.
   367      *         results in an <tt>IOException</tt>.
   368      * @throws InvalidPreferencesFormatException Data on input stream does not
   368      * @throws InvalidPreferencesFormatException Data on input stream does not
   369      *         constitute a valid XML document with the mandated document type.
   369      *         constitute a valid XML document with the mandated document type.
   370      */
   370      */
   371     static void importMap(InputStream is, Map m)
   371     static void importMap(InputStream is, Map<String, String> m)
   372         throws IOException, InvalidPreferencesFormatException
   372         throws IOException, InvalidPreferencesFormatException
   373     {
   373     {
   374         try {
   374         try {
   375             Document doc = loadPrefsDoc(is);
   375             Document doc = loadPrefsDoc(is);
   376             Element xmlMap = doc.getDocumentElement();
   376             Element xmlMap = doc.getDocumentElement();