1 package mircoders.servlet;
3 import freemarker.template.SimpleHash;
4 import mir.entity.EntityList;
5 import mir.misc.HTMLParseException;
6 import mir.misc.HTMLTemplateProcessor;
7 import mir.misc.Logfile;
8 import mir.misc.MirConfig;
9 import mir.module.ModuleException;
10 import mir.servlet.ServletModule;
11 import mir.servlet.ServletModuleException;
12 import mir.storage.StorageObjectException;
13 import mircoders.module.ModuleLanguage;
14 import mircoders.module.ModuleLinksImcs;
15 import mircoders.storage.DatabaseLanguage;
16 import mircoders.storage.DatabaseLinksImcs;
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20 import java.io.IOException;
21 import java.io.PrintWriter;
22 import java.net.URLEncoder;
25 * ServletModuleLinksImcs -
26 * liefert HTML fuer LinksImcs
32 public class ServletModuleLinksImcs extends ServletModule {
33 private ModuleLanguage languageModule;
35 // Singelton / Kontruktor
36 private static ServletModuleLinksImcs instance = new ServletModuleLinksImcs();
38 public static ServletModule getInstance() {
43 private ServletModuleLinksImcs() {
44 theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.LinksImcs.Logfile"));
45 templateListString = MirConfig.getProp("ServletModule.LinksImcs.ListTemplate");
46 templateObjektString = MirConfig.getProp("ServletModule.LinksImcs.ObjektTemplate");
47 templateConfirmString = MirConfig.getProp("ServletModule.LinksImcs.ConfirmTemplate");
50 mainModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
51 languageModule = new ModuleLanguage(DatabaseLanguage.getInstance());
53 catch (StorageObjectException e) {
54 theLog.printDebugInfo("ServletModuleLinksImcs konnte nicht initialisiert werden");
58 public void add(HttpServletRequest req, HttpServletResponse res)
59 throws ServletModuleException {
61 SimpleHash modelRoot = new SimpleHash();
62 EntityList theParentList;
63 EntityList theLanguageList;
66 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
67 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
69 modelRoot.put("new", "1");
70 modelRoot.put("parentlist", theParentList);
71 modelRoot.put("languagelist", theLanguageList);
73 if (theParentList == null || theParentList.getCount() == 0 || theParentList.getCount() > 1) {
74 HTMLTemplateProcessor.process(res, templateObjektString, modelRoot, res.getWriter(), getLocale(req));
77 deliver(req, res, modelRoot, templateObjektString);
81 catch (ModuleException e) {
82 throw new ServletModuleException(e.toString());
84 catch (HTMLParseException e) {
85 throw new ServletModuleException(e.toString());
87 catch (IOException e) {
88 throw new ServletModuleException(e.toString());
92 public void list(HttpServletRequest req, HttpServletResponse res)
93 throws ServletModuleException {
96 SimpleHash modelRoot = new SimpleHash();
97 EntityList theParentList;
98 EntityList theImcsList;
99 EntityList theLanguageList;
100 String offsetParam = req.getParameter("offset");
103 PrintWriter out = res.getWriter();
105 // Parameter auswerten
106 String query_text = req.getParameter("query_text");
107 modelRoot.put("query_text", query_text);
108 if (query_text != null) modelRoot.put("query_text_encoded", URLEncoder.encode(query_text));
109 String query_field = req.getParameter("query_field");
110 modelRoot.put("query_field", query_field);
111 String parent = req.getParameter("to_parent_id");
112 modelRoot.put("to_parent_id", parent);
113 String language = req.getParameter("to_language");
114 modelRoot.put("to_language", language);
115 modelRoot.put("language", getLanguage(req));
117 String whereClause = "";
118 boolean isFirst = true;
119 if (query_text != null && !query_text.equalsIgnoreCase("")) {
120 whereClause += "lower(" + query_field + ") like lower('%" + query_text + "%')";
123 if (parent != null && !parent.equals("")) {
124 if (isFirst == false) whereClause += " and ";
125 whereClause += "to_parent_id='" + parent + "'";
128 if (language != null && !language.equals("")) {
129 if (isFirst == false) whereClause += " and ";
130 whereClause += "to_language='" + language + "'";
134 // hier offsetcode bearbeiten
135 if (offsetParam != null && !offsetParam.equals("")) {
136 offset = offsetParam;
138 if (req.getParameter("next") != null) {
139 offset = req.getParameter("nextoffset");
142 if (req.getParameter("prev") != null) {
143 offset = req.getParameter("prevoffset");
147 if (offset == null || offset.equals("")) offset = "0";
148 modelRoot.put("offset", (new Integer(offset)).toString());
150 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", 0, 1000);
151 theImcsList = mainModule.getByWhereClause(whereClause, "title", (new Integer(offset)).intValue());
152 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
154 modelRoot.put("parentlist", theParentList);
155 modelRoot.put("imcslist", theImcsList);
156 modelRoot.put("languagelist", theLanguageList);
157 modelRoot.put("count", (new Integer(theImcsList.getCount())).toString());
158 modelRoot.put("from", (new Integer(theImcsList.getFrom())).toString());
159 modelRoot.put("to", (new Integer(theImcsList.getTo())).toString());
160 if (theImcsList.hasNextBatch())
161 modelRoot.put("next", (new Integer(theImcsList.getNextBatch())).toString());
162 if (theImcsList.hasPrevBatch())
163 modelRoot.put("prev", (new Integer(theImcsList.getPrevBatch())).toString());
165 HTMLTemplateProcessor.process(res, templateListString, modelRoot, res.getWriter(), getLocale(req));
168 catch (Exception e) {
169 throw new ServletModuleException(e.toString());
173 public void edit(HttpServletRequest req, HttpServletResponse res)
174 throws ServletModuleException {
177 SimpleHash modelRoot = new SimpleHash();
178 EntityList parentList;
179 EntityList theLanguageList;
181 String idParam = req.getParameter("id");
184 parentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
185 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
187 modelRoot.put("parentlist", parentList);
188 modelRoot.put("languagelist", theLanguageList);
189 modelRoot.put("entity", mainModule.getById(idParam));
190 modelRoot.put("new", "0");
191 deliver(req, res, modelRoot, templateObjektString);
194 catch (ModuleException e) {
195 throw new ServletModuleException(e.toString());