projects.jspf revision 892
1088N/A<%--
606N/ACDDL HEADER START
606N/A
919N/AThe contents of this file are subject to the terms of the
919N/ACommon Development and Distribution License (the "License").
919N/AYou may not use this file except in compliance with the License.
919N/A
919N/ASee LICENSE.txt included in this distribution for the specific
919N/Alanguage governing permissions and limitations under the License.
919N/A
919N/AWhen distributing Covered Code, include this CDDL HEADER in each
919N/Afile and include the License file at LICENSE.txt.
919N/AIf applicable, add the following below this CDDL HEADER, with the
919N/Afields enclosed by brackets "[]" replaced with your own identifying
919N/Ainformation: Portions Copyright [yyyy] [name of copyright owner]
919N/A
919N/ACDDL HEADER END
919N/A
919N/ACopyright 2009 Sun Microsystems, Inc. All rights reserved.
919N/AUse is subject to license terms.
1088N/A
1124N/A--%><%@ page import="org.opensolaris.opengrok.configuration.*,
1124N/Ajava.util.ArrayList,java.util.List,java.util.Iterator" %><%
1124N/Aboolean hasProjects = false;
1124N/A// watch for iterators for below in case you will want to change it to List<Project>
705N/A//TODO also deduplication at this point might be nice
705N/AList<String> project = new ArrayList<String>();
705N/AList<Project> projects;
705N/AString context = request.getContextPath();
705N/ARuntimeEnvironment env = RuntimeEnvironment.getInstance();
705N/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 is passed...
705N/A if (pr != null && pr[0].length() > 0) {
705N/A //NOTE this means project name CANNOT have a "," char in it !!!
705N/A String p[] = pr[0].split(",");
851N/A for (int idx = 0; idx < p.length; idx++) {
1124N/A if (Project.getByDescription(p[idx]) != null) {
1124N/A project.add(p[idx]);
1124N/A }
1124N/A }
1124N/A } else { //fill in from cookies
705N/A Cookie[] cookies = request.getCookies();
705N/A if (cookies != null) {
705N/A for (Cookie cookie : cookies) {
705N/A if (cookie.getName().equals("OpenGrok/project")) {
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 Project defaultProject = env.getDefaultProject();
705N/A if (defaultProject != null && !project.contains(defaultProject.getDescription())) {
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("OpenGrok/project", sproject.toString());
1124N/A response.addCookie(cookie);
1124N/A}
1124N/A%>