View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider.webdav;
18  
19  import java.io.ByteArrayOutputStream;
20  import java.io.IOException;
21  import java.io.OutputStream;
22  import java.net.HttpURLConnection;
23  import java.util.ArrayList;
24  import java.util.HashMap;
25  import java.util.Iterator;
26  import java.util.List;
27  import java.util.Map;
28  
29  import org.apache.commons.httpclient.HttpMethod;
30  import org.apache.commons.httpclient.HttpMethodBase;
31  import org.apache.commons.httpclient.HttpStatus;
32  import org.apache.commons.httpclient.URIException;
33  import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
34  import org.apache.commons.httpclient.methods.RequestEntity;
35  import org.apache.commons.httpclient.params.HttpMethodParams;
36  import org.apache.commons.httpclient.util.DateUtil;
37  import org.apache.commons.vfs2.FileContentInfoFactory;
38  import org.apache.commons.vfs2.FileNotFolderException;
39  import org.apache.commons.vfs2.FileNotFoundException;
40  import org.apache.commons.vfs2.FileObject;
41  import org.apache.commons.vfs2.FileSystemException;
42  import org.apache.commons.vfs2.FileType;
43  import org.apache.commons.vfs2.NameScope;
44  import org.apache.commons.vfs2.provider.AbstractFileName;
45  import org.apache.commons.vfs2.provider.DefaultFileContent;
46  import org.apache.commons.vfs2.provider.URLFileName;
47  import org.apache.commons.vfs2.provider.http.HttpFileObject;
48  import org.apache.commons.vfs2.util.FileObjectUtils;
49  import org.apache.commons.vfs2.util.MonitorOutputStream;
50  import org.apache.jackrabbit.webdav.DavConstants;
51  import org.apache.jackrabbit.webdav.DavException;
52  import org.apache.jackrabbit.webdav.MultiStatus;
53  import org.apache.jackrabbit.webdav.MultiStatusResponse;
54  import org.apache.jackrabbit.webdav.client.methods.CheckinMethod;
55  import org.apache.jackrabbit.webdav.client.methods.CheckoutMethod;
56  import org.apache.jackrabbit.webdav.client.methods.DavMethod;
57  import org.apache.jackrabbit.webdav.client.methods.DeleteMethod;
58  import org.apache.jackrabbit.webdav.client.methods.MkColMethod;
59  import org.apache.jackrabbit.webdav.client.methods.MoveMethod;
60  import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
61  import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod;
62  import org.apache.jackrabbit.webdav.client.methods.PutMethod;
63  import org.apache.jackrabbit.webdav.client.methods.UncheckoutMethod;
64  import org.apache.jackrabbit.webdav.client.methods.VersionControlMethod;
65  import org.apache.jackrabbit.webdav.property.DavProperty;
66  import org.apache.jackrabbit.webdav.property.DavPropertyName;
67  import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
68  import org.apache.jackrabbit.webdav.property.DavPropertySet;
69  import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
70  import org.apache.jackrabbit.webdav.version.DeltaVConstants;
71  import org.apache.jackrabbit.webdav.version.VersionControlledResource;
72  import org.apache.jackrabbit.webdav.xml.Namespace;
73  import org.w3c.dom.Node;
74  
75  /**
76   * A WebDAV file.
77   *
78   * @since 2.0
79   */
80  public class WebdavFileObject extends HttpFileObject<WebdavFileSystem> {
81  
82      /**
83       * An OutputStream that writes to a Webdav resource.
84       * <p>
85       * TODO - Use piped stream to avoid temporary file.
86       * </p>
87       */
88      private class WebdavOutputStream extends MonitorOutputStream {
89          private final WebdavFileObject file;
90  
91          public WebdavOutputStream(final WebdavFileObject file) {
92              super(new ByteArrayOutputStream());
93              this.file = file;
94          }
95  
96          private boolean createVersion(final String urlStr) {
97              try {
98                  final VersionControlMethod method = new VersionControlMethod(urlStr);
99                  setupMethod(method);
100                 execute(method);
101                 return true;
102             } catch (final Exception ex) {
103                 return false;
104             }
105         }
106 
107         /**
108          * Called after this stream is closed.
109          */
110         @Override
111         protected void onClose() throws IOException {
112             final RequestEntity entity = new ByteArrayRequestEntity(((ByteArrayOutputStream) out).toByteArray());
113             final URLFileName./../../../org/apache/commons/vfs2/provider/URLFileName.html#URLFileName">URLFileName fileName = (URLFileName) getName();
114             final String urlStr = toUrlString(fileName);
115             if (builder.isVersioning(getFileSystem().getFileSystemOptions())) {
116                 DavPropertySet set = null;
117                 boolean fileExists = true;
118                 boolean isCheckedIn = true;
119                 try {
120                     set = getPropertyNames(fileName);
121                 } catch (final FileNotFoundException fnfe) {
122                     fileExists = false;
123                 }
124                 if (fileExists && set != null) {
125                     if (set.contains(VersionControlledResource.CHECKED_OUT)) {
126                         isCheckedIn = false;
127                     } else if (!set.contains(VersionControlledResource.CHECKED_IN)) {
128                         DavProperty prop = set.get(VersionControlledResource.AUTO_VERSION);
129                         if (prop != null) {
130                             prop = getProperty(fileName, VersionControlledResource.AUTO_VERSION);
131                             if (DeltaVConstants.XML_CHECKOUT_CHECKIN.equals(prop.getValue())) {
132                                 createVersion(urlStr);
133                             }
134                         }
135                     }
136                 }
137                 if (fileExists && isCheckedIn) {
138                     try {
139                         final CheckoutMethod checkout = new CheckoutMethod(urlStr);
140                         setupMethod(checkout);
141                         execute(checkout);
142                         isCheckedIn = false;
143                     } catch (final FileSystemException ex) {
144                         // Ignore the exception checking out.
145                     }
146                 }
147 
148                 try {
149                     final PutMethod method = new PutMethod(urlStr);
150                     method.setRequestEntity(entity);
151                     setupMethod(method);
152                     execute(method);
153                     setUserName(fileName, urlStr);
154                 } catch (final FileSystemException ex) {
155                     if (!isCheckedIn) {
156                         try {
157                             final UncheckoutMethod method = new UncheckoutMethod(urlStr);
158                             setupMethod(method);
159                             execute(method);
160                             isCheckedIn = true;
161                         } catch (final Exception e) {
162                             // Ignore the exception. Going to throw original.
163                         }
164                         throw ex;
165                     }
166                 }
167                 if (!fileExists) {
168                     createVersion(urlStr);
169                     try {
170                         final DavPropertySet props = getPropertyNames(fileName);
171                         isCheckedIn = !props.contains(VersionControlledResource.CHECKED_OUT);
172                     } catch (final FileNotFoundException fnfe) {
173                         // Ignore the error
174                     }
175                 }
176                 if (!isCheckedIn) {
177                     final CheckinMethod checkin = new CheckinMethod(urlStr);
178                     setupMethod(checkin);
179                     execute(checkin);
180                 }
181             } else {
182                 final PutMethod method = new PutMethod(urlStr);
183                 method.setRequestEntity(entity);
184                 setupMethod(method);
185                 execute(method);
186                 try {
187                     setUserName(fileName, urlStr);
188                 } catch (final IOException e) {
189                     // Ignore the exception if unable to set the user name.
190                 }
191             }
192             ((DefaultFileContent) this.file.getContent()).resetAttributes();
193         }
194 
195         private void setUserName(final URLFileName fileName, final String urlStr) throws IOException {
196             final List<DefaultDavProperty> list = new ArrayList<>();
197             String name = builder.getCreatorName(getFileSystem().getFileSystemOptions());
198             final String userName = fileName.getUserName();
199             if (name == null) {
200                 name = userName;
201             } else {
202                 if (userName != null) {
203                     final String comment = "Modified by user " + userName;
204                     list.add(new DefaultDavProperty(DeltaVConstants.COMMENT, comment));
205                 }
206             }
207             list.add(new DefaultDavProperty(DeltaVConstants.CREATOR_DISPLAYNAME, name));
208             final PropPatchMethod method = new PropPatchMethod(urlStr, list);
209             setupMethod(method);
210             execute(method);
211         }
212     }
213 
214     /** The character set property name. */
215     public static final DavPropertyName RESPONSE_CHARSET = DavPropertyName.create("response-charset");
216 
217     /** The FileSystemConfigBuilder */
218     private final WebdavFileSystemConfigBuilder builder;
219 
220     private final WebdavFileSystem fileSystem;
221 
222     protected WebdavFileObject(final AbstractFileName name, final WebdavFileSystem fileSystem) {
223         super(name, fileSystem, WebdavFileSystemConfigBuilder.getInstance());
224         this.fileSystem = fileSystem;
225         builder = (WebdavFileSystemConfigBuilder) WebdavFileSystemConfigBuilder.getInstance();
226     }
227 
228     protected void configureMethod(final HttpMethodBase httpMethod) {
229         httpMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, WebdavMethodRetryHandler.getInstance());
230     }
231 
232     /**
233      * Creates this file as a folder.
234      */
235     @Override
236     protected void doCreateFolder() throws Exception {
237         final DavMethod method = new MkColMethod(toUrlString((URLFileName) getName()));
238         setupMethod(method);
239         try {
240             execute(method);
241         } catch (final FileSystemException fse) {
242             throw new FileSystemException("vfs.provider.webdav/create-collection.error", getName(), fse);
243         }
244     }
245 
246     /**
247      * Deletes the file.
248      */
249     @Override
250     protected void doDelete() throws Exception {
251         final DavMethod method = new DeleteMethod(toUrlString((URLFileName) getName()));
252         setupMethod(method);
253         execute(method);
254     }
255 
256     /**
257      * Returns the properties of the Webdav resource.
258      */
259     @Override
260     protected Map<String, Object> doGetAttributes() throws Exception {
261         final Map<String, Object> attributes = new HashMap<>();
262         try {
263             final URLFileName./../../../org/apache/commons/vfs2/provider/URLFileName.html#URLFileName">URLFileName fileName = (URLFileName) getName();
264             DavPropertySet properties = getProperties(fileName, DavConstants.PROPFIND_ALL_PROP,
265                     new DavPropertyNameSet(), false);
266             @SuppressWarnings("unchecked") // iterator() is documented to return DavProperty instances
267             final Iterator<DavProperty> iter = properties.iterator();
268             while (iter.hasNext()) {
269                 final DavProperty property = iter.next();
270                 attributes.put(property.getName().toString(), property.getValue());
271             }
272             properties = getPropertyNames(fileName);
273             @SuppressWarnings("unchecked") // iterator() is documented to return DavProperty instances
274             final Iterator<DavProperty> iter2 = properties.iterator();
275             while (iter2.hasNext()) {
276                 DavProperty property = iter2.next();
277                 if (!attributes.containsKey(property.getName().getName())) {
278                     property = getProperty(fileName, property.getName());
279                     if (property != null) {
280                         final Object name = property.getName();
281                         final Object value = property.getValue();
282                         if (name != null && value != null) {
283                             attributes.put(name.toString(), value);
284                         }
285                     }
286                 }
287             }
288             return attributes;
289         } catch (final Exception e) {
290             throw new FileSystemException("vfs.provider.webdav/get-attributes.error", getName(), e);
291         }
292     }
293 
294     /**
295      * Returns the size of the file content (in bytes).
296      */
297     @Override
298     protected long doGetContentSize() throws Exception {
299         final DavProperty property = getProperty((URLFileName) getName(), DavConstants.PROPERTY_GETCONTENTLENGTH);
300         if (property != null) {
301             final String value = (String) property.getValue();
302             return Long.parseLong(value);
303         }
304         return 0;
305     }
306 
307     /**
308      * Returns the last modified time of this file. Is only called if {@link #doGetType} does not return
309      * {@link FileType#IMAGINARY}.
310      */
311     @Override
312     protected long doGetLastModifiedTime() throws Exception {
313         final DavProperty property = getProperty((URLFileName) getName(), DavConstants.PROPERTY_GETLASTMODIFIED);
314         if (property != null) {
315             final String value = (String) property.getValue();
316             return DateUtil.parseDate(value).getTime();
317         }
318         return 0;
319     }
320 
321     @Override
322     protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception {
323         return new WebdavOutputStream(this);
324     }
325 
326     /**
327      * Determines the type of this file. Must not return null. The return value of this method is cached, so the
328      * implementation can be expensive.
329      */
330     @Override
331     protected FileType doGetType() throws Exception {
332         try {
333             return isDirectory((URLFileName) getName()) ? FileType.FOLDER : FileType.FILE;
334         } catch (final FileNotFolderException fnfe) {
335             return FileType.IMAGINARY;
336         } catch (final FileNotFoundException fnfe) {
337             return FileType.IMAGINARY;
338         }
339 
340     }
341 
342     /**
343      * Determines if this file can be written to. Is only called if {@link #doGetType} does not return
344      * {@link FileType#IMAGINARY}.
345      * <p>
346      * This implementation always returns true.
347      *
348      * @return true if the file is writable.
349      * @throws Exception if an error occurs.
350      */
351     @Override
352     protected boolean doIsWriteable() throws Exception {
353         return true;
354     }
355 
356     /**
357      * Lists the children of the file.
358      */
359     @Override
360     protected String[] doListChildren() throws Exception {
361         // use doListChildrenResolved for performance
362         return null;
363     }
364 
365     /**
366      * Lists the children of the file.
367      */
368     @Override
369     protected FileObject[] doListChildrenResolved() throws Exception {
370         PropFindMethod method = null;
371         try {
372             final URLFileName../../../../../org/apache/commons/vfs2/provider/URLFileName.html#URLFileName">URLFileName name = (URLFileName) getName();
373             if (isDirectory(name)) {
374                 final DavPropertyNameSet nameSet = new DavPropertyNameSet();
375                 nameSet.add(DavPropertyName.create(DavConstants.PROPERTY_DISPLAYNAME));
376 
377                 method = new PropFindMethod(toUrlString(name), nameSet, DavConstants.DEPTH_1);
378 
379                 execute(method);
380                 final List<WebdavFileObject> vfs = new ArrayList<>();
381                 if (method.succeeded()) {
382                     final MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses();
383 
384                     for (final MultiStatusResponse response : responses) {
385                         if (isCurrentFile(response.getHref(), name)) {
386                             continue;
387                         }
388                         final String resourceName = resourceName(response.getHref());
389                         if (resourceName != null && resourceName.length() > 0) {
390                             final WebdavFileObject../../../../org/apache/commons/vfs2/provider/webdav/WebdavFileObject.html#WebdavFileObject">WebdavFileObject fo = (WebdavFileObject) FileObjectUtils.getAbstractFileObject(
391                                     getFileSystem().resolveFile(getFileSystem().getFileSystemManager()
392                                             .resolveName(getName(), resourceName, NameScope.CHILD)));
393                             vfs.add(fo);
394                         }
395                     }
396                 }
397                 return vfs.toArray(new WebdavFileObject[vfs.size()]);
398             }
399             throw new FileNotFolderException(getName());
400         } catch (final FileNotFolderException fnfe) {
401             throw fnfe;
402         } catch (final DavException e) {
403             throw new FileSystemException(e.getMessage(), e);
404         } catch (final IOException e) {
405             throw new FileSystemException(e.getMessage(), e);
406         } finally {
407             if (method != null) {
408                 method.releaseConnection();
409             }
410         }
411     }
412 
413     /**
414      * Rename the file.
415      */
416     @Override
417     protected void doRename(final FileObject newFile) throws Exception {
418         final String url = encodePath(toUrlString((URLFileName) getName()));
419         final String dest = toUrlString((URLFileName) newFile.getName(), false);
420         final DavMethod method = new MoveMethod(url, dest, false);
421         setupMethod(method);
422         execute(method);
423     }
424 
425     /**
426      * Sets an attribute of this file. Is only called if {@link #doGetType} does not return {@link FileType#IMAGINARY}.
427      */
428     @Override
429     protected void doSetAttribute(final String attrName, final Object value) throws Exception {
430         try {
431             final URLFileName./../../../org/apache/commons/vfs2/provider/URLFileName.html#URLFileName">URLFileName fileName = (URLFileName) getName();
432             final String urlStr = toUrlString(fileName);
433             final DavPropertySet properties = new DavPropertySet();
434             final DavPropertyNameSet propertyNameSet = new DavPropertyNameSet();
435             final DavProperty property = new DefaultDavProperty(attrName, value, Namespace.EMPTY_NAMESPACE);
436             if (value != null) {
437                 properties.add(property);
438             } else {
439                 propertyNameSet.add(property.getName()); // remove property
440             }
441 
442             final PropPatchMethod method = new PropPatchMethod(urlStr, properties, propertyNameSet);
443             setupMethod(method);
444             execute(method);
445             if (!method.succeeded()) {
446                 throw new FileSystemException("Property '" + attrName + "' could not be set.");
447             }
448         } catch (final FileSystemException fse) {
449             throw fse;
450         } catch (final Exception e) {
451             throw new FileSystemException("vfs.provider.webdav/set-attributes", e, getName(), attrName);
452         }
453     }
454 
455     /**
456      * Execute a 'Workspace' operation.
457      *
458      * @param method The DavMethod to invoke.
459      * @throws FileSystemException If an error occurs.
460      */
461     private void execute(final DavMethod method) throws FileSystemException {
462         try {
463             final int status = fileSystem.getClient().executeMethod(method);
464             if (status == HttpURLConnection.HTTP_NOT_FOUND || status == HttpURLConnection.HTTP_GONE) {
465                 throw new FileNotFoundException(method.getURI());
466             }
467             method.checkSuccess();
468         } catch (final FileSystemException fse) {
469             throw fse;
470         } catch (final IOException e) {
471             throw new FileSystemException(e);
472         } catch (final DavException e) {
473             throw ExceptionConverter.generate(e);
474         } finally {
475             if (method != null) {
476                 method.releaseConnection();
477             }
478         }
479     }
480 
481     @Override
482     protected FileContentInfoFactory getFileContentInfoFactory() {
483         return new WebdavFileContentInfoFactory();
484     }
485 
486     DavPropertySet getProperties(final URLFileName name) throws FileSystemException {
487         return getProperties(name, DavConstants.PROPFIND_ALL_PROP, new DavPropertyNameSet(), false);
488     }
489 
490     DavPropertySet getProperties(final URLFileName name, final DavPropertyNameSet nameSet, final boolean addEncoding)
491             throws FileSystemException {
492         return getProperties(name, DavConstants.PROPFIND_BY_PROPERTY, nameSet, addEncoding);
493     }
494 
495     DavPropertySet getProperties(final URLFileName name, final int type, final DavPropertyNameSet nameSet,
496             final boolean addEncoding) throws FileSystemException {
497         try {
498             final String urlStr = toUrlString(name);
499             final PropFindMethod method = new PropFindMethod(urlStr, type, nameSet, DavConstants.DEPTH_0);
500             setupMethod(method);
501             execute(method);
502             if (method.succeeded()) {
503                 final MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
504                 final MultiStatusResponse response = multiStatus.getResponses()[0];
505                 final DavPropertySet props = response.getProperties(HttpStatus.SC_OK);
506                 if (addEncoding) {
507                     final DavProperty prop = new DefaultDavProperty(RESPONSE_CHARSET, method.getResponseCharSet());
508                     props.add(prop);
509                 }
510                 return props;
511             }
512             return new DavPropertySet();
513         } catch (final FileSystemException fse) {
514             throw fse;
515         } catch (final Exception e) {
516             throw new FileSystemException("vfs.provider.webdav/get-property.error", e, getName(), name, type,
517                     nameSet.getContent(), addEncoding);
518         }
519     }
520 
521     DavProperty getProperty(final URLFileName fileName, final DavPropertyName name) throws FileSystemException {
522         final DavPropertyNameSet nameSet = new DavPropertyNameSet();
523         nameSet.add(name);
524         final DavPropertySet propertySet = getProperties(fileName, nameSet, false);
525         return propertySet.get(name);
526     }
527 
528     DavProperty getProperty(final URLFileName fileName, final String property) throws FileSystemException {
529         return getProperty(fileName, DavPropertyName.create(property));
530     }
531 
532     DavPropertySet getPropertyNames(final URLFileName name) throws FileSystemException {
533         return getProperties(name, DavConstants.PROPFIND_PROPERTY_NAMES, new DavPropertyNameSet(), false);
534     }
535 
536     /**
537      * Convert the FileName to an encoded url String.
538      *
539      * @param name The FileName.
540      * @return The encoded URL String.
541      */
542     private String hrefString(final URLFileName name) {
543         final URLFileNameider/URLFileName.html#URLFileName">URLFileName newFile = new URLFileName("http", name.getHostName(), name.getPort(), name.getDefaultPort(),
544                 null, null, name.getPath(), name.getType(), name.getQueryString());
545         try {
546             return newFile.getURIEncoded(this.getUrlCharset());
547         } catch (final Exception e) {
548             return name.getURI();
549         }
550     }
551 
552     private boolean isCurrentFile(final String href, final URLFileName fileName) {
553         String name = hrefString(fileName);
554         if (href.endsWith("/") && !name.endsWith("/")) {
555             name += "/";
556         }
557         return href.equals(name) || href.equals(fileName.getPath());
558     }
559 
560     private boolean isDirectory(final URLFileName name) throws IOException {
561         try {
562             final DavProperty property = getProperty(name, DavConstants.PROPERTY_RESOURCETYPE);
563             Node node;
564             if (property != null && (node = (Node) property.getValue()) != null) {
565                 return node.getLocalName().equals(DavConstants.XML_COLLECTION);
566             }
567             return false;
568         } catch (final FileNotFoundException fse) {
569             throw new FileNotFolderException(name);
570         }
571     }
572 
573     /**
574      * Returns the resource name from the path.
575      *
576      * @param path the path to the file.
577      * @return The resource name
578      */
579     private String resourceName(String path) {
580         if (path.endsWith("/")) {
581             path = path.substring(0, path.length() - 1);
582         }
583         final int i = path.lastIndexOf("/");
584         return i >= 0 ? path.substring(i + 1) : path;
585     }
586 
587     /**
588      * Prepares a Method object.
589      *
590      * @param method the HttpMethod.
591      * @throws FileSystemException if an error occurs encoding the uri.
592      * @throws URIException if the URI is in error.
593      */
594     @Override
595     protected void setupMethod(final HttpMethod method) throws FileSystemException, URIException {
596         final String pathEncoded = ((URLFileName) getName()).getPathQueryEncoded(this.getUrlCharset());
597         method.setPath(pathEncoded);
598         method.setFollowRedirects(this.getFollowRedirect());
599         method.setRequestHeader("User-Agent", "Jakarta-Commons-VFS");
600         method.addRequestHeader("Cache-control", "no-cache");
601         method.addRequestHeader("Cache-store", "no-store");
602         method.addRequestHeader("Pragma", "no-cache");
603         method.addRequestHeader("Expires", "0");
604     }
605 
606     private String toUrlString(final URLFileName name) {
607         return toUrlString(name, true);
608     }
609 
610     /**
611      * Converts the given URLFileName to an encoded URL String.
612      *
613      * @param name The FileName.
614      * @param includeUserInfo true if user information should be included.
615      * @return The encoded URL String.
616      */
617     private String toUrlString(final URLFileName name, final boolean includeUserInfo) {
618         String user = null;
619         String password = null;
620         if (includeUserInfo) {
621             user = name.getUserName();
622             password = name.getPassword();
623         }
624         final URLFileNameider/URLFileName.html#URLFileName">URLFileName newFile = new URLFileName("http", name.getHostName(), name.getPort(), name.getDefaultPort(),
625                 user, password, name.getPath(), name.getType(), name.getQueryString());
626         try {
627             return newFile.getURIEncoded(this.getUrlCharset());
628         } catch (final Exception e) {
629             return name.getURI();
630         }
631     }
632 }