<class name="com.gitblit.FederationServlet" />\r
<class name="com.gitblit.GitFilter" />\r
<class name="com.gitblit.git.GitServlet" />\r
+ <class name="com.gitblit.LogoServlet" />\r
<class name="com.gitblit.PagesFilter" />\r
<class name="com.gitblit.PagesServlet" />\r
<class name="com.gitblit.RobotsTxtServlet" />\r
<class name="com.gitblit.FederationServlet" />\r
<class name="com.gitblit.GitFilter" />\r
<class name="com.gitblit.git.GitServlet" />\r
+ <class name="com.gitblit.LogoServlet" />\r
<class name="com.gitblit.PagesFilter" />\r
<class name="com.gitblit.PagesServlet" />\r
<class name="com.gitblit.RobotsTxtServlet" />\r
<servlet-name>PagesServlet</servlet-name> \r
<url-pattern>/pages/*</url-pattern>\r
</servlet-mapping> \r
+\r
\r
+ <!-- Logo Servlet\r
+ <url-pattern> MUST match: \r
+ * Wicket Filter ignorePaths parameter -->\r
+ <servlet>\r
+ <servlet-name>LogoServlet</servlet-name>\r
+ <servlet-class>com.gitblit.LogoServlet</servlet-class>\r
+ </servlet>\r
+ <servlet-mapping>\r
+ <servlet-name>LogoServlet</servlet-name> \r
+ <url-pattern>/logo.png</url-pattern>\r
+ </servlet-mapping>\r
+\r
\r
<!-- Robots.txt Servlet\r
<url-pattern> MUST match: \r
* PagesFilter <url-pattern>\r
* PagesServlet <url-pattern>\r
* com.gitblit.Constants.PAGES_PATH -->\r
- <param-value>git/,feed/,zip/,federation/,rpc/,pages/,robots.txt,sparkleshare/</param-value>\r
+ <param-value>git/,feed/,zip/,federation/,rpc/,pages/,robots.txt,logo.png,sparkleshare/</param-value>\r
</init-param>\r
</filter>\r
<filter-mapping>\r
--- /dev/null
+/*\r
+ * Copyright 2013 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit;\r
+\r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+\r
+import javax.servlet.ServletContext;\r
+import javax.servlet.ServletException;\r
+import javax.servlet.http.HttpServlet;\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+/**\r
+ * Handles requests for logo.png\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class LogoServlet extends HttpServlet {\r
+ \r
+ private static final long serialVersionUID = 1L;\r
+ \r
+ private static final long lastModified = System.currentTimeMillis();\r
+\r
+ public LogoServlet() {\r
+ super();\r
+ }\r
+ \r
+ @Override\r
+ protected long getLastModified(HttpServletRequest req) {\r
+ File file = GitBlit.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\r
+ if (file.exists()) {\r
+ return file.lastModified();\r
+ } else {\r
+ return lastModified;\r
+ }\r
+ }\r
+ \r
+ @Override\r
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)\r
+ throws ServletException, IOException {\r
+ InputStream is = null;\r
+ try {\r
+ String contentType = null;\r
+ File file = GitBlit.getFileOrFolder(Keys.web.headerLogo, "${baseFolder}/logo.png");\r
+ if (file.exists()) {\r
+ // custom logo\r
+ ServletContext context = request.getSession().getServletContext();\r
+ contentType = context.getMimeType(file.getName());\r
+ response.setContentLength((int) file.length());\r
+ response.setDateHeader("Last-Modified", file.lastModified());\r
+ is = new FileInputStream(file);\r
+ } else {\r
+ // default logo\r
+ response.setDateHeader("Last-Modified", lastModified);\r
+ is = getClass().getResourceAsStream("/logo.png");\r
+ } \r
+ if (contentType == null) {\r
+ contentType = "image/png";\r
+ }\r
+ response.setContentType(contentType);\r
+ OutputStream os = response.getOutputStream();\r
+ byte[] buf = new byte[4096];\r
+ int bytesRead = is.read(buf);\r
+ while (bytesRead != -1) {\r
+ os.write(buf, 0, bytesRead);\r
+ bytesRead = is.read(buf);\r
+ }\r
+ os.flush();\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ } finally {\r
+ is.close();\r
+ }\r
+ }\r
+}\r