James Moger
2013-09-30 699e71e76b15081baf746c6ce9c9144f7e5f1ff9
src/main/java/com/gitblit/PagesServlet.java
@@ -18,6 +18,8 @@
import java.io.IOException;
import java.text.MessageFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -39,9 +41,9 @@
/**
 * Serves the content of a gh-pages branch.
 *
 *
 * @author James Moger
 *
 *
 */
public class PagesServlet extends HttpServlet {
@@ -55,7 +57,7 @@
   /**
    * Returns an url to this servlet for the specified parameters.
    *
    *
    * @param baseURL
    * @param repository
    * @param path
@@ -71,7 +73,7 @@
   /**
    * Retrieves the specified resource from the gh-pages branch of the
    * repository.
    *
    *
    * @param request
    * @param response
    * @throws javax.servlet.ServletException
@@ -139,7 +141,6 @@
            r.close();
            return;
         }
         response.setDateHeader("Last-Modified", JGitUtils.getCommitDate(commit).getTime());
         String [] encodings = GitBlit.getEncodings();
@@ -147,10 +148,18 @@
         byte[] content = null;
         if (StringUtils.isEmpty(resource)) {
            // find resource
            String[] files = { "index.html", "index.htm", "index.mkd" };
            for (String file : files) {
               content = JGitUtils.getStringContent(r, tree, file, encodings)
                     .getBytes(Constants.ENCODING);
            List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
            List<String> extensions = new ArrayList<String>(markdownExtensions.size() + 2);
            extensions.add("html");
            extensions.add("htm");
            extensions.addAll(markdownExtensions);
            for (String ext : extensions){
               String file = "index." + ext;
               String stringContent = JGitUtils.getStringContent(r, tree, file, encodings);
               if(stringContent == null){
                  continue;
               }
               content = stringContent.getBytes(Constants.ENCODING);
               if (content != null) {
                  resource = file;
                  // assume text/html unless the servlet container
@@ -209,12 +218,15 @@
            if (resource.endsWith(ext)) {
               String mkd = new String(content, Constants.ENCODING);
               content = MarkdownUtils.transformMarkdown(mkd).getBytes(Constants.ENCODING);
               response.setContentType("text/html; charset=" + Constants.ENCODING);
               break;
            }
         }
         try {
            // output the content
            response.setHeader("Cache-Control", "public, max-age=3600, must-revalidate");
            response.setDateHeader("Last-Modified", JGitUtils.getCommitDate(commit).getTime());
            response.getOutputStream().write(content);
            response.flushBuffer();
         } catch (Throwable t) {