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
0b1585a
..
7319b2b
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
+++ b/
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
@@
-17,6
+17,8
@@
package net.pterodactylus.sone.text;
package net.pterodactylus.sone.text;
+import static java.util.logging.Logger.getLogger;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
@@
-28,11
+30,10
@@
import java.util.regex.Pattern;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.data.
SoneImpl
;
+import net.pterodactylus.sone.data.
impl.IdOnlySone
;
import net.pterodactylus.sone.database.PostProvider;
import net.pterodactylus.sone.database.SoneProvider;
import net.pterodactylus.util.io.Closer;
import net.pterodactylus.sone.database.PostProvider;
import net.pterodactylus.sone.database.SoneProvider;
import net.pterodactylus.util.io.Closer;
-import net.pterodactylus.util.logging.Logging;
import com.google.common.base.Optional;
import com.google.common.base.Optional;
@@
-46,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 =
Logging.getLogger(SoneTextParser.class
);
+ 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]");
@@
-58,41
+59,21
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
*/
private enum LinkType {
*/
private enum LinkType {
- /** Link is a KSK. */
- KSK("KSK@"),
-
- /** 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://"),
+ 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 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;
}
/**
}
/**
@@
-104,6
+85,10
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
return scheme;
}
return scheme;
}
+ public boolean isFreenetLink() {
+ return freenetLink;
+ }
+
}
/** The Sone provider. */
}
/** The Sone provider. */
@@
-210,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);
}
@@
-249,7
+234,7
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
* don’t use create=true above, we don’t want
* the empty shell.
*/
* don’t use create=true above, we don’t want
* the empty shell.
*/
- sone = Optional.<Sone>of(new
SoneImpl(soneId, false
));
+ sone = Optional.<Sone>of(new
IdOnlySone(soneId
));
}
parts.add(new SonePart(sone.get()));
line = line.substring(50);
}
parts.add(new SonePart(sone.get()));
line = line.substring(50);