Merge branch 'message-recipient'
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 27 Nov 2010 15:22:51 +0000 (16:22 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 27 Nov 2010 15:22:51 +0000 (16:22 +0100)
Conflicts:
src/main/resources/templates/include/viewPost.html

32 files changed:
pom.xml
src/main/java/net/pterodactylus/sone/template/PostAccessor.java
src/main/java/net/pterodactylus/sone/template/ReplyAccessor.java
src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/text/Parser.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/text/Part.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/text/PartContainer.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/text/TemplatePart.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/CreateReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/DeletePostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/DeleteReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/DismissNotificationAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/FollowSoneAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetLikesAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetPostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetReplyAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetTranslationPage.java
src/main/java/net/pterodactylus/sone/web/ajax/LikeAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/LockSoneAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/MarkPostAsKnownPage.java
src/main/java/net/pterodactylus/sone/web/ajax/MarkReplyAsKnownPage.java
src/main/java/net/pterodactylus/sone/web/ajax/UnfollowSoneAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/UnlikeAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/UnlockSoneAjaxPage.java
src/main/resources/static/javascript/sone.js
src/main/resources/templates/include/viewPost.html
src/main/resources/templates/include/viewReply.html
src/main/resources/templates/knownSones.html
src/main/resources/templates/viewPost.html

diff --git a/pom.xml b/pom.xml
index 510ec62..7a14a0e 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
                <dependency>
                        <groupId>net.pterodactylus</groupId>
                        <artifactId>utils</artifactId>
-                       <version>0.7</version>
+                       <version>0.7.1</version>
                </dependency>
                <dependency>
                        <groupId>junit</groupId>
                </dependency>
                <dependency>
                        <groupId>org.freenetproject</groupId>
-                       <artifactId>fred-ext</artifactId>
+                       <artifactId>freenet-ext</artifactId>
                        <version>26</version>
                        <scope>provided</scope>
                </dependency>
                <dependency>
                        <groupId>net.pterodactylus</groupId>
                        <artifactId>utils.json</artifactId>
-                       <version>0.1-SNAPSHOT</version>
+                       <version>0.1</version>
                </dependency>
        </dependencies>
+       <repositories>
+               <repository>
+                       <id>pterodactylus</id>
+                       <url>http://maven.pterodactylus.net/</url>
+               </repository>
+       </repositories>
        <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
                        </plugin>
                </plugins>
        </build>
+       <reporting>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-javadoc-plugin</artifactId>
+                               <configuration>
+                                       <links>
+                                               <link>http://download.oracle.com/javase/6/docs/api/</link>
+                                               <link>http://java.pterodactylus.net/utils/apidocs/</link>
+                                               <link>http://java.pterodactylus.net/utils.json/apidocs/</link>
+                                       </links>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </reporting>
 </project>
index de96780..746ed25 100644 (file)
 
 package net.pterodactylus.sone.template;
 
+import java.io.IOException;
+import java.io.StringReader;
+
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.text.FreenetLinkParser;
 import net.pterodactylus.util.template.DataProvider;
 import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateFactory;
 
 /**
  * Accessor for {@link Post} objects that adds additional properties:
@@ -34,6 +39,9 @@ import net.pterodactylus.util.template.ReflectionAccessor;
  */
 public class PostAccessor extends ReflectionAccessor {
 
+       /** Parser for Freenet links. */
+       private final FreenetLinkParser linkParser;
+
        /** The core to get the replies from. */
        private final Core core;
 
@@ -42,9 +50,12 @@ public class PostAccessor extends ReflectionAccessor {
         *
         * @param core
         *            The core to get the replies from
+        * @param templateFactory
+        *            The template factory for the text parser
         */
-       public PostAccessor(Core core) {
+       public PostAccessor(Core core, TemplateFactory templateFactory) {
                this.core = core;
+               linkParser = new FreenetLinkParser(templateFactory);
        }
 
        /**
@@ -62,6 +73,13 @@ public class PostAccessor extends ReflectionAccessor {
                        return (currentSone != null) && (currentSone.isLikedPostId(post.getId()));
                } else if (member.equals("new")) {
                        return core.isNewPost(post.getId(), false);
+               } else if (member.equals("text")) {
+                       String text = post.getText();
+                       try {
+                               return linkParser.parse(new StringReader(text));
+                       } catch (IOException ioe1) {
+                               /* ignore. */
+                       }
                }
                return super.get(dataProvider, object, member);
        }
index d664697..1ec4e04 100644 (file)
 
 package net.pterodactylus.sone.template;
 
+import java.io.IOException;
+import java.io.StringReader;
+
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.text.FreenetLinkParser;
 import net.pterodactylus.util.template.Accessor;
 import net.pterodactylus.util.template.DataProvider;
 import net.pterodactylus.util.template.ReflectionAccessor;
+import net.pterodactylus.util.template.TemplateFactory;
 
 /**
  * {@link Accessor} implementation that adds a couple of properties to
@@ -32,6 +37,9 @@ import net.pterodactylus.util.template.ReflectionAccessor;
  */
 public class ReplyAccessor extends ReflectionAccessor {
 
+       /** Parser for Freenet links. */
+       private final FreenetLinkParser linkParser;
+
        /** The core. */
        private final Core core;
 
@@ -40,9 +48,12 @@ public class ReplyAccessor extends ReflectionAccessor {
         *
         * @param core
         *            The core
+        * @param templateFactory
+        *            The template factory for the text parser
         */
-       public ReplyAccessor(Core core) {
+       public ReplyAccessor(Core core, TemplateFactory templateFactory) {
                this.core = core;
+               linkParser = new FreenetLinkParser(templateFactory);
        }
 
        /**
@@ -58,6 +69,13 @@ public class ReplyAccessor extends ReflectionAccessor {
                        return (currentSone != null) && (currentSone.isLikedReplyId(reply.getId()));
                } else if (member.equals("new")) {
                        return core.isNewReply(reply.getId(), false);
+               } else if (member.equals("text")) {
+                       String text = reply.getText();
+                       try {
+                               return linkParser.parse(new StringReader(text));
+                       } catch (IOException ioe1) {
+                               /* ignore. */
+                       }
                }
                return super.get(dataProvider, object, member);
        }
diff --git a/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java b/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java
new file mode 100644 (file)
index 0000000..85bda1a
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Sone - FreenetLinkParser.java - Copyright © 2010 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.template.TemplateFactory;
+
+/**
+ * {@link Parser} implementation that can recognize Freenet URIs.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class FreenetLinkParser implements Parser {
+
+       /** The logger. */
+       private static final Logger logger = Logging.getLogger(FreenetLinkParser.class);
+
+       /** Pattern to detect whitespace. */
+       private static final Pattern whitespacePattern = Pattern.compile("[\\p{javaWhitespace}]");
+
+       /**
+        * Enumeration for all recognized link types.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       private enum LinkType {
+
+               /** Link is a KSK. */
+               KSK,
+
+               /** Link is a CHK. */
+               CHK,
+
+               /** Link is an SSK. */
+               SSK,
+
+               /** Link is a USK. */
+               USK
+
+       }
+
+       /** The template factory. */
+       private final TemplateFactory templateFactory;
+
+       /**
+        * Creates a new freenet link parser.
+        *
+        * @param templateFactory
+        *            The template factory
+        */
+       public FreenetLinkParser(TemplateFactory templateFactory) {
+               this.templateFactory = templateFactory;
+       }
+
+       //
+       // PART METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public Part parse(Reader source) throws IOException {
+               PartContainer parts = new PartContainer();
+               BufferedReader bufferedReader = (source instanceof BufferedReader) ? (BufferedReader) source : new BufferedReader(source);
+               String line;
+               while ((line = bufferedReader.readLine()) != null) {
+                       line = line.trim() + "\n";
+                       while (line.length() > 0) {
+                               int nextKsk = line.indexOf("KSK@");
+                               int nextChk = line.indexOf("CHK@");
+                               int nextSsk = line.indexOf("SSK@");
+                               int nextUsk = line.indexOf("USK@");
+                               if ((nextKsk == -1) && (nextChk == -1) && (nextSsk == -1) && (nextUsk == -1)) {
+                                       parts.add(createPlainTextPart(line));
+                                       break;
+                               }
+                               int next = Integer.MAX_VALUE;
+                               LinkType linkType = null;
+                               if ((nextKsk > -1) && (nextKsk < next)) {
+                                       next = nextKsk;
+                                       linkType = LinkType.KSK;
+                               }
+                               if ((nextChk > -1) && (nextChk < next)) {
+                                       next = nextChk;
+                                       linkType = LinkType.CHK;
+                               }
+                               if ((nextSsk > -1) && (nextSsk < next)) {
+                                       next = nextSsk;
+                                       linkType = LinkType.SSK;
+                               }
+                               if ((nextUsk > -1) && (nextUsk < next)) {
+                                       next = nextUsk;
+                                       linkType = LinkType.USK;
+                               }
+                               if ((next >= 8) && (line.substring(next - 8, next).equals("freenet:"))) {
+                                       next -= 8;
+                                       line = line.substring(0, next) + line.substring(next + 8);
+                               }
+                               Matcher matcher = whitespacePattern.matcher(line);
+                               int nextSpace = matcher.find(next) ? matcher.start() : line.length();
+                               if (nextSpace > (next + 4)) {
+                                       parts.add(createPlainTextPart(line.substring(0, next)));
+                                       String link = line.substring(next, nextSpace);
+                                       String name = link;
+                                       logger.log(Level.FINER, "Found link: " + link);
+                                       logger.log(Level.FINEST, "Next: %d, CHK: %d, SSK: %d, USK: %d", new Object[] { next, nextChk, nextSsk, nextUsk });
+                                       if (((linkType == LinkType.CHK) || (linkType == LinkType.SSK) || (linkType == LinkType.USK)) && (link.length() > 98) && (link.charAt(47) == ',') && (link.charAt(91) == ',') && (link.charAt(99) == '/')) {
+                                               name = link.substring(0, 47) + "…" + link.substring(99);
+                                       }
+                                       parts.add(createLinkPart(link, name));
+                                       line = line.substring(nextSpace);
+                               } else {
+                                       parts.add(createPlainTextPart(line.substring(0, next + 4)));
+                                       line = line.substring(next + 4);
+                               }
+                       }
+               }
+               return parts;
+       }
+
+       //
+       // PRIVATE METHODS
+       //
+
+       /**
+        * Creates a new plain text part based on a template.
+        *
+        * @param text
+        *            The text to display
+        * @return The part that displays the given text
+        */
+       private Part createPlainTextPart(String text) {
+               return new TemplatePart(templateFactory.createTemplate(new StringReader("<% text|html>"))).set("text", text);
+       }
+
+       /**
+        * Creates a new link part based on a template.
+        *
+        * @param link
+        *            The target of the link
+        * @param name
+        *            The name of the link
+        * @return The part that displays the link
+        */
+       private Part createLinkPart(String link, String name) {
+               return new TemplatePart(templateFactory.createTemplate(new StringReader("<a href=\"/<% link|html>\"><% name|html></a>"))).set("link", link).set("name", name);
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/text/Parser.java b/src/main/java/net/pterodactylus/sone/text/Parser.java
new file mode 100644 (file)
index 0000000..ccec36a
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Sone - Parser.java - Copyright © 2010 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import java.io.IOException;
+import java.io.Reader;
+
+/**
+ * Interface for parsers that can create {@link Part}s from a text source
+ * (usually a {@link Reader}).
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface Parser {
+
+       /**
+        * Create a {@link Part} from the given text source.
+        *
+        * @param source
+        *            The text source
+        * @return The parsed part
+        * @throws IOException
+        *             if an I/O error occurs
+        */
+       public Part parse(Reader source) throws IOException;
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/text/Part.java b/src/main/java/net/pterodactylus/sone/text/Part.java
new file mode 100644 (file)
index 0000000..b9083b7
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Sone - Part.java - Copyright © 2010 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import net.pterodactylus.util.io.Renderable;
+
+/**
+ * A part is a single piece of information that can be displayed as a single
+ * element.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface Part extends Renderable {
+
+       /* all required methods are inherited from {@link Renderable}. */
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/text/PartContainer.java b/src/main/java/net/pterodactylus/sone/text/PartContainer.java
new file mode 100644 (file)
index 0000000..7399859
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Sone - PartContainer.java - Copyright © 2010 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Part implementation that can contain an arbitrary amount of other parts.
+ * Parts are added using the {@link #add(Part)} method and will be rendered in
+ * the order they are added.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class PartContainer implements Part {
+
+       /** The parts to render. */
+       private final List<Part> parts = new ArrayList<Part>();
+
+       //
+       // ACCESSORS
+       //
+
+       /**
+        * Adds a part to render.
+        *
+        * @param part
+        *            The part to add
+        */
+       public void add(Part part) {
+               parts.add(part);
+       }
+
+       //
+       // PART METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void render(Writer writer) throws IOException {
+               for (Part part : parts) {
+                       part.render(writer);
+               }
+       }
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/text/TemplatePart.java b/src/main/java/net/pterodactylus/sone/text/TemplatePart.java
new file mode 100644 (file)
index 0000000..2b27a89
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Sone - TemplatePart.java - Copyright © 2010 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.text;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import net.pterodactylus.util.template.Template;
+
+/**
+ * {@link Part} implementation that is rendered using a {@link Template}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class TemplatePart implements Part {
+
+       /** The template to render for this part. */
+       private final Template template;
+
+       /**
+        * Creates a new template part.
+        *
+        * @param template
+        *            The template to render
+        */
+       public TemplatePart(Template template) {
+               this.template = template;
+       }
+
+       //
+       // ACTIONS
+       //
+
+       /**
+        * Sets a variable in the template.
+        *
+        * @param key
+        *            The key of the variable
+        * @param value
+        *            The value of the variable
+        * @return This template part (for method chaining)
+        */
+       public TemplatePart set(String key, String value) {
+               template.set(key, value);
+               return this;
+       }
+
+       //
+       // PART METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public void render(Writer writer) throws IOException {
+               template.render(writer);
+       }
+
+}
index f7e6d36..75b218c 100644 (file)
@@ -142,8 +142,8 @@ public class WebInterface implements CoreListener {
                templateFactory.addAccessor(Object.class, new ReflectionAccessor());
                templateFactory.addAccessor(Collection.class, new CollectionAccessor());
                templateFactory.addAccessor(Sone.class, new SoneAccessor(getCore()));
-               templateFactory.addAccessor(Post.class, new PostAccessor(getCore()));
-               templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore()));
+               templateFactory.addAccessor(Post.class, new PostAccessor(getCore(), templateFactory));
+               templateFactory.addAccessor(Reply.class, new ReplyAccessor(getCore(), templateFactory));
                templateFactory.addAccessor(Identity.class, new IdentityAccessor(getCore()));
                templateFactory.addAccessor(NotificationManager.class, new NotificationManagerAccessor());
                templateFactory.addFilter("date", new DateFilter());
