2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with the com.oreilly.servlet library, any library
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24 * the above that use the same license as the above), and distribute linked
25 * combinations including the two. You must obey the GNU General Public
26 * License in all respects for all of the code used other than the above
27 * mentioned libraries. If you modify this file, you may extend this exception
28 * to your version of the file, but you are not obligated to do so. If you do
29 * not wish to do so, delete this exception statement from your version.
32 package mircoders.servlet;
34 import java.io.PrintWriter;
35 import java.net.URLEncoder;
37 import javax.servlet.http.HttpServletRequest;
38 import javax.servlet.http.HttpServletResponse;
40 import mir.entity.EntityList;
41 import mir.log.LoggerWrapper;
42 import mir.misc.HTMLTemplateProcessor;
43 import mir.servlet.ServletModule;
44 import mir.servlet.ServletModuleExc;
45 import mir.servlet.ServletModuleFailure;
46 import mir.storage.StorageObjectFailure;
47 import mircoders.module.ModuleLanguage;
48 import mircoders.module.ModuleLinksImcs;
49 import mircoders.storage.DatabaseLanguage;
50 import mircoders.storage.DatabaseLinksImcs;
51 import freemarker.template.SimpleHash;
54 * ServletModuleLinksImcs -
55 * liefert HTML fuer LinksImcs
61 public class ServletModuleLinksImcs extends ServletModule {
62 private ModuleLanguage languageModule;
64 // Singelton / Kontruktor
65 private static ServletModuleLinksImcs instance = new ServletModuleLinksImcs();
67 public static ServletModule getInstance() {
72 private ServletModuleLinksImcs() {
74 logger = new LoggerWrapper("ServletModule.LinksImcs");
75 templateListString = configuration.getString("ServletModule.LinksImcs.ListTemplate");
76 templateObjektString = configuration.getString("ServletModule.LinksImcs.ObjektTemplate");
77 templateConfirmString = configuration.getString("ServletModule.LinksImcs.ConfirmTemplate");
80 mainModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
81 languageModule = new ModuleLanguage(DatabaseLanguage.getInstance());
83 catch (StorageObjectFailure e) {
84 logger.error("Initialization of ServletModuleLinksImcs failed!: " + e.getMessage());
88 public void add(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc {
90 SimpleHash modelRoot = new SimpleHash();
91 EntityList theParentList;
92 EntityList theLanguageList;
95 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
96 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
98 modelRoot.put("new", "1");
99 modelRoot.put("parentlist", theParentList);
100 modelRoot.put("languagelist", theLanguageList);
102 if (theParentList == null || theParentList.getCount() == 0 || theParentList.getCount() > 1) {
103 HTMLTemplateProcessor.process(res, templateObjektString, modelRoot, res.getWriter(), getLocale(req));
106 deliver(req, res, modelRoot, templateObjektString);
110 catch (Throwable e) {
111 throw new ServletModuleFailure(e);
115 public void list(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc {
118 SimpleHash modelRoot = new SimpleHash();
119 EntityList theParentList;
120 EntityList theImcsList;
121 EntityList theLanguageList;
122 String offsetParam = req.getParameter("offset");
125 PrintWriter out = res.getWriter();
127 // Parameter auswerten
128 String query_text = req.getParameter("query_text");
129 modelRoot.put("query_text", query_text);
130 if (query_text != null) modelRoot.put("query_text_encoded", URLEncoder.encode(query_text));
131 String query_field = req.getParameter("query_field");
132 modelRoot.put("query_field", query_field);
133 String parent = req.getParameter("to_parent_id");
134 modelRoot.put("to_parent_id", parent);
135 String language = req.getParameter("to_language");
136 modelRoot.put("to_language", language);
137 modelRoot.put("language", getLanguage(req));
139 String whereClause = "";
140 boolean isFirst = true;
141 if (query_text != null && !query_text.equalsIgnoreCase("")) {
142 whereClause += "lower(" + query_field + ") like lower('%" + query_text + "%')";
145 if (parent != null && !parent.equals("")) {
146 if (isFirst == false) whereClause += " and ";
147 whereClause += "to_parent_id='" + parent + "'";
150 if (language != null && !language.equals("")) {
151 if (isFirst == false) whereClause += " and ";
152 whereClause += "to_language='" + language + "'";
156 // hier offsetcode bearbeiten
157 if (offsetParam != null && !offsetParam.equals("")) {
158 offset = offsetParam;
160 if (req.getParameter("next") != null) {
161 offset = req.getParameter("nextoffset");
164 if (req.getParameter("prev") != null) {
165 offset = req.getParameter("prevoffset");
169 if (offset == null || offset.equals("")) offset = "0";
170 modelRoot.put("offset", (new Integer(offset)).toString());
172 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", 0, 1000);
173 theImcsList = mainModule.getByWhereClause(whereClause, "title", (new Integer(offset)).intValue());
174 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
176 modelRoot.put("parentlist", theParentList);
177 modelRoot.put("imcslist", theImcsList);
178 modelRoot.put("languagelist", theLanguageList);
179 modelRoot.put("count", (new Integer(theImcsList.getCount())).toString());
180 modelRoot.put("from", (new Integer(theImcsList.getFrom())).toString());
181 modelRoot.put("to", (new Integer(theImcsList.getTo())).toString());
182 if (theImcsList.hasNextBatch())
183 modelRoot.put("next", (new Integer(theImcsList.getNextBatch())).toString());
184 if (theImcsList.hasPrevBatch())
185 modelRoot.put("prev", (new Integer(theImcsList.getPrevBatch())).toString());
187 HTMLTemplateProcessor.process(res, templateListString, modelRoot, res.getWriter(), getLocale(req));
190 catch (Throwable e) {
191 throw new ServletModuleFailure(e);
195 public void edit(HttpServletRequest req, HttpServletResponse res)
196 throws ServletModuleExc {
199 SimpleHash modelRoot = new SimpleHash();
200 EntityList parentList;
201 EntityList theLanguageList;
203 String idParam = req.getParameter("id");
206 parentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
207 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
209 modelRoot.put("parentlist", parentList);
210 modelRoot.put("languagelist", theLanguageList);
211 modelRoot.put("entity", mainModule.getById(idParam));
212 modelRoot.put("new", "0");
213 deliver(req, res, modelRoot, templateObjektString);
216 catch (Throwable e) {
217 throw new ServletModuleFailure(e);