1 package mircoders.servlet;
7 import javax.servlet.*;
8 import javax.servlet.http.*;
10 import freemarker.template.*;
18 import mircoders.entity.*;
19 import mircoders.storage.*;
20 import mircoders.module.*;
23 * ServletModuleLinksImcs -
24 * liefert HTML fuer LinksImcs
30 public class ServletModuleLinksImcs extends ServletModule
32 private ModuleLanguage languageModule;
34 // Singelton / Kontruktor
35 private static ServletModuleLinksImcs instance = new ServletModuleLinksImcs();
36 public static ServletModule getInstance() { return instance; }
39 private ServletModuleLinksImcs() {
40 theLog = Logfile.getInstance(this.getClass().getName());
41 templateListString = MirConfig.getProp("ServletModule.LinksImcs.ListTemplate");
42 templateObjektString = MirConfig.getProp("ServletModule.LinksImcs.ObjektTemplate");
43 templateConfirmString = MirConfig.getProp("ServletModule.LinksImcs.ConfirmTemplate");
46 mainModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
47 languageModule = new ModuleLanguage(DatabaseLanguage.getInstance());
48 } catch (StorageObjectException e) {
49 theLog.printDebugInfo("ServletModuleLinksImcs konnte nicht initialisiert werden");
53 public void add(HttpServletRequest req, HttpServletResponse res)
54 throws ServletModuleException {
56 SimpleHash modelRoot = new SimpleHash();
57 EntityList theParentList;
58 EntityList theLanguageList;
61 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
62 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
64 modelRoot.put("new", "1");
65 modelRoot.put("parentlist",HTMLTemplateProcessor.makeSimpleList(theParentList));
66 modelRoot.put("languagelist",HTMLTemplateProcessor.makeSimpleList(theLanguageList));
68 if (theParentList == null || theParentList.getCount() == 0 || theParentList.getCount()>1){
69 HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateObjektString, modelRoot, res.getWriter());
71 deliver(req, res, modelRoot, templateObjektString);
74 } catch(ModuleException e) {
75 throw new ServletModuleException(e.toString());
76 } catch (HTMLParseException e) {
77 throw new ServletModuleException(e.toString());
78 } catch (IOException e) {
79 throw new ServletModuleException(e.toString());
80 } catch(StorageObjectException e) {
81 throw new ServletModuleException(e.toString());
85 public void list(HttpServletRequest req, HttpServletResponse res)
86 throws ServletModuleException {
89 SimpleHash modelRoot = new SimpleHash();
90 EntityList theParentList;
91 EntityList theImcsList;
92 EntityList theLanguageList;
93 String offsetParam = req.getParameter("offset");
96 PrintWriter out = res.getWriter();
98 // Parameter auswerten
99 String query_text = req.getParameter("query_text");
100 modelRoot.put("query_text",query_text);
101 if (query_text!=null) modelRoot.put("query_text_encoded",URLEncoder.encode(query_text));
102 String query_field = req.getParameter("query_field");
103 modelRoot.put("query_field",query_field);
104 String parent = req.getParameter("to_parent_id");
105 modelRoot.put("to_parent_id",parent);
106 String language = req.getParameter("to_language");
107 modelRoot.put("to_language",language);
108 modelRoot.put("language", getLanguage(req));
110 String whereClause=""; boolean isFirst=true;
111 if (query_text!=null && !query_text.equalsIgnoreCase("")) {
112 whereClause += "lower("+query_field+") like lower('%"+query_text+"%')"; isFirst=false;}
113 if (parent != null && !parent.equals("")) {
114 if (isFirst==false) whereClause+=" and ";
115 whereClause += "to_parent_id='"+parent+"'";
118 if (language != null && !language.equals("")) {
119 if (isFirst==false) whereClause+=" and ";
120 whereClause += "to_language='"+language+"'";
124 // hier offsetcode bearbeiten
125 if (offsetParam != null && !offsetParam.equals("")){
126 offset = offsetParam;
128 if (req.getParameter("next") != null){
129 offset= req.getParameter("nextoffset");
131 if (req.getParameter("prev") != null){
132 offset = req.getParameter("prevoffset");
136 if (offset==null || offset.equals("")) offset="0";
137 modelRoot.put("offset",(new Integer(offset)).toString());
139 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", 0, 1000);
140 theImcsList = mainModule.getByWhereClause(whereClause, "title", (new Integer(offset)).intValue());
141 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
143 modelRoot.put("parentlist",HTMLTemplateProcessor.makeSimpleList(theParentList));
144 modelRoot.put("imcslist",HTMLTemplateProcessor.makeSimpleList(theImcsList));
145 modelRoot.put("languagelist",HTMLTemplateProcessor.makeSimpleList(theLanguageList));
146 modelRoot.put("count", (new Integer(theImcsList.getCount())).toString());
147 modelRoot.put("from", (new Integer(theImcsList.getFrom())).toString());
148 modelRoot.put("to", (new Integer(theImcsList.getTo())).toString());
149 if (theImcsList.hasNextBatch())
150 modelRoot.put("next", (new Integer(theImcsList.getNextBatch())).toString());
151 if (theImcsList.hasPrevBatch())
152 modelRoot.put("prev", (new Integer(theImcsList.getPrevBatch())).toString());
154 HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, modelRoot, res.getWriter());
156 } catch (Exception e) {
157 throw new ServletModuleException(e.toString());
161 public void edit(HttpServletRequest req, HttpServletResponse res)
162 throws ServletModuleException {
165 SimpleHash modelRoot = new SimpleHash();
166 EntityList parentList;
167 EntityList theLanguageList;
169 String idParam = req.getParameter("id");
172 parentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
173 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
175 modelRoot.put("parentlist",HTMLTemplateProcessor.makeSimpleList(parentList));
176 modelRoot.put("languagelist",HTMLTemplateProcessor.makeSimpleList(theLanguageList));
177 modelRoot.put("entity", mainModule.getById(idParam));
178 deliver(req, res, modelRoot, templateObjektString);
180 } catch(ModuleException e) {
181 throw new ServletModuleException(e.toString());
182 } catch(StorageObjectException e) {
183 throw new ServletModuleException(e.toString());