From 0e44acbb2fec928a1606dc60f427a148fff405c9 Mon Sep 17 00:00:00 2001
From: Mohamed Ragab <moragab@gmail.com>
Date: Wed, 02 May 2012 11:15:01 -0400
Subject: [PATCH] Added a script to facilitate setting the proxy host and port and no proxy hosts, and then it concatenates all the java system properties for setting the java proxy configurations and puts the resulting string in an environment variable JAVA_PROXY_CONFIG, modified the scirpts gitblit,  gitblit-ubuntu, and gitblit-centos to source the java-proxy-config.sh script and then include the resulting java proxy configuration in the java command

---
 src/com/gitblit/wicket/PageRegistration.java |  176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 172 insertions(+), 4 deletions(-)

diff --git a/src/com/gitblit/wicket/PageRegistration.java b/src/com/gitblit/wicket/PageRegistration.java
index ac00fb5..e8eeaba 100644
--- a/src/com/gitblit/wicket/PageRegistration.java
+++ b/src/com/gitblit/wicket/PageRegistration.java
@@ -16,10 +16,13 @@
 package com.gitblit.wicket;
 
 import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.WebPage;
 
-import com.gitblit.wicket.pages.BasePage;
+import com.gitblit.utils.StringUtils;
 
 /**
  * Represents a page link registration for the topbar.
@@ -31,17 +34,182 @@
 	private static final long serialVersionUID = 1L;
 
 	public final String translationKey;
-	public final Class<? extends BasePage> pageClass;
+	public final Class<? extends WebPage> pageClass;
 	public final PageParameters params;
 
-	public PageRegistration(String translationKey, Class<? extends BasePage> pageClass) {
+	public PageRegistration(String translationKey, Class<? extends WebPage> pageClass) {
 		this(translationKey, pageClass, null);
 	}
 
-	public PageRegistration(String translationKey, Class<? extends BasePage> pageClass,
+	public PageRegistration(String translationKey, Class<? extends WebPage> pageClass,
 			PageParameters params) {
 		this.translationKey = translationKey;
 		this.pageClass = pageClass;
 		this.params = params;
 	}
+
+	/**
+	 * Represents a page link to a non-Wicket page. Might be external.
+	 * 
+	 * @author James Moger
+	 * 
+	 */
+	public static class OtherPageLink extends PageRegistration {
+
+		private static final long serialVersionUID = 1L;
+
+		public final String url;
+
+		public OtherPageLink(String translationKey, String url) {
+			super(translationKey, null);
+			this.url = url;
+		}
+	}
+
+	/**
+	 * Represents a DropDownMenu for the topbar
+	 * 
+	 * @author James Moger
+	 * 
+	 */
+	public static class DropDownMenuRegistration extends PageRegistration {
+
+		private static final long serialVersionUID = 1L;
+
+		public final List<DropDownMenuItem> menuItems;
+
+		public DropDownMenuRegistration(String translationKey, Class<? extends WebPage> pageClass) {
+			super(translationKey, pageClass);
+			menuItems = new ArrayList<DropDownMenuItem>();
+		}
+	}
+
+	/**
+	 * A MenuItem for the DropDownMenu.
+	 * 
+	 * @author James Moger
+	 * 
+	 */
+	public static class DropDownMenuItem implements Serializable {
+
+		private static final long serialVersionUID = 1L;
+
+		final PageParameters parameters;
+		final String displayText;
+		final String parameter;
+		final String value;
+		final boolean isSelected;
+
+		/**
+		 * Divider constructor.
+		 */
+		public DropDownMenuItem() {
+			this(null, null, null, null);
+		}
+
+		/**
+		 * Standard Menu Item constructor.
+		 * 
+		 * @param displayText
+		 * @param parameter
+		 * @param value
+		 */
+		public DropDownMenuItem(String displayText, String parameter, String value) {
+			this(displayText, parameter, value, null);
+		}
+
+		/**
+		 * Standard Menu Item constructor that preserves aggregate parameters.
+		 * 
+		 * @param displayText
+		 * @param parameter
+		 * @param value
+		 */
+		public DropDownMenuItem(String displayText, String parameter, String value,
+				PageParameters params) {
+			this.displayText = displayText;
+			this.parameter = parameter;
+			this.value = value;
+
+			if (params == null) {
+				// no parameters specified
+				parameters = new PageParameters();
+				setParameter(parameter, value);
+				isSelected = false;
+			} else {
+				parameters = new PageParameters(params);
+				if (parameters.containsKey(parameter)) {
+					isSelected = params.getString(parameter).equals(value);
+					if (isSelected) {
+						// already selected, so remove this enables toggling
+						parameters.remove(parameter);
+					} else {
+						// set the new selection value
+						setParameter(parameter, value);
+					}
+				} else {
+					// not currently selected
+					isSelected = false;
+					setParameter(parameter, value);
+				}
+			}
+		}
+
+		private void setParameter(String parameter, String value) {
+			if (!StringUtils.isEmpty(parameter)) {
+				if (StringUtils.isEmpty(value)) {
+					this.parameters.remove(parameter);
+				} else {
+					this.parameters.put(parameter, value);
+				}
+			}
+		}
+
+		public String formatParameter() {
+			if (StringUtils.isEmpty(parameter) || StringUtils.isEmpty(value)) {
+				return "";
+			}
+			return parameter + "=" + value;
+		}
+
+		public PageParameters getPageParameters() {
+			return parameters;
+		}
+
+		public boolean isDivider() {
+			return displayText == null && value == null && parameter == null;
+		}
+
+		public boolean isSelected() {
+			return isSelected;
+		}
+
+		@Override
+		public int hashCode() {
+			if (isDivider()) {
+				// divider menu item
+				return super.hashCode();
+			}
+			if (StringUtils.isEmpty(displayText)) {
+				return value.hashCode() + parameter.hashCode();
+			}
+			return displayText.hashCode();
+		}
+
+		@Override
+		public boolean equals(Object o) {
+			if (o instanceof DropDownMenuItem) {
+				return hashCode() == o.hashCode();
+			}
+			return false;
+		}
+
+		@Override
+		public String toString() {
+			if (StringUtils.isEmpty(displayText)) {
+				return formatParameter();
+			}
+			return displayText;
+		}
+	}
 }
\ No newline at end of file

--
Gitblit v1.9.1