remove serialization, add some more convenience to URL

This commit is contained in:
Jörg Prante 2018-02-27 11:39:04 +01:00
parent f1f32cbedf
commit 51a19b2af7
62 changed files with 93 additions and 214 deletions

View file

@ -52,7 +52,7 @@ subprojects {
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all" << "-profile" << "compact1"
options.compilerArgs << "-Xlint:all,-serial" << "-profile" << "compact1"
}
jar {

View file

@ -1,8 +1,8 @@
group = org.xbib
name = net
version = 1.0.4
version = 1.1.0
junit.version = 4.12
asciidoclet.version = 1.5.4
wagon.version = 2.12
jackson.version = 2.8.4
wagon.version = 3.0.0
jackson.version = 2.8.10

View file

@ -1,5 +1,6 @@
task xbibUpload(type: Upload) {
group = 'publish'
configuration = configurations.archives
uploadDescriptor = true
repositories {
@ -15,6 +16,7 @@ task xbibUpload(type: Upload) {
}
task sonatypeUpload(type: Upload, dependsOn: build) {
group = 'publish'
configuration = configurations.archives
uploadDescriptor = true
repositories {

Binary file not shown.

View file

@ -1,5 +1,6 @@
#Tue Feb 27 11:11:33 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-rc-1-all.zip

View file

@ -5,11 +5,10 @@ import java.util.List;
import java.util.stream.Collectors;
/**
* Query parameters.
*/
public class QueryParameters extends ArrayList<QueryParameters.Pair<String, String>> {
private static final long serialVersionUID = 1195469379836789386L;
private final int max;
public QueryParameters() {

View file

@ -3,7 +3,6 @@ package org.xbib.net;
import org.xbib.net.scheme.Scheme;
import org.xbib.net.scheme.SchemeRegistry;
import java.io.Serializable;
import java.net.IDN;
import java.net.Inet4Address;
import java.net.Inet6Address;
@ -43,12 +42,10 @@ import java.util.logging.Logger;
* --
*
*/
public class URL implements Comparable<URL>, Serializable {
public class URL implements Comparable<URL> {
private static final Logger logger = Logger.getLogger(URL.class.getName());
private static final long serialVersionUID = 7936984038051707342L;
private static final char SEPARATOR_CHAR = '/';
private static final char QUESTION_CHAR = '?';
@ -102,7 +99,7 @@ public class URL implements Comparable<URL>, Serializable {
/**
* A special, scheme-less URL denoting the fact that this URL should be considered as invalid.
*/
public static final URL INVALID = URL.builder().build();
private static final URL INVALID = URL.builder().build();
public static Builder file() {
return new Builder().scheme(Scheme.FILE);
@ -236,33 +233,45 @@ public class URL implements Comparable<URL>, Serializable {
return new Resolver(URL.create(base));
}
public static URL getInvalid() {
return INVALID;
}
public static URL from(String input) {
try {
return parser().parse(input, true);
} catch (URLSyntaxException e) {
throw new IllegalArgumentException(e);
}
return from(input, true);
}
public static URL create(String input) {
return from(input, false);
}
public static URL from(String input, boolean resolve) {
try {
return parser().parse(input, false);
return parser().parse(input, resolve);
} catch (URLSyntaxException e) {
throw new IllegalArgumentException(e);
}
}
public URL resolve(String spec) {
return from(this, spec);
}
public static URL from(URL base, String spec) {
try {
return new Resolver(this).resolve(spec);
return new Resolver(base).resolve(spec);
} catch (URLSyntaxException e) {
throw new IllegalArgumentException(e);
}
}
public URL resolve(URL spec) {
return from(this, spec);
}
public static URL from(URL base, URL spec) {
try {
return new Resolver(this).resolve(spec);
return new Resolver(base).resolve(spec);
} catch (URLSyntaxException e) {
throw new IllegalArgumentException(e);
}
@ -1252,9 +1261,7 @@ public class URL implements Comparable<URL>, Serializable {
}
}
private static class URLWithFragmentComparator implements Comparator<URL>, Serializable {
private static final long serialVersionUID = -5048272347975931901L;
private static class URLWithFragmentComparator implements Comparator<URL> {
@Override
public int compare(URL o1, URL o2) {
@ -1262,9 +1269,7 @@ public class URL implements Comparable<URL>, Serializable {
}
}
private static class URLWithoutFragmentComparator implements Comparator<URL>, Serializable {
private static final long serialVersionUID = 818948352939772199L;
private static class URLWithoutFragmentComparator implements Comparator<URL> {
@Override
public int compare(URL o1, URL o2) {

View file

@ -1,12 +1,10 @@
package org.xbib.net;
/**
*
* URL syntax exception.
*/
public class URLSyntaxException extends Exception {
private static final long serialVersionUID = 1813084470937980392L;
URLSyntaxException(String message) {
super(message);
}

View file

@ -13,7 +13,7 @@ import java.nio.charset.UnmappableCharacterException;
*/
public class PathDecoder {
private static final Integer MAX_PARAM_COUNT = 1000;
private static final Integer MAX_PARAM_COUNT = 1024;
private PercentDecoder decoder;

View file

@ -11,7 +11,7 @@ import java.util.Map;
import java.util.StringTokenizer;
/**
*
* Path matcher.
*/
public class PathMatcher {
@ -312,8 +312,6 @@ public class PathMatcher {
*/
private static class LRUCache<K, V> extends LinkedHashMap<K, V> {
private static final long serialVersionUID = -2795566703268944901L;
private final int cacheSize;
LRUCache(int cacheSize) {

View file

@ -5,6 +5,7 @@ import java.util.LinkedList;
import java.util.StringTokenizer;
/**
* Path normalizer.
*/
public class PathNormalizer {
@ -13,100 +14,6 @@ public class PathNormalizer {
private PathNormalizer() {
}
/*public static String normalizePath(String path) {
return normalizePath(path, false);
}
public static String normalizePath(String path, boolean keepSeparator) {
if (path == null || path.equals("") || path.equals("/")) {
return "/";
}
path = path.replaceAll("/+", "/");
int size = path.length();
if (size == 0) {
return path;
}
int prefix = getPrefixLength(path);
if (prefix < 0) {
return "";
}
char[] ch = new char[size + 2];
path.getChars(0, path.length(), ch, 0);
boolean firstIsDirectory = true;
if (ch[0] != separator) {
firstIsDirectory = false;
}
boolean lastIsDirectory = true;
if (ch[size - 1] != separator) {
lastIsDirectory = false;
}
for (int i = prefix + 1; i < size; i++) {
if (ch[i] == separator && ch[i - 1] == separator) {
System.arraycopy(ch, i, ch, i - 1, size - i);
size--;
i--;
}
}
for (int i = prefix + 1; i < size; i++) {
if (ch[i] == separator && ch[i - 1] == '.'
&& (i == prefix + 1 || ch[i - 2] == separator)) {
if (i == size - 1) {
lastIsDirectory = true;
}
System.arraycopy(ch, i + 1, ch, i - 1, size - i);
size -=2;
i--;
}
}
int i = prefix + 2;
while (i < size) {
if (ch[i] == separator && ch[i - 1] == '.' && ch[i - 2] == '.'
&& (i == prefix + 2 || ch[i - 3] == separator)) {
if (i == prefix + 2) {
return "";
}
if (i == size - 1) {
lastIsDirectory = true;
}
int j;
boolean b = false;
for (j = i - 4 ; j >= prefix; j--) {
if (ch[j] == separator) {
System.arraycopy(ch, i + 1, ch, j + 1, size - i);
size -= (i - j);
i = j + 1;
b = true;
break;
}
}
if (b) {
continue;
}
System.arraycopy(ch, i + 1, ch, prefix, size - i);
size -= (i + 1 - prefix);
i = prefix + 1;
}
i++;
}
if (size <= 0) {
return "";
}
String s = new String(ch, 0, size);
if (size <= prefix) {
return s;
}
if (!keepSeparator) {
if (firstIsDirectory && lastIsDirectory) {
return s.substring(1, s.length() - 1);
} else if (firstIsDirectory) {
return s.substring(1);
} else if (lastIsDirectory) {
return s.substring(0, s.length() - 1);
}
}
return s;
}*/
public static String normalize(String path) {
if (path == null || "".equals(path) || "/".equals(path)) {
return "/";
@ -147,48 +54,4 @@ public class PathNormalizer {
}
return sb.toString();
}
private static int getPrefixLength(String filename) {
if (filename == null) {
return -1;
}
int len = filename.length();
if (len == 0) {
return 0;
}
char ch0 = filename.charAt(0);
if (ch0 == ':') {
return -1;
}
if (len == 1) {
if (ch0 == '~') {
return 2;
}
return ch0 == separator ? 1 : 0;
} else {
if (ch0 == '~') {
int pos = filename.indexOf(separator, 1);
return pos == -1 ? len + 1 : pos + 1;
}
char ch1 = filename.charAt(1);
if (ch1 == ':') {
ch0 = Character.toUpperCase(ch0);
if (ch0 >= ('A') && ch0 <= ('Z')) {
if (len == 2 || filename.charAt(2) != separator) {
return 2;
}
return 3;
}
return -1;
} else if (ch0 == separator && ch1 == separator) {
int pos = filename.indexOf(separator, 2);
if (pos == -1 || pos == 2) {
return -1;
}
return pos + 1;
} else {
return ch0 == separator ? 1 : 0;
}
}
}
}

View file

@ -1,13 +1,11 @@
package org.xbib.net.path;
import java.io.Serializable;
import java.util.Comparator;
/**
* Path pattern comparator.
*/
public class PathPatternComparator implements Comparator<String>, Serializable {
private static final long serialVersionUID = -5286803094119345841L;
public class PathPatternComparator implements Comparator<String> {
private final String path;

View file

@ -3,6 +3,7 @@ package org.xbib.net.path;
import java.util.regex.Pattern;
/**
* Path pattern info.
*/
class PathPatternInfo {

View file

@ -1,6 +1,7 @@
package org.xbib.net.path;
/**
* Path separator pattern cache.
*/
class PathSeparatorPatternCache {

View file

@ -8,6 +8,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Path string matcher.
*/
class PathStringMatcher {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Default scheme.
*/
public class DefaultScheme extends AbstractScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* File scheme.
*/
class FileScheme extends HttpScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* FTP scheme.
*/
class FtpScheme extends HttpScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Git scheme.
*/
class GitScheme extends HttpScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Git secure scheme.
*/
class GitSecureHttpScheme extends HttpScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Gopher scheme.
*/
class GopherScheme extends AbstractScheme {

View file

@ -4,7 +4,7 @@ import org.xbib.net.URL;
import org.xbib.net.path.PathNormalizer;
/**
*
* HTTP scheme.
*/
class HttpScheme extends AbstractScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Redis scheme.
*/
class RedisScheme extends AbstractScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Rsync scheme.
*/
class RsyncScheme extends SshScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Rtmp scheme.
*/
class RtmpScheme extends AbstractScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Secure HTTP scheme.
*/
class SecureHttpScheme extends HttpScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
* The IMAP scheme.
* The secure IMAP scheme.
* @see <a href="https://tools.ietf.org/html/rfc5092">IMAP scheme RFC</a>
*/
class SecureImapScheme extends ImapScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
* The LDAPS scheme.
* The secure LDAP scheme.
*
* @see <a href="https://tools.ietf.org/html/rfc4516">LDAP RFC</a>
*/

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
* The snews scheme.
* The secure news scheme.
*
* @see <a href="https://tools.ietf.org/html/rfc5538">news RFC</a>
*/

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
* The POP3S scheme.
* The secure POP3 scheme.
*
* @see <a href="https://tools.ietf.org/html/rfc2595">POP3 RFC</a>
*/

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
* The SMTPS scheme.
* The secure SMTP scheme.
*
* @see <a href="https://tools.ietf.org/html/rfc4409">SMTP RFC</a>
*/

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Secure web socket scheme.
*/
class SecureWebSocketScheme extends WebSocketScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Secure FTP scheme.
*/
class SftpScheme extends SshScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Secure shell scheme.
*/
class SshScheme extends HttpScheme {

View file

@ -1,7 +1,7 @@
package org.xbib.net.scheme;
/**
*
* Web socket scheme.
*/
class WebSocketScheme extends HttpScheme {

View file

@ -8,7 +8,7 @@ import org.xbib.net.template.vars.Variables;
import java.util.List;
/**
*
* URI templates.
*/
public class URITemplate {

View file

@ -1,6 +1,7 @@
package org.xbib.net.template.expression;
/**
* Expression types.
*/
public enum ExpressionType {
/*

View file

@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* Template expression.
*/
public class TemplateExpression implements URITemplateExpression {

View file

@ -3,6 +3,7 @@ package org.xbib.net.template.expression;
import org.xbib.net.template.vars.Variables;
/**
* Template literal.
*/
public
class TemplateLiteral implements URITemplateExpression {

View file

@ -3,6 +3,7 @@ package org.xbib.net.template.expression;
import org.xbib.net.template.vars.Variables;
/**
* Template expression interface.
*/
public interface URITemplateExpression {

View file

@ -13,6 +13,7 @@ import java.util.List;
import java.util.Map;
/**
* Expression parser.
*/
public class ExpressionParser implements TemplateParser {

View file

@ -7,6 +7,7 @@ import org.xbib.net.template.expression.URITemplateExpression;
import java.nio.CharBuffer;
/**
* Literal parser.
*/
public
class LiteralParser implements TemplateParser {

View file

@ -5,7 +5,7 @@ import org.xbib.net.template.expression.URITemplateExpression;
import java.nio.CharBuffer;
/**
*
* Template parser interface.
*/
public interface TemplateParser {
URITemplateExpression parse(CharBuffer buffer);

View file

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* URI template parser.
*/
public class URITemplateParser {

View file

@ -11,6 +11,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* Variable spec parser.
*/
public class VariableSpecParser {

View file

@ -8,7 +8,7 @@ import java.util.List;
import java.util.stream.Collectors;
/**
*
* Liste renderer.
*/
public class ListRenderer extends MultiValueRenderer {

View file

@ -9,7 +9,7 @@ import java.util.List;
import java.util.stream.Collectors;
/**
*
* Map renderer.
*/
public class MapRenderer extends MultiValueRenderer {

View file

@ -7,7 +7,7 @@ import org.xbib.net.template.vars.values.VariableValue;
import java.util.List;
/**
*
* Multi value renderer.
*/
abstract class MultiValueRenderer extends ValueRenderer {

View file

@ -7,7 +7,7 @@ import org.xbib.net.template.vars.values.VariableValue;
import java.util.List;
/**
*
* Null renderer.
*/
public class NullRenderer extends ValueRenderer {

View file

@ -8,7 +8,7 @@ import java.util.Collections;
import java.util.List;
/**
*
* String renderer.
*/
public class StringRenderer extends ValueRenderer {

View file

@ -78,4 +78,3 @@ public abstract class ValueRenderer {
}
}
}

View file

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map;
/**
* Variables.
*/
public class Variables {

View file

@ -1,7 +1,7 @@
package org.xbib.net.template.vars.specs;
/**
*
* Exploded variable.
*/
public class ExplodedVariable extends VariableSpec {

View file

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List;
/**
*
* List value.
*/
public class ListValue extends VariableValue {

View file

@ -4,7 +4,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
*
* Map value.
*/
public class MapValue extends VariableValue {

View file

@ -1,6 +1,7 @@
package org.xbib.net.template.vars.values;
/**
* Null value.
*/
public class NullValue extends VariableValue {

View file

@ -1,7 +1,7 @@
package org.xbib.net.template.vars.values;
/**
*
* Scalar value.
*/
public class ScalarValue extends VariableValue {

View file

@ -8,6 +8,7 @@ import org.xbib.net.template.render.StringRenderer;
import org.xbib.net.template.render.ValueRenderer;
/**
* Value types.
*/
public enum ValueType {

View file

@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map;
/**
* Variable value.
*/
public abstract class VariableValue {

View file

@ -29,7 +29,7 @@ public class IRITest {
@Test
public void testIpv6Invalid() {
URL iri = URL.from("http://[2001:0db8:85a3:08d3:1319:8a2e:0370:734o]");
assertEquals(URL.INVALID, iri);
assertEquals(URL.getInvalid(), iri);
}
@Test

View file

@ -6,7 +6,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
*
@ -15,17 +14,17 @@ public class URLParserTest {
@Test
public void testNull() {
assertEquals(URL.INVALID, URL.from(null));
assertEquals(URL.getInvalid(), URL.from(null));
}
@Test
public void testEmpty() {
assertEquals(URL.INVALID, URL.from(""));
assertEquals(URL.getInvalid(), URL.from(""));
}
@Test
public void testNewline() {
assertEquals(URL.INVALID, URL.from("\n"));
assertEquals(URL.getInvalid(), URL.from("\n"));
}
@Test(expected = IllegalArgumentException.class)

View file

@ -94,9 +94,11 @@ public class URLResolverTest {
// scheme
resolve("http://a/b/c/d;p?q", "http:g", "http:g");
resolve("http://a/b/c/d;p?q", "http:", "http:");
// absolute
resolve("http://a/b/c/d;p?q", "http://e/f/g/h", "http://e/f/g/h");
}
private void resolve(String inputBase, String relative, String expected) throws URLSyntaxException {
assertEquals(expected, URL.base(inputBase).resolve(relative).toExternalForm());
private void resolve(String inputBase, String spec, String expected) throws URLSyntaxException {
assertEquals(expected, URL.base(inputBase).resolve(spec).toExternalForm());
}
}