projects.jspf revision 9a1d88884173bd5eeb2dd780323e8085dfafe85d
<%--
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.*,
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 is passed...
if (pr != null && pr[0].length() > 0) {
//NOTE this means project name CANNOT have a "," char in it !!!
String p[] = pr[0].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);
}
}
}
}
}
}
}
Project defaultProject = env.getDefaultProject();
if (defaultProject != null && !project.contains(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);
}
%>