|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.nbnResolving.common.URNUtils
public class URNUtils
Class to generate URNs and/or URN-Checksums See the URN documentation and www.persistent-identifier.de Some URL normalizing utility functions are also implemented.
URI,
{@link "http://tools.ietf.org/html/rfc2141"}
{@link "http://tools.ietf.org/html/rfc3188"}
{@link "http://tools.ietf.org/html/rfc3986"}| Constructor Summary | |
|---|---|
URNUtils()
|
|
| Method Summary | |
|---|---|
static AbstractMap<String,String> |
addMaps(AbstractMap<String,String> map1,
AbstractMap<String,String> map2)
Adds two given maps and returns a map that contains key|value pairs of both. |
static String |
addParamsToUrl(String urlStr,
AbstractMap<String,String> params)
Adds given new parameters to existing URL. |
static String |
addQueryToUrl(String urlStr,
String aq)
Adds given new query to existing URL. |
static String |
buildUrl(String protocol,
String userInfo,
String host,
int port,
String path,
AbstractMap<String,String> params,
boolean encodeParams,
String anchor,
boolean checkJavaURI)
Builds an URI from its given components. |
static String |
correctUrlString(String urlStr,
boolean correctEncoding,
boolean checkJavaURI)
Tries to return a RFC compatible, normalized URL as string from a given string. |
static String |
correctUtf8error(String strToCorrect)
Corrects wrong converted or encoded strings. |
static int |
getChecksum(String tmpurn)
Calculates the checksum of the given string. |
static String |
getDateURN(String ns)
Returns a valid URN for the given Namespace beginning with actual date. |
static String |
getNormalisedPath(String path)
Normalises given URL Path. |
static TreeMap<String,String> |
getParameterMap(String query,
String regex)
Parses a URL query and returns key, value pairs as a TreeMap. |
static TreeMap<String,String> |
getParameterMap(URL url)
Parses an URL query and returns key|value pairs as a TreeMap. |
static String |
getRandomURN(String ns)
Returns a random generated, valid URN for the given Namespace. |
static String |
getURN(String tmpurn)
Returns a valid URN with checksum for the given identifier without checksum. |
static String |
getURNforId(String ns,
String id)
Returns a valid URN for the given Namespace and another id. |
static String |
mapToEncodedString(AbstractMap<String,String> map,
String delimiter)
Iterates all elements of a map and returns key=value pairs separated with given delimiter as URLEncoded string. |
static String |
mapToString(AbstractMap<String,String> map,
String delimiter)
Iterates all elements of a map and returns key=value pairs separated with given delimiter as string. |
static String |
normalize(String str,
boolean lowerCase)
Normalizes the "Percent Encoding" of an URI |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public URNUtils()
| Method Detail |
|---|
public static int getChecksum(String tmpurn)
tmpurn - URN without checksum
public static String getURN(String tmpurn)
tmpurn - URN without checksum
public static String getURNforId(String ns,
String id)
ns - Namespaceid - Another unique number
public static String getRandomURN(String ns)
ns - Namespace for this URN.
public static String getDateURN(String ns)
ns - Namespace for this URN.
public static String mapToString(AbstractMap<String,String> map,
String delimiter)
map - A map containing Key, Value pairsdelimiter - String between Key=Value pairs. (normally "&" or ";" for URLs).
public static String mapToEncodedString(AbstractMap<String,String> map,
String delimiter)
throws UnsupportedEncodingException
map - A map containing Key, Value pairsdelimiter - String between Key=Value pairs. "&" or ";" for URIs.
UnsupportedEncodingExceptionURLEncoder
public static TreeMap<String,String> getParameterMap(String query,
String regex)
throws UnsupportedEncodingException
query - (URI) Query to parseregex - Regular expression to use for splitting.
UnsupportedEncodingException
public static TreeMap<String,String> getParameterMap(URL url)
throws UnsupportedEncodingException
url - URL to parse
UnsupportedEncodingException
public static AbstractMap<String,String> addMaps(AbstractMap<String,String> map1,
AbstractMap<String,String> map2)
throws UnsupportedEncodingException
map1 - First map.map2 - Second map.
UnsupportedEncodingExceptionTreeMap,
URLDecoder,
URLEncoder
public static String getNormalisedPath(String path)
throws UnsupportedEncodingException
path - URL Path to parse.
UnsupportedEncodingException{@link "http://www.w3.org/TR/html401"}
public static String correctUtf8error(String strToCorrect)
throws UnsupportedEncodingException
strToCorrect - String to check.
UnsupportedEncodingException
public static String correctUrlString(String urlStr,
boolean correctEncoding,
boolean checkJavaURI)
urlStr - URL to correct as string.correctEncoding - Try to correct common wrong Latin1 - UTF-8 conversions.checkJavaURI - Check if Java can parse this string as Java URL and URI without exception
public static String addQueryToUrl(String urlStr,
String aq)
throws MalformedURLException,
UnsupportedEncodingException,
URISyntaxException
urlStr - URL to correct as string.aq - Additional query: query to add to given URL.
"http://www.w3.org/TR/html401"
MalformedURLException
UnsupportedEncodingException
URISyntaxException
public static String addParamsToUrl(String urlStr,
AbstractMap<String,String> params)
throws UnsupportedEncodingException,
MalformedURLException,
URISyntaxException
urlStr - URL as java string.params - New parameters to add.
UnsupportedEncodingException
MalformedURLException
URISyntaxException
public static String buildUrl(String protocol,
String userInfo,
String host,
int port,
String path,
AbstractMap<String,String> params,
boolean encodeParams,
String anchor,
boolean checkJavaURI)
throws UnsupportedEncodingException,
URISyntaxException,
MalformedURLException
protocol - Protocol part of this URIuserInfo - User info part of this URIhost - Host part of this URIport - Port part of this URIpath - Path part of this URIparams - Parameters part of this URIencodeParams - TRUE if the parameters must be encodedanchor - Anchor part of this URIcheckJavaURI - TRUE if extra validation wanted
UnsupportedEncodingException
URISyntaxException
MalformedURLException
public static String normalize(String str,
boolean lowerCase)
throws UnsupportedEncodingException
str - The URI to normalize as Java StringlowerCase - TRUE if the string should be converted to all lower case.
UnsupportedEncodingException
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||