public class UrlUtil
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
UrlUtil.HTTPDetails
Deprecated.
use the real class
|
static class |
UrlUtil.HttpMethod
list of all http methods
|
static class |
UrlUtil.URLProtocol
rough classification of protocol type
|
static class |
UrlUtil.URLWriter
Deprecated.
use the real class
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACCEPT |
static java.lang.String |
APPLICATION_CFF2
zip, maybe?
|
static java.lang.String |
APPLICATION_JSON |
static java.lang.String |
APPLICATION_PDF
pdf, duh...
|
static java.lang.String |
APPLICATION_PS
ps, duh...
|
static java.lang.String |
APPLICATION_XML
the preferred value for XML!
|
static java.lang.String |
APPLICATION_XZIP
zip, maybe?
|
static java.lang.String |
APPLICATION_ZIP |
static java.lang.String |
AUTHORIZATION |
static java.lang.String |
BASE64 |
static java.lang.String |
BINARY |
static java.lang.String |
CLOSE |
static java.lang.String |
CONNECT |
static java.lang.String |
CONNECTION |
static java.lang.String |
CONTENT_ID |
static java.lang.String |
CONTENT_LENGTH
more commonly used strings
|
static java.lang.String |
CONTENT_TRANSFER_ENCODING |
static java.lang.String |
CONTENT_TYPE
more commonly used strings
|
static java.lang.String |
DELETE |
static java.lang.String |
GET
http get method
|
static java.lang.String |
HEAD
http head method
|
static java.lang.String |
KEEPALIVE |
static java.lang.String |
m_UNCEscape
strings that must be escaped in uncs
|
static java.lang.String |
m_URIEscape
strings that must be escaped in urls
|
static int |
MAX_STREAM |
static java.lang.String |
OPTIONS |
static java.lang.String |
PATCH |
static java.lang.String |
POST
http post method
|
static java.lang.String |
PUT
http put method
|
static java.lang.String |
TEXT_CSV |
static java.lang.String |
TEXT_HTML |
static java.lang.String |
TEXT_JSON |
static java.lang.String |
TEXT_PLAIN |
static java.lang.String |
TEXT_UNKNOWN |
static java.lang.String |
TEXT_XML |
static java.lang.String |
TRACE |
static java.lang.String |
VND_JDF |
static java.lang.String |
VND_JMF |
static java.lang.String |
VND_PPF |
static java.lang.String |
VND_PTK |
static java.lang.String |
VND_XJDF |
static java.lang.String |
VND_XJDF_J |
static java.lang.String |
VND_XJMF |
static java.lang.String |
VND_XJMF_J |
| Constructor and Description |
|---|
UrlUtil() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
addParameter(java.lang.String baseUrl,
java.lang.String key,
java.lang.String val)
adds a parameter to a given url using either ? or &
|
static java.lang.String |
addPath(java.lang.String baseUrl,
java.lang.String path)
adds a path to a given url , keeping the parameters
|
static java.lang.String |
cleanDots(java.lang.String url)
remove any internal "../" "./" and "//" from a url
|
static java.lang.String |
cleanHttpURL(java.lang.String url)
create a "real" url from a user input url add http://
|
static java.lang.String |
createHttpUrl(boolean bSecure,
java.lang.String host,
int port,
java.lang.String path)
get a prinect url for this host and path
|
static java.lang.String |
escape(java.lang.String toEscape,
boolean bEscape128)
standard url escaping
|
static java.lang.String |
escape(java.lang.String toEscape,
boolean bEscape128,
boolean escapeSlash)
standard url escaping
|
static java.lang.String |
extension(java.lang.String pathName)
get the filename extension of pathName excluding the '.' if no '.' is found, returns null if trailing .
|
static java.lang.String |
fileToUrl(java.io.File f,
boolean bEscape128)
Convert a File to a valid file URL or IRL
note that some internal functions use network protocol and therefor performance may be non-optimal |
static byte[] |
getBytesFromIP(java.lang.String ip)
get the ip address as a set of bytes with the left byte at pos 0
|
static java.io.InputStream |
getCidURLStream(java.lang.String url,
javax.mail.Multipart multipart)
get a readable inputstream from the CID url
|
static int |
getConnectionTimeout()
Returns connection timeout in milliseconds as integer.
|
static java.io.File |
getCreateDirectory(java.lang.String newDir)
Deprecated.
use FileUtil.getCreateDirectory(newDir);
|
static java.lang.String |
getExtensionFromMimeType(java.lang.String contentType)
generates the correct extension for a given mime content type
|
static java.lang.String |
getFileName(java.lang.String url,
javax.mail.Multipart mp)
get the file name for a url.
|
static java.lang.String |
getIPFromBytes(byte[] ip)
get the ip address as a string with the left byte at pos 0
|
static java.lang.String |
getLocalURL(java.lang.String directory,
java.lang.String url)
get the local url without directory schemes in the base url are case insensitive, all others are case sensitive
|
static java.lang.String |
getMimeTypeFromURL(java.lang.String url)
generates the correct MIMEType for a given URL and sets it
|
static java.lang.String |
getParentDirectory(java.lang.String url)
get the parent directory of a file or url
|
static UrlUtil.URLProtocol |
getProtocol(java.lang.String url)
returns the general protocol type of a url
|
static java.lang.String |
getRelativePath(java.io.File f,
java.io.File fCWD)
returns the relative URL of a file relative to the current working directory
this includes escaping of %20 etc. |
static java.lang.String |
getRelativeURL(java.io.File f,
java.io.File baseDir,
boolean bEscape128)
returns the relative URL of a file relative to the current working directory
|
static java.io.InputStream |
getURLInputStream(java.lang.String urlString) |
static java.io.InputStream |
getURLInputStream(java.lang.String urlString,
javax.mail.BodyPart bodyPart)
get the opened input stream for a given url string
|
static UrlPart[] |
getURLParts(java.net.HttpURLConnection connection)
get an array of urlparts, regardless of whether this was mime or not if the stream is mime/multipart get also extract that
|
static java.lang.String |
getURLWithDirectory(java.lang.String directory,
java.lang.String url)
concatenate directory and url to a single path IF and only IF url is a relative url
relative urls MUST NOT have a scheme (e.g. |
static boolean |
isCID(java.lang.String url)
test whether a given url is a cid (cid:)
|
static boolean |
isEscaped(java.lang.String url)
test whether a given url is escaped as utf-8
|
static boolean |
isFile(java.lang.String url)
is this a valid file url
|
static boolean |
isFileOK(java.io.File f)
checks whether there is a remote chance that the file is useful for reading
|
static boolean |
isFtp(java.lang.String url)
test whether a given url is an http url (excluding https - @see isHttps)
|
static boolean |
isHttp(java.lang.String url)
test whether a given url is an http url (excluding https - @see isHttps)
|
static boolean |
isHttps(java.lang.String url)
test whether a given url is an https url
|
static boolean |
isIRL(java.lang.String val) |
static boolean |
isJSONType(java.lang.String contentType)
check whether the mime type is a known xml dialect
|
static boolean |
isMIME(java.io.File file)
check whether a file is a mime file only check extensions TODO sniff file rather than check extensions
|
static boolean |
isMIMEExtenstension(java.lang.String lower)
check whether a file is a mime file
|
static boolean |
isNet(java.lang.String url)
test whether a given url is any network style url, currently either http, https or ftp
|
static boolean |
isNotCID(java.lang.String url)
test whether a given url is NOT a cid this may be a local identifier
|
static boolean |
isRedirect(int responseCode)
return true if the response code should redirect
|
static boolean |
isRelativeURL(java.lang.String url)
if true this url is relative
|
static boolean |
isReturnCodeOK(int responseCode)
return true if the response code should redirect
|
static boolean |
isReturnCodeOK(UrlPart p)
return true if the response code should redirect
|
static boolean |
isUNC(java.lang.String pathName)
test whether a given url is a unc path
|
static boolean |
isURL(java.lang.String val) |
static boolean |
isWindowsLocalPath(java.lang.String pathName) |
static boolean |
isXMLType(java.lang.String contentType)
check whether the mime type is a known xml dialect
|
static boolean |
isZIPType(java.lang.String contentType)
check whether the mime type is a known zip dialect
|
static java.io.File |
moveToDir(IURLSetter parent,
java.io.File dir,
boolean overWrite)
Deprecated.
use moveToDir(parent, dir, null, overWrite);
|
static java.io.File |
moveToDir(IURLSetter urlSetter,
java.io.File dir,
java.lang.String cwd,
boolean overWrite)
physically store the file at the location specified in dir and also modify parent to reflect the new location
|
static java.io.File |
moveToDir(IURLSetter urlSetter,
java.io.File dir,
java.lang.String cwd,
boolean overWrite,
boolean deleteFile)
physically store the file at the location specified in dir and also modify parent to reflect the new location
|
static java.lang.String |
newExtension(java.lang.String strWork,
java.lang.String newExt)
replace the .extension of a file name
|
static java.lang.String |
normalize(java.lang.String urlString)
normalize a url string by grinding it through url
|
static java.lang.String |
prefix(java.lang.String strWork)
inverse of extension
|
static java.lang.String |
removeExtension(java.lang.String pathName)
Deprecated.
use prefix(pathName)
|
static java.lang.String |
removeProtocol(java.lang.String url)
remove the protocol part of a url, if it is specified
|
static void |
setConnectionTimeout(int timeout)
Returns connection timeout in milliseconds as integer.
|
static java.net.URL |
stringToURL(java.lang.String urlString)
Create a URL for any url string using heuristics and escaping
|
static java.lang.String |
uncToUrl(java.lang.String unc,
boolean escape128) |
static java.lang.String |
unEscape(java.lang.String toEscape)
standard url unescaping
|
static java.io.File |
urlToFile(java.lang.String urlString)
Retrieve a file for a relative or absolute file url
|
static java.lang.String |
urlToFileName(java.lang.String urlString) |
static java.lang.String |
urlToString(java.net.URL url)
null safe url to string converter
|
static java.lang.String |
urlToUNC(java.lang.String urlString)
Retrieve a UNC path for a relative or absolute file url, any of '/'or "\\" is assumed a path separator
|
static UrlPart |
writerToURL(java.lang.String strUrl,
IStreamWriter streamWriter,
java.lang.String method,
java.lang.String contentType,
HTTPDetails det)
write the contents of an IStreamWriter to an output URL File: and http: are currently supported Use HttpURLConnection.getInputStream() to retrieve the http response
|
static UrlPart |
writeToURL(java.lang.String strUrl,
java.io.InputStream stream,
java.lang.String method,
java.lang.String contentType,
HTTPDetails det)
write a Stream to an output URL File: and http: are currently supported Use HttpURLConnection.getInputStream() to retrieve the http response
|
public static final int MAX_STREAM
public static final java.lang.String POST
public static final java.lang.String PUT
public static final java.lang.String GET
public static final java.lang.String HEAD
public static final java.lang.String DELETE
public static final java.lang.String CONNECT
public static final java.lang.String OPTIONS
public static final java.lang.String TRACE
public static final java.lang.String PATCH
public static final java.lang.String KEEPALIVE
public static final java.lang.String ACCEPT
public static final java.lang.String CLOSE
public static final java.lang.String CONTENT_TRANSFER_ENCODING
public static final java.lang.String m_URIEscape
public static final java.lang.String m_UNCEscape
public static final java.lang.String TEXT_HTML
public static final java.lang.String TEXT_PLAIN
public static final java.lang.String TEXT_UNKNOWN
public static final java.lang.String APPLICATION_XML
public static final java.lang.String APPLICATION_CFF2
public static final java.lang.String APPLICATION_ZIP
public static final java.lang.String APPLICATION_XZIP
public static final java.lang.String APPLICATION_PDF
public static final java.lang.String APPLICATION_PS
public static final java.lang.String TEXT_XML
public static final java.lang.String TEXT_CSV
public static final java.lang.String TEXT_JSON
public static final java.lang.String APPLICATION_JSON
public static final java.lang.String VND_PPF
public static final java.lang.String VND_PTK
public static final java.lang.String VND_JDF
public static final java.lang.String VND_JMF
public static final java.lang.String VND_XJDF
public static final java.lang.String VND_XJMF
public static final java.lang.String VND_XJDF_J
public static final java.lang.String VND_XJMF_J
public static final java.lang.String CONTENT_ID
public static final java.lang.String CONTENT_TYPE
public static final java.lang.String CONTENT_LENGTH
public static final java.lang.String BASE64
public static final java.lang.String BINARY
public static final java.lang.String CONNECTION
public static final java.lang.String AUTHORIZATION
public static void setConnectionTimeout(int timeout)
public static int getConnectionTimeout()
public static java.lang.String getRelativeURL(java.io.File f,
java.io.File baseDir,
boolean bEscape128)
f - the file to get the relative url forbaseDir - the file that describes cwd, if null cwd is calculatedbEscape128 - if true, escape > 128 (URL), else retain (IRL)public static java.lang.String createHttpUrl(boolean bSecure,
java.lang.String host,
int port,
java.lang.String path)
bSecure - if true, make httpshost - hostnameport - the port, duhpath - may be nullpublic static java.lang.String getRelativePath(java.io.File f,
java.io.File fCWD)
f - the file to get the relative path forfCWD - the file that describes cwd, if null cwd is calculated from user.dirpublic static java.lang.String getFileName(java.lang.String url,
javax.mail.Multipart mp)
url - mp - public static java.io.InputStream getCidURLStream(java.lang.String url,
javax.mail.Multipart multipart)
url - the url to get a stream formultipart - the multipart mime to which the cid refersnull if broken or non-existentpublic static java.lang.String extension(java.lang.String pathName)
pathName - the pathName to get the extension for@Deprecated public static java.lang.String removeExtension(java.lang.String pathName)
pathName - the pathName to get the extension forpublic static UrlPart[] getURLParts(java.net.HttpURLConnection connection)
connection - public static java.io.InputStream getURLInputStream(java.lang.String urlString,
javax.mail.BodyPart bodyPart)
urlString - bodyPart - public static java.io.InputStream getURLInputStream(java.lang.String urlString)
urlString - @Deprecated public static java.io.File getCreateDirectory(java.lang.String newDir)
newDir - the path or URL of the new directorypublic static java.lang.String fileToUrl(java.io.File f,
boolean bEscape128)
f - the File to parse,bEscape128 - if true, escape non -ascii chars (URI), if false, don't (IRI)public static java.lang.String urlToFileName(java.lang.String urlString)
urlString - the string to parse for a file namepublic static java.io.File urlToFile(java.lang.String urlString)
urlString - the file url to retrieve a file forpublic static java.lang.String urlToUNC(java.lang.String urlString)
urlString - the file url to retrieve a UNC path forpublic static java.lang.String uncToUrl(java.lang.String unc,
boolean escape128)
unc - escape128 - if true escape chars>128public static java.lang.String urlToString(java.net.URL url)
url - public static java.lang.String addParameter(java.lang.String baseUrl,
java.lang.String key,
java.lang.String val)
baseUrl - the base url - already escaped and ready to gokey - the key to add - NOT escapedval - the value to add - NOT escaped - if null nothing is setpublic static java.lang.String addPath(java.lang.String baseUrl,
java.lang.String path)
baseUrl - the base url - already escaped and ready to gopath - the path to addpublic static java.lang.String escape(java.lang.String toEscape,
boolean bEscape128)
toEscape - the string to escapebEscape128 - if true, also escape >128, else leave non-ascii7 as ispublic static java.lang.String escape(java.lang.String toEscape,
boolean bEscape128,
boolean escapeSlash)
toEscape - the string to escapebEscape128 - if true, also escape >128, else leave non-ascii7 as isescapeSlash - if true also escape '/'public static java.lang.String unEscape(java.lang.String toEscape)
toEscape - the string to unescapepublic static java.net.URL stringToURL(java.lang.String urlString)
urlString - the file url to retrieve a file forpublic static boolean isFileOK(java.io.File f)
f - - File to checkpublic static boolean isEscaped(java.lang.String url)
url - the url to testpublic static java.lang.String getExtensionFromMimeType(java.lang.String contentType)
contentType - public static java.lang.String getMimeTypeFromURL(java.lang.String url)
url - public static boolean isCID(java.lang.String url)
url - the url to testpublic static boolean isNotCID(java.lang.String url)
url - the url to testpublic static boolean isFile(java.lang.String url)
url - public static boolean isWindowsLocalPath(java.lang.String pathName)
pathName - public static boolean isHttp(java.lang.String url)
url - the url to testpublic static boolean isFtp(java.lang.String url)
url - the url to testpublic static boolean isHttps(java.lang.String url)
url - the url to testpublic static boolean isNet(java.lang.String url)
url - the url to testpublic static java.lang.String normalize(java.lang.String urlString)
urlString - public static boolean isUNC(java.lang.String pathName)
pathName - public static boolean isMIME(java.io.File file)
file - the FILE to checkpublic static UrlUtil.URLProtocol getProtocol(java.lang.String url)
url - public static java.lang.String getIPFromBytes(byte[] ip)
ip - public static byte[] getBytesFromIP(java.lang.String ip)
ip - public static boolean isMIMEExtenstension(java.lang.String lower)
lower - public static boolean isIRL(java.lang.String val)
val - public static java.lang.String removeProtocol(java.lang.String url)
url - the url string to work onpublic static boolean isURL(java.lang.String val)
val - public static java.lang.String getLocalURL(java.lang.String directory,
java.lang.String url)
directory - the url of the directoryurl - the absolute urlpublic static java.lang.String getURLWithDirectory(java.lang.String directory,
java.lang.String url)
directory - the url of the directoryurl - the relative url of the filepublic static java.lang.String getParentDirectory(java.lang.String url)
url - public static java.lang.String cleanDots(java.lang.String url)
url - the url to cleanpublic static java.lang.String cleanHttpURL(java.lang.String url)
url - the input urlpublic static UrlPart writeToURL(java.lang.String strUrl, java.io.InputStream stream, java.lang.String method, java.lang.String contentType, HTTPDetails det)
strUrl - the URL to write tostream - the input stream to read frommethod - HEAD, GET or POSTcontentType - the contenttype to set, if NULL defaults to TEXT/UNKNOWNdet - UrlPart the opened http connection, null in case of errorpublic static UrlPart writerToURL(java.lang.String strUrl, IStreamWriter streamWriter, java.lang.String method, java.lang.String contentType, HTTPDetails det)
strUrl - the URL to write tostreamWriter - the IStreamWriter to read frommethod - HEAD, GET or POSTcontentType - the contenttype to set, if NULL defaults to TEXT/UNKNOWNdet - UrlPart the opened http connection, null in case of error@Deprecated public static java.io.File moveToDir(IURLSetter parent, java.io.File dir, boolean overWrite)
parent - the parent element, trypically a filespec or previewdir - the directory to move to. dir is created if it does not exist. If dir exists and dir is not a directory, the call fails and null is returnedoverWrite - if true, zapp any old files with the same namepublic static java.io.File moveToDir(IURLSetter urlSetter, java.io.File dir, java.lang.String cwd, boolean overWrite)
urlSetter - the parent element, typically a filespec or previewdir - the directory to move to. dir is created if it does not exist. If dir exists and dir is not a directory, the call fails and null is returnedcwd - the current working dir for local urlsoverWrite - if true, zapp any old files with the same namepublic static java.io.File moveToDir(IURLSetter urlSetter, java.io.File dir, java.lang.String cwd, boolean overWrite, boolean deleteFile)
urlSetter - the parent element, typically a filespec or previewdir - the directory to move to. dir is created if it does not exist. If dir exists and dir is not a directory, the call fails and null is returnedcwd - the current working dir for local urlsoverWrite - if true, zapp any old files with the same namejava.lang.IllegalArgumentException - in case the filename contains '..'public static boolean isRelativeURL(java.lang.String url)
url - the url string to testpublic static boolean isXMLType(java.lang.String contentType)
contentType - public static boolean isJSONType(java.lang.String contentType)
contentType - public static boolean isZIPType(java.lang.String contentType)
contentType - public static java.lang.String newExtension(java.lang.String strWork,
java.lang.String newExt)
strWork - the file pathnewExt - the new extension (works with or without the initial "."public static java.lang.String prefix(java.lang.String strWork)
strWork - the string to work onpublic static boolean isRedirect(int responseCode)
responseCode - public static boolean isReturnCodeOK(int responseCode)
responseCode - public static boolean isReturnCodeOK(UrlPart p)
responseCode -