org.opengis.cite.ogcapifeatures10.util.UrnValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ets-ogcapi-features10 Show documentation
Show all versions of ets-ogcapi-features10 Show documentation
Describe purpose of test suite.
package org.opengis.cite.ogcapifeatures10.util;
/**
* https://github.com/BruceZu/broken_colored_glass/blob/master/project/src/main/java/URN8141.java
*
* @author Lyn Goltz
*/
public class UrnValidator {
/**
*
* DIGIT = 0-9
* ALPHA = A-Z / a-z
* alphanum = ALPHA / DIGIT
* ldh = alphanum / "-"
* NID = (alphanum) 0*30(ldh) (alphanum)
*
*/
private static String NID = "\\p{Alnum}[a-zA-Z0-9\\-]{0,30}\\p{Alnum}";
/**
*
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
* HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
* pct-encoded = "%" HEXDIG HEXDIG ;
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
*
*/
private static String PCHAR = "[a-zA-Z0-9\\-\\._~!\\$&'\\(\\)\\*\\+,;=:@]|(%[0-9A-F]{2})";
/**
*
* NSS = pchar * ( pchar / "/" )
*
*
* @see #PCHAR
*/
private static String NSS = "(" + PCHAR + ")((" + PCHAR + ")|/)*";
/**
*
* assigned-name = "urn" ":" NID ":" NSS
*
*
* The leading scheme (urn:) is case-insensitive
*
* @see Wiki: Uniform Resource Name
*/
private static String ASSIGNED_NAME = "([uU][rR][nN]):(" + NID + "):(" + NSS + ")";
/**
*
* fragment = *( pchar / "/" / "?" )
*
*/
private static String FRAGMENT = "((" + PCHAR + ")|/|\\?)*";
/**
*
* r-component = pchar *( pchar / "/" / "?" )
* q-component = pchar *( pchar / "/" / "?" )
*
*/
private static String R_Q_COMPONENT = "(" + PCHAR + ")" + FRAGMENT;
/**
*
* rq-components = [ "?+" r-component ] [ "?=" q-component ]
*
*
* The order is not gurantee as the '?' can be used in fragment, and the '+' and '=' can be used in pchar.
*
* @see #R_Q_COMPONENT
*/
private static String RQ_COMPONENTS = "((\\?\\+)(" + R_Q_COMPONENT + "))?((\\?=)(" + R_Q_COMPONENT + "))?";
/**
*
* f-component = fragment
* namestring = assigned-name [ rq-components ] [ "#" f-component ]
*
*/
private static String URN_RFC8141 = "^" + ASSIGNED_NAME + RQ_COMPONENTS + "(#" + FRAGMENT + ")?$";
/**
* Checks if the passed urn is a valid urn according RFC 8141, Section 2
* (https://tools.ietf.org/html/rfc8141#section-2)
*
* @param urn
* the urn to check, null
results in a invalid URN.
* @return true
if the urn is valid according to RFC 8141, Section 2, false
if the urn is
* null, empty or not valid.
*/
public boolean isValid( String urn ) {
if ( urn == null )
return false;
return urn.matches( URN_RFC8141 );
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy