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 freemarker.template.SimpleHash;
36 import java.io.IOException;
37 import java.io.PrintWriter;
38 import java.net.URLEncoder;
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpServletResponse;
43 import mir.entity.EntityList;
44 import mir.misc.HTMLParseException;
45 import mir.misc.HTMLTemplateProcessor;
46 import mir.misc.Logfile;
47 import mir.misc.MirConfig;
48 import mir.module.ModuleException;
49 import mir.servlet.ServletModule;
50 import mir.servlet.ServletModuleException;
51 import mir.storage.StorageObjectException;
54 import mircoders.module.ModuleLanguage;
55 import mircoders.module.ModuleLinksImcs;
56 import mircoders.storage.DatabaseLanguage;
57 import mircoders.storage.DatabaseLinksImcs;
60 * ServletModuleLinksImcs -
61 * liefert HTML fuer LinksImcs
67 public class ServletModuleLinksImcs extends ServletModule {
68 private ModuleLanguage languageModule;
70 // Singelton / Kontruktor
71 private static ServletModuleLinksImcs instance = new ServletModuleLinksImcs();
73 public static ServletModule getInstance() {
78 private ServletModuleLinksImcs() {
79 logger = new LoggerWrapper("ServletModule.LinksImcs");
80 templateListString = MirConfig.getProp("ServletModule.LinksImcs.ListTemplate");
81 templateObjektString = MirConfig.getProp("ServletModule.LinksImcs.ObjektTemplate");
82 templateConfirmString = MirConfig.getProp("ServletModule.LinksImcs.ConfirmTemplate");
85 mainModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
86 languageModule = new ModuleLanguage(DatabaseLanguage.getInstance());
88 catch (StorageObjectException e) {
89 logger.error("Initialization of ServletModuleLinksImcs failed!: " + e.getMessage());
93 public void add(HttpServletRequest req, HttpServletResponse res)
94 throws ServletModuleException {
96 SimpleHash modelRoot = new SimpleHash();
97 EntityList theParentList;
98 EntityList theLanguageList;
101 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
102 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
104 modelRoot.put("new", "1");
105 modelRoot.put("parentlist", theParentList);
106 modelRoot.put("languagelist", theLanguageList);
108 if (theParentList == null || theParentList.getCount() == 0 || theParentList.getCount() > 1) {
109 HTMLTemplateProcessor.process(res, templateObjektString, modelRoot, res.getWriter(), getLocale(req));
112 deliver(req, res, modelRoot, templateObjektString);
116 catch (ModuleException e) {
117 throw new ServletModuleException(e.toString());
119 catch (HTMLParseException e) {
120 throw new ServletModuleException(e.toString());
122 catch (IOException e) {
123 throw new ServletModuleException(e.toString());
127 public void list(HttpServletRequest req, HttpServletResponse res)
128 throws ServletModuleException {
131 SimpleHash modelRoot = new SimpleHash();
132 EntityList theParentList;
133 EntityList theImcsList;
134 EntityList theLanguageList;
135 String offsetParam = req.getParameter("offset");
138 PrintWriter out = res.getWriter();
140 // Parameter auswerten
141 String query_text = req.getParameter("query_text");
142 modelRoot.put("query_text", query_text);
143 if (query_text != null) modelRoot.put("query_text_encoded", URLEncoder.encode(query_text));
144 String query_field = req.getParameter("query_field");
145 modelRoot.put("query_field", query_field);
146 String parent = req.getParameter("to_parent_id");
147 modelRoot.put("to_parent_id", parent);
148 String language = req.getParameter("to_language");
149 modelRoot.put("to_language", language);
150 modelRoot.put("language", getLanguage(req));
152 String whereClause = "";
153 boolean isFirst = true;
154 if (query_text != null && !query_text.equalsIgnoreCase("")) {
155 whereClause += "lower(" + query_field + ") like lower('%" + query_text + "%')";
158 if (parent != null && !parent.equals("")) {
159 if (isFirst == false) whereClause += " and ";
160 whereClause += "to_parent_id='" + parent + "'";
163 if (language != null && !language.equals("")) {
164 if (isFirst == false) whereClause += " and ";
165 whereClause += "to_language='" + language + "'";
169 // hier offsetcode bearbeiten
170 if (offsetParam != null && !offsetParam.equals("")) {
171 offset = offsetParam;
173 if (req.getParameter("next") != null) {
174 offset = req.getParameter("nextoffset");
177 if (req.getParameter("prev") != null) {
178 offset = req.getParameter("prevoffset");
182 if (offset == null || offset.equals("")) offset = "0";
183 modelRoot.put("offset", (new Integer(offset)).toString());
185 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", 0, 1000);
186 theImcsList = mainModule.getByWhereClause(whereClause, "title", (new Integer(offset)).intValue());
187 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
189 modelRoot.put("parentlist", theParentList);
190 modelRoot.put("imcslist", theImcsList);
191 modelRoot.put("languagelist", theLanguageList);
192 modelRoot.put("count", (new Integer(theImcsList.getCount())).toString());
193 modelRoot.put("from", (new Integer(theImcsList.getFrom())).toString());
194 modelRoot.put("to", (new Integer(theImcsList.getTo())).toString());
195 if (theImcsList.hasNextBatch())
196 modelRoot.put("next", (new Integer(theImcsList.getNextBatch())).toString());
197 if (theImcsList.hasPrevBatch())
198 modelRoot.put("prev", (new Integer(theImcsList.getPrevBatch())).toString());
200 HTMLTemplateProcessor.process(res, templateListString, modelRoot, res.getWriter(), getLocale(req));
203 catch (Exception e) {
204 throw new ServletModuleException(e.toString());
208 public void edit(HttpServletRequest req, HttpServletResponse res)
209 throws ServletModuleException {
212 SimpleHash modelRoot = new SimpleHash();
213 EntityList parentList;
214 EntityList theLanguageList;
216 String idParam = req.getParameter("id");
219 parentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
220 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
222 modelRoot.put("parentlist", parentList);
223 modelRoot.put("languagelist", theLanguageList);
224 modelRoot.put("entity", mainModule.getById(idParam));
225 modelRoot.put("new", "0");
226 deliver(req, res, modelRoot, templateObjektString);
229 catch (ModuleException e) {
230 throw new ServletModuleException(e.toString());