Revision 3486
Added by barteau over 16 years ago
ClientViewHelper.java | ||
---|---|---|
103 | 103 |
} |
104 | 104 |
} |
105 | 105 |
//*** END: manual bind params to bean. |
106 |
|
|
107 |
try { |
|
108 |
if (action.equals("Login")) { |
|
109 |
//posted_ldapUserName = String.format(LDAP_TEMPLATE, clientViewBean.getUsername(), clientViewBean.getOrganization()); |
|
110 |
tmp = LDAP_TEMPLATE.replaceFirst("%1s", clientViewBean.getUsername()); |
|
111 |
posted_ldapUserName = tmp.replaceFirst("%2s", clientViewBean.getOrganization()); |
|
112 |
|
|
113 |
serverResponse = metacatClient.login(posted_ldapUserName, clientViewBean.getPassword()); |
|
114 |
setLoggedIn(serverResponse); |
|
115 |
message = parseXml("message", serverResponse); |
|
116 |
contactName = parseXml("name", serverResponse); |
|
117 |
clientViewBean.setMessage(ClientView.LOGIN_MESSAGE, message); |
|
118 |
clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, ""); |
|
119 |
if (isLoggedIn()) { |
|
120 |
clientViewBean.setSessionid(metacatClient.getSessionId()); |
|
106 |
if (action != null) { |
|
107 |
try { |
|
108 |
if (action.equals("Login")) { |
|
109 |
//posted_ldapUserName = String.format(LDAP_TEMPLATE, clientViewBean.getUsername(), clientViewBean.getOrganization()); |
|
110 |
tmp = LDAP_TEMPLATE.replaceFirst("%1s", clientViewBean.getUsername()); |
|
111 |
posted_ldapUserName = tmp.replaceFirst("%2s", clientViewBean.getOrganization()); |
|
112 |
|
|
113 |
serverResponse = metacatClient.login(posted_ldapUserName, clientViewBean.getPassword()); |
|
114 |
setLoggedIn(serverResponse); |
|
115 |
message = parseXml("message", serverResponse); |
|
116 |
contactName = parseXml("name", serverResponse); |
|
117 |
clientViewBean.setMessage(ClientView.LOGIN_MESSAGE, message); |
|
118 |
clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, ""); |
|
119 |
if (isLoggedIn()) { |
|
120 |
clientViewBean.setSessionid(metacatClient.getSessionId()); |
|
121 |
} |
|
122 |
//*** Now that the action has been processed, clear it. |
|
123 |
clientViewBean.setAction(""); |
|
124 |
} else if (action.equals("Logout")) { |
|
125 |
message = metacatClient.logout(); |
|
126 |
setLoggedIn(message); |
|
127 |
message = parseXml("message", message); |
|
128 |
clientViewBean.setMessage(ClientView.LOGIN_MESSAGE, message); |
|
129 |
clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, ""); |
|
130 |
if (!isLoggedIn()) { |
|
131 |
clientViewBean.setUsername(""); |
|
132 |
clientViewBean.setPassword(""); |
|
133 |
clientViewBean.setOrganization(""); |
|
134 |
clientViewBean.setSessionid(null); |
|
135 |
} |
|
136 |
//*** Now that the action has been processed, clear it. |
|
137 |
clientViewBean.setAction(""); |
|
138 |
|
|
139 |
} else if (action.equals("Delete")) { |
|
140 |
|
|
141 |
ClientFgdcHelper.clientDeleteRequest(clientViewBean, this); |
|
142 |
clientViewBean.setAction("read"); //*** Set for re-query. |
|
143 |
//*** Note: the clientViewBean will already have the updated Meta Doc Id. |
|
144 |
} else if (action.equals("Upload")) { |
|
145 |
message = ""; |
|
146 |
//*** Only process request if a file upload. |
|
147 |
if (isLoggedIn()) { |
|
148 |
//*** Init the MultipartParser. |
|
149 |
multipartParser = new MultipartParser(request, sizeLimit * 1024 * 1024); |
|
150 |
message = handlePackageUpload(clientViewBean, multipartParser); |
|
151 |
} |
|
152 |
clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, message); |
|
153 |
//*** Now that the action has been processed, clear it. |
|
154 |
clientViewBean.setAction(""); |
|
155 |
|
|
156 |
} else if (action.equals("Update")) { |
|
157 |
System.out.println("This is not implemented here. Call ClientViewHelper.jspx"); |
|
158 |
} else if (action.equals("Scope")) { |
|
159 |
message = handleDocIdSelect(); |
|
160 |
clientViewBean.setMessage(ClientView.SELECT_MESSAGE, message); |
|
161 |
} else if (action.equals("Download")) { |
|
162 |
System.out.println("ClientViewHelper.clientRequest: action = " + action); |
|
163 |
download(clientViewBean, response); |
|
121 | 164 |
} |
122 |
//*** Now that the action has been processed, clear it. |
|
123 |
clientViewBean.setAction(""); |
|
124 |
} else if (action.equals("Logout")) { |
|
125 |
message = metacatClient.logout(); |
|
126 |
setLoggedIn(message); |
|
127 |
message = parseXml("message", message); |
|
128 |
clientViewBean.setMessage(ClientView.LOGIN_MESSAGE, message); |
|
129 |
clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, ""); |
|
130 |
if (!isLoggedIn()) { |
|
131 |
clientViewBean.setUsername(""); |
|
132 |
clientViewBean.setPassword(""); |
|
133 |
clientViewBean.setOrganization(""); |
|
134 |
} |
|
135 |
//*** Now that the action has been processed, clear it. |
|
136 |
clientViewBean.setAction(""); |
|
137 | 165 |
|
138 |
} else if (action.equals("Delete")) { |
|
139 |
|
|
140 |
ClientFgdcHelper.clientDeleteRequest(clientViewBean, this); |
|
141 |
clientViewBean.setAction("read"); //*** Set for re-query. |
|
142 |
//*** Note: the clientViewBean will already have the updated Meta Doc Id. |
|
143 |
} else if (action.equals("Upload")) { |
|
144 |
message = ""; |
|
145 |
//*** Only process request if a file upload. |
|
146 |
if (isLoggedIn()) { |
|
147 |
//*** Init the MultipartParser. |
|
148 |
multipartParser = new MultipartParser(request, sizeLimit * 1024 * 1024); |
|
149 |
message = handlePackageUpload(clientViewBean, multipartParser); |
|
150 |
} |
|
151 |
clientViewBean.setMessage(ClientView.UPLOAD_MESSAGE, message); |
|
152 |
//*** Now that the action has been processed, clear it. |
|
153 |
clientViewBean.setAction(""); |
|
154 |
|
|
155 |
} else if (action.equals("Update")) { |
|
156 |
System.out.println("This is not implemented here. Call ClientViewHelper.jspx"); |
|
157 |
} else if (action.equals("Scope")) { |
|
158 |
message = handleDocIdSelect(); |
|
159 |
clientViewBean.setMessage(ClientView.SELECT_MESSAGE, message); |
|
160 |
} else if (action.equals("Download")) { |
|
161 |
System.out.println("ClientViewHelper.clientRequest: action = " + action); |
|
162 |
download(clientViewBean, response); |
|
166 |
} catch (Exception ex) { |
|
167 |
message = ex.getMessage(); |
|
168 |
clientViewBean.setMessage(ClientView.ERROR_MESSAGE, message); |
|
169 |
ex.printStackTrace(); |
|
163 | 170 |
} |
164 |
|
|
165 |
} catch (Exception ex) { |
|
166 |
message = ex.getMessage(); |
|
167 |
clientViewBean.setMessage(ClientView.ERROR_MESSAGE, message); |
|
168 |
ex.printStackTrace(); |
|
169 | 171 |
} |
170 | 172 |
} else { |
171 | 173 |
System.out.println("ClientViewHelper.clientRequest: ClientView bean is not instantiated."); |
... | ... | |
262 | 264 |
int sizeLimit, idx; |
263 | 265 |
InputStream inputStream; |
264 | 266 |
HashMap paramsMap, dataDocIDs; |
265 |
StringBuilder fileName;
|
|
267 |
StringBuffer fileName;
|
|
266 | 268 |
boolean sendIt; |
267 | 269 |
|
268 | 270 |
//*** Get the First file, which should be the metadata file. |
269 | 271 |
paramsMap = new HashMap(); |
270 |
fileName = new StringBuilder();
|
|
272 |
fileName = new StringBuffer();
|
|
271 | 273 |
inputStream = getNextInputStream(multipartParser, fileName, paramsMap); |
272 | 274 |
metaFileName = fileName.toString(); |
273 | 275 |
if (metaFileName.toLowerCase().endsWith(".xml")) { |
... | ... | |
279 | 281 |
|
280 | 282 |
//*** Loop thru all of the data files, get fileName and inputStream. |
281 | 283 |
dataDocIDs = new HashMap(); |
282 |
fileName = new StringBuilder();
|
|
284 |
fileName = new StringBuffer();
|
|
283 | 285 |
while ((inputStream = getNextInputStream(multipartParser, fileName, paramsMap)) != null) { |
284 | 286 |
//*** Get the data file's DOC ID. |
285 | 287 |
nextDocId = nextDocId(lastDocId, clientViewBean.getUsername()); |
... | ... | |
290 | 292 |
getMetacatClient().upload(nextDocId, fileName.toString(), inputStream, Integer.MAX_VALUE); |
291 | 293 |
|
292 | 294 |
lastDocId = nextDocId; |
293 |
fileName = new StringBuilder();
|
|
295 |
fileName = new StringBuffer();
|
|
294 | 296 |
} |
295 | 297 |
|
296 | 298 |
if (ClientFgdcHelper.isFGDC(getMetadataDoc())) { |
... | ... | |
327 | 329 |
String result = "", fNm, action, lastDocId, newDocId, xPathQuery, qFrmt; |
328 | 330 |
InputStream inputStream; |
329 | 331 |
HashMap paramsMap; |
330 |
StringBuilder fileName;
|
|
332 |
StringBuffer fileName;
|
|
331 | 333 |
Iterator iterIt; |
332 | 334 |
boolean sendIt; |
333 | 335 |
String metadataDocId, fileInfo[]; |
334 | 336 |
|
335 | 337 |
paramsMap = new HashMap(); |
336 |
fileName = new StringBuilder();
|
|
338 |
fileName = new StringBuffer();
|
|
337 | 339 |
if ((inputStream = getNextInputStream(multipartParser, fileName, paramsMap)) != null) { |
338 | 340 |
action = (String) paramsMap.get("action"); |
339 | 341 |
//*** Get the Doc Id. |
... | ... | |
446 | 448 |
return(newDocId); |
447 | 449 |
} |
448 | 450 |
|
449 |
private InputStream getNextInputStream(MultipartParser multipartParser, StringBuilder fileName, HashMap paramsMap)
|
|
451 |
private InputStream getNextInputStream(MultipartParser multipartParser, StringBuffer fileName, HashMap paramsMap)
|
|
450 | 452 |
throws IOException { |
451 | 453 |
InputStream result = null; |
452 | 454 |
Part part; |
... | ... | |
462 | 464 |
} else if (part.isFile()) { |
463 | 465 |
fnam = ((FilePart) part).getFileName(); |
464 | 466 |
if (fnam != null && !fnam.equals("")) { |
465 |
//*** File name is passed back via StringBuilder fileName param.
|
|
467 |
//*** File name is passed back via StringBuffer fileName param.
|
|
466 | 468 |
fileName.append(fnam); |
467 | 469 |
result = ((FilePart) part).getInputStream(); |
468 | 470 |
System.out.println("ClientViewHelper.getNextInputStream: fileName = " + fileName + " inputStream = " + result.toString()); |
Also available in: Unified diff
Fixed 3 bugs:
1) If there is a call to this class without an "action" (i.e. the initial time the login form is loaded) a null pointer exception would be thrown.
2) If the user logged out, and then tried to query, the server would send an error (invalidated session)
3) When the code is compiled under 1.4, the usages of StringBuilder would error. Replaced them with StringBuffer.