summaryrefslogtreecommitdiffstats
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
parent3e50f103fa49b40f86966877084e0282a8d97ff8 (diff)
Bug 1063: Further Uri completion - As a result of JOGL Uri adoption
-rwxr-xr-xmake/scripts/runtest.sh4
-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
-rw-r--r--src/java/com/jogamp/common/util/IOUtil.java41
-rw-r--r--src/junit/com/jogamp/common/net/TestUriQueryProps.java (renamed from src/junit/com/jogamp/common/net/TestURIQueryProps.java)21
5 files changed, 63 insertions, 67 deletions
diff --git a/make/scripts/runtest.sh b/make/scripts/runtest.sh
index a02f22e..97df488 100755
--- a/make/scripts/runtest.sh
+++ b/make/scripts/runtest.sh
@@ -110,10 +110,10 @@ function onetest() {
#onetest com.jogamp.common.util.TestBitstream03 2>&1 | tee -a $LOG
#onetest com.jogamp.common.util.TestBitstream04 2>&1 | tee -a $LOG
#onetest com.jogamp.common.net.TestUrisWithAssetHandler 2>&1 | tee -a $LOG
-#onetest com.jogamp.common.net.TestURIQueryProps 2>&1 | tee -a $LOG
+onetest com.jogamp.common.net.TestUriQueryProps 2>&1 | tee -a $LOG
#onetest com.jogamp.common.net.TestUri01 2>&1 | tee -a $LOG
#onetest com.jogamp.common.net.TestUri02Composing 2>&1 | tee -a $LOG
-onetest com.jogamp.common.net.TestUri03Resolving 2>&1 | tee -a $LOG
+#onetest com.jogamp.common.net.TestUri03Resolving 2>&1 | tee -a $LOG
#onetest com.jogamp.common.net.TestUri99LaunchOnReservedCharPathBug908 2>&1 | tee -a $LOG
#onetest com.jogamp.common.net.AssetURLConnectionUnregisteredTest 2>&1 | tee -a $LOG
#onetest com.jogamp.common.net.AssetURLConnectionRegisteredTest 2>&1 | tee -a $LOG
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) {
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java
index 3a09835..d9fb9cf 100644
--- a/src/java/com/jogamp/common/util/IOUtil.java
+++ b/src/java/com/jogamp/common/util/IOUtil.java
@@ -536,20 +536,6 @@ public class IOUtil {
}
/**
- * Wraps {@link #getRelativeOf(URI, String)} for convenience.
- * @param relativePath denotes a relative file to the baseLocation's parent directory (URI encoded)
- * @throws IOException
- * @deprecated Use {@link Uri#getRelativeOf(com.jogamp.common.net.Uri.Encoded)}.
- */
- public static URL getRelativeOf(final URL baseURL, final String relativePath) throws IOException {
- try {
- return Uri.valueOf(baseURL).getRelativeOf(Uri.Encoded.cast(relativePath)).toURL();
- } catch (final URISyntaxException e) {
- throw new IOException(e);
- }
- }
-
- /**
* Generates a path for the 'relativeFile' relative to the 'baseLocation'.
*
* @param baseLocation denotes a directory
@@ -620,30 +606,17 @@ public class IOUtil {
public static final Pattern patternSpaceEnc = Pattern.compile("%20");
/**
- * If <code>uri</code> is a <i>file scheme</i>,
- * implementation completes space-decoding <i>[ "//"+{@link URI#getAuthority()} ] + {@link URI#getPath()}</i>.<br>
- * Then it processes the <code>path</code> if {@link File#separatorChar} <code> == '\\'</code>
- * as follows:
- * <ul>
- * <li>slash -> backslash</li>
- * <li>drop a starting single backslash, preserving windows UNC</li>
- * </ul>
- * </p>
+ * If <code>uri</code> is a <i>file scheme</i>
+ * implementation returns {@link Uri#toFile()}.{@link File#getPath()}.
* <p>
* Otherwise it returns the {@link URI#toASCIIString()} encoded URI.
* </p>
- * @deprecated Use {@link Uri#toFile()}
*/
- public static String decodeURIIfFilePath(final java.net.URI uri) {
- try {
- final File file = Uri.valueOf(uri).toFile();
- if( null != file ) {
- return file.getPath();
- } else {
- return uri.toASCIIString();
- }
- } catch (final URISyntaxException e) {
- throw new RuntimeException(e);
+ public static String getUriFilePathOrASCII(final Uri uri) {
+ if( uri.isFileScheme() ) {
+ return uri.toFile().getPath();
+ } else {
+ return uri.toASCIIString().get();
}
}
diff --git a/src/junit/com/jogamp/common/net/TestURIQueryProps.java b/src/junit/com/jogamp/common/net/TestUriQueryProps.java
index 4f4435a..471cae2 100644
--- a/src/junit/com/jogamp/common/net/TestURIQueryProps.java
+++ b/src/junit/com/jogamp/common/net/TestUriQueryProps.java
@@ -1,9 +1,8 @@
package com.jogamp.common.net;
-import static com.jogamp.common.net.URIDumpUtil.showURI;
+import static com.jogamp.common.net.URIDumpUtil.showUri;
import java.io.IOException;
-import java.net.URI;
import java.net.URISyntaxException;
import org.junit.Assert;
@@ -15,7 +14,7 @@ import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestURIQueryProps extends JunitTracer {
+public class TestUriQueryProps extends JunitTracer {
@Test
public void test() throws IOException, URISyntaxException {
@@ -29,22 +28,22 @@ public class TestURIQueryProps extends JunitTracer {
for(int i=0; i<args.length-1; i+=2) {
final String uri_s0 = args[i];
final String uri_s1 = args[i+1];
- final URI uri0 = new URI(uri_s0);
- final URI uri1 = new URI(uri_s1);
- showURI(uri0);
- showURI(uri1);
- final URIQueryProps data = URIQueryProps.create(uri1, ';');
+ final Uri uri0 = Uri.cast(uri_s0);
+ final Uri uri1 = Uri.cast(uri_s1);
+ showUri(uri0);
+ showUri(uri1);
+ final UriQueryProps data = UriQueryProps.create(uri1, ';');
if(null == data) {
System.err.println("Error: NULL: <"+uri_s1+"> -> "+uri1+" -> NULL");
} else {
- final URI uri1T = data.appendQuery(uri0);
- showURI(uri1T);
+ final Uri uri1T = data.appendQuery(uri0);
+ showUri(uri1T);
Assert.assertEquals(uri1, uri1T);
}
}
}
public static void main(final String args[]) throws IOException {
- final String tstname = TestURIQueryProps.class.getName();
+ final String tstname = TestUriQueryProps.class.getName();
org.junit.runner.JUnitCore.main(tstname);
}
}