KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > dialog > DialogWebDAV


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.dialog;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.gui.control.Button;
17 import info.magnolia.cms.gui.control.Hidden;
18 import info.magnolia.cms.gui.misc.CssConstants;
19 import info.magnolia.cms.gui.misc.Sources;
20 import info.magnolia.cms.gui.misc.Spacer;
21 import info.magnolia.cms.i18n.MessagesManager;
22
23 import java.io.IOException JavaDoc;
24 import java.io.UnsupportedEncodingException JavaDoc;
25 import java.io.Writer JavaDoc;
26 import java.net.URLDecoder JavaDoc;
27 import java.text.DateFormat JavaDoc;
28 import java.text.SimpleDateFormat JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collections JavaDoc;
31 import java.util.Date JavaDoc;
32 import java.util.Enumeration JavaDoc;
33 import java.util.Hashtable JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Map JavaDoc;
37
38 import javax.jcr.PropertyType;
39 import javax.jcr.RepositoryException;
40 import javax.servlet.http.HttpServletRequest JavaDoc;
41 import javax.servlet.http.HttpServletResponse JavaDoc;
42
43 import org.apache.commons.httpclient.HttpURL;
44 import org.apache.commons.lang.StringUtils;
45 import org.apache.log4j.Logger;
46 import org.apache.webdav.lib.Property;
47 import org.apache.webdav.lib.WebdavResource;
48 import org.apache.webdav.lib.methods.XMLResponseMethodBase;
49
50
51 /**
52  * @author Vinzenz Wyser
53  * @version 2.0
54  */

