summaryrefslogtreecommitdiffstats
path: root/src/java/com/jogamp/common/net
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-09-08 13:49:45 +0200
committerSven Gothel <[email protected]>2014-09-08 13:49:45 +0200
commit6a466e3f1e92a1e831ea61d1bb72c32f56b2a28d (patch)
tree35c8509454e940a1d751fa6121e51e510005445d /src/java/com/jogamp/common/net
parent3e50f103fa49b40f86966877084e0282a8d97ff8 (diff)
Bug 1063: Further Uri completion - As a result of JOGL Uri adoption
Diffstat (limited to 'src/java/com/jogamp/common/net')
-rw-r--r--src/java/com/jogamp/common/net/Uri.java39
-rw-r--r--src/java/com/jogamp/common/net/UriQueryProps.java (renamed from src/java/com/jogamp/common/net/URIQueryProps.java)25
2 files changed, 44 insertions, 20 deletions
diff --git a/src/java/com/jogamp/common/net/Uri.java b/src/java/com/jogamp/common/net/Uri.java
index d1f2016..a2c8833 100644
--- a/src/java/com/jogamp/common/net/Uri.java
+++ b/src/java/com/jogamp/common/net/Uri.java
@@ -276,6 +276,8 @@ public class Uri {
/** {@value} */
public static final char SCHEME_SEPARATOR = ':';
/** {@value} */
+ public static final char QUERY_SEPARATOR = '?';
+ /** {@value} */
public static final char FRAGMENT_SEPARATOR = '#';
/** {@value} */
public static final String FILE_SCHEME = "file";
@@ -735,7 +737,7 @@ public class Uri {
}
if ( !emptyString(query) ) {
- uri.append('?');
+ uri.append(QUERY_SEPARATOR);
// QUOTE ILLEGAL CHARS
uri.append(encode(query, QUERY_LEGAL));
}
@@ -816,7 +818,7 @@ public class Uri {
}
if ( !emptyString(query) ) {
// QUOTE ILLEGAL CHARS
- uri.append('?');
+ uri.append(QUERY_SEPARATOR);
uri.append(encode(query, QUERY_LEGAL));
}
if ( !emptyString(fragment) ) {
@@ -1255,6 +1257,27 @@ public class Uri {
}
}
+ /**
+ * Returns a new Uri instance w/ the given new query {@code newQuery}.
+ *
+ * @throws URISyntaxException if this Uri is {@link #opaque}
+ * or if the new string {@code uri} doesn't fit to the
+ * specification RFC2396 and RFC3986 or could not be parsed correctly.
+ */
+ public final Uri getNewQuery(final String newQuery) throws URISyntaxException {
+ if( opaque ) {
+ throw new URISyntaxException(input.decode(), "Opaque Uri cannot permute by query");
+ } else if( null != host ) {
+ // with host validation
+ return Uri.create(decode(scheme), decode(userInfo), decode(host), port,
+ decode(path), newQuery, decode(fragment));
+ } else {
+ // without host validation
+ return Uri.create(decode(scheme), decode(authority),
+ decode(path), newQuery, decode(fragment));
+ }
+ }
+
/// NEW START
/**
@@ -1317,7 +1340,7 @@ public class Uri {
// cut off optional query in scheme-specific-part
final String query;
- final int queryI = schemeSpecificPartS.lastIndexOf('?');
+ final int queryI = schemeSpecificPartS.lastIndexOf(QUERY_SEPARATOR);
if( queryI >= 0 ) {
query = schemeSpecificPartS.substring(queryI+1);
schemeSpecificPartS = schemeSpecificPartS.substring(0, queryI);
@@ -1336,11 +1359,11 @@ public class Uri {
uri.append(':');
uri.append(schemeSpecificPartS);
if ( null != query ) {
- uri.append('?');
+ uri.append(QUERY_SEPARATOR);
uri.append(query);
}
if ( null != fragment ) {
- uri.append('#');
+ uri.append(FRAGMENT_SEPARATOR);
uri.append(fragment.get());
}
return Uri.cast(uri.toString());
@@ -1532,7 +1555,7 @@ public class Uri {
}
if (query != null) {
- result.append('?');
+ result.append(QUERY_SEPARATOR);
result.append(query.get());
}
}
@@ -1577,7 +1600,7 @@ public class Uri {
final int indexSchemeSep = temp.indexOf(SCHEME_SEPARATOR);
index = indexSchemeSep;
final int indexSSP = temp.indexOf('/');
- final int indexQuerySep = temp.indexOf('?');
+ final int indexQuerySep = temp.indexOf(QUERY_SEPARATOR);
String sspTemp; // may get modified due to error correction
@@ -1610,7 +1633,7 @@ public class Uri {
// Query
temp = sspTemp;
- index = temp.indexOf('?');
+ index = temp.indexOf(QUERY_SEPARATOR);
if (index != -1) {
query = new Encoded( temp.substring(index + 1) );
temp = temp.substring(0, index);
diff --git a/src/java/com/jogamp/common/net/URIQueryProps.java b/src/java/com/jogamp/common/net/UriQueryProps.java
index 138ff9b..8d9bcb4 100644
--- a/src/java/com/jogamp/common/net/URIQueryProps.java
+++ b/src/java/com/jogamp/common/net/UriQueryProps.java
@@ -27,7 +27,6 @@
*/
package com.jogamp.common.net;
-import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Iterator;
@@ -44,8 +43,12 @@ import java.util.Map.Entry;
* w/ authority: [user-info@]host[:port]
* Note: 'path' starts w/ fwd slash
* </pre>
+ * <p>
+ * Since 2.3.0 renamed from {@code URIQueryProps} to {@code UriQueryProps},
+ * and using {@link Uri} instead of {@link java.net.URI}.
+ * </p>
*/
-public class URIQueryProps {
+public class UriQueryProps {
private static final String QMARK = "?";
private static final char ASSIG = '=';
private static final String EMPTY = "";
@@ -53,7 +56,7 @@ public class URIQueryProps {
private final HashMap<String, String> properties = new HashMap<String, String>();
- private URIQueryProps(final char querySeparator) {
+ private UriQueryProps(final char querySeparator) {
query_separator = String.valueOf(querySeparator);
}
@@ -64,8 +67,8 @@ public class URIQueryProps {
boolean needsSep = false;
final StringBuilder sb = new StringBuilder();
if ( null != baseQuery ) {
- if( !baseQuery.startsWith(QMARK) ) {
- baseQuery = baseQuery.substring(1);
+ if( baseQuery.startsWith(QMARK) ) {
+ baseQuery = baseQuery.substring(1); // cut off '?'
}
sb.append(baseQuery);
if( !baseQuery.endsWith(query_separator) ) {
@@ -87,10 +90,8 @@ public class URIQueryProps {
return sb.toString();
}
- public final URI appendQuery(final URI base) throws URISyntaxException {
- return new URI(base.getScheme(),
- base.getRawUserInfo(), base.getHost(), base.getPort(),
- base.getRawPath(), appendQuery(base.getRawQuery()), base.getRawFragment());
+ public final Uri appendQuery(final Uri base) throws URISyntaxException {
+ return base.getNewQuery( appendQuery( Uri.decode(base.query) ) );
}
/**
@@ -100,12 +101,12 @@ public class URIQueryProps {
* @return
* @throws IllegalArgumentException if <code>querySeparator</code> is illegal, i.e. neither <i>;</i> nor <i>&</i>
*/
- public static final URIQueryProps create(final URI uri, final char querySeparator) throws IllegalArgumentException {
+ public static final UriQueryProps create(final Uri uri, final char querySeparator) throws IllegalArgumentException {
if( ';' != querySeparator && '&' != querySeparator ) {
throw new IllegalArgumentException("querySeparator is invalid: "+querySeparator);
}
- final URIQueryProps data = new URIQueryProps(querySeparator);
- final String q = uri.getQuery();
+ final UriQueryProps data = new UriQueryProps(querySeparator);
+ final String q = Uri.decode(uri.query);
final int q_l = null != q ? q.length() : -1;
int q_e = -1;
while(q_e < q_l) {