Package org.cip4.jdflib.util
Class UrlUtil
- java.lang.Object
-
- org.cip4.jdflib.util.UrlUtil
-
- Direct Known Subclasses:
MimeUtil
public class UrlUtil extends java.lang.Objectcollection of helper routines to convert urls
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classUrlUtil.HTTPDetailsDeprecated.use the real classstatic classUrlUtil.HttpMethodlist of all http methodsstatic classUrlUtil.URLProtocolrough classification of protocol typestatic classUrlUtil.URLWriterDeprecated.use the real class
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringACCEPTstatic java.lang.StringAPPLICATION_CFF2zip, maybe?static java.lang.StringAPPLICATION_JSONstatic java.lang.StringAPPLICATION_PDFpdf, duh...static java.lang.StringAPPLICATION_PSps, duh...static java.lang.StringAPPLICATION_XMLthe preferred value for XML!static java.lang.StringAPPLICATION_XZIPzip, maybe?static java.lang.StringAPPLICATION_ZIPstatic java.lang.StringAUTHORIZATIONstatic java.lang.StringBASE64static java.lang.StringBINARYstatic java.lang.StringCLOSEstatic java.lang.StringCONNECTstatic java.lang.StringCONNECTIONstatic java.lang.StringCONTENT_IDstatic java.lang.StringCONTENT_LENGTHmore commonly used stringsstatic java.lang.StringCONTENT_TRANSFER_ENCODINGstatic java.lang.StringCONTENT_TYPEmore commonly used stringsstatic java.lang.StringDELETEstatic java.lang.StringGEThttp get methodstatic java.lang.StringHEADhttp head methodstatic java.lang.StringKEEPALIVEstatic java.lang.Stringm_UNCEscapestrings that must be escaped in uncsstatic java.lang.Stringm_URIEscapestrings that must be escaped in urlsstatic intMAX_STREAMstatic java.lang.StringOPTIONSstatic java.lang.StringPATCHstatic java.lang.StringPOSThttp post methodstatic java.lang.StringPUThttp put methodstatic java.lang.StringTEXT_CSVstatic java.lang.StringTEXT_HTMLstatic java.lang.StringTEXT_JSONstatic java.lang.StringTEXT_PLAINstatic java.lang.StringTEXT_UNKNOWNstatic java.lang.StringTEXT_XMLstatic java.lang.StringTRACEstatic java.lang.StringVND_JDFstatic java.lang.StringVND_JMFstatic java.lang.StringVND_PPFstatic java.lang.StringVND_PTKstatic java.lang.StringVND_PTK_Jstatic java.lang.StringVND_XJDFstatic java.lang.StringVND_XJDF_Jstatic java.lang.StringVND_XJMFstatic java.lang.StringVND_XJMF_Jstatic java.lang.StringZIP
-
Constructor Summary
Constructors Constructor Description UrlUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.StringaddParameter(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.StringaddPath(java.lang.String baseUrl, java.lang.String path)adds a path to a given url , keeping the parametersstatic java.lang.StringaddSecure(java.lang.String baseURL, java.lang.String url)securely add a subdirectorystatic java.lang.StringcleanDots(java.lang.String url)remove any internal "../" "./" and "//" from a urlstatic java.lang.StringcleanHttpURL(java.lang.String url)create a "real" url from a user input url add http://static java.lang.StringcreateHttpUrl(boolean bSecure, java.lang.String host, int port, java.lang.String path)get a prinect url for this host and pathstatic java.lang.Stringescape(java.lang.String toEscape, boolean bEscape128)standard url escapingstatic java.lang.Stringescape(java.lang.String toEscape, boolean bEscape128, boolean escapeSlash)standard url escapingstatic java.lang.Stringextension(java.lang.String pathName)get the filename extension of pathName excluding the '.' if no '.' is found, returns null if trailing .static java.lang.StringfileToUrl(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-optimalstatic byte[]getBytesFromIP(java.lang.String ip)get the ip address as a set of bytes with the left byte at pos 0static java.io.InputStreamgetCidURLStream(java.lang.String url, javax.mail.Multipart multipart)get a readable inputstream from the CID urlstatic intgetConnectionTimeout()Returns connection timeout in milliseconds as integer.static java.io.FilegetCreateDirectory(java.lang.String newDir)Deprecated.use FileUtil.getCreateDirectory(newDir);static java.lang.StringgetExtensionFromMimeType(java.lang.String contentType)generates the correct extension for a given mime content typestatic java.lang.StringgetFileName(java.lang.String url, javax.mail.Multipart mp)get the file name for a url.static java.lang.StringgetIPFromBytes(byte[] ip)get the ip address as a string with the left byte at pos 0static java.lang.StringgetLocalURL(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 sensitivestatic java.lang.StringgetMimeTypeFromURL(java.lang.String url)generates the correct MIMEType for a given URL and sets itstatic java.lang.StringgetParameter(java.lang.String baseUrl, java.lang.String key)static java.lang.StringgetParentDirectory(java.lang.String url)get the parent directory of a file or urlstatic UrlUtil.URLProtocolgetProtocol(java.lang.String url)returns the general protocol type of a urlstatic java.lang.StringgetRelativePath(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.StringgetRelativeURL(java.io.File f, java.io.File baseDir, boolean bEscape128)returns the relative URL of a file relative to the current working directorystatic java.lang.StringgetSecurePath(java.lang.String url, boolean allowAbsolute)secure check of a file pathstatic java.io.InputStreamgetURLInputStream(java.lang.String urlString)static java.io.InputStreamgetURLInputStream(java.lang.String urlString, javax.mail.BodyPart bodyPart)get the opened input stream for a given url stringstatic java.io.InputStreamgetURLInputStream(java.lang.String urlString, javax.mail.BodyPart bodyPart, ZipReader zr)get the opened input stream for a given url stringstatic 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 thatstatic java.lang.StringgetURLWithDirectory(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 booleanisCID(java.lang.String url)test whether a given url is a cid (cid:)static booleanisEscaped(java.lang.String url)test whether a given url is escaped as utf-8static booleanisFile(java.lang.String url)is this a valid file urlstatic booleanisFileOK(java.io.File f)checks whether there is a remote chance that the file is useful for readingstatic booleanisFtp(java.lang.String url)test whether a given url is an http url (excluding https - @see isHttps)static booleanisHttp(java.lang.String url)test whether a given url is an http url (excluding https - @see isHttps)static booleanisHttps(java.lang.String url)test whether a given url is an https urlstatic booleanisIRL(java.lang.String val)static booleanisJSONType(java.lang.String contentType)check whether the mime type is a known xml dialectstatic booleanisMIME(java.io.File file)check whether a file is a mime file only check extensions TODO sniff file rather than check extensionsstatic booleanisMIMEExtenstension(java.lang.String lower)check whether a file is a mime filestatic booleanisNet(java.lang.String url)test whether a given url is any network style url, currently either http, https or ftpstatic booleanisNotCID(java.lang.String url)test whether a given url is NOT a cid this may be a local identifierstatic booleanisRedirect(int responseCode)return true if the response code should redirectstatic booleanisRelativeURL(java.lang.String url)if true this url is relativestatic booleanisReturnCodeOK(int responseCode)return true if the response code should redirectstatic booleanisReturnCodeOK(UrlPart p)return true if the response code should redirectstatic booleanisUNC(java.lang.String pathName)test whether a given url is a unc pathstatic booleanisURL(java.lang.String val)static booleanisWindowsLocalPath(java.lang.String pathName)static booleanisXMLType(java.lang.String contentType)check whether the mime type is a known xml dialectstatic booleanisZip(java.lang.String url)check whether the url type is a known zipstatic booleanisZIPType(java.lang.String contentType)check whether the mime type is a known zip dialectstatic java.io.FilemoveToDir(IURLSetter parent, java.io.File dir, boolean overWrite)Deprecated.use moveToDir(parent, dir, null, overWrite);static java.io.FilemoveToDir(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 locationstatic java.io.FilemoveToDir(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 locationstatic java.lang.StringnewExtension(java.lang.String strWork, java.lang.String newExt)replace the .extension of a file namestatic java.lang.Stringnormalize(java.lang.String urlString)normalize a url string by grinding it through urlstatic java.lang.Stringprefix(java.lang.String strWork)inverse of extensionstatic java.lang.StringremoveExtension(java.lang.String pathName)Deprecated.use prefix(pathName)static java.lang.StringremoveProtocol(java.lang.String url)remove the protocol part of a url, if it is specifiedstatic voidsetConnectionTimeout(int timeout)Returns connection timeout in milliseconds as integer.static java.lang.StringsetParameter(java.lang.String baseUrl, java.lang.String key, java.lang.String val)adds a parameter to a given url using either ? or &static java.net.URLstringToURL(java.lang.String urlString)Create a URL for any url string using heuristics and escapingstatic java.lang.StringuncToUrl(java.lang.String unc, boolean escape128)static java.lang.StringunEscape(java.lang.String toEscape)standard url unescapingstatic java.io.FileurlToFile(java.lang.String urlString)Retrieve a file for a relative or absolute file urlstatic java.lang.StringurlToFileName(java.lang.String urlString)static java.lang.StringurlToString(java.net.URL url)null safe url to string converterstatic java.lang.StringurlToUNC(java.lang.String urlString)Retrieve a UNC path for a relative or absolute file url, any of '/'or "\\" is assumed a path separatorstatic UrlPartwriterToURL(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 responsestatic UrlPartwriteToURL(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
-
-
-
Field Detail
-
ZIP
public static final java.lang.String ZIP
- See Also:
- Constant Field Values
-
MAX_STREAM
public static final int MAX_STREAM
- See Also:
- Constant Field Values
-
POST
public static final java.lang.String POST
http post method
-
PUT
public static final java.lang.String PUT
http put method
-
GET
public static final java.lang.String GET
http get method
-
HEAD
public static final java.lang.String HEAD
http head method
-
DELETE
public static final java.lang.String DELETE
-
CONNECT
public static final java.lang.String CONNECT
-
OPTIONS
public static final java.lang.String OPTIONS
-
TRACE
public static final java.lang.String TRACE
-
PATCH
public static final java.lang.String PATCH
-
KEEPALIVE
public static final java.lang.String KEEPALIVE
- See Also:
- Constant Field Values
-
ACCEPT
public static final java.lang.String ACCEPT
- See Also:
- Constant Field Values
-
CLOSE
public static final java.lang.String CLOSE
- See Also:
- Constant Field Values
-
CONTENT_TRANSFER_ENCODING
public static final java.lang.String CONTENT_TRANSFER_ENCODING
- See Also:
- Constant Field Values
-
m_URIEscape
public static final java.lang.String m_URIEscape
strings that must be escaped in urls- See Also:
- Constant Field Values
-
m_UNCEscape
public static final java.lang.String m_UNCEscape
strings that must be escaped in uncs- See Also:
- Constant Field Values
-
TEXT_HTML
public static final java.lang.String TEXT_HTML
- See Also:
- Constant Field Values
-
TEXT_PLAIN
public static final java.lang.String TEXT_PLAIN
- See Also:
- Constant Field Values
-
TEXT_UNKNOWN
public static final java.lang.String TEXT_UNKNOWN
- See Also:
- Constant Field Values
-
APPLICATION_XML
public static final java.lang.String APPLICATION_XML
the preferred value for XML!- See Also:
- Constant Field Values
-
APPLICATION_CFF2
public static final java.lang.String APPLICATION_CFF2
zip, maybe?- See Also:
- Constant Field Values
-
APPLICATION_ZIP
public static final java.lang.String APPLICATION_ZIP
- See Also:
- Constant Field Values
-
APPLICATION_XZIP
public static final java.lang.String APPLICATION_XZIP
zip, maybe?- See Also:
- Constant Field Values
-
APPLICATION_PDF
public static final java.lang.String APPLICATION_PDF
pdf, duh...- See Also:
- Constant Field Values
-
APPLICATION_PS
public static final java.lang.String APPLICATION_PS
ps, duh...- See Also:
- Constant Field Values
-
TEXT_XML
public static final java.lang.String TEXT_XML
- See Also:
- Constant Field Values
-
TEXT_CSV
public static final java.lang.String TEXT_CSV
- See Also:
- Constant Field Values
-
TEXT_JSON
public static final java.lang.String TEXT_JSON
- See Also:
- Constant Field Values
-
APPLICATION_JSON
public static final java.lang.String APPLICATION_JSON
- See Also:
- Constant Field Values
-
VND_PPF
public static final java.lang.String VND_PPF
- See Also:
- Constant Field Values
-
VND_PTK
public static final java.lang.String VND_PTK
- See Also:
- Constant Field Values
-
VND_PTK_J
public static final java.lang.String VND_PTK_J
- See Also:
- Constant Field Values
-
VND_JDF
public static final java.lang.String VND_JDF
- See Also:
- Constant Field Values
-
VND_JMF
public static final java.lang.String VND_JMF
- See Also:
- Constant Field Values
-
VND_XJDF
public static final java.lang.String VND_XJDF
- See Also:
- Constant Field Values
-
VND_XJMF
public static final java.lang.String VND_XJMF
- See Also:
- Constant Field Values
-
VND_XJDF_J
public static final java.lang.String VND_XJDF_J
- See Also:
- Constant Field Values
-
VND_XJMF_J
public static final java.lang.String VND_XJMF_J
- See Also:
- Constant Field Values
-
CONTENT_ID
public static final java.lang.String CONTENT_ID
- See Also:
- Constant Field Values
-
CONTENT_TYPE
public static final java.lang.String CONTENT_TYPE
more commonly used strings- See Also:
- Constant Field Values
-
CONTENT_LENGTH
public static final java.lang.String CONTENT_LENGTH
more commonly used strings- See Also:
- Constant Field Values
-
BASE64
public static final java.lang.String BASE64
- See Also:
- Constant Field Values
-
BINARY
public static final java.lang.String BINARY
- See Also:
- Constant Field Values
-
CONNECTION
public static final java.lang.String CONNECTION
- See Also:
- Constant Field Values
-
AUTHORIZATION
public static final java.lang.String AUTHORIZATION
- See Also:
- Constant Field Values
-
-
Method Detail
-
setConnectionTimeout
public static void setConnectionTimeout(int timeout)
Returns connection timeout in milliseconds as integer.
-
getConnectionTimeout
public static int getConnectionTimeout()
Returns connection timeout in milliseconds as integer.- Returns:
- connectionTimeout in milliseconds
-
getRelativeURL
public 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- Parameters:
f- the file to get the relative url forbaseDir- the file that describes cwd, ifnullcwd is calculatedbEscape128- if true, escape > 128 (URL), else retain (IRL)- Returns:
-
createHttpUrl
public 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- Parameters:
bSecure- if true, make httpshost- hostnameport- the port, duhpath- may be null- Returns:
-
getRelativePath
public 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.- Parameters:
f- the file to get the relative path forfCWD- the file that describes cwd, ifnullcwd is calculated from user.dir- Returns:
-
getFileName
public static java.lang.String getFileName(java.lang.String url, javax.mail.Multipart mp)get the file name for a url. extract it from a mime package, if appropriate- Parameters:
url-mp-- Returns:
-
getCidURLStream
public static java.io.InputStream getCidURLStream(java.lang.String url, javax.mail.Multipart multipart)get a readable inputstream from the CID url- Parameters:
url- the url to get a stream formultipart- the multipart mime to which the cid refers- Returns:
- InputStream - the readable input stream that this filespec refers to,
nullif broken or non-existent
-
extension
public 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 . is found, returns ""- Parameters:
pathName- the pathName to get the extension for- Returns:
- String - the filename extension
-
removeExtension
@Deprecated public static java.lang.String removeExtension(java.lang.String pathName)
Deprecated.use prefix(pathName)get the path name without extension of pathName- Parameters:
pathName- the pathName to get the extension for- Returns:
- String - the filename without extension
-
getURLParts
public 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- Parameters:
connection-- Returns:
- the array of body parts input stream
-
getURLInputStream
public static java.io.InputStream getURLInputStream(java.lang.String urlString, javax.mail.BodyPart bodyPart, ZipReader zr)get the opened input stream for a given url string- Parameters:
urlString-bodyPart-zr-- Returns:
-
getURLInputStream
public static java.io.InputStream getURLInputStream(java.lang.String urlString, javax.mail.BodyPart bodyPart)get the opened input stream for a given url string- Parameters:
urlString-bodyPart-- Returns:
-
getURLInputStream
public static java.io.InputStream getURLInputStream(java.lang.String urlString)
- Parameters:
urlString-- Returns:
-
getCreateDirectory
@Deprecated public static java.io.File getCreateDirectory(java.lang.String newDir)
Deprecated.use FileUtil.getCreateDirectory(newDir);create a new directory and return null if the directory could not be created- Parameters:
newDir- the path or URL of the new directory- Returns:
-
fileToUrl
public 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- Parameters:
f- the File to parse,bEscape128- if true, escape non -ascii chars (URI), if false, don't (IRI)- Returns:
- the URL string
-
urlToFileName
public static java.lang.String urlToFileName(java.lang.String urlString)
- Parameters:
urlString- the string to parse for a file name- Returns:
- the filename
-
urlToFile
public static java.io.File urlToFile(java.lang.String urlString)
Retrieve a file for a relative or absolute file url- Parameters:
urlString- the file url to retrieve a file for- Returns:
- the file located at url
-
urlToUNC
public 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- Parameters:
urlString- the file url to retrieve a UNC path for- Returns:
- the UNC
-
uncToUrl
public static java.lang.String uncToUrl(java.lang.String unc, boolean escape128)- Parameters:
unc-escape128- if true escape chars>128- Returns:
-
urlToString
public static java.lang.String urlToString(java.net.URL url)
null safe url to string converter- Parameters:
url-- Returns:
-
addParameter
public 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 &- Parameters:
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 set- Returns:
- the escaped new url
-
getSecurePath
public static java.lang.String getSecurePath(java.lang.String url, boolean allowAbsolute) throws java.lang.IllegalArgumentExceptionsecure check of a file path- Parameters:
baseFile-file-- Returns:
- Throws:
java.lang.IllegalArgumentException
-
setParameter
public static java.lang.String setParameter(java.lang.String baseUrl, java.lang.String key, java.lang.String val)adds a parameter to a given url using either ? or &- Parameters:
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 set- Returns:
- the escaped new url
-
getParameter
public static java.lang.String getParameter(java.lang.String baseUrl, java.lang.String key)
-
addPath
public static java.lang.String addPath(java.lang.String baseUrl, java.lang.String path) throws java.lang.IllegalArgumentExceptionadds a path to a given url , keeping the parameters- Parameters:
baseUrl- the base url - already escaped and ready to gopath- the path to add- Returns:
- the escaped new url
- Throws:
java.lang.IllegalArgumentException
-
escape
public static java.lang.String escape(java.lang.String toEscape, boolean bEscape128)standard url escaping- Parameters:
toEscape- the string to escapebEscape128- if true, also escape >128, else leave non-ascii7 as is- Returns:
- the escaped string
-
escape
public static java.lang.String escape(java.lang.String toEscape, boolean bEscape128, boolean escapeSlash)standard url escaping- Parameters:
toEscape- the string to escapebEscape128- if true, also escape >128, else leave non-ascii7 as isescapeSlash- if true also escape '/'- Returns:
- the escaped string
-
unEscape
public static java.lang.String unEscape(java.lang.String toEscape)
standard url unescaping- Parameters:
toEscape- the string to unescape- Returns:
- the escaped string
-
stringToURL
public static java.net.URL stringToURL(java.lang.String urlString)
Create a URL for any url string using heuristics and escaping- Parameters:
urlString- the file url to retrieve a file for- Returns:
-
isFileOK
public static boolean isFileOK(java.io.File f)
checks whether there is a remote chance that the file is useful for reading- Parameters:
f- - File to check- Returns:
- true if the file is ok
-
isEscaped
public static boolean isEscaped(java.lang.String url)
test whether a given url is escaped as utf-8- Parameters:
url- the url to test- Returns:
-
getExtensionFromMimeType
public static java.lang.String getExtensionFromMimeType(java.lang.String contentType)
generates the correct extension for a given mime content type- Parameters:
contentType-- Returns:
-
getMimeTypeFromURL
public static java.lang.String getMimeTypeFromURL(java.lang.String url)
generates the correct MIMEType for a given URL and sets it- Parameters:
url-- Returns:
-
isCID
public static boolean isCID(java.lang.String url)
test whether a given url is a cid (cid:)- Parameters:
url- the url to test- Returns:
-
isNotCID
public static boolean isNotCID(java.lang.String url)
test whether a given url is NOT a cid this may be a local identifier- Parameters:
url- the url to test- Returns:
- true if we are either a cid or a local url
-
isFile
public static boolean isFile(java.lang.String url)
is this a valid file url- Parameters:
url-- Returns:
-
isWindowsLocalPath
public static boolean isWindowsLocalPath(java.lang.String pathName)
- Parameters:
pathName-- Returns:
-
isHttp
public static boolean isHttp(java.lang.String url)
test whether a given url is an http url (excluding https - @see isHttps)- Parameters:
url- the url to test- Returns:
-
isFtp
public static boolean isFtp(java.lang.String url)
test whether a given url is an http url (excluding https - @see isHttps)- Parameters:
url- the url to test- Returns:
-
isHttps
public static boolean isHttps(java.lang.String url)
test whether a given url is an https url- Parameters:
url- the url to test- Returns:
-
isNet
public static boolean isNet(java.lang.String url)
test whether a given url is any network style url, currently either http, https or ftp- Parameters:
url- the url to test- Returns:
-
normalize
public static java.lang.String normalize(java.lang.String urlString)
normalize a url string by grinding it through url- Parameters:
urlString-- Returns:
- the normalized string, null if not a valid url
-
isUNC
public static boolean isUNC(java.lang.String pathName)
test whether a given url is a unc path- Parameters:
pathName-- Returns:
-
isMIME
public 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- Parameters:
file- the FILE to check- Returns:
- true if the file is a MIME file
-
getProtocol
public static UrlUtil.URLProtocol getProtocol(java.lang.String url)
returns the general protocol type of a url- Parameters:
url-- Returns:
-
getIPFromBytes
public static java.lang.String getIPFromBytes(byte[] ip)
get the ip address as a string with the left byte at pos 0- Parameters:
ip-- Returns:
-
getBytesFromIP
public static byte[] getBytesFromIP(java.lang.String ip)
get the ip address as a set of bytes with the left byte at pos 0- Parameters:
ip-- Returns:
-
isMIMEExtenstension
public static boolean isMIMEExtenstension(java.lang.String lower)
check whether a file is a mime file- Parameters:
lower-- Returns:
-
isIRL
public static boolean isIRL(java.lang.String val)
- Parameters:
val-- Returns:
-
removeProtocol
public static java.lang.String removeProtocol(java.lang.String url)
remove the protocol part of a url, if it is specified- Parameters:
url- the url string to work on- Returns:
- the input string without the protocol and ":"
-
isURL
public static boolean isURL(java.lang.String val)
- Parameters:
val-- Returns:
-
getLocalURL
public 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- Parameters:
directory- the url of the directoryurl- the absolute url- Returns:
- String - the local URL of url after removing directory
-
addSecure
public static java.lang.String addSecure(java.lang.String baseURL, java.lang.String url) throws java.lang.IllegalArgumentExceptionsecurely add a subdirectory- Parameters:
baseURL-url-- Returns:
- Throws:
java.lang.IllegalArgumentException
-
getURLWithDirectory
public 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. file:)- Parameters:
directory- the url of the directoryurl- the relative url of the file- Returns:
- String - the concatenated URL of the directory + file
-
getParentDirectory
public static java.lang.String getParentDirectory(java.lang.String url)
get the parent directory of a file or url- Parameters:
url-- Returns:
-
cleanDots
public static java.lang.String cleanDots(java.lang.String url)
remove any internal "../" "./" and "//" from a url- Parameters:
url- the url to clean- Returns:
- String - the clean path
-
cleanHttpURL
public static java.lang.String cleanHttpURL(java.lang.String url)
create a "real" url from a user input url add http://- Parameters:
url- the input url- Returns:
- the - hopefully - usable url
-
writeToURL
public 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- Parameters:
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-- Returns:
UrlPartthe opened http connection, null in case of error
-
writerToURL
public 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- Parameters:
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-- Returns:
UrlPartthe opened http connection, null in case of error
-
moveToDir
@Deprecated public static java.io.File moveToDir(IURLSetter parent, java.io.File dir, boolean overWrite)
Deprecated.use moveToDir(parent, dir, null, overWrite);physically store the file at the location specified in dir and also modify this to reflect the new location- Parameters:
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- Returns:
- the file that corresponds to the moved url reference, null if an error occurred
-
moveToDir
public 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- Parameters:
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 name- Returns:
- the file that corresponds to the moved url reference, null if an error occurred
-
moveToDir
public 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- Parameters:
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 name- Returns:
- the file that corresponds to the moved url reference, null if an error occurred
- Throws:
java.lang.IllegalArgumentException- in case the filename contains '..'
-
isRelativeURL
public static boolean isRelativeURL(java.lang.String url)
if true this url is relative- Parameters:
url- the url string to test- Returns:
- true if relative
-
isXMLType
public static boolean isXMLType(java.lang.String contentType)
check whether the mime type is a known xml dialect- Parameters:
contentType-- Returns:
-
isJSONType
public static boolean isJSONType(java.lang.String contentType)
check whether the mime type is a known xml dialect- Parameters:
contentType-- Returns:
-
isZIPType
public static boolean isZIPType(java.lang.String contentType)
check whether the mime type is a known zip dialect- Parameters:
contentType-- Returns:
-
isZip
public static boolean isZip(java.lang.String url)
check whether the url type is a known zip- Parameters:
url-- Returns:
-
newExtension
public static java.lang.String newExtension(java.lang.String strWork, java.lang.String newExt)replace the .extension of a file name- Parameters:
strWork- the file pathnewExt- the new extension (works with or without the initial "."- Returns:
- the strWork with a replaced extension
-
prefix
public static java.lang.String prefix(java.lang.String strWork)
inverse of extension- Parameters:
strWork- the string to work on- Returns:
- the prefix
-
isRedirect
public static boolean isRedirect(int responseCode)
return true if the response code should redirect- Parameters:
responseCode-- Returns:
-
isReturnCodeOK
public static boolean isReturnCodeOK(int responseCode)
return true if the response code should redirect- Parameters:
responseCode-- Returns:
-
isReturnCodeOK
public static boolean isReturnCodeOK(UrlPart p)
return true if the response code should redirect- Parameters:
responseCode-- Returns:
-
-