projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add some documentation for later when I have to look at it again.
[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
98bb800
..
d271203
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
+++ b/
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
@@
-26,7
+26,8
@@
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.core.PostProvider;
+import net.pterodactylus.sone.core.SoneProvider;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.util.logging.Logging;
@@
-78,17
+79,23
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
}
}
- /** The core. */
- private final Core core;
+ /** The Sone provider. */
+ private final SoneProvider soneProvider;
+
+ /** The post provider. */
+ private final PostProvider postProvider;
/**
* Creates a new freenet link parser.
*
/**
* Creates a new freenet link parser.
*
- * @param core
- * The core
+ * @param soneProvider
+ * The Sone provider
+ * @param postProvider
+ * The post provider
*/
*/
- public SoneTextParser(Core core) {
- this.core = core;
+ public SoneTextParser(SoneProvider soneProvider, PostProvider postProvider) {
+ this.soneProvider = soneProvider;
+ this.postProvider = postProvider;
}
//
}
//
@@
-116,6
+123,11
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
continue;
}
emptyLines = 0;
continue;
}
emptyLines = 0;
+ /*
+ * lineComplete tracks whether the block you are parsing is the
+ * first block of the line. this is important because sometimes you
+ * have to add an additional line break.
+ */
boolean lineComplete = true;
while (line.length() > 0) {
int nextKsk = line.indexOf("KSK@");
boolean lineComplete = true;
while (line.length() > 0) {
int nextKsk = line.indexOf("KSK@");
@@
-170,12
+182,16
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
}
if (linkType == LinkType.SONE) {
if (next > 0) {
}
if (linkType == LinkType.SONE) {
if (next > 0) {
- parts.add(new PlainTextPart(line.substring(0, next)));
+ if (lineComplete && !lastLineEmpty) {
+ parts.add(new PlainTextPart("\n" + line.substring(0, next)));
+ } else {
+ parts.add(new PlainTextPart(line.substring(0, next)));
+ }
}
if (line.length() >= (next + 7 + 43)) {
String soneId = line.substring(next + 7, next + 50);
}
if (line.length() >= (next + 7 + 43)) {
String soneId = line.substring(next + 7, next + 50);
- Sone sone =
core
.getSone(soneId, false);
- if (
sone != null
) {
+ Sone sone =
soneProvider
.getSone(soneId, false);
+ if (
(sone != null) && (sone.getName() != null)
) {
parts.add(new SonePart(sone));
} else {
parts.add(new PlainTextPart(line.substring(next, next + 50)));
parts.add(new SonePart(sone));
} else {
parts.add(new PlainTextPart(line.substring(next, next + 50)));
@@
-185,6
+201,7
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
parts.add(new PlainTextPart(line.substring(next)));
line = "";
}
parts.add(new PlainTextPart(line.substring(next)));
line = "";
}
+ lineComplete = false;
continue;
}
if (linkType == LinkType.POST) {
continue;
}
if (linkType == LinkType.POST) {
@@
-193,10
+210,8
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
}
if (line.length() >= (next + 7 + 36)) {
String postId = line.substring(next + 7, next + 43);
}
if (line.length() >= (next + 7 + 36)) {
String postId = line.substring(next + 7, next + 43);
- Post post =
core
.getPost(postId, false);
+ Post post =
postProvider
.getPost(postId, false);
if ((post != null) && (post.getSone() != null)) {
if ((post != null) && (post.getSone() != null)) {
- String postText = post.getText();
- postText = postText.substring(0, Math.min(postText.length(), 20)) + "…";
parts.add(new PostPart(post));
} else {
parts.add(new PlainTextPart(line.substring(next, next + 43)));
parts.add(new PostPart(post));
} else {
parts.add(new PlainTextPart(line.substring(next, next + 43)));
@@
-218,7
+233,9
@@
public class SoneTextParser implements Parser<SoneTextParserContext> {
if (!lastLineEmpty && lineComplete) {
parts.add(new PlainTextPart("\n" + line.substring(0, next)));
} else {
if (!lastLineEmpty && lineComplete) {
parts.add(new PlainTextPart("\n" + line.substring(0, next)));
} else {
- parts.add(new PlainTextPart(line.substring(0, next)));
+ if (next > 0) {
+ parts.add(new PlainTextPart(line.substring(0, next)));
+ }
}
String link = line.substring(next, nextSpace);
String name = link;
}
String link = line.substring(next, nextSpace);
String name = link;