001: /*
002: * $Id: NetfileUtil.java,v 1.9 2003/06/20 11:39:57 mm132998 Exp $
003: * $Source: /m/portal/ps/srap/src/migration/modules/srap/ldap/Attic/NetfileUtil.java,v $
004: * $Log: NetfileUtil.java,v $
005: * Revision 1.9 2003/06/20 11:39:57 mm132998
006: * Initial changes for 6.2
007: *
008: * Revision 1.8.2.1 2002/09/30 10:48:25 bv131302
009: * LihueRtm_branch changes
010: *
011: * Revision 1.7.2.1 2002/09/13 15:34:29 mm132998
012: * CRT #1963
013: *
014: * Revision 1.7 2002/08/28 13:57:57 bv131302
015: * Hana CRT#1924 - password lowercased
016: *
017: * Revision 1.6 2002/08/27 16:42:08 mm132998
018: * CRT : 1921
019: *
020: * Revision 1.5 2002/08/21 10:44:19 bv131302
021: * 4730557 fix
022: *
023: * Revision 1.4 2002/08/19 15:04:04 bv131302
024: * commonhost data migration
025: *
026: * Revision 1.3 2002/08/14 12:34:19 mm132998
027: * CRT : 1868 , Bugs : 4730677 ,4730681 , 4730685
028: *
029: * Revision 1.2 2002/07/22 08:47:29 mm132998
030: * Bug ID - 4718198 , Desc - Initial code changes
031: *
032: *
033: */
034: /**
035: * $Id: NetfileUtil.java,v 1.9 2003/06/20 11:39:57 mm132998 Exp $
036: * Copyright 2002 Sun Microsystems, Inc. All
037: * rights reserved. Use of this product is subject
038: * to license terms. Federal Acquisitions:
039: * Commercial Software -- Government Users
040: * Subject to Standard License Terms and
041: * Conditions.
042: *
043: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
044: * are trademarks or registered trademarks of Sun Microsystems,
045: * Inc. in the United States and other countries.
046: */package migration.modules.srap.ldap;
047:
048: import java.util.*;
049:
050: public class NetfileUtil {
051: static final String SEP = "\n";
052: static final String ENCODING = "Unicode(UTF-8)";
053: static final String IPS3_MACHINE_NAME = "name";
054: static final String IPS3_MACHINE_TYPE = "type";
055: static final String IPS3_MACHINE_DOMAIN = "domain";
056: static final String IPS3_MACHINE_PASSWORD = "password";
057: static final String IPS3_MACHINE_USER_NAME = "username";
058: static final String IPS3_SHARE_NAME = "share";
059: static final String IPS3_WIN_PASSWORD = "winpassword";
060:
061: static final String IPS6_MACHINE_NAME = "machine_name=";
062: static final String IPS6_MACHINE_TYPE = "machine_type=";
063: static final String IPS6_MACHINE_DOMAIN = "machine_domain=";
064: static final String IPS6_MACHINE_PASSWORD = "machine_password=";
065: static final String IPS6_MACHINE_USER_NAME = "machine_user_name=";
066: static final String IPS6_SHARE_NAME = "share_name=";
067: static final String IPS6_SHARE_PASSWORD = "share_password=";
068: static final String IPS6_MACHINE_ENCODING = "machine_encoding=";
069:
070: public static final int STRING_ARRAY = 1;
071: public static final int SINGLE_STRING = 2;
072:
073: public static void main(String args[]) {
074: String sampleData = "name=pserv8|type=WIN|username=nfjuser|password=nfjuser|share=test|winpassword=nfjuser^name=pserv5|type=NFS|username=nfjuser|password=nfjuser|share=/space/home/nfjuser/non-empty^name=pserv1|type=FTP|username=nfjuser|password=nfjuser|share=/usr/home/nfjuser/non-empty^name=pserv10*iportal|type=NT|username=nfjuser|password=nfjuser|share=test^name=pserv11|type=NETWARE|username=nfjuser|password=nfjuser|share=/sys/home/nfjuser/non-empty^name=pserv10|domain=IPORTAL|type=NT|share=test^";
075: System.out.println("IPS 3.0 data :");
076: System.out.println(sampleData);
077: System.out.println();
078: System.out.println("IPS 6.0 data :");
079: System.out.println(getHostTypePassShareAttrb(sampleData,
080: SINGLE_STRING));
081: }
082:
083: public static Object getHostTypePassShareAttrb(String hostData,
084: int retType) {
085: if (hostData == null)
086: return null;
087: StringBuffer newAttrib = new StringBuffer();
088: LinkedList retvalList = new LinkedList();
089:
090: StringTokenizer hostTypePassShares = new StringTokenizer(
091: hostData, "^");
092: while (hostTypePassShares.hasMoreTokens()) {
093: boolean isWin = false;
094: String hostinfo = hostTypePassShares.nextToken();
095: HashMap map = getHostTypePassShareMap(hostinfo);
096:
097: newAttrib.append(IPS6_MACHINE_NAME);
098: if (map.containsKey(IPS3_MACHINE_NAME)) {
099: newAttrib.append((String) map.get(IPS3_MACHINE_NAME));
100: }
101: newAttrib.append(SEP);
102:
103: newAttrib.append(IPS6_MACHINE_TYPE);
104: if (map.containsKey(IPS3_MACHINE_TYPE)) {
105: String type = (String) map.get(IPS3_MACHINE_TYPE);
106: newAttrib.append(type);
107: if (type.equals("WIN")) {
108: isWin = true;
109: }
110: }
111: newAttrib.append(SEP);
112:
113: newAttrib.append(IPS6_MACHINE_ENCODING);
114: newAttrib.append(ENCODING);
115: newAttrib.append(SEP);
116:
117: newAttrib.append(IPS6_MACHINE_DOMAIN);
118: if (map.containsKey(IPS3_MACHINE_DOMAIN)) {
119: newAttrib.append((String) map.get(IPS3_MACHINE_DOMAIN));
120: }
121: newAttrib.append(SEP);
122:
123: newAttrib.append(IPS6_MACHINE_PASSWORD);
124: if (map.containsKey(IPS3_MACHINE_PASSWORD)) {
125: newAttrib.append((String) map
126: .get(IPS3_MACHINE_PASSWORD));
127: }
128: newAttrib.append(SEP);
129:
130: newAttrib.append(IPS6_MACHINE_USER_NAME);
131: if (map.containsKey(IPS3_MACHINE_USER_NAME)) {
132: newAttrib.append((String) map
133: .get(IPS3_MACHINE_USER_NAME));
134: }
135: newAttrib.append(SEP);
136:
137: newAttrib.append(IPS6_SHARE_NAME);
138: if (map.containsKey(IPS3_SHARE_NAME)) {
139: newAttrib.append((String) map.get(IPS3_SHARE_NAME));
140: }
141: newAttrib.append(SEP);
142:
143: newAttrib.append(IPS6_SHARE_PASSWORD);
144: if (isWin) {
145: if (map.containsKey(IPS3_WIN_PASSWORD)) {
146: newAttrib.append((String) map
147: .get(IPS3_WIN_PASSWORD));
148: }
149: } else {
150: if (map.containsKey(IPS3_MACHINE_PASSWORD)) {
151: newAttrib.append((String) map
152: .get(IPS3_MACHINE_PASSWORD));
153: }
154: }
155: newAttrib.append(SEP);
156: if (retType == STRING_ARRAY) {
157: retvalList.add(newAttrib.toString());
158: newAttrib.setLength(0);
159: }
160: }
161: if (retType == STRING_ARRAY) {
162: // Convert the LinkedList to an Array and return that.
163: String retArray[] = new String[retvalList.size()];
164: Iterator iter = retvalList.iterator();
165: int count;
166: for (count = 0; count < retArray.length; count++) {
167: retArray[count] = iter.next().toString();
168: }
169: return retArray;
170: }
171: return newAttrib.toString();
172: }
173:
174: public static HashMap getHostTypePassShareMap(String hostinfo) {
175: HashMap map = new HashMap();
176: StringTokenizer hostTypePassShareTokens = new StringTokenizer(
177: hostinfo, "|");
178: while (hostTypePassShareTokens.hasMoreTokens()) {
179: String hostTypePassShareToken = hostTypePassShareTokens
180: .nextToken();
181: StringTokenizer keyval = new StringTokenizer(
182: hostTypePassShareToken, "=");
183: if (keyval.countTokens() == 2) {
184: String key = keyval.nextToken();
185: String val = keyval.nextToken();
186: int indx = val.indexOf("*");
187: if ((key.equals(IPS3_MACHINE_NAME)) && (indx != -1)) {
188: map.put(key, val.substring(0, indx));
189: map.put(IPS3_MACHINE_DOMAIN, val.substring(
190: indx + 1, val.length()));
191: } else {
192: map.put(key, val);
193: }
194: }
195: }
196: return map;
197: }
198: }
|