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