Package dap4.core.util
Class XURI
- java.lang.Object
-
- dap4.core.util.XURI
-
public class XURI extends Object
Provide an extended form of URI parser with the following features: 1. can parse the query and fragment parts. 2. supports multiple protocols 3. supports modification of the URI path. 4. supports url -> string as controlled by flags
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XURI.Parts
-
Field Summary
Fields Modifier and Type Field Description protected static Pattern
drivelettertest
protected static Pattern
filedrivelettertest
protected Map<String,String>
fragfields
protected boolean
isfile
protected List<String>
nonleadschemes
protected Map<String,String>
queryfields
static EnumSet<XURI.Parts>
URLALL
static EnumSet<XURI.Parts>
URLONLY
static EnumSet<XURI.Parts>
URLQUERY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String[]
allSchemes(String xu)
Extract all schemes at front of a url.String
assemble(EnumSet<XURI.Parts> parts)
Reassemble the url using the specified partsstatic String
canonical(String s)
Canonicalize a part of a URLprotected List<String>
escapedsplit(String s, char sep, char escape)
protected int
findunescaped(String s, int start, char sep, char escape, int len)
String
fixdriveletter(URI uri)
Map<String,String>
getFragFields()
String
getFragment()
String
getHost()
String
getPath()
int
getPort()
String
getQuery()
Map<String,String>
getQueryFields()
String
getRealPath()
Return a path that can be used to open a fileString
getScheme()
List<String>
getSchemes()
String
getUserInfo()
static boolean
hasDriveLetter(String path)
return true if this path appears to start with a windows drive letter including those hidden by leading '/'static String
hideDriveLetter(String path)
Return a path with possible windows drive letter hidden by '/'.protected Map<String,String>
insertAmpField(String key, String value, String query)
void
insertFragmentField(String key, String newval)
Allow fragment fields to be insertedvoid
insertQueryField(String key, String newval)
Allow queryfields to be insertedboolean
isFile()
protected Map<String,String>
parseAmpList(String s, char sep, char escape)
protected void
parseFragment()
protected void
parseQuery()
protected void
rebuildQuery()
Rebuild query from current queryfieldsprotected Map<String,String>
removeAmpField(String key, String query)
void
removeQueryField(String key)
Allow queryfields to be removedvoid
setFragment(String xfragment)
void
setHost(String xhost)
void
setPath(String xpath)
void
setPort(int xport)
void
setQuery(String xquery)
void
setScheme(String xscheme)
void
setUserInfo(String xuserinfo)
String
toString()
static String
truePath(String path)
return repaired path; if this path appears to start with a windows drive letter hidden by leading '/', then the leading '/' is removed
-
-
-
Field Detail
-
drivelettertest
protected static final Pattern drivelettertest
-
filedrivelettertest
protected static final Pattern filedrivelettertest
-
URLONLY
public static final EnumSet<XURI.Parts> URLONLY
-
URLALL
public static final EnumSet<XURI.Parts> URLALL
-
URLQUERY
public static final EnumSet<XURI.Parts> URLQUERY
-
isfile
protected boolean isfile
-
-
Constructor Detail
-
XURI
public XURI(String xu) throws URISyntaxException
- Throws:
URISyntaxException
-
XURI
public XURI(URL xu) throws URISyntaxException
- Throws:
URISyntaxException
-
XURI
public XURI(URI xu) throws URISyntaxException
- Throws:
URISyntaxException
-
-
Method Detail
-
getUserInfo
public String getUserInfo()
-
getHost
public String getHost()
-
getPort
public int getPort()
-
getPath
public String getPath()
-
getRealPath
public String getRealPath()
Return a path that can be used to open a file- Returns:
-
getQuery
public String getQuery()
-
getFragment
public String getFragment()
-
getScheme
public String getScheme()
-
setScheme
public void setScheme(String xscheme)
-
setUserInfo
public void setUserInfo(String xuserinfo)
-
setHost
public void setHost(String xhost)
-
setPort
public void setPort(int xport)
-
setPath
public void setPath(String xpath)
-
setQuery
public void setQuery(String xquery)
-
setFragment
public void setFragment(String xfragment)
-
insertQueryField
public void insertQueryField(String key, String newval)
Allow queryfields to be inserted- Parameters:
key
-newval
-
-
insertFragmentField
public void insertFragmentField(String key, String newval)
Allow fragment fields to be inserted- Parameters:
key
-newval
-
-
removeQueryField
public void removeQueryField(String key)
Allow queryfields to be removed- Parameters:
key
-
-
rebuildQuery
protected void rebuildQuery()
Rebuild query from current queryfields
-
isFile
public boolean isFile()
-
parseQuery
protected void parseQuery()
-
parseFragment
protected void parseFragment()
-
insertAmpField
protected Map<String,String> insertAmpField(String key, String value, String query)
-
findunescaped
protected int findunescaped(String s, int start, char sep, char escape, int len)
-
assemble
public String assemble(EnumSet<XURI.Parts> parts)
Reassemble the url using the specified parts- Parameters:
parts
- to include- Returns:
- the assembled uri
-
fixdriveletter
public String fixdriveletter(URI uri) throws URISyntaxException
- Throws:
URISyntaxException
-
canonical
public static String canonical(String s)
Canonicalize a part of a URL- Parameters:
s
- part of the url
-
hasDriveLetter
public static boolean hasDriveLetter(String path)
return true if this path appears to start with a windows drive letter including those hidden by leading '/'- Parameters:
path
-- Returns:
- true, if path has drive letter
-
hideDriveLetter
public static String hideDriveLetter(String path)
Return a path with possible windows drive letter hidden by '/'. Repair => convert "x:/" to "/x:/" where x is a drive letter- Returns:
- repaired path
-
allSchemes
public static String[] allSchemes(String xu)
Extract all schemes at front of a url.- Returns:
- vector of schemes
-
-