xref: /AOO41X/main/javainstaller2/src/JavaSetup/org/openoffice/setup/Util/Converter.java (revision 67e470dafe1997e73f56ff7ff4878983707e3e07)
1*9a1eeea9SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9a1eeea9SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9a1eeea9SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9a1eeea9SAndrew Rist  * distributed with this work for additional information
6*9a1eeea9SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9a1eeea9SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9a1eeea9SAndrew Rist  * "License"); you may not use this file except in compliance
9*9a1eeea9SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9a1eeea9SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9a1eeea9SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9a1eeea9SAndrew Rist  * software distributed under the License is distributed on an
15*9a1eeea9SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9a1eeea9SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9a1eeea9SAndrew Rist  * specific language governing permissions and limitations
18*9a1eeea9SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9a1eeea9SAndrew Rist  *************************************************************/
21*9a1eeea9SAndrew Rist 
22*9a1eeea9SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package org.openoffice.setup.Util;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.util.HashMap;
27cdf0e10cSrcweir import java.util.Iterator;
28cdf0e10cSrcweir import java.util.Map;
29cdf0e10cSrcweir import java.util.Vector;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir public class Converter {
32cdf0e10cSrcweir 
Converter()33cdf0e10cSrcweir     private Converter() {
34cdf0e10cSrcweir     }
35cdf0e10cSrcweir 
convertHashmapToStringArray(HashMap map)36cdf0e10cSrcweir     static public String[] convertHashmapToStringArray(HashMap map) {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir         int size = map.size();
39cdf0e10cSrcweir         String[] myStringArray = new String[size];
40cdf0e10cSrcweir 
41cdf0e10cSrcweir         Iterator m = map.entrySet().iterator();
42cdf0e10cSrcweir         int counter = 0;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir         while ( m.hasNext() ) {
45cdf0e10cSrcweir             Map.Entry entry = (Map.Entry) m.next();
46cdf0e10cSrcweir             String env = entry.getKey() + "=" + entry.getValue();
47cdf0e10cSrcweir             myStringArray[counter] = env;
48cdf0e10cSrcweir             counter = counter + 1;
49cdf0e10cSrcweir         }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir         return myStringArray;
52cdf0e10cSrcweir     }
53cdf0e10cSrcweir 
convertVectorToHashmap(Vector vec)54cdf0e10cSrcweir     static public HashMap convertVectorToHashmap(Vector vec) {
55cdf0e10cSrcweir         HashMap map = new HashMap();
56cdf0e10cSrcweir 
57cdf0e10cSrcweir         for (int i = 0; i < vec.size(); i++) {
58cdf0e10cSrcweir             String key = null;
59cdf0e10cSrcweir             String value = null;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir             String line = (String)vec.get(i);
62cdf0e10cSrcweir             int position = line.indexOf("=");
63cdf0e10cSrcweir             if ( position > -1 ) {
64cdf0e10cSrcweir                 key = line.substring(0, position);
65cdf0e10cSrcweir                 value = line.substring(position + 1, line.length());
66cdf0e10cSrcweir             } else {
67cdf0e10cSrcweir                 key = line;
68cdf0e10cSrcweir                 value = null;
69cdf0e10cSrcweir             }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir             map.put(key, value);
72cdf0e10cSrcweir         }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         return map;
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
convertHashMapToVector(HashMap hash)77cdf0e10cSrcweir     static public Vector convertHashMapToVector(HashMap hash) {
78cdf0e10cSrcweir         Vector vec = new Vector();
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         Iterator m = hash.entrySet().iterator();
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         while ( m.hasNext() ) {
83cdf0e10cSrcweir             Map.Entry entry = (Map.Entry) m.next();
84cdf0e10cSrcweir             String line = entry.getKey() + "=" + entry.getValue();
85cdf0e10cSrcweir             vec.add(line);
86cdf0e10cSrcweir         }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         return vec;
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir }
92