001: /**
002: * $Id: NetFileServerUtil.java,v 1.7 2005/11/30 11:26:39 ss150821 Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.netfile.servlet.java2;
014:
015: import java.util.*;
016:
017: import com.sun.portal.netfile.shared.*;
018:
019: public class NetFileServerUtil {
020:
021: public static synchronized String mergeCommonData(
022: String s_user_added_host_share,
023: Vector v_host_shares_set_by_admin) {
024: if (s_user_added_host_share == null) {
025: } else {
026: int i_index_of_name = s_user_added_host_share
027: .indexOf("machine_name=");
028: if (i_index_of_name < -1) {
029: } else {
030: i_index_of_name = "machine_name=".length();
031:
032: int i_index_of_eol = s_user_added_host_share
033: .indexOf("\n");
034: String s_host_added_by_user = s_user_added_host_share
035: .substring(i_index_of_name, i_index_of_eol);
036:
037: int i_host_shares_set_by_admin_number = v_host_shares_set_by_admin
038: .size();
039: for (int i = 0; i < i_host_shares_set_by_admin_number; ++i) {
040: String s_host_shares_added_by_admin = (String) (v_host_shares_set_by_admin
041: .elementAt(i));
042: i_index_of_name = "name=".length();
043: int i_index_of_parallel = s_host_shares_added_by_admin
044: .indexOf("|", i_index_of_name);
045: if (i_index_of_parallel <= i_index_of_name) {
046: i_index_of_parallel = -1;
047: }
048: String s_host_added_by_admin = null;
049: if (i_index_of_parallel < 0) {
050: s_host_added_by_admin = s_host_shares_added_by_admin
051: .substring(i_index_of_name,
052: s_host_added_by_admin.length());
053: } else {
054: s_host_added_by_admin = s_host_shares_added_by_admin
055: .substring(i_index_of_name,
056: i_index_of_parallel);
057: }
058:
059: if (s_host_added_by_user
060: .equals(s_host_added_by_admin)) {
061: s_user_added_host_share = mergeHosts(
062: s_user_added_host_share,
063: s_host_shares_added_by_admin);
064: v_host_shares_set_by_admin.removeElementAt(i);
065: break;
066: }
067: }
068: }
069: }
070:
071: return s_user_added_host_share;
072: }
073:
074: public static synchronized String mergeHosts(
075: String s_user_added_host_share,
076: String s_host_shares_added_by_admin) {
077: System.out.println("s_host_shares_added_by_admin="
078: + s_host_shares_added_by_admin);
079: int i_index_of_type = s_host_shares_added_by_admin
080: .indexOf("|type=");
081: System.out.println("i_index_of_type=" + i_index_of_type);
082: if (i_index_of_type < 0) {
083: } else {
084: i_index_of_type += "|type=".length();
085: System.out.println("i_index_of_type=" + i_index_of_type);
086: int i_index_of_parallel = s_host_shares_added_by_admin
087: .indexOf("|", i_index_of_type);
088: if (i_index_of_type >= i_index_of_parallel) {
089: i_index_of_parallel = -1;
090: }
091: System.out.println("i_index_of_parallel="
092: + i_index_of_parallel);
093: String s_type_set_by_admin = null;
094: if (i_index_of_parallel < 0) {
095: System.out.println("i_index_of_type=" + i_index_of_type
096: + ",s_host_shares_added_by_admin.length()="
097: + s_host_shares_added_by_admin.length());
098: s_type_set_by_admin = s_host_shares_added_by_admin
099: .substring(i_index_of_type,
100: s_host_shares_added_by_admin.length());
101: } else {
102: s_type_set_by_admin = s_host_shares_added_by_admin
103: .substring(i_index_of_type, i_index_of_parallel);
104: }
105:
106: //s_host_shares_added_by_admin.substring(i_index_of_type,i_index_of_parallel);
107: System.out.println("s_type_set_by_admin="
108: + s_type_set_by_admin);
109: i_index_of_type = s_user_added_host_share
110: .indexOf("\nmachine_type=");
111: i_index_of_type += "\nmachine_type=".length();
112: int i_index_of_eol = s_user_added_host_share.indexOf("\n",
113: i_index_of_type);
114: String s_user_set_type = s_user_added_host_share.substring(
115: i_index_of_type, i_index_of_eol);
116: System.out.println("s_user_set_type=" + s_user_set_type);
117: if (s_user_set_type.equals(s_type_set_by_admin)) {
118: Vector v_user_added_share_list = new Vector();
119: Vector v_admin_added_share_list = new Vector();
120: int i_index_of_share_name = 0;
121: while (true) {
122: System.out.println("i_index_of_share_name="
123: + i_index_of_share_name);
124: int i_last_index_of_share_name = i_index_of_share_name;
125: i_index_of_share_name = s_user_added_host_share
126: .indexOf("\nshare_name=",
127: i_index_of_share_name);
128:
129: if (i_index_of_share_name < -1) {
130: break;
131: }
132: if (i_last_index_of_share_name >= i_index_of_share_name) {
133: break;
134: }
135: i_index_of_share_name += ("\nshare_name=".length());
136: i_index_of_eol = s_user_added_host_share.indexOf(
137: "\n", i_index_of_share_name);
138: String s_share_added_by_user = s_user_added_host_share
139: .substring(i_index_of_share_name,
140: i_index_of_eol);
141: System.out.println("s_share_added_by_user="
142: + s_share_added_by_user);
143: v_user_added_share_list
144: .addElement(s_share_added_by_user);
145: i_index_of_share_name = i_index_of_eol;
146: }
147: i_index_of_share_name = 0;
148: while (true) {
149: int i_last_index_of_share_name = i_index_of_share_name;
150: i_index_of_share_name = s_host_shares_added_by_admin
151: .indexOf("|share=", i_index_of_share_name);
152: if (i_index_of_share_name < -1) {
153: break;
154: }
155: if (i_last_index_of_share_name >= i_index_of_share_name) {
156: break;
157: }
158: i_index_of_share_name += ("|share=".length());
159: System.out.println("|share= ends at="
160: + i_index_of_share_name);
161: i_index_of_parallel = s_host_shares_added_by_admin
162: .indexOf("|", i_index_of_share_name);
163: if (i_index_of_share_name >= i_index_of_parallel) {
164: i_index_of_parallel = -1;
165: }
166: System.out.println("index of parallel="
167: + i_index_of_parallel);
168: String s_share_added_by_admin = null;
169: if (i_index_of_parallel < 0) {
170: s_share_added_by_admin = s_host_shares_added_by_admin
171: .substring(i_index_of_share_name,
172: s_host_shares_added_by_admin
173: .length());
174: } else {
175: s_share_added_by_admin = s_host_shares_added_by_admin
176: .substring(i_index_of_share_name,
177: i_index_of_parallel);
178: }
179: System.out.println("s_share_added_by_admin="
180: + s_share_added_by_admin);
181: v_admin_added_share_list
182: .addElement(s_share_added_by_admin);
183: //i_index_of_share_name=i_index_of_eol;
184: }
185: if (v_admin_added_share_list.size() != 0) {
186: s_user_added_host_share = mergeShares(
187: s_user_added_host_share,
188: v_user_added_share_list,
189: v_admin_added_share_list);
190: }
191: }
192: }
193: return s_user_added_host_share;
194: }
195:
196: public static synchronized String mergeShares(
197: String s_user_added_host_share,
198: Vector v_user_added_share_list,
199: Vector v_admin_added_share_list) {
200: s_user_added_host_share = s_user_added_host_share.substring(0,
201: s_user_added_host_share.length() - 1);
202: int i_admin_added_share_list_size = v_admin_added_share_list
203: .size();
204: if (i_admin_added_share_list_size < 1) {
205: } else {
206: int i_user_added_share_list_size = v_user_added_share_list
207: .size();
208: for (int j = 0; j < i_admin_added_share_list_size; ++j) {
209: if (i_admin_added_share_list_size < 1) {
210: break;
211: }
212: String s_admin_added_share = (String) (v_admin_added_share_list
213: .elementAt(j));
214: System.out.println("s_admin_added_share="
215: + s_admin_added_share);
216: boolean is_this _admin_added_share_listed = false;
217: Object object_to_be_removed = null;
218: for (int i = 0; i < i_user_added_share_list_size; ++i) {
219: object_to_be_removed = v_user_added_share_list
220: .elementAt(i);
221: String s_user_added_share = (String) (object_to_be_removed);
222: if (s_admin_added_share.equals(s_user_added_share)) {
223: is_this _admin_added_share_listed = true;
224: break;
225: }
226: }
227: if (is_this _admin_added_share_listed) {
228: v_admin_added_share_list
229: .removeElement(object_to_be_removed);
230: --i_admin_added_share_list_size;
231: System.out.println((String) (object_to_be_removed)
232: + " is listed");
233: } else {
234: s_user_added_host_share += ("share_name="
235: + s_admin_added_share + "\nshare_password=\n");
236: System.out
237: .println((String) (s_user_added_host_share)
238: + " is added");
239: v_admin_added_share_list
240: .removeElement((Object) (s_user_added_host_share));
241: --i_admin_added_share_list_size;
242: }
243: }
244: }
245: s_user_added_host_share += ("\n");
246: System.out.println(s_user_added_host_share);
247: return s_user_added_host_share;
248: }
249:
250: /* public String getPlatformLocalisedString(String string){
251: return nfr_platform_locale_i18n_bucket.getString(string);
252: }
253:
254:
255: public NetFileResource getPlatformLocalisedBundle(){
256: if( nfr_platform_locale_i18n_bucket==null){
257: debug.error(" nfr_platform_locale_i18n_bucket not initialised yet in FileOption");
258: }
259: return nfr_platform_locale_i18n_bucket;
260: }
261:
262:
263: private synchronized static void setPlatformLocaleBundle()throws NetFileException{
264: if(nfr_platform_locale_i18n_bucket==null){
265: nfr_platform_locale_i18n_bucket=new NetFileResource("iwtNetFileServlet");
266: s_platform_locale_error=nfr_platform_locale_i18n_bucket.getString("error");
267: if(s_platform_locale_error==null){
268: throw new NetFileException("There is no entry for key error in iwtNetFileServlet.properties");
269: }
270: }
271: }
272:
273: */
274: }
|