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