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;
35 import mir.entity.EntityList;
36 import mir.misc.HTMLParseException;
37 import mir.misc.HTMLTemplateProcessor;
38 import mir.misc.Logfile;
39 import mir.misc.MirConfig;
40 import mir.module.ModuleException;
41 import mir.servlet.ServletModule;
42 import mir.servlet.ServletModuleException;
43 import mir.storage.StorageObjectException;
44 import mircoders.module.ModuleLanguage;
45 import mircoders.module.ModuleLinksImcs;
46 import mircoders.storage.DatabaseLanguage;
47 import mircoders.storage.DatabaseLinksImcs;
49 import javax.servlet.http.HttpServletRequest;
50 import javax.servlet.http.HttpServletResponse;
51 import java.io.IOException;
52 import java.io.PrintWriter;
53 import java.net.URLEncoder;
56 * ServletModuleLinksImcs -
57 * liefert HTML fuer LinksImcs
63 public class ServletModuleLinksImcs extends ServletModule {
64 private ModuleLanguage languageModule;
66 // Singelton / Kontruktor
67 private static ServletModuleLinksImcs instance = new ServletModuleLinksImcs();
69 public static ServletModule getInstance() {
74 private ServletModuleLinksImcs() {
75 theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.LinksImcs.Logfile"));
76 templateListString = MirConfig.getProp("ServletModule.LinksImcs.ListTemplate");
77 templateObjektString = MirConfig.getProp("ServletModule.LinksImcs.ObjektTemplate");
78 templateConfirmString = MirConfig.getProp("ServletModule.LinksImcs.ConfirmTemplate");
81 mainModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
82 languageModule = new ModuleLanguage(DatabaseLanguage.getInstance());
84 catch (StorageObjectException e) {
85 theLog.printDebugInfo("ServletModuleLinksImcs konnte nicht initialisiert werden");
89 public void add(HttpServletRequest req, HttpServletResponse res)
90 throws ServletModuleException {
92 SimpleHash modelRoot = new SimpleHash();
93 EntityList theParentList;
94 EntityList theLanguageList;
97 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
98 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
100 modelRoot.put("new", "1");
101 modelRoot.put("parentlist", theParentList);
102 modelRoot.put("languagelist", theLanguageList);
104 if (theParentList == null || theParentList.getCount() == 0 || theParentList.getCount() > 1) {
105 HTMLTemplateProcessor.process(res, templateObjektString, modelRoot, res.getWriter(), getLocale(req));
108 deliver(req, res, modelRoot, templateObjektString);
112 catch (ModuleException e) {
113 throw new ServletModuleException(e.toString());
115 catch (HTMLParseException e) {
116 throw new ServletModuleException(e.toString());
118 catch (IOException e) {
119 throw new ServletModuleException(e.toString());
123 public void list(HttpServletRequest req, HttpServletResponse res)
124 throws ServletModuleException {
127 SimpleHash modelRoot = new SimpleHash();
128 EntityList theParentList;
129 EntityList theImcsList;
130 EntityList theLanguageList;
131 String offsetParam = req.getParameter("offset");
134 PrintWriter out = res.getWriter();
136 // Parameter auswerten
137 String query_text = req.getParameter("query_text");
138 modelRoot.put("query_text", query_text);
139 if (query_text != null) modelRoot.put("query_text_encoded", URLEncoder.encode(query_text));
140 String query_field = req.getParameter("query_field");
141 modelRoot.put("query_field", query_field);
142 String parent = req.getParameter("to_parent_id");
143 modelRoot.put("to_parent_id", parent);
144 String language = req.getParameter("to_language");
145 modelRoot.put("to_language", language);
146 modelRoot.put("language", getLanguage(req));
148 String whereClause = "";
149 boolean isFirst = true;
150 if (query_text != null && !query_text.equalsIgnoreCase("")) {
151 whereClause += "lower(" + query_field + ") like lower('%" + query_text + "%')";
154 if (parent != null && !parent.equals("")) {
155 if (isFirst == false) whereClause += " and ";
156 whereClause += "to_parent_id='" + parent + "'";
159 if (language != null && !language.equals("")) {
160 if (isFirst == false) whereClause += " and ";
161 whereClause += "to_language='" + language + "'";
165 // hier offsetcode bearbeiten
166 if (offsetParam != null && !offsetParam.equals("")) {
167 offset = offsetParam;
169 if (req.getParameter("next") != null) {
170 offset = req.getParameter("nextoffset");
173 if (req.getParameter("prev") != null) {
174 offset = req.getParameter("prevoffset");
178 if (offset == null || offset.equals("")) offset = "0";
179 modelRoot.put("offset", (new Integer(offset)).toString());
181 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", 0, 1000);
182 theImcsList = mainModule.getByWhereClause(whereClause, "title", (new Integer(offset)).intValue());
183 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
185 modelRoot.put("parentlist", theParentList);
186 modelRoot.put("imcslist", theImcsList);
187 modelRoot.put("languagelist", theLanguageList);
188 modelRoot.put("count", (new Integer(theImcsList.getCount())).toString());
189 modelRoot.put("from", (new Integer(theImcsList.getFrom())).toString());
190 modelRoot.put("to", (new Integer(theImcsList.getTo())).toString());
191 if (theImcsList.hasNextBatch())
192 modelRoot.put("next", (new Integer(theImcsList.getNextBatch())).toString());
193 if (theImcsList.hasPrevBatch())
194 modelRoot.put("prev", (new Integer(theImcsList.getPrevBatch())).toString());
196 HTMLTemplateProcessor.process(res, templateListString, modelRoot, res.getWriter(), getLocale(req));
199 catch (Exception e) {
200 throw new ServletModuleException(e.toString());
204 public void edit(HttpServletRequest req, HttpServletResponse res)
205 throws ServletModuleException {
208 SimpleHash modelRoot = new SimpleHash();
209 EntityList parentList;
210 EntityList theLanguageList;
212 String idParam = req.getParameter("id");
215 parentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
216 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
218 modelRoot.put("parentlist", parentList);
219 modelRoot.put("languagelist", theLanguageList);
220 modelRoot.put("entity", mainModule.getById(idParam));
221 modelRoot.put("new", "0");
222 deliver(req, res, modelRoot, templateObjektString);
225 catch (ModuleException e) {
226 throw new ServletModuleException(e.toString());