private enum LinkType {
/** Link is a KSK. */
- KSK,
+ KSK("KSK@"),
/** Link is a CHK. */
- CHK,
+ CHK("CHK@"),
/** Link is an SSK. */
- SSK,
+ SSK("SSK@"),
/** Link is a USK. */
- USK,
+ USK("USK@"),
/** Link is HTTP. */
- HTTP,
+ HTTP("http://"),
/** Link is HTTPS. */
- HTTPS,
+ HTTPS("https://"),
/** Link is a Sone. */
- SONE,
+ SONE("sone://"),
/** Link is a post. */
- POST,
+ POST("post://");
+
+ /** The scheme identifying this link type. */
+ private final String scheme;
+
+ /**
+ * Creates a new link type identified by the given scheme.
+ *
+ * @param scheme
+ * The scheme of the link type
+ */
+ private LinkType(String scheme) {
+ this.scheme = scheme;
+ }
+
+ /**
+ * Returns the scheme of this link type.
+ *
+ * @return The scheme of this link type
+ */
+ public String getScheme() {
+ return scheme;
+ }
}
}
lineComplete = false;
+ Matcher matcher = whitespacePattern.matcher(line);
+ int nextSpace = matcher.find(0) ? matcher.start() : line.length();
+ String link = line.substring(0, nextSpace);
+ String name = link;
+ logger.log(Level.FINER, String.format("Found link: %s", link));
+ logger.log(Level.FINEST, String.format("CHK: %d, SSK: %d, USK: %d", nextChk, nextSsk, nextUsk));
+
+ /* if there is no text after the scheme, it’s not a link! */
+ if (link.equals(linkType.getScheme())) {
+ parts.add(new PlainTextPart(linkType.getScheme()));
+ line = line.substring(linkType.getScheme().length());
+ continue;
+ }
+
if (linkType == LinkType.SONE) {
if (line.length() >= (7 + 43)) {
String soneId = line.substring(7, 50);
* don’t use create=true above, we don’t want
* the empty shell.
*/
- sone = new Sone(soneId);
+ sone = new Sone(soneId, false);
}
parts.add(new SonePart(sone));
line = line.substring(50);
}
continue;
}
- Matcher matcher = whitespacePattern.matcher(line);
- int nextSpace = matcher.find(0) ? matcher.start() : line.length();
- String link = line.substring(0, nextSpace);
- String name = link;
- logger.log(Level.FINER, String.format("Found link: %s", link));
- logger.log(Level.FINEST, String.format("CHK: %d, SSK: %d, USK: %d", nextChk, nextSsk, nextUsk));
if ((linkType == LinkType.KSK) || (linkType == LinkType.CHK) || (linkType == LinkType.SSK) || (linkType == LinkType.USK)) {
FreenetURI uri;