import net.pterodactylus.sone.freenet.L10nFilter;
import net.pterodactylus.sone.main.SonePlugin;
import net.pterodactylus.sone.template.SoneAccessor;
-import net.pterodactylus.sone.web.page.CSSPage;
import net.pterodactylus.sone.web.page.PageToadlet;
import net.pterodactylus.sone.web.page.PageToadletFactory;
+import net.pterodactylus.sone.web.page.StaticPage;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.service.AbstractService;
import net.pterodactylus.util.template.DateFilter;
pageToadlets.add(pageToadletFactory.createPageToadlet(new DeleteSonePage(deleteSoneTemplate, this), "DeleteSone"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new LoginPage(loginTemplate, this), "Login"));
pageToadlets.add(pageToadletFactory.createPageToadlet(new LogoutPage(logoutTemplate, this), "Logout"));
- pageToadlets.add(pageToadletFactory.createPageToadlet(new CSSPage("css/", "/static/css/")));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("css/", "/static/css/", "text/css")));
+ pageToadlets.add(pageToadletFactory.createPageToadlet(new StaticPage("javascript/", "/static/javascript/", "text/javascript")));
ToadletContainer toadletContainer = sonePlugin.pluginRespirator().getToadletContainer();
toadletContainer.getPageMaker().addNavigationCategory("/Sone/index.html", "Navigation.Menu.Name", "Navigation.Menu.Tooltip", sonePlugin);
+++ /dev/null
-/*
- * shortener - CSSPage.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.web.page;
-
-import java.io.InputStream;
-
-/**
- * {@link Page} implementation that delivers CSS files from the class path.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public class CSSPage implements Page {
-
- /** The prefix for {@link #getPath()}. */
- private final String pathPrefix;
-
- /** The path used as prefix when loading resources. */
- private final String resourcePathPrefix;
-
- /**
- * Creates a new CSS page.
- *
- * @param pathPrefix
- * The prefix for {@link #getPath()}
- * @param resourcePathPrefix
- * The path prefix when loading resources
- */
- public CSSPage(String pathPrefix, String resourcePathPrefix) {
- this.pathPrefix = pathPrefix;
- this.resourcePathPrefix = resourcePathPrefix;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getPath() {
- return pathPrefix;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Response handleRequest(Request request) {
- String path = request.getURI().getPath();
- int lastSlash = path.lastIndexOf('/');
- String cssFilename = path.substring(lastSlash + 1);
- InputStream cssInputStream = getClass().getResourceAsStream(resourcePathPrefix + cssFilename);
- if (cssInputStream == null) {
- return new Response(404, "Not found.", null, (String) null);
- }
- return new Response(200, "OK", "text/css", null, cssInputStream);
- }
-
-}
--- /dev/null
+/*
+ * shortener - CSSPage.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.web.page;
+
+import java.io.InputStream;
+
+/**
+ * {@link Page} implementation that delivers static files from the class path.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class StaticPage implements Page {
+
+ /** The prefix for {@link #getPath()}. */
+ private final String pathPrefix;
+
+ /** The path used as prefix when loading resources. */
+ private final String resourcePathPrefix;
+
+ /** The MIME type for the files this path contains. */
+ private final String mimeType;
+
+ /**
+ * Creates a new CSS page.
+ *
+ * @param pathPrefix
+ * The prefix for {@link #getPath()}
+ * @param resourcePathPrefix
+ * The path prefix when loading resources
+ * @param mimeType
+ * The MIME type of the files this path contains
+ */
+ public StaticPage(String pathPrefix, String resourcePathPrefix, String mimeType) {
+ this.pathPrefix = pathPrefix;
+ this.resourcePathPrefix = resourcePathPrefix;
+ this.mimeType = mimeType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getPath() {
+ return pathPrefix;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Response handleRequest(Request request) {
+ String path = request.getURI().getPath();
+ int lastSlash = path.lastIndexOf('/');
+ String filename = path.substring(lastSlash + 1);
+ InputStream fileInputStream = getClass().getResourceAsStream(resourcePathPrefix + filename);
+ if (fileInputStream == null) {
+ return new Response(404, "Not found.", null, (String) null);
+ }
+ return new Response(200, "OK", mimeType, null, fileInputStream);
+ }
+
+}