index ce2462c..1e45a60 100644 (file)
@@ -36,7 +36,7 @@ public class CreatePostAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public CreatePostAjaxPage(WebInterface webInterface) {
-               super("ajax/createPost.ajax", webInterface);
+               super("createPost.ajax", webInterface);
        }
 
        /**
index 486fb75..0181ff2 100644 (file)
@@ -37,7 +37,7 @@ public class CreateReplyAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public CreateReplyAjaxPage(WebInterface webInterface) {
-               super("ajax/createReply.ajax", webInterface);
+               super("createReply.ajax", webInterface);
        }
 
        //
index d2a7a39..479e71e 100644 (file)
@@ -36,7 +36,7 @@ public class DeletePostAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public DeletePostAjaxPage(WebInterface webInterface) {
-               super("ajax/deletePost.ajax", webInterface);
+               super("deletePost.ajax", webInterface);
        }
 
        //
index 6563a7c..7614de8 100644 (file)
@@ -36,7 +36,7 @@ public class DeleteReplyAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public DeleteReplyAjaxPage(WebInterface webInterface) {
-               super("ajax/deleteReply.ajax", webInterface);
+               super("deleteReply.ajax", webInterface);
        }
 
        //
index 44171e3..283e924 100644 (file)
@@ -35,7 +35,7 @@ public class DismissNotificationAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public DismissNotificationAjaxPage(WebInterface webInterface) {
-               super("ajax/dismissNotification.ajax", webInterface);
+               super("dismissNotification.ajax", webInterface);
        }
 
        /**
index 5cb03e1..1269b41 100644 (file)
@@ -35,7 +35,7 @@ public class FollowSoneAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public FollowSoneAjaxPage(WebInterface webInterface) {
-               super("ajax/followSone.ajax", webInterface);
+               super("followSone.ajax", webInterface);
        }
 
        /**
index 58b1265..a8b991d 100644 (file)
@@ -44,7 +44,7 @@ public class GetLikesAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public GetLikesAjaxPage(WebInterface webInterface) {
-               super("ajax/getLikes.ajax", webInterface);
+               super("getLikes.ajax", webInterface);
        }
 
        //
index 452fc5a..764c5bf 100644 (file)
@@ -46,7 +46,7 @@ public class GetPostAjaxPage extends JsonPage {
         *            The template to render for posts
         */
        public GetPostAjaxPage(WebInterface webInterface, Template postTemplate) {
-               super("ajax/getPost.ajax", webInterface);
+               super("getPost.ajax", webInterface);
                this.postTemplate = postTemplate;
        }
 