55 public class DialogWebDAV extends DialogBox {
56
57     private static final int ICONS_HEIGHT = 16;
58
59     private static final int ICONS_WIDTH = 23;
60
61     public static final String JavaDoc NULLGIF = "/admindocroot/0.gif"; //$NON-NLS-1$
62

63     /**
64      * Logger.
65      */

66     private static Logger log = Logger.getLogger(DialogWebDAV.class);
67
68     // dev; remove values later (StringUtils.EMPTY; not null!)
69
private String JavaDoc host = StringUtils.EMPTY;
70
71     private int port;
72
73     private String JavaDoc directory = StringUtils.EMPTY;
74
75     private String JavaDoc subDirectory = StringUtils.EMPTY;
76
77     private String JavaDoc user = StringUtils.EMPTY;
78
79     private String JavaDoc password = StringUtils.EMPTY;
80
81     private String JavaDoc protocol = "http"; //$NON-NLS-1$
82

83     private WebdavResource davConnection;
84
85     /**
86      * Empty constructor should only be used by DialogFactory.
87      */

88     protected DialogWebDAV() {
89     }
90
91     /**
92      * @see info.magnolia.cms.gui.dialog.DialogInterface#init(HttpServletRequest, HttpServletResponse, Content, Content)
93      */

94     public void init(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Content websiteNode, Content configNode)
95         throws RepositoryException {
96         super.init(request, response, websiteNode, configNode);
97         initIconExtensions();
98     }
99
100     public void setHost(String JavaDoc s) {
101         this.host = s;
102     }
103
104     public String JavaDoc getHost() {
105         return this.host;
106     }
107
108     public void setPort(String JavaDoc s) {
109         try {
110             this.port = (new Integer JavaDoc(s)).intValue();
111         }
112         catch (NumberFormatException JavaDoc nfe) {
113             this.port = 0;
114         }
115     }
116
117     public void setPort(int i) {
118         this.port = i;
119     }
120
121     public int getPort() {
122         if (this.port == 0) {
123             return 80;
124         }
125
126         return this.port;
127     }
128
129     public void setDirectory(String JavaDoc s) {
130         this.directory = s;
131     }
132
133     public String JavaDoc getDirectory() {
134         return this.directory;
135     }
136
137     public void setSubDirectory(String JavaDoc s) {
138         this.subDirectory = s;
139     }
140
141     public String JavaDoc getSubDirectory() {
142         return this.subDirectory;
143     }
144
145     public void setUser(String JavaDoc s) {
146         this.user = s;
147     }
148
149     public String JavaDoc getUser() {
150         return this.user;
151     }
152
153     public void setPassword(String JavaDoc s) {
154         this.password = s;
155     }
156
157     public String JavaDoc getPassword() {
158         return this.password;
159     }
160
161     public void setProtocol(String JavaDoc s) {
162         this.protocol = s;
163     }
164
165     public String JavaDoc getProtocol() {
166         return this.protocol;
167     }
168
169     public String JavaDoc getHtmlDecodeURI(String JavaDoc s) {
170         return "<script type=\"text/javascript\">document.write(decodeURI(\"" + s + "\"));</script>"; //$NON-NLS-1$ //$NON-NLS-2$
171
}
172
173     public void setDAVConnection(WebdavResource w) {
174         this.davConnection = w;
175     }
176
177     public WebdavResource getDAVConnection() {
178         return this.davConnection;
179     }
180
181     private String JavaDoc getSizeValue() {
182         if (this.getWebsiteNode() != null) {
183             return this.getWebsiteNode().getNodeData(this.getName() + "_size").getString(); //$NON-NLS-1$
184
}
185
186         return StringUtils.EMPTY;
187     }
188
189     private String JavaDoc getModDateValue() {
190         if (this.getWebsiteNode() != null) {
191             return this.getWebsiteNode().getNodeData(this.getName() + "_lastModified").getString(); //$NON-NLS-1$
192
}
193
194         return StringUtils.EMPTY;
195     }
196
197     public void setDAVConnection() {
198         WebdavResource wdr = null;
199         try {
200
201             wdr = new WebdavResource(new HttpURL(
202                 this.getUser(),
203                 this.getPassword(),
204                 this.getHost(),
205                 this.getPort(),
206                 this.getDirectory()));
207
208         }
209         catch (Exception JavaDoc e) {
210             log.error(e.getMessage(), e);
211         }
212         this.setDAVConnection(wdr);
213     }
214
215     /**
216      * @see info.magnolia.cms.gui.dialog.DialogInterface#drawHtml(Writer)
217      */

218     public void drawHtml(Writer JavaDoc out) throws IOException JavaDoc {
219         this.drawHtmlPre(out);
220         this.setDAVConnection();
221         this.setSessionAttribute();
222         String JavaDoc showName = "&nbsp;"; //$NON-NLS-1$
223
String JavaDoc showPath = StringUtils.EMPTY;
224         String JavaDoc showIcon = StringUtils.EMPTY;
225         if (StringUtils.isNotEmpty(this.getValue())) {
226             String JavaDoc valueTmp = StringUtils.EMPTY;
227             boolean isDirectory = false;
228             if (this.getValue().lastIndexOf("/") == this.getValue().length() - 1) { //$NON-NLS-1$
229
// value is directory
230
valueTmp = this.getValue().substring(0, this.getValue().length() - 1);
231                 isDirectory = true;
232                 this.setSubDirectory(this.getValue());
233                 showIcon = ICONS_PATH + ICONS_FOLDER;
234             }
235             else {
236                 // value is file
237
valueTmp = this.getValue();
238                 showIcon = this.getIconPath(this.getValue());
239             }
240             if (valueTmp.indexOf("/") != -1) { //$NON-NLS-1$
241
showName = valueTmp.substring(valueTmp.lastIndexOf("/") + 1); //$NON-NLS-1$
242
if (!isDirectory) {
243                     this.setSubDirectory(valueTmp.substring(0, valueTmp.lastIndexOf("/") + 1)); //$NON-NLS-1$
244
}
245             }
246             else {
247                 showName = valueTmp;
248                 if (!isDirectory) {
249                     this.setSubDirectory(StringUtils.EMPTY);
250                 }
251             }
252             showPath = "/" + this.getSubDirectory().substring(0, this.getSubDirectory().lastIndexOf("/") + 1); //$NON-NLS-1$ //$NON-NLS-2$
253
showPath = "<a HREF=\"javascript:mgnlDialogDAVBrowse('" //$NON-NLS-1$
254
+ this.getName() + "_iFrame','selectedValue');\">" //$NON-NLS-1$
255
+ this.getHtmlDecodeURI(showPath) + "</a>"; //$NON-NLS-1$
256
}
257         else {
258             showPath = "<i>" + MessagesManager.get(this.getRequest(), "dialog.webdav.noSelection") + "</i>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
259
showIcon = NULLGIF;
260         }
261
262         this.setDescription(MessagesManager.get(this.getRequest(), "dialog.webdav.connectedTo") //$NON-NLS-1$
263
+ this.getProtocol() + "://" //$NON-NLS-1$
264
+ this.getHost() + ":" //$NON-NLS-1$
265
+ this.getPort() + this.getDirectory() + "<br />" //$NON-NLS-1$
266
+ this.getDescription());
267         out.write(Spacer.getHtml(2, 2));
268         out.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">"); //$NON-NLS-1$
269
out.write("<tr>"); //$NON-NLS-1$
270
out.write("<td><img id=\"" //$NON-NLS-1$
271
+ this.getName() + "_showIcon\" SRC=\"" //$NON-NLS-1$
272
+ this.getRequest().getContextPath() + showIcon + "\" width=\"" //$NON-NLS-1$
273
+ ICONS_WIDTH + "\" height=\"" //$NON-NLS-1$
274
+ ICONS_HEIGHT + "\"></td>"); //$NON-NLS-1$
275
out.write("<td id=\"" + this.getName() + "_showName\">" //$NON-NLS-1$ //$NON-NLS-2$
276
+ this.getHtmlDecodeURI(showName) + "</td>"); //$NON-NLS-1$
277
out.write("</tr><tr height=\"4\"><td></td></tr><tr>"); //$NON-NLS-1$
278
out.write("<td><img SRC=\"" //$NON-NLS-1$
279
+ this.getRequest().getContextPath() + ICONS_PATH + ICONS_FOLDER + "\"></td>"); //$NON-NLS-1$
280
out.write("<td id=\"" + this.getName() + "_showPath\">" + showPath + "</td>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
281
out.write("</tr></table>"); //$NON-NLS-1$
282
out.write(new Hidden(this.getName(), this.getValue()).getHtml());
283         Hidden size = new Hidden(this.getName() + "_size", this.getSizeValue()); //$NON-NLS-1$
284
size.setType(PropertyType.TYPENAME_LONG);
285         out.write(size.getHtml());
286         Hidden lastMod = new Hidden(this.getName() + "_lastModified", this.getModDateValue()); //$NON-NLS-1$
287
lastMod.setType(PropertyType.TYPENAME_DATE);
288         out.write(lastMod.getHtml());
289         out.write(this.getHtmlSessionAttributeRemoveControl());
290         out.write(Spacer.getHtml(12, 12));
291         Button home = new Button();
292         home.setSaveInfo(false);
293         home.setLabel(MessagesManager.get(this.getRequest(), "dialog.webdav.home")); //$NON-NLS-1$
294
home.setOnclick("mgnlDialogDAVBrowse('" //$NON-NLS-1$
295
+ this.getName() + "_iFrame','homeDirectory')"); //$NON-NLS-1$
296
out.write(home.getHtml());
297         Button refresh = new Button();
298         refresh.setSaveInfo(false);
299         refresh.setLabel(MessagesManager.get(this.getRequest(), "dialog.webdav.refresh")); //$NON-NLS-1$
300
refresh.setOnclick("mgnlDialogDAVBrowse('" + this.getName() //$NON-NLS-1$
301
+ "_iFrame','refreshDirectory')"); //$NON-NLS-1$
302
out.write(refresh.getHtml());
303         Button up = new Button();
304         up.setSaveInfo(false);
305         up.setId(this.getName() + "_upDiv"); //$NON-NLS-1$
306
up.setLabel(MessagesManager.get(this.getRequest(), "dialog.webdav.parentdirectory")); //$NON-NLS-1$
307
up.setOnclick("mgnlDialogDAVBrowse('" //$NON-NLS-1$
308
+ this.getName() + "_iFrame','parentDirectory')"); //$NON-NLS-1$
309
out.write(up.getHtml());
310         out.write(Spacer.getHtml(3, 3));
311         // #################
312
// iFrame
313
// #################
314
out.write("<iframe"); //$NON-NLS-1$
315
out.write(" id=\"" + this.getName() + "_iFrame\""); //$NON-NLS-1$ //$NON-NLS-2$
316
out.write(" class=\"" + CssConstants.CSSCLASS_WEBDAVIFRAME + "\""); //$NON-NLS-1$ //$NON-NLS-2$
317
if (this.getConfigValue("height", null) != null) { //$NON-NLS-1$
318
out.write(" style=\"height:" + this.getConfigValue("height") + ";\")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
319
}
320         out.write(" frameborder=\"0\""); //$NON-NLS-1$
321
out.write(" SRC=\"/.magnolia/dialogpages/webDAVIFrame.html?" //$NON-NLS-1$
322
+ SESSION_ATTRIBUTENAME_DIALOGOBJECT + "=" //$NON-NLS-1$
323
+ this.getConfigValue(SESSION_ATTRIBUTENAME_DIALOGOBJECT) + "&mgnlCK=" //$NON-NLS-1$
324
+ new Date JavaDoc().getTime() + "\""); //$NON-NLS-1$
325
out.write(" reloadsrc=\"0\""); //$NON-NLS-1$
326
out.write(" usecss=\"1\""); //$NON-NLS-1$
327
out.write(" strict_output=\"1\""); //$NON-NLS-1$
328
out.write(" content_type=\"application/xhtml+xml\""); //$NON-NLS-1$
329
out.write(" scrolling=\"auto\""); //$NON-NLS-1$
330
out.write("></iframe>"); //$NON-NLS-1$
331
this.drawHtmlPost(out);
332     }
333
334     public void drawHtmlList(Writer JavaDoc out) {
335         Enumeration JavaDoc fileList = null;
336         String JavaDoc dir = this.getDirectory() + this.getSubDirectory();
337         WebdavResource wdr = this.getDAVConnection();
338         try {
339             dir = URLDecoder.decode(dir, "UTF-8"); //$NON-NLS-1$
340
}
341         catch (UnsupportedEncodingException JavaDoc uee) {
342             // should never happen
343
}
344         try {
345             if (StringUtils.isEmpty(dir)) {
346                 fileList = wdr.propfindMethod(1);
347             }
348             else {
349                 try {
350                     fileList = wdr.propfindMethod(dir, 1);
351                 }
352                 catch (Exception JavaDoc e) {
353                     dir = this.getDirectory();
354                     fileList = wdr.propfindMethod(dir, 1);
355                 }
356             }
357             out.write("<html><head>"); //$NON-NLS-1$
358
out.write(new Sources(this.getRequest().getContextPath()).getHtmlCss());
359             out.write(new Sources(this.getRequest().getContextPath()).getHtmlJs());
360             String JavaDoc parentDirectory = StringUtils.EMPTY;
361             if (!this.getDirectory().equals(dir)) {
362                 parentDirectory = this.getSubDirectory().substring(0, this.getSubDirectory().length() - 1); // get rid
363
// of last /
364
// (/dir/home/
365
// ->
366
// /dir/home)
367
parentDirectory = parentDirectory.substring(0, parentDirectory.lastIndexOf("/") + 1); //$NON-NLS-1$
368
out.write("<script type=\"text/javascript\">mgnlDialogDAVShow('" //$NON-NLS-1$
369
+ this.getName() + "_upDiv',true);</script>"); //$NON-NLS-1$
370
}
371             else {
372                 // home
373
out.write("<script type=\"text/javascript\">mgnlDialogDAVShow('" //$NON-NLS-1$
374
+ this.getName() + "_upDiv',false);</script>"); //$NON-NLS-1$
375
}
376             out.write("</head>"); //$NON-NLS-1$
377
out.write("<body>"); //$NON-NLS-1$
378
out.write("<table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\">"); //$NON-NLS-1$
379
out.write("<form name=\"mgnlDialogDAVBrowseForm\" method=\"post\">"); //$NON-NLS-1$
380
out.write(new Hidden("subDirectory", StringUtils.EMPTY, false).getHtml()); //$NON-NLS-1$
381
out.write(new Hidden("parentDirectory", parentDirectory, false).getHtml()); //$NON-NLS-1$
382
out.write(new Hidden("homeDirectory", StringUtils.EMPTY, false).getHtml()); //$NON-NLS-1$
383
out.write(new Hidden("refreshDirectory", this.getSubDirectory(), false).getHtml()); //$NON-NLS-1$
384
out.write(new Hidden("selectedValue", this.getValue(), false).getHtml()); //$NON-NLS-1$
385
out.write(new Hidden(SESSION_ATTRIBUTENAME_DIALOGOBJECT, this
386                 .getConfigValue(SESSION_ATTRIBUTENAME_DIALOGOBJECT), false).getHtml());
387             out.write("</form>"); //$NON-NLS-1$
388
List JavaDoc fileListAS = new ArrayList JavaDoc();
389             List JavaDoc dirListAS = new ArrayList JavaDoc();
390             List JavaDoc selfAS = new ArrayList JavaDoc();
391             while (fileList.hasMoreElements()) {
392                 XMLResponseMethodBase.Response response = (XMLResponseMethodBase.Response) fileList.nextElement();
393                 Map JavaDoc properties = this.getDAVProperties(response);
394                 if (StringUtils.isEmpty((String JavaDoc) properties.get("name"))) { //$NON-NLS-1$
395
continue;
396                 }
397                 String JavaDoc name = (String JavaDoc) properties.get("name"); //$NON-NLS-1$
398
if (this.getSubDirectory().equals(name) || this.getSubDirectory().equals(name + "/")) { //$NON-NLS-1$
399
// self directory
400
properties.put("isSelf", "true"); //$NON-NLS-1$ //$NON-NLS-2$
401
}
402                 if (name.indexOf("/") != -1) { //$NON-NLS-1$
403
// when path contains spaces, the name contains the entire path -> get rid of path
404
name = name.substring(name.lastIndexOf("/") + 1); //$NON-NLS-1$
405
}
406                 if (name.startsWith("._")) { //$NON-NLS-1$
407
continue;
408                 }
409                 if (name.startsWith(".") //$NON-NLS-1$
410
&& !this.getConfigValue("showHiddenFiles", "false").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
411
continue;
412                 }
413                 properties.put("name", name); //$NON-NLS-1$
414
String JavaDoc displayType = (String JavaDoc) properties.get("displayType"); //$NON-NLS-1$
415
if (properties.get("isSelf") != null) { //$NON-NLS-1$
416
selfAS.add(properties);
417                 }
418                 else if (displayType.equals("folder")) { //$NON-NLS-1$
419
dirListAS.add(properties);
420                 }
421                 else {
422                     fileListAS.add(properties);
423                 }
424             }
425             int i = 0;
426             List JavaDoc parentAS = new ArrayList JavaDoc();
427             if (!this.getDirectory().equals(dir)) {
428                 Map JavaDoc parentProp = new Hashtable JavaDoc();
429                 String JavaDoc name = StringUtils.EMPTY;
430                 if (StringUtils.isEmpty(parentDirectory)) {
431                     name = "/"; //$NON-NLS-1$
432
}
433                 else {
434                     name = parentDirectory.substring(0, parentDirectory.length() - 1);
435                     if (name.indexOf("/") != -1) { //$NON-NLS-1$
436
name = name.substring(0, name.lastIndexOf("/")); //$NON-NLS-1$
437
}
438                 }
439                 parentProp.put("name", name); //$NON-NLS-1$
440
parentProp.put("isParent", "true"); //$NON-NLS-1$ //$NON-NLS-2$
441
parentProp.put("href", parentDirectory); //$NON-NLS-1$
442
parentProp.put("displayType", "folder"); //$NON-NLS-1$ //$NON-NLS-2$
443
parentProp.put("sizeStringValue", StringUtils.EMPTY); //$NON-NLS-1$
444
parentProp.put("sizeStringUnit", StringUtils.EMPTY); //$NON-NLS-1$
445
parentProp.put("lastModifiedString", StringUtils.EMPTY); //$NON-NLS-1$
446
parentAS.add(parentProp);
447                 i = drawHtmlList(out, parentAS, i);
448             }
449             i = drawHtmlList(out, selfAS, i);
450             i = drawHtmlList(out, dirListAS, i);
451             i = drawHtmlList(out, fileListAS, i);
452             if (i == 1) {
453                 out.write("<tr><td colspan=\"3\"></td><td colspan=\"3\"><em>" //$NON-NLS-1$
454
+ MessagesManager.get(this.getRequest(), "dialog.webdav.directoryIsEmpty") //$NON-NLS-1$
455
+ "</em></td></tr>"); //$NON-NLS-1$
456
}
457             out.write("</table>"); //$NON-NLS-1$
458
out.write("</body></html>"); //$NON-NLS-1$
459
}
460         catch (Exception JavaDoc e) {
461             log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
462
}
463     }
464
465     public int drawHtmlList(Writer JavaDoc out, List JavaDoc as, int i) throws IOException JavaDoc {
466
467         boolean alt = (i % 2 == 0);
468
469         // todo: better sorting
470
Collections.sort(as, new DialogWebDAVComparator());
471         Iterator JavaDoc it = as.iterator();
472         while (it.hasNext()) {
473             Map JavaDoc properties = (Hashtable JavaDoc) it.next();
474             String JavaDoc displayType = (String JavaDoc) properties.get("displayType"); //$NON-NLS-1$
475
String JavaDoc name = (String JavaDoc) properties.get("name"); //$NON-NLS-1$
476
if (!alt) {
477                 out.write("<tr>"); //$NON-NLS-1$
478
}
479             else {
480                 out.write("<tr class=" + CssConstants.CSSCLASS_BGALT + ">"); //$NON-NLS-1$ //$NON-NLS-2$
481
}
482             alt = !alt;
483             out.write("<td></td>"); //$NON-NLS-1$
484
out.write("<td>"); //$NON-NLS-1$
485
if (properties.get("isParent") == null //$NON-NLS-1$
486
&& (displayType.indexOf("folder") == -1 || this //$NON-NLS-1$
487
.getConfigValue("allowDirectorySelection") //$NON-NLS-1$
488
.equals("true"))) { //$NON-NLS-1$
489
String JavaDoc lastModified = StringUtils.EMPTY;
490                 if (properties.get("lastModified") != null) { //$NON-NLS-1$
491
lastModified = ((String JavaDoc) properties.get("lastModified")) //$NON-NLS-1$
492
.replaceAll(" ", "%20"); //$NON-NLS-1$ //$NON-NLS-2$
493
}
494                 out.write("<input type=\"radio\" name=\"" + this.getName() + "_radio\""); //$NON-NLS-1$ //$NON-NLS-2$
495
out.write(" onclick=mgnlDialogDAVSelect(\"" //$NON-NLS-1$
496
+ this.getName() + "\",\"" //$NON-NLS-1$
497
+ name + "\",\"" //$NON-NLS-1$
498
+ i + "\",\"" //$NON-NLS-1$
499
+ (String JavaDoc) properties.get("size") //$NON-NLS-1$
500
+ "\",\"" //$NON-NLS-1$
501
+ lastModified + "\");"); //$NON-NLS-1$
502
// if (this.getValue().equals(this.getSubDirectory()+name) ||
503
// this.getValue().equals(this.getSubDirectory()+name+"/")) out.write(" checked");
504
boolean checked = false;
505                 if (properties.get("isSelf") != null) { //$NON-NLS-1$
506
if (this.getValue().equals(this.getSubDirectory())) {
507                         checked = true;
508                     }
509                 }
510                 else {
511                     if (this.getValue().equals(this.getSubDirectory() + name)
512                         || this.getValue().equals(this.getSubDirectory() + name + "/")) { //$NON-NLS-1$
513
checked = true;
514                     }
515                 }
516                 if (checked) {
517                     out.write(MessagesManager.get(this.getRequest(), "dialog.webdav.checked")); //$NON-NLS-1$
518
}
519                 out.write(" />"); //$NON-NLS-1$
520
}
521             out.write("</td>"); //$NON-NLS-1$
522
// out.write("<td>"+this.getValue()+"..."+this.getSubDirectory()+"..."+name+"</td>");
523
String JavaDoc idHidden = this.getName() + "_" + i + "_hidden"; //$NON-NLS-1$ //$NON-NLS-2$
524
String JavaDoc idIcon = this.getName() + "_" + i + "_icon"; //$NON-NLS-1$ //$NON-NLS-2$
525
i++;
526             String JavaDoc iconPath;
527             if (displayType.equals("folder")) { //$NON-NLS-1$
528
iconPath = ICONS_PATH + ICONS_FOLDER;
529             }
530             else {
531                 iconPath = this.getIconPath(name);
532             }
533             out.write("<td>"); //$NON-NLS-1$
534
out.write("<img SRC=\"" //$NON-NLS-1$
535
+ this.getRequest().getContextPath() + iconPath + "\" border=\"0\" id=\"" //$NON-NLS-1$
536
+ idIcon + "\">"); //$NON-NLS-1$
537
out.write("</td>"); //$NON-NLS-1$
538
out.write("<td width=\"100%\">"); //$NON-NLS-1$
539
if (displayType.indexOf("folder") == 0) { //$NON-NLS-1$
540
if (properties.get("isSelf") != null) { //$NON-NLS-1$
541
out.write(this.getHtmlDecodeURI("<b><i>.&nbsp;&nbsp;" + name + "</i></b>")); //$NON-NLS-1$ //$NON-NLS-2$
542
}
543                 else {
544                     if (properties.get("isParent") != null) { //$NON-NLS-1$
545
name = "<b><i>..&nbsp;&nbsp;" + name + "</i></b>"; //$NON-NLS-1$ //$NON-NLS-2$
546
}
547                     out.write("<a HREF=\"javascript:mgnlDialogDAVBrowse('','" + idHidden + "');\">"); //$NON-NLS-1$ //$NON-NLS-2$
548
out.write(this.getHtmlDecodeURI(name));
549                     out.write("</a>"); //$NON-NLS-1$
550
}
551             }
552             else {
553                 out.write(this.getHtmlDecodeURI(name));
554                 out.write("[<a HREF=\"" //$NON-NLS-1$
555
+ this.getProtocol() + "://" //$NON-NLS-1$
556
+ this.getHost() + ":" //$NON-NLS-1$
557
+ this.getPort() + this.getDirectory() + (String JavaDoc) properties.get("href") //$NON-NLS-1$
558
+ "\" target=\"blank\">view</a>]"); //$NON-NLS-1$
559
}
560             out.write(new Hidden(idHidden, (String JavaDoc) properties.get("href"), false).getHtml()); //$NON-NLS-1$
561
out.write("</td>"); //$NON-NLS-1$
562
out.write("<td style=\"text-align:right;\">" + (String JavaDoc) properties.get("sizeStringValue") + "</td>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
563
out.write("<td>" + (String JavaDoc) properties.get("sizeStringUnit") + "</td>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
564
out.write("<td></td>"); //$NON-NLS-1$
565
out.write("<td style='white-space:nowrap;'>" + (String JavaDoc) properties.get("lastModifiedString") + "</td>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
566
out.write("<td></td>"); //$NON-NLS-1$
567
out.write("</tr>"); //$NON-NLS-1$
568
}
569
570         return i;
571     }
572
573     public Map JavaDoc getDAVProperties(XMLResponseMethodBase.Response response) {
574         Map JavaDoc properties = new Hashtable JavaDoc();
575         /* get the short name */
576         Enumeration JavaDoc props = response.getProperties();
577         String JavaDoc href = response.getHref();
578         properties.put("href", href.replaceFirst(this.getDirectory(), StringUtils.EMPTY)); //$NON-NLS-1$
579
while (props.hasMoreElements()) {
580             Property property = (Property) props.nextElement();
581             if (property.getLocalName().equalsIgnoreCase("getcontenttype")) { //$NON-NLS-1$
582
if (property.getPropertyAsString().equalsIgnoreCase("httpd/unix-directory")) { //$NON-NLS-1$
583
properties.put("displayType", "folder"); //$NON-NLS-1$ //$NON-NLS-2$
584
if (href.length() > this.getDirectory().length()) {
585                         String JavaDoc name = href.replaceFirst(this.getDirectory(), StringUtils.EMPTY);
586                         name = name.substring(0, name.length() - 1);
587                         name = name.substring(0, name.length());
588                         properties.put("name", name); //$NON-NLS-1$
589
}
590                 }
591             }
592             else if (property.getLocalName().equalsIgnoreCase("getcontentlength")) { //$NON-NLS-1$
593
properties.put("size", property.getPropertyAsString()); //$NON-NLS-1$
594
}
595             else if (property.getLocalName().equalsIgnoreCase("getlastmodified")) { //$NON-NLS-1$
596
properties.put("lastModifiedString", //$NON-NLS-1$
597
this.getFormattedDate(property.getPropertyAsString(), "MMM dd yyyy")); //$NON-NLS-1$
598
properties.put("lastModified", //$NON-NLS-1$
599
this.getFormattedDate(property.getPropertyAsString(), "yyyy-MM-dd, HH:mm:ss")); //$NON-NLS-1$
600
}
601         }
602         if (properties.get("name") == null) { //$NON-NLS-1$
603
if (href.length() > this.getDirectory().length()) {
604                 String JavaDoc name = href.replaceFirst(this.getDirectory(), StringUtils.EMPTY);
605                 properties.put("name", name); //$NON-NLS-1$
606
}
607             int index = href.lastIndexOf("."); //$NON-NLS-1$
608
if (index > -1) {
609                 properties.put("displayType", (href.substring(index + 1)).toLowerCase()); //$NON-NLS-1$
610
}
611             else {
612                 properties.put("displayType", "general"); //$NON-NLS-1$ //$NON-NLS-2$
613
}
614         }
615         if (properties.get("size") == null) { //$NON-NLS-1$
616
properties.put("size", StringUtils.EMPTY); //$NON-NLS-1$
617
properties.put("sizeStringValue", StringUtils.EMPTY); //$NON-NLS-1$
618
properties.put("sizeStringUnit", StringUtils.EMPTY); //$NON-NLS-1$
619
}
620         else {
621             String JavaDoc[] size = this.getFileSizeString((String JavaDoc) properties.get("size")).split(" "); //$NON-NLS-1$ //$NON-NLS-2$
622
properties.put("sizeStringValue", size[0]); //$NON-NLS-1$
623
properties.put("sizeStringUnit", size[1]); //$NON-NLS-1$
624
}
625         return properties;
626     }
627
628     public String JavaDoc getFileSizeString(String JavaDoc fileSize) {
629         int bytes = (new Integer JavaDoc(fileSize)).intValue();
630         int size = (bytes / 1024);
631         if (size == 0) {
632             return (bytes + " " + MessagesManager.get(this.getRequest(), "file.bytes")); //$NON-NLS-1$ //$NON-NLS-2$
633
}
634         else if (size >= 1024) {
635             return ((size / 1024) + " " + MessagesManager.get(this.getRequest(), "file.mb")); //$NON-NLS-1$ //$NON-NLS-2$
636
}
637         return (size + " " + MessagesManager.get(this.getRequest(), "file.kb")); //$NON-NLS-1$ //$NON-NLS-2$
638
}
639
640     public String JavaDoc getFormattedDate(String JavaDoc date, String JavaDoc format) {
641         SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc(format);
642
643         try {
644             Date JavaDoc x = DateFormat.getDateTimeInstance().parse(date);
645             return sdf.format(x);
646         }
647         catch (Exception JavaDoc e) {
648             log.error(e.getMessage(), e);
649             return date;
650         }
651     }
652
653     private String JavaDoc getHtmlSessionAttributeRemoveControl() {
654         return new Hidden(SESSION_ATTRIBUTENAME_DIALOGOBJECT_REMOVE, this
655             .getConfigValue(SESSION_ATTRIBUTENAME_DIALOGOBJECT), false).getHtml();
656     }
657 }
658
Popular Tags