From 13a3f5bc3e2d25fc76850f86070dc34efe60d77a Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 07 Sep 2012 22:06:15 -0400
Subject: [PATCH] Draft project pages, project metadata, and RSS feeds

---
 src/com/gitblit/wicket/pages/RepositoriesPage.java |   69 +++++++++++++++++++++++++++++++---
 1 files changed, 62 insertions(+), 7 deletions(-)

diff --git a/src/com/gitblit/wicket/pages/RepositoriesPage.java b/src/com/gitblit/wicket/pages/RepositoriesPage.java
index a15a7d9..98dade6 100644
--- a/src/com/gitblit/wicket/pages/RepositoriesPage.java
+++ b/src/com/gitblit/wicket/pages/RepositoriesPage.java
@@ -16,7 +16,8 @@
 package com.gitblit.wicket.pages;
 
 import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.text.MessageFormat;
@@ -26,6 +27,8 @@
 import org.apache.wicket.PageParameters;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.resource.ContextRelativeResource;
+import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
+import org.eclipse.jgit.lib.Constants;
 
 import com.gitblit.GitBlit;
 import com.gitblit.Keys;
@@ -33,6 +36,9 @@
 import com.gitblit.utils.MarkdownUtils;
 import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.GitBlitWebSession;
+import com.gitblit.wicket.PageRegistration;
+import com.gitblit.wicket.PageRegistration.DropDownMenuItem;
+import com.gitblit.wicket.PageRegistration.DropDownMenuRegistration;
 import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.panels.RepositoriesPanel;
 
@@ -46,6 +52,11 @@
 	public RepositoriesPage(PageParameters params) {
 		super(params);
 		setup(params);
+	}
+
+	@Override
+	protected boolean reusePageParameters() {
+		return true;
 	}
 
 	private void setup(PageParameters params) {
@@ -80,6 +91,26 @@
 		add(repositoriesPanel);
 	}
 
+	@Override
+	protected void addDropDownMenus(List<PageRegistration> pages) {
+		PageParameters params = getPageParameters();
+
+		DropDownMenuRegistration menu = new DropDownMenuRegistration("gb.filters",
+				RepositoriesPage.class);
+		// preserve time filter option on repository choices
+		menu.menuItems.addAll(getRepositoryFilterItems(params));
+
+		// preserve repository filter option on time choices
+		menu.menuItems.addAll(getTimeFilterItems(params));
+
+		if (menu.menuItems.size() > 0) {
+			// Reset Filter
+			menu.menuItems.add(new DropDownMenuItem(getString("gb.reset"), null, null));
+		}
+
+		pages.add(menu);
+	}
+
 	private String readMarkdown(String messageSource, String resource) {
 		String message = "";
 		if (messageSource.equalsIgnoreCase("gitblit")) {
@@ -91,14 +122,17 @@
 				File file = new File(messageSource);
 				if (file.exists()) {
 					try {
-						FileReader reader = new FileReader(file);
+						FileInputStream fis = new FileInputStream(file);
+						InputStreamReader reader = new InputStreamReader(fis,
+								Constants.CHARACTER_ENCODING);
 						message = MarkdownUtils.transformMarkdown(reader);
+						reader.close();
 					} catch (Throwable t) {
-						message = "Failed to read " + file;
+						message = getString("gb.failedToRead") + " " + file;
 						warn(message, t);
 					}
 				} else {
-					message = messageSource + " is not a valid file.";
+					message = messageSource + " " + getString("gb.isNotValidFile");
 				}
 			}
 		}
@@ -106,15 +140,36 @@
 	}
 
 	private String readDefaultMarkdown(String file) {
+		String content = readDefaultMarkdown(file, getLanguageCode());
+		if (StringUtils.isEmpty(content)) {
+			content = readDefaultMarkdown(file, null);
+		}
+		return content;
+	}
+	
+	private String readDefaultMarkdown(String file, String lc) {
+		if (!StringUtils.isEmpty(lc)) {
+			// convert to file_lc.mkd
+			file = file.substring(0, file.lastIndexOf('.')) + "_" + lc + file.substring(file.lastIndexOf('.'));
+		}
 		String message;
-		try {
+		try {			
 			ContextRelativeResource res = WicketUtils.getResource(file);
 			InputStream is = res.getResourceStream().getInputStream();
-			InputStreamReader reader = new InputStreamReader(is);
+			InputStreamReader reader = new InputStreamReader(is, Constants.CHARACTER_ENCODING);
 			message = MarkdownUtils.transformMarkdown(reader);
 			reader.close();
+		} catch (ResourceStreamNotFoundException t) {
+			if (lc == null) {
+				// could not find default language resource
+				message = MessageFormat.format(getString("gb.failedToReadMessage"), file);
+				error(message, t, false);
+			} else {
+				// ignore so we can try default language resource
+				message = null;
+			}
 		} catch (Throwable t) {
-			message = MessageFormat.format("Failed to read default message from {0}!", file);
+			message = MessageFormat.format(getString("gb.failedToReadMessage"), file);
 			error(message, t, false);
 		}
 		return message;

--
Gitblit v1.9.1