projects.jspf revision 71d11848fb42ba93f678493de4e75daa6108388c
<%--
CDDL HEADER START
The contents of this file are subject to the terms of the
Common Development and Distribution License (the "License").
You may not use this file except in compliance with the License.
See LICENSE.txt included in this distribution for the specific
language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each
file and include the License file at LICENSE.txt.
If applicable, add the following below this CDDL HEADER, with the
fields enclosed by brackets "[]" replaced with your own identifying
information: Portions Copyright [yyyy] [name of copyright owner]
CDDL HEADER END
Copyright 2009 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
--%><%@ page import="org.opensolaris.opengrok.configuration.*,
java.util.ArrayList,java.util.List,java.util.Iterator" %><%
boolean hasProjects = false;
// watch for iterators for below in case you will want to change it to List<Project>
//TODO also deduplication at this point might be nice
List<String> project = new ArrayList<String>();
List<Project> projects;
String context = request.getContextPath();
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setUrlPrefix(context + "/s?");
env.register();
StringBuffer sproject=new StringBuffer("");
if (env.hasProjects()) {
hasProjects = true;
projects = env.getProjects();
String pr[] = request.getParameterValues("project");
// see if a new parameter(s) is passed...
// code bellow will accept more parameters project= and their format is either one by one, or separated by "," in one parameter
if (pr != null && pr[0].length() > 0) {
for (int midx = 0; midx < pr.length; midx++) {
//NOTE this means project name CANNOT have a "," char in it !!!
String p[] = pr[midx].split(",");
for (int idx = 0; idx < p.length; idx++) {
if (Project.getByDescription(p[idx]) != null) {
project.add(p[idx]);
}
}
}
} else { //fill in from cookies
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("OpenGrok/project")) {
for (String proj : cookie.getValue().split(",")) {
if (proj != "") {
if (Project.getByDescription(proj) != null) {
project.add(proj);
}
}
}
}
}
}
}
//default project is only shown when no other project there (no cookie, empty project list)
Project defaultProject = env.getDefaultProject();
if (defaultProject != null && project.isEmpty()) {
project.add(defaultProject.getDescription());
}
//only save found projects into cookies
for (Iterator it = project.iterator(); it.hasNext();) {
sproject.append((String) it.next() + ",");
}
// update the cookie
Cookie cookie = new Cookie("OpenGrok/project", sproject.toString());
response.addCookie(cookie);
}
%>