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(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.LinksImcs.Logfile"));
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,
70 modelRoot, res.getWriter(), req.getLocale());
72 deliver(req, res, modelRoot, templateObjektString);
75 } catch(ModuleException e) {
76 throw new ServletModuleException(e.toString());
77 } catch (HTMLParseException e) {
78 throw new ServletModuleException(e.toString());
79 } catch (IOException e) {
80 throw new ServletModuleException(e.toString());
81 } catch(StorageObjectException e) {
82 throw new ServletModuleException(e.toString());
86 public void list(HttpServletRequest req, HttpServletResponse res)
87 throws ServletModuleException {
90 SimpleHash modelRoot = new SimpleHash();
91 EntityList theParentList;
92 EntityList theImcsList;
93 EntityList theLanguageList;
94 String offsetParam = req.getParameter("offset");
97 PrintWriter out = res.getWriter();
99 // Parameter auswerten
100 String query_text = req.getParameter("query_text");
101 modelRoot.put("query_text",query_text);
102 if (query_text!=null) modelRoot.put("query_text_encoded",URLEncoder.encode(query_text));
103 String query_field = req.getParameter("query_field");
104 modelRoot.put("query_field",query_field);
105 String parent = req.getParameter("to_parent_id");
106 modelRoot.put("to_parent_id",parent);
107 String language = req.getParameter("to_language");
108 modelRoot.put("to_language",language);
109 modelRoot.put("language", getLanguage(req));
111 String whereClause=""; boolean isFirst=true;
112 if (query_text!=null && !query_text.equalsIgnoreCase("")) {
113 whereClause += "lower("+query_field+") like lower('%"+query_text+"%')"; isFirst=false;}
114 if (parent != null && !parent.equals("")) {
115 if (isFirst==false) whereClause+=" and ";
116 whereClause += "to_parent_id='"+parent+"'";
119 if (language != null && !language.equals("")) {
120 if (isFirst==false) whereClause+=" and ";
121 whereClause += "to_language='"+language+"'";
125 // hier offsetcode bearbeiten
126 if (offsetParam != null && !offsetParam.equals("")){
127 offset = offsetParam;
129 if (req.getParameter("next") != null){
130 offset= req.getParameter("nextoffset");
132 if (req.getParameter("prev") != null){
133 offset = req.getParameter("prevoffset");
137 if (offset==null || offset.equals("")) offset="0";
138 modelRoot.put("offset",(new Integer(offset)).toString());
140 theParentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", 0, 1000);
141 theImcsList = mainModule.getByWhereClause(whereClause, "title", (new Integer(offset)).intValue());
142 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
144 modelRoot.put("parentlist",HTMLTemplateProcessor.makeSimpleList(theParentList));
145 modelRoot.put("imcslist",HTMLTemplateProcessor.makeSimpleList(theImcsList));
146 modelRoot.put("languagelist",HTMLTemplateProcessor.makeSimpleList(theLanguageList));
147 modelRoot.put("count", (new Integer(theImcsList.getCount())).toString());
148 modelRoot.put("from", (new Integer(theImcsList.getFrom())).toString());
149 modelRoot.put("to", (new Integer(theImcsList.getTo())).toString());
150 if (theImcsList.hasNextBatch())
151 modelRoot.put("next", (new Integer(theImcsList.getNextBatch())).toString());
152 if (theImcsList.hasPrevBatch())
153 modelRoot.put("prev", (new Integer(theImcsList.getPrevBatch())).toString());
155 HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString,
156 modelRoot, res.getWriter(), req.getLocale());
158 } catch (Exception e) {
159 throw new ServletModuleException(e.toString());
163 public void edit(HttpServletRequest req, HttpServletResponse res)
164 throws ServletModuleException {
167 SimpleHash modelRoot = new SimpleHash();
168 EntityList parentList;
169 EntityList theLanguageList;
171 String idParam = req.getParameter("id");
174 parentList = mainModule.getByWhereClause("to_parent_id=NULL", "title", offset, 1000);
175 theLanguageList = languageModule.getByWhereClause(null, "name", 0);
177 modelRoot.put("parentlist",HTMLTemplateProcessor.makeSimpleList(parentList));
178 modelRoot.put("languagelist",HTMLTemplateProcessor.makeSimpleList(theLanguageList));
179 modelRoot.put("entity", mainModule.getById(idParam));
180 deliver(req, res, modelRoot, templateObjektString);
182 } catch(ModuleException e) {
183 throw new ServletModuleException(e.toString());
184 } catch(StorageObjectException e) {
185 throw new ServletModuleException(e.toString());