|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.cip4.jdflib.util.UrlUtil
public class UrlUtil
collection of helper routines to convert urls
| Nested Class Summary | |
|---|---|
static class |
UrlUtil.HTTPDetails
helper class to set mime details |
static class |
UrlUtil.URLProtocol
rough classification of protocol type |
private static class |
UrlUtil.URLWriter
|
| Field Summary | |
|---|---|
static java.lang.String |
APPLICATION_PDF
pdf, duh... |
static java.lang.String |
APPLICATION_XML
the preferred value for XML! |
static java.lang.String |
APPLICATION_ZIP
zip, maybe? |
static java.lang.String |
BASE64
|
static java.lang.String |
BINARY
|
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 |
GET
http get method |
static java.lang.String |
HEAD
http head method |
static java.lang.String |
KEEPALIVE
|
static java.lang.String |
m_URIEscape
strings that must be escaped in urls |
private static java.util.HashMap<java.lang.String,java.lang.String> |
mimeMap
|
static java.lang.String |
POST
http post method |
static java.lang.String |
TEXT_HTML
|
static java.lang.String |
TEXT_PLAIN
|
static java.lang.String |
TEXT_UNKNOWN
|
static java.lang.String |
TEXT_XML
|
static java.lang.String |
VND_JDF
|
static java.lang.String |
VND_JMF
|
| Constructor Summary | |
|---|---|
UrlUtil()
|
|
| Method Summary | |
|---|---|
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 |
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 java.io.InputStream |
getCidURLStream(java.lang.String url,
javax.mail.Multipart multipart)
get a readable inputstream from the CID url |
static java.io.File |
getCreateDirectory(java.lang.String newDir)
Deprecated. use FileUtil.getCreateDirectory(newDir); |
static java.lang.String |
getFileName(java.lang.String url,
javax.mail.Multipart mp)
get the file name for a url. |
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 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 |
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 |
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 |
isNotCID(java.lang.String url)
test whether a given url is NOT a cid this may be a local identifier |
static boolean |
isRelativeURL(java.lang.String url)
if true this url is relative |
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)
|
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 parent,
java.io.File dir,
java.lang.String cwd,
boolean overWrite)
physically store the file at the location specified in dir and also modify this 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 athe protocol part of a url, if it is specified |
static java.net.URL |
stringToURL(java.lang.String urlString)
Create a URL for any url string using heuristics and escaping |
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 file for a relative or absolute file url |
static UrlPart |
writeToURL(java.lang.String strUrl,
java.io.InputStream stream,
java.lang.String method,
java.lang.String contentType,
UrlUtil.HTTPDetails details)
write a Stream to an output URL File: and http: are currently supported Use HttpURLConnection.getInputStream() to retrieve the http response |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String POST
public static final java.lang.String GET
public static final java.lang.String HEAD
public static final java.lang.String KEEPALIVE
public static final java.lang.String CONTENT_TRANSFER_ENCODING
public static final java.lang.String m_URIEscape
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_ZIP
public static final java.lang.String APPLICATION_PDF
public static final java.lang.String TEXT_XML
public static final java.lang.String VND_JDF
public static final java.lang.String VND_JMF
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
private static java.util.HashMap<java.lang.String,java.lang.String> mimeMap
| Constructor Detail |
|---|
public UrlUtil()
| Method Detail |
|---|
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 null
public 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.dir
public 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 refers
null 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 for
public 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 directory
public 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 name
public static java.io.File urlToFile(java.lang.String urlString)
urlString - the file url to retrieve a file for
public static java.lang.String urlToUNC(java.lang.String urlString)
urlString - the file url to retrieve a file for
public 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
public 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 add
public 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 is
public static java.lang.String unEscape(java.lang.String toEscape)
toEscape - the string to unescape
public static java.net.URL stringToURL(java.lang.String urlString)
urlString - the file url to retrieve a file for
public static boolean isFileOK(java.io.File f)
f - - File to check
public static boolean isEscaped(java.lang.String url)
url - the url to test
public static java.lang.String getMimeTypeFromURL(java.lang.String url)
url -
public static boolean isCID(java.lang.String url)
url - the url to test
public static boolean isNotCID(java.lang.String url)
url - the url to test
public 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 test
public static boolean isHttps(java.lang.String url)
url - the url to test
public 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 check
public static UrlUtil.URLProtocol getProtocol(java.lang.String url)
url -
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 on
public 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 url
public static java.lang.String getURLWithDirectory(java.lang.String directory,
java.lang.String url)
directory - the url of the directoryurl - the relative url of the file
public static java.lang.String cleanDots(java.lang.String url)
url - the url to clean
public static java.lang.String cleanHttpURL(java.lang.String url)
url - the input url
public static UrlPart writeToURL(java.lang.String strUrl,
java.io.InputStream stream,
java.lang.String method,
java.lang.String contentType,
UrlUtil.HTTPDetails details)
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/UNKNOWNdetails -
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 name
public static java.io.File moveToDir(IURLSetter parent,
java.io.File dir,
java.lang.String cwd,
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 returnedcwd - the current working dir for local urlsoverWrite - if true, zapp any old files with the same name
public static boolean isRelativeURL(java.lang.String url)
url - the url string to test
public static boolean isXMLType(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 on
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||