projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add “isFreenetLink” attribute to LinkType
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
text
/
SoneTextParser.java
diff --git
a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
index
cc5c59b
..
7319b2b
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
+++ b/
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
@@
-47,7
+47,7
@@
import freenet.keys.FreenetURI;
public class SoneTextParser implements Parser<SoneTextParserContext> {
/** The logger. */
public class SoneTextParser implements Parser<SoneTextParserContext> {
/** The logger. */
- private static final Logger logger = getLogger(
"Sone.Data.Parser"
);
+ private static final Logger logger = getLogger(
SoneTextParser.class.getName()
);
/** Pattern to detect whitespace. */
private static final Pattern whitespacePattern = Pattern.compile("[\\u000a\u0020\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u200c\u200d\u202f\u205f\u2060\u2800\u3000]");
/** Pattern to detect whitespace. */
private static final Pattern whitespacePattern = Pattern.compile("[\\u000a\u0020\u00a0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u200c\u200d\u202f\u205f\u2060\u2800\u3000]");
@@
-59,41
+59,21
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
*/
private enum LinkType {
*/
private enum LinkType {
- /** Link is a KSK. */
- KSK("KSK@"),
+ KSK("KSK@", true),
+ CHK("CHK@", true),
+ SSK("SSK@", true),
+ USK("USK@", true),
+ HTTP("http://", false),
+ HTTPS("https://", false),
+ SONE("sone://", false),
+ POST("post://", false);
- /** Link is a CHK. */
- CHK("CHK@"),
-
- /** Link is an SSK. */
- SSK("SSK@"),
-
- /** Link is a USK. */
- USK("USK@"),
-
- /** Link is HTTP. */
- HTTP("http://"),
-
- /** Link is HTTPS. */
- HTTPS("https://"),
-
- /** Link is a Sone. */
- SONE("sone://"),
-
- /** Link is a post. */
- POST("post://");
-
- /** The scheme identifying this link type. */
private final String scheme;
private final String scheme;
+ private final boolean freenetLink;
- /**
- * Creates a new link type identified by the given scheme.
- *
- * @param scheme
- * The scheme of the link type
- */
- private LinkType(String scheme) {
+ LinkType(String scheme, boolean freenetLink) {
this.scheme = scheme;
this.scheme = scheme;
+ this.freenetLink = freenetLink;
}
/**
}
/**
@@
-105,6
+85,10
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
return scheme;
}
return scheme;
}
+ public boolean isFreenetLink() {
+ return freenetLink;
+ }
+
}
/** The Sone provider. */
}
/** The Sone provider. */
@@
-211,7
+195,7
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
}
/* cut off “freenet:” from before keys. */
}
/* cut off “freenet:” from before keys. */
- if (
((linkType == LinkType.KSK) || (linkType == LinkType.CHK) || (linkType == LinkType.SSK) || (linkType == LinkType.USK)
) && (next >= 8) && (line.substring(next - 8, next).equals("freenet:"))) {
+ if (
linkType.isFreenetLink(
) && (next >= 8) && (line.substring(next - 8, next).equals("freenet:"))) {
next -= 8;
line = line.substring(0, next) + line.substring(next + 8);
}
next -= 8;
line = line.substring(0, next) + line.substring(next + 8);
}