index 3c43593..77b3ada 100644 (file)
@@ -45,7 +45,7 @@ public class GetReplyAjaxPage extends JsonPage {
         *            The template to render
         */
        public GetReplyAjaxPage(WebInterface webInterface, Template replyTemplate) {
-               super("ajax/getReply.ajax", webInterface);
+               super("getReply.ajax", webInterface);
                this.replyTemplate = replyTemplate;
        }
 
index 8b1612b..ae3dfc2 100644 (file)
@@ -22,6 +22,7 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -52,7 +53,7 @@ public class GetStatusAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public GetStatusAjaxPage(WebInterface webInterface) {
-               super("ajax/getStatus.ajax", webInterface);
+               super("getStatus.ajax", webInterface);
        }
 
        /**
@@ -62,7 +63,10 @@ public class GetStatusAjaxPage extends JsonPage {
        protected JsonObject createJsonObject(Request request) {
                /* load Sones. */
                boolean loadAllSones = Boolean.parseBoolean(request.getHttpRequest().getParam("loadAllSones", "true"));
-               Set<Sone> sones = loadAllSones ? webInterface.getCore().getSones() : Collections.singleton(getCurrentSone(request.getToadletContext()));
+               Set<Sone> sones = new HashSet<Sone>(Collections.singleton(getCurrentSone(request.getToadletContext())));
+               if (loadAllSones) {
+                       sones.addAll(webInterface.getCore().getSones());
+               }
                JsonArray jsonSones = new JsonArray();
                for (Sone sone : sones) {
                        JsonObject jsonSone = createJsonSone(sone);
index 014bc88..36327ca 100644 (file)
@@ -34,7 +34,7 @@ public class GetTranslationPage extends JsonPage {
         *            The Sone web interface
         */
        public GetTranslationPage(WebInterface webInterface) {
-               super("ajax/getTranslation.ajax", webInterface);
+               super("getTranslation.ajax", webInterface);
        }
 
        //
index 17438d4..efd1439 100644 (file)
@@ -36,7 +36,7 @@ public class LikeAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public LikeAjaxPage(WebInterface webInterface) {
-               super("ajax/like.ajax", webInterface);
+               super("like.ajax", webInterface);
        }
 
        /**
index d1a21d3..6c4ece0 100644 (file)
@@ -36,7 +36,7 @@ public class LockSoneAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public LockSoneAjaxPage(WebInterface webInterface) {
-               super("ajax/lockSone.ajax", webInterface);
+               super("lockSone.ajax", webInterface);
        }
 
        /**
index b44d7f1..c2b0ca3 100644 (file)
@@ -35,7 +35,7 @@ public class MarkPostAsKnownPage extends JsonPage {
         *            The Sone web interface
         */
        public MarkPostAsKnownPage(WebInterface webInterface) {
-               super("ajax/markPostAsKnown.ajax", webInterface);
+               super("markPostAsKnown.ajax", webInterface);
        }
 
        /**
index 2406c7a..6a4f72b 100644 (file)
@@ -35,7 +35,7 @@ public class MarkReplyAsKnownPage extends JsonPage {
         *            The Sone web interface
         */
        public MarkReplyAsKnownPage(WebInterface webInterface) {
-               super("ajax/markReplyAsKnown.ajax", webInterface);
+               super("markReplyAsKnown.ajax", webInterface);
        }
 
        /**
index 586ab55..c2379e8 100644 (file)
@@ -35,7 +35,7 @@ public class UnfollowSoneAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public UnfollowSoneAjaxPage(WebInterface webInterface) {
-               super("ajax/unfollowSone.ajax", webInterface);
+               super("unfollowSone.ajax", webInterface);
        }
 
        /**
index fb0445b..e5c933d 100644 (file)
@@ -36,7 +36,7 @@ public class UnlikeAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public UnlikeAjaxPage(WebInterface webInterface) {
-               super("ajax/unlike.ajax", webInterface);
+               super("unlike.ajax", webInterface);
        }
 
        /**
index 5ea3aa9..02682b2 100644 (file)
@@ -36,7 +36,7 @@ public class UnlockSoneAjaxPage extends JsonPage {
         *            The Sone web interface
         */
        public UnlockSoneAjaxPage(WebInterface webInterface) {
-               super("ajax/unlockSone.ajax", webInterface);
+               super("unlockSone.ajax", webInterface);
        }
 
        /**
index 01dd77c..02a02a8 100644 (file)
@@ -105,7 +105,7 @@ function getTranslation(key, callback) {
                callback(translations[key]);
                return;
        }
-       $.getJSON("ajax/getTranslation.ajax", {"key": key}, function(data, textStatus) {
+       $.getJSON("getTranslation.ajax", {"key": key}, function(data, textStatus) {
                if ((data != null) && data.success) {
                        translations[key] = data.value;
                        callback(data.value);
@@ -201,7 +201,7 @@ function enhanceDeleteButton(button, text, deleteCallback) {
  */
 function enhanceDeletePostButton(button, postId, text) {
        enhanceDeleteButton(button, text, function() {
-               $.getJSON("ajax/deletePost.ajax", { "post": postId, "formPassword": getFormPassword() }, function(data, textStatus) {
+               $.getJSON("deletePost.ajax", { "post": postId, "formPassword": getFormPassword() }, function(data, textStatus) {
                        if (data == null) {
                                return;
                        }
@@ -232,7 +232,7 @@ function enhanceDeletePostButton(button, postId, text) {
  */
 function enhanceDeleteReplyButton(button, replyId, text) {
        enhanceDeleteButton(button, text, function() {
-               $.getJSON("ajax/deleteReply.ajax", { "reply": replyId, "formPassword": $("#sone #formPassword").text() }, function(data, textStatus) {
+               $.getJSON("deleteReply.ajax", { "reply": replyId, "formPassword": $("#sone #formPassword").text() }, function(data, textStatus) {
                        if (data == null) {
                                return;
                        }
@@ -314,7 +314,7 @@ function getReplyTime(element) {
 }
 
 function likePost(postId) {
-       $.getJSON("ajax/like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
+       $.getJSON("like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
                if ((data == null) || !data.success) {
                        return;
                }
@@ -327,7 +327,7 @@ function likePost(postId) {
 }
 
 function unlikePost(postId) {
-       $.getJSON("ajax/unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
+       $.getJSON("unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
                if ((data == null) || !data.success) {
                        return;
                }
@@ -340,7 +340,7 @@ function unlikePost(postId) {
 }
 
 function updatePostLikes(postId) {
-       $.getJSON("ajax/getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
+       $.getJSON("getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
                if ((data != null) && data.success) {
                        $("#sone .post#" + postId + " > .inner-part > .status-line .likes").toggleClass("hidden", data.likes == 0)
                        $("#sone .post#" + postId + " > .inner-part > .status-line .likes span.like-count").text(data.likes);
@@ -352,7 +352,7 @@ function updatePostLikes(postId) {
 }
 
 function likeReply(replyId) {
-       $.getJSON("ajax/like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
+       $.getJSON("like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
                if ((data == null) || !data.success) {
                        return;
                }
@@ -365,7 +365,7 @@ function likeReply(replyId) {
 }
 
 function unlikeReply(replyId) {
-       $.getJSON("ajax/unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
+       $.getJSON("unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
                if ((data == null) || !data.success) {
                        return;
                }
@@ -378,7 +378,7 @@ function unlikeReply(replyId) {
 }
 
 function updateReplyLikes(replyId) {
-       $.getJSON("ajax/getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
+       $.getJSON("getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
                if ((data != null) && data.success) {
                        $("#sone .reply#" + replyId + " .status-line .likes").toggleClass("hidden", data.likes == 0)
                        $("#sone .reply#" + replyId + " .status-line .likes span.like-count").text(data.likes);
@@ -401,7 +401,7 @@ function updateReplyLikes(replyId) {
  *            parameters: success, error, replyId)
  */
 function postReply(postId, text, callbackFunction) {
-       $.getJSON("ajax/createReply.ajax", { "formPassword" : getFormPassword(), "post" : postId, "text": text }, function(data, textStatus) {
+       $.getJSON("createReply.ajax", { "formPassword" : getFormPassword(), "post" : postId, "text": text }, function(data, textStatus) {
                if (data == null) {
                        /* TODO - show error */
                        return;
@@ -426,7 +426,7 @@ function postReply(postId, text, callbackFunction) {
  *            replyDisplayTime, text, html)
  */
 function getReply(replyId, callbackFunction) {
-       $.getJSON("ajax/getReply.ajax", { "reply" : replyId }, function(data, textStatus) {
+       $.getJSON("getReply.ajax", { "reply" : replyId }, function(data, textStatus) {
                if ((data != null) && data.success) {
                        callbackFunction(data.soneId, data.soneName, data.time, data.displayTime, data.text, data.html);
                }
@@ -549,7 +549,7 @@ function ajaxifyNotification(notification) {
                return false;
        });
        notification.find("form.dismiss button").click(function() {
-               $.getJSON("ajax/dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
+               $.getJSON("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
                        /* dismiss in case of error, too. */
                        notification.slideUp();
                }, function(xmlHttpRequest, textStatus, error) {
@@ -560,7 +560,7 @@ function ajaxifyNotification(notification) {
 }
 
 function getStatus() {
-       $.getJSON("ajax/getStatus.ajax", {}, function(data, textStatus) {
+       $.getJSON("getStatus.ajax", {"loadAllSones": isKnownSonesPage()}, function(data, textStatus) {
                if ((data != null) && data.success) {
                        /* process Sone information. */
                        $.each(data.sones, function(index, value) {
@@ -636,10 +636,40 @@ function isViewSonePage() {
  *
  * @returns The ID of the currently shown Sone
  */
-function getSoneId() {
+function getShownSoneId() {
        return $("#sone .sone-id").text();
 }
 
+/**
+ * Returns whether the current page is a “view post” page.
+ *
+ * @returns {Boolean} <code>true</code> if the current page is a “view post”
+ *          page, <code>false</code> otherwise
+ */
+function isViewPostPage() {
+       return getPageId() == "view-post";
+}
+
+/**
+ * Returns the ID of the currently shown post. This will only return a sensible
+ * value if isViewPostPage() returns <code>true</code>.
+ *
+ * @returns The ID of the currently shown post
+ */
+function getShownPostId() {
+       return $("#sone .post-id").text();
+}
+
+/**
+ * Returns whether the current page is the “known Sones” page.
+ *
+ * @returns {Boolean} <code>true</code> if the current page is the “known
+ *          Sones” page, <code>false</code> otherwise
+ */
+function isKnownSonesPage() {
+       return getPageId() == "known-sones";
+}
+
 var loadedPosts = {};
 var loadedReplies = {};
 
@@ -648,9 +678,9 @@ function loadNewPost(postId) {
                return;
        }
        loadedPosts[postId] = true;
-       $.getJSON("ajax/getPost.ajax", { "post" : postId }, function(data, textStatus) {
+       $.getJSON("getPost.ajax", { "post" : postId }, function(data, textStatus) {
                if ((data != null) && data.success) {
-                       if (!isIndexPage() && !(isViewSonePage() && (getSoneId() == data.post.sone))) {
+                       if (!isIndexPage() && !(isViewSonePage() && (getShownSoneId() == data.post.sone))) {
                                return;
                        }
                        var firstOlderPost = null;
@@ -678,7 +708,7 @@ function loadNewReply(replyId) {
                return;
        }
        loadedReplies[replyId] = true;
-       $.getJSON("ajax/getReply.ajax", { "reply": replyId }, function(data, textStatus) {
+       $.getJSON("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
                /* find post. */
                if ((data != null) && data.success) {
                        $("#sone .post#" + data.reply.postId).each(function() {
@@ -712,7 +742,7 @@ function markPostAsKnown(postElements) {
                postElement = this;
                if ($(postElement).hasClass("new")) {
                        (function(postElement) {
-                               $.getJSON("ajax/markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) {
+                               $.getJSON("markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) {
                                        $(postElement).removeClass("new");
                                });
                        })(postElement);
@@ -726,7 +756,7 @@ function markReplyAsKnown(replyElements) {
                replyElement = this;
                if ($(replyElement).hasClass("new")) {
                        (function(replyElement) {
-                               $.getJSON("ajax/markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) {
+                               $.getJSON("markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) {
                                        $(replyElement).removeClass("new");
                                });
                        })(replyElement);
@@ -785,7 +815,7 @@ $(document).ready(function() {
                registerInputTextareaSwap("#sone #update-status .status-input", defaultText, "text", false, false);
                $("#sone #update-status").submit(function() {
                        text = $(this).find(":input:enabled").val();
-                       $.getJSON("ajax/createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) {
+                       $.getJSON("createPost.ajax", { "formPassword": getFormPassword(), "text": text }, function(data, textStatus) {
                                if ((data != null) && data.success) {
                                        loadNewPost(data.postId);
                                }
@@ -823,30 +853,32 @@ $(document).ready(function() {
        });
 
        /* hides all replies but the latest two. */
-       getTranslation("WebInterface.ClickToShow.Replies", function(text) {
-               $("#sone .post .replies").each(function() {
-                       allReplies = $(this).find(".reply");
-                       if (allReplies.length > 2) {
-                               newHidden = false;
-                               for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) {
-                                       $(allReplies[replyIndex]).addClass("hidden");
-                                       newHidden |= $(allReplies[replyIndex]).hasClass("new");
-                               }
-                               clickToShowElement = $("<div></div>").addClass("click-to-show");
-                               if (newHidden) {
-                                       clickToShowElement.addClass("new");
+       if (!isViewPostPage()) {
+               getTranslation("WebInterface.ClickToShow.Replies", function(text) {
+                       $("#sone .post .replies").each(function() {
+                               allReplies = $(this).find(".reply");
+                               if (allReplies.length > 2) {
+                                       newHidden = false;
+                                       for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) {
+                                               $(allReplies[replyIndex]).addClass("hidden");
+                                               newHidden |= $(allReplies[replyIndex]).hasClass("new");
+                                       }
+                                       clickToShowElement = $("<div></div>").addClass("click-to-show");
+                                       if (newHidden) {
+                                               clickToShowElement.addClass("new");
+                                       }
+                                       (function(clickToShowElement, allReplies, text) {
+                                               clickToShowElement.text(text);
+                                               clickToShowElement.click(function() {
+                                                       allReplies.removeClass("hidden");
+                                                       clickToShowElement.addClass("hidden");
+                                               });
+                                       })(clickToShowElement, allReplies, text);
+                                       $(allReplies[0]).before(clickToShowElement);
                                }
-                               (function(clickToShowElement, allReplies, text) {
-                                       clickToShowElement.text(text);
-                                       clickToShowElement.click(function() {
-                                               allReplies.removeClass("hidden");
-                                               clickToShowElement.addClass("hidden");
-                                       });
-                               })(clickToShowElement, allReplies, text);
-                               $(allReplies[0]).before(clickToShowElement);
-                       }
+                       });
                });
-       });
+       }
 
        /*
         * convert all “follow”, “unfollow”, “lock”, and “unlock” links to something
@@ -854,7 +886,7 @@ $(document).ready(function() {
         */
        $("#sone .follow").submit(function() {
                var followElement = this;
-               $.getJSON("ajax/followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
+               $.getJSON("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
                        $(followElement).addClass("hidden");
                        $(followElement).parent().find(".unfollow").removeClass("hidden");
                });
@@ -862,7 +894,7 @@ $(document).ready(function() {
        });
        $("#sone .unfollow").submit(function() {
                var unfollowElement = this;
-               $.getJSON("ajax/unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
+               $.getJSON("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
                        $(unfollowElement).addClass("hidden");
                        $(unfollowElement).parent().find(".follow").removeClass("hidden");
                });
@@ -870,7 +902,7 @@ $(document).ready(function() {
        });
        $("#sone .lock").submit(function() {
                var lockElement = this;
-               $.getJSON("ajax/lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
+               $.getJSON("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
                        $(lockElement).addClass("hidden");
                        $(lockElement).parent().find(".unlock").removeClass("hidden");
                });
@@ -878,7 +910,7 @@ $(document).ready(function() {
        });
        $("#sone .unlock").submit(function() {
                var unlockElement = this;
-               $.getJSON("ajax/unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
+               $.getJSON("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
                        $(unlockElement).addClass("hidden");
                        $(unlockElement).parent().find(".lock").removeClass("hidden");
                });
index ffc7608..3d593bc 100644 (file)
@@ -15,7 +15,7 @@
                                        <div class="recipient profile-link"><a href="viewSone.html?sone=<% post.recipient.id|html>"><% post.recipient.niceName|html></a></div>
                                <%/if>
                        <%/if>
-                       <div class="text"><% post.text|html></div>
+                       <div class="text"><% post.text></div>
                </div>
                <div class="post-status-line status-line">
                        <div class="time"><a href="viewPost.html?post=<% post.id|html>"><% post.time|date format="MMM d, yyyy, HH:mm:ss"></a></div>
index d77625b..d11aa5f 100644 (file)
@@ -7,7 +7,7 @@
        <div class="inner-part">
                <div>
                        <div class="author profile-link"><a href="viewSone.html?sone=<% reply.sone.id|html>"><% reply.sone.niceName|html></a></div>
-                       <div class="text"><% reply.text|html></div>
+                       <div class="text"><% reply.text></div>
                </div>
                <div class="reply-status-line status-line">
                        <div class="time"><% reply.time|date format="MMM d, yyyy, HH:mm:ss"></div>
index 4520967..f5907a0 100644 (file)
@@ -1,5 +1,7 @@
 <%include include/head.html>
 
+       <div class="page-id hidden">known-sones</div>
+
        <h1><%= Page.KnownSones.Page.Title|l10n|html></h1>
 
        <div id="known-sones">
index 867971c..3de8ebc 100644 (file)
@@ -1,5 +1,8 @@
 <%include include/head.html>
 
+       <div class="page-id hidden">view-post</div>
+       <div class="post-id hidden"><% post.id|html></div>
+
        <h1><%= Page.ViewPost.Page.Title|l10n|insert needle="{sone}" key=post.sone.niceName|html></h1>
 
        <%include include/viewPost.html>