Send out <link> header exposing the OpenSearchDescription document.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 2 Apr 2011 14:57:11 +0000 (16:57 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 2 Apr 2011 14:57:11 +0000 (16:57 +0200)
src/main/java/net/pterodactylus/sone/web/SoneTemplatePage.java
src/main/java/net/pterodactylus/sone/web/WebInterface.java
src/main/resources/templates/xml/OpenSearch.xml [new file with mode: 0644]

index f969208..d6c41c1 100644 (file)
@@ -21,11 +21,15 @@ import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
+import java.util.Map;
 
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.main.SonePlugin;
 import net.pterodactylus.sone.web.page.Page;
 import net.pterodactylus.sone.web.page.FreenetTemplatePage;
+import net.pterodactylus.util.collection.ListBuilder;
+import net.pterodactylus.util.collection.MapBuilder;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
 import freenet.clients.http.SessionManager.Session;
@@ -209,6 +213,14 @@ public class SoneTemplatePage extends FreenetTemplatePage {
         * {@inheritDoc}
         */
        @Override
+       protected List<Map<String, String>> getAdditionalLinkNodes(Request request) {
+               return new ListBuilder<Map<String, String>>().add(new MapBuilder<String, String>().put("rel", "search").put("type", "application/opensearchdescription+xml").put("title", "Sone").put("href", "http://" + request.getHttpRequest().getHeader("host") + "/Sone/OpenSearch.xml").get()).get();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
        protected Collection<String> getStyleSheets() {
                return Arrays.asList("css/sone.css");
        }
index 6341f2c..acfdc7f 100644 (file)
@@ -86,6 +86,7 @@ import net.pterodactylus.sone.web.ajax.UntrustAjaxPage;
 import net.pterodactylus.sone.web.page.PageToadlet;
 import net.pterodactylus.sone.web.page.PageToadletFactory;
 import net.pterodactylus.sone.web.page.StaticPage;
+import net.pterodactylus.sone.web.page.TemplatePage;
 import net.pterodactylus.util.cache.Cache;
 import net.pterodactylus.util.cache.CacheException;
 import net.pterodactylus.util.cache.CacheItem;
@@ -537,6 +538,7 @@ public class WebInterface implements CoreListener {
                Template invalidTemplate = TemplateParser.parse(createReader("/templates/invalid.html"));
                Template postTemplate = TemplateParser.parse(createReader("/templates/include/viewPost.html"));
                Template replyTemplate = TemplateParser.parse(createReader("/templates/include/viewReply.html"));
+               Template openSearchTemplate = TemplateParser.parse(createReader("/templates/xml/OpenSearch.xml"));
 
                PageToadletFactory pageToadletFactory = new PageToadletFactory(sonePlugin.pluginRespirator().getHLSimpleClient(), "/Sone/");
                pageToadlets.add(pageToadletFactory.createPageToadlet(new IndexPage(indexTemplate, this), "Index"));
@@ -576,6 +578,7 @@ public class WebInterface implements CoreListener {
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css")));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript")));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("images/", "/static/images/", "image/png")));
+               pageToadlets.add(pageToadletFactory.createPageToadlet(new TemplatePage("OpenSearch.xml", "application/opensearchdescription+xml", templateContextFactory, openSearchTemplate)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetTranslationPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new GetStatusAjaxPage(this)));
                pageToadlets.add(pageToadletFactory.createPageToadlet(new DismissNotificationAjaxPage(this)));
diff --git a/src/main/resources/templates/xml/OpenSearch.xml b/src/main/resources/templates/xml/OpenSearch.xml
new file mode 100644 (file)
index 0000000..37f0d35
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+       <ShortName>Sone</ShortName>
+       <Description>Search Sone Profiles and Posts</Description>
+       <Image width="32" height="32" type="image/png">http://<%request.httpRequest.host>/Sone/images/icon.png</Image>
+       <Url type="text/html" method="get" template="http://<%request.httpRequest.host>/Sone/search.html?query={searchTerms}" />
+</OpenSearchDescription>