1 package org.apache.commons.vfs.provider; 2 3 import org.apache.commons.httpclient.URIException; 4 import org.apache.commons.httpclient.util.URIUtil; 5 import org.apache.commons.vfs.FileName; 6 import org.apache.commons.vfs.FileSystemException; 7 import org.apache.commons.vfs.FileType; 8 9 public class URLFileName extends GenericFileName 10 { 11 private final String queryString; 12 13 public URLFileName(final String scheme, 14 final String hostName, 15 final int port, 16 final int defaultPort, 17 final String userName, 18 final String password, 19 final String path, 20 final FileType type, 21 final String queryString) 22 { 23 super(scheme, hostName, port, defaultPort, userName, password, path, type); 24 this.queryString = queryString; 25 } 26 27 32 public String getQueryString() 33 { 34 return queryString; 35 } 36 37 42 public String getPathQuery() 43 { 44 StringBuffer sb = new StringBuffer (250); 45 sb.append(getPath()); 46 sb.append("?"); 47 sb.append(getQueryString()); 48 49 return sb.toString(); 50 } 51 52 57 public String getPathQueryEncoded(String charset) throws URIException, FileSystemException 58 { 59 if (getQueryString() == null) 60 { 61 if (charset != null) 62 { 63 return URIUtil.encodePath(getPathDecoded(), charset); 64 } 65 else 66 { 67 return URIUtil.encodePath(getPathDecoded()); 68 } 69 } 70 71 StringBuffer sb = new StringBuffer (250); 72 if (charset != null) 73 { 74 sb.append(URIUtil.encodePath(getPathDecoded(), charset)); 75 } 76 else 77 { 78 sb.append(URIUtil.encodePath(getPathDecoded())); 79 } 80 sb.append("?"); 81 sb.append(getQueryString()); 82 return sb.toString(); 83 } 84 85 public FileName createName(final String absPath, FileType type) 86 { 87 return new URLFileName(getScheme(), 88 getHostName(), 89 getPort(), 90 getDefaultPort(), 91 getUserName(), 92 getPassword(), 93 absPath, 94 type, 95 getQueryString()); 96 } 97 98 103 protected String createURI() 104 { 105 if (getQueryString() != null) 106 { 107 StringBuffer sb = new StringBuffer (250); 108 sb.append(super.createURI()); 109 sb.append("?"); 110 sb.append(getQueryString()); 111 112 return sb.toString(); 113 } 114 115 return super.createURI(); 116 } 117 118 public String getURIEncoded(String charset) throws FileSystemException, URIException 119 { 120 StringBuffer sb = new StringBuffer (80); 121 appendRootUri(sb); 122 sb.append(getPathQueryEncoded(charset)); 123 return sb.toString(); 124 } 125 } 126 | Popular Tags |