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