projects.jspf revision 52cdd45a95eb7c48af1c19ea6e401448a97545bf
<%--
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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
--%><%@ page import="org.opensolaris.opengrok.configuration.*,
java.util.ArrayList,java.util.List,java.util.Iterator" %><%
// Use UTF-8 if no encoding is specified in the request
if (request.getCharacterEncoding() == null) {
request.setCharacterEncoding("UTF-8");
}
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("OpenGrokProject")) {
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("OpenGrokProject", sproject.toString());
response.addCookie(cookie);
}
%>