001 /*
002 *
003 * $Revision: 15330 $ $Date: 2009-06-08 15:47:06 +0200 (Mon, 08 Jun 2009) $
004 *
005 * This file is part of *** M y C o R e ***
006 * See http://www.mycore.de/ for details.
007 *
008 * This program is free software; you can use it, redistribute it
009 * and / or modify it under the terms of the GNU General Public License
010 * (GPL) as published by the Free Software Foundation; either version 2
011 * of the License or (at your option) any later version.
012 *
013 * This program is distributed in the hope that it will be useful, but
014 * WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program, in a file called gpl.txt or license.txt.
020 * If not, write to the Free Software Foundation Inc.,
021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA
022 */
023
024 package org.mycore.frontend.indexbrowser.sql;
025
026 import java.util.StringTokenizer;
027
028 import javax.servlet.http.HttpServletRequest;
029
030 /**
031 * @author Frank Lützenkirchen
032 */
033 class MCRBrowseRequest {
034 String index;
035
036 int from = 1;
037
038 int to = Integer.MAX_VALUE;
039
040 StringBuffer path;
041
042 String search;
043
044 String mode;
045
046 MCRBrowseRequest(HttpServletRequest req) {
047 StringTokenizer st = new StringTokenizer(req.getPathInfo(), "/-");
048
049 if (!st.hasMoreTokens()) {
050 throw new RuntimeException();
051 }
052
053 index = st.nextToken();
054
055 path = new StringBuffer(index);
056 path.append("/");
057
058 while (st.countTokens() > 1)
059 addRange(st.nextToken(), st.nextToken());
060
061 search = req.getParameter("search");
062 mode = req.getParameter("mode");
063 }
064
065 void addRange(String from, String to) {
066 this.from = Integer.parseInt(from);
067 this.to = Integer.parseInt(to);
068 path.append(this.from);
069 path.append("-");
070 path.append(this.to);
071 path.append("/");
072 }
073
074 String getCanonicalRequestPath() {
075 return "index/" + path.toString();
076 }
077
078 int getFrom() {
079 return from;
080 }
081
082 int getTo() {
083 return to;
084 }
085
086 String getIndex() {
087 return index;
088 }
089 }