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