James Moger
2013-10-01 4360b3af73e5e9e575adee9f8d8b462a20445553
commit | author | age
27506b 1 /*
JM 2  * Copyright 2012 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit;
17
18 import java.io.File;
19 import java.io.IOException;
20
21 import javax.servlet.ServletException;
22 import javax.servlet.http.HttpServlet;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25
26 import com.gitblit.utils.FileUtils;
27
28 /**
29  * Handles requests for robots.txt
699e71 30  *
27506b 31  * @author James Moger
699e71 32  *
27506b 33  */
JM 34 public class RobotsTxtServlet extends HttpServlet {
35
36     private static final long serialVersionUID = 1L;
37
38     public RobotsTxtServlet() {
39         super();
40     }
699e71 41
27506b 42     @Override
JM 43     protected void doPost(HttpServletRequest request, HttpServletResponse response)
44             throws ServletException, java.io.IOException {
45         processRequest(request, response);
46     }
47
48     @Override
49     protected void doGet(HttpServletRequest request, HttpServletResponse response)
50             throws ServletException, IOException {
51         processRequest(request, response);
52     }
53
54     protected void processRequest(javax.servlet.http.HttpServletRequest request,
55             javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException,
56             java.io.IOException {
93d506 57         File file = GitBlit.getFileOrFolder(Keys.web.robots.txt, null);
27506b 58         String content = "";
93d506 59         if (file.exists()) {
JM 60             content = FileUtils.readContent(file, "\n");
27506b 61         }
JM 62         response.getWriter().append(content);
63     }
64 }