}
if (linkType == LinkType.SONE) {
- if (line.length() >= (7 + 43)) {
+ if (lineIsLongEnoughToContainASoneLink(line)) {
String soneId = line.substring(7, 50);
Optional<Sone> sone = database.getSone(soneId);
if (!sone.isPresent()) {
continue;
}
if (linkType == LinkType.POST) {
- if (line.length() >= (7 + 36)) {
+ if (lineIsLongEnoughToContainAPostLink(line)) {
String postId = line.substring(7, 43);
Optional<Post> post = database.getPost(postId);
if (post.isPresent()) {
if (name == null) {
name = link.substring(0, Math.min(9, link.length()));
}
- boolean fromPostingSone = ((linkType == LinkType.SSK) || (linkType == LinkType.USK)) && (context != null) && (context.getPostingSone() != null) && link.substring(4, Math.min(link.length(), 47)).equals(context.getPostingSone().getId());
+ boolean fromPostingSone = ((linkType == LinkType.SSK) || (linkType == LinkType.USK)) && linkMatchesPostingSone(context, link);
parts.add(new FreenetLinkPart(link, name, fromPostingSone));
} catch (MalformedURLException mue1) {
/* not a valid link, insert as plain text. */
}
}
+ private boolean linkMatchesPostingSone(SoneTextParserContext context, String link) {
+ return (context != null) && (context.getPostingSone() != null) && link.substring(4, Math.min(link.length(), 47)).equals(context.getPostingSone().getId());
+ }
+
+ private boolean lineIsLongEnoughToContainAPostLink(String line) {
+ return line.length() >= (7 + 36);
+ }
+
+ private boolean lineIsLongEnoughToContainASoneLink(String line) {
+ return line.length() >= (7 + 43);
+ }
+
private int findNextWhitespace(String line) {
Matcher matcher = whitespacePattern.matcher(line);
return matcher.find(0) ? matcher.start() : line.length();