]> source.dussan.org Git - gitblit.git/commitdiff
Support custom header logo images of 120x45 (issue 208)
authorJames Moger <james.moger@gitblit.com>
Wed, 26 Jun 2013 21:09:01 +0000 (17:09 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 26 Jun 2013 21:09:01 +0000 (17:09 -0400)
build.xml
releases.moxie
src/main/distrib/data/gitblit.properties
src/main/java/WEB-INF/web.xml
src/main/java/com/gitblit/LogoServlet.java [new file with mode: 0644]
src/main/java/com/gitblit/wicket/pages/RootPage.html
src/main/java/logo.png [new file with mode: 0644]
src/main/resources/gitblit.css

index 308ec43b23f36a9d3cf6f0df8cf0962d1d9b7c04..6138c20d4c983c1a43296d536de9e0ff16965f0d 100644 (file)
--- a/build.xml
+++ b/build.xml
                        <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
index a8b2f4c4be245c277f6fa819f4176ed00023d613..0327e4beb43f7c72fa9d439c95eb20b1caae197d 100644 (file)
@@ -52,6 +52,7 @@ r17: {
     additions: \r
         - Added a ui for the ref log introduced in 1.2.1 (issue-177)\r
         - Added weblogic.xml to WAR for deployment on WebLogic (issue 199)\r
+        - Support setting a custom header logo (issue 208)\r
         - Support username substitution in web.otherUrls (issue 213)\r
         - Option to force client-side basic authentication instead of form-based authentication if web.authenticateViewPages=true (issue 222)\r
         - Setting to automatically create an user account based on an authenticated user principal from the servlet container (issue-246)\r
index d5573a61c122ad1daa3bb2a9f96fb928da4ce54e..50b09f300399c3c9c8fff96d6ff051b16c0d79e5 100644 (file)
@@ -531,6 +531,13 @@ realm.minPasswordLength = 5
 # SINCE 0.5.0\r
 web.siteName =\r
 \r
+# You may specify a different logo image for the header but it must be 120x45px.\r
+# If the specified file does not exist, the default Gitblit logo will be used.\r
+#\r
+# SINCE 1.3.0\r
+# BASEFOLDER\r
+web.headerLogo = ${baseFolder}/logo.png\r
+\r
 # If *web.authenticateAdminPages*=true, users with "admin" role can create\r
 # repositories, create users, and edit repository metadata.\r
 #\r
index 573305c4e2c94ca45491225c1efdc548c8afda3f..bf121663d63fdb80bc7d5cca1fd253ce92cc078a 100644 (file)
                <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
diff --git a/src/main/java/com/gitblit/LogoServlet.java b/src/main/java/com/gitblit/LogoServlet.java
new file mode 100644 (file)
index 0000000..7402fc1
--- /dev/null
@@ -0,0 +1,93 @@
+/*\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
index 69cd5f0a616644d2a1255e90c7bb665c0ed1bc69..696ddfd7935adcf4b5f1137de66b1561dd133d15 100644 (file)
@@ -14,7 +14,7 @@
                                <span class="icon-bar"></span>\r
                        </a>\r
                                <a class="brand" wicket:id="rootLink">\r
-                                       <img src="gitblt_25_white.png" width="79" height="25" alt="gitblit" class="logo"/>\r
+                                       <img src="logo.png" height="45" width="120" class="logo"/>\r
                                </a>\r
                                \r
                                <div class="nav-collapse">\r
diff --git a/src/main/java/logo.png b/src/main/java/logo.png
new file mode 100644 (file)
index 0000000..e909530
Binary files /dev/null and b/src/main/java/logo.png differ
index 6074b36900eb2ca0915f65c0334b00b3d718a47d..d10f3809c285d2f516a369d68ee12a07da3846a3 100644 (file)
@@ -59,7 +59,7 @@ hr {
 }\r
 \r
 .navbar .brand {\r
-       padding: 10px 20px;\r
+       padding: 0px 10px 0px 20px;\r
 }\r
 \r
 .navbar .pull-right {\r