From: fh Date: Thu, 4 Oct 2001 12:06:49 +0000 (+0000) Subject: no message X-Git-Tag: prexmlproducerconfig~371 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=444d36f8d479fa6a0f76ecab532cd98a3e83ce35;p=mir.git no message --- diff --git a/source/mircoders/servlet/ServletModuleLinksImcs.java b/source/mircoders/servlet/ServletModuleLinksImcs.java index 6f89bfca..9ea67a96 100755 --- a/source/mircoders/servlet/ServletModuleLinksImcs.java +++ b/source/mircoders/servlet/ServletModuleLinksImcs.java @@ -13,7 +13,7 @@ import mir.module.*; import mir.misc.*; import mir.entity.*; import mir.storage.*; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleException; import mircoders.entity.*; import mircoders.storage.*; @@ -56,7 +56,7 @@ public class ServletModuleLinksImcs extends ServletModule theList = mainModule.getByWhereClause("to_parent_id=NULL", offset); modelRoot.put("new", "1"); - modelRoot.put("contentlist",HTMLTemplateProcessor.makeSimpleList(theList)); + modelRoot.put("imcsparentlist",HTMLTemplateProcessor.makeSimpleList(theList)); if (theList == null || theList.getCount() == 0 || theList.getCount()>1){ HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateObjektString, modelRoot, res.getWriter()); @@ -74,8 +74,80 @@ public class ServletModuleLinksImcs extends ServletModule } catch(StorageObjectException e) { throw new ServletModuleException(e.toString()); } + } + + public void list(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException { + try { + + theLog.printDebugInfo("-- links_imcs_list: list"); + EntityList theList; + SimpleHash modelRoot = new SimpleHash(); + String offsetParam = req.getParameter("offset"); + int offset=0; + PrintWriter out = res.getWriter(); + // hier offsetcode bearbeiten + if (offsetParam != null && !offsetParam.equals("")){ + offset = Integer.parseInt(offsetParam); + } + if (req.getParameter("next") != null){ + offset=Integer.parseInt(req.getParameter("nextoffset")); + } else { + if (req.getParameter("prev") != null){ + offset = Integer.parseInt(req.getParameter("prevoffset")); + } + } + theList = mainModule.getByWhereClause(null, offset); + modelRoot.put("imcsparentlist",HTMLTemplateProcessor.makeSimpleList(theList)); + HTMLTemplateProcessor.process(res,getLanguage(req)+"/"+templateListString, modelRoot, res.getWriter()); + } catch (Exception e) { + throw new ServletModuleException(e.toString()); + } } + + public void edit(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException { + try { + SimpleHash modelRoot = new SimpleHash(); + EntityList theList; + int offset = 0; + String idParam = req.getParameter("id"); + + theList = mainModule.getByWhereClause("to_parent_id=NULL", offset); + + modelRoot.put("imcsparentlist",HTMLTemplateProcessor.makeSimpleList(theList)); + deliver(req, res, mainModule.getById(idParam), modelRoot, templateObjektString); + + } catch(ModuleException e) { + throw new ServletModuleException(e.toString()); + } catch(StorageObjectException e) { + throw new ServletModuleException(e.toString()); + } + } + + public void update(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException { + try { + String idParam = req.getParameter("id"); + HashMap withValues = getIntersectingValues(req, mainModule.getStorageObject()); + String id = mainModule.set(withValues); + //theLog.printInfo("Showing Entity with id: " + id); + //edit(req,res); + String whereParam = req.getParameter("where"); + String orderParam = req.getParameter("order"); + if ((whereParam!=null && !whereParam.equals("")) || (orderParam!=null && !orderParam.equals(""))){ + //theLog.printDebugInfo("update to list"); + list(req,res); + } else { + edit(req, res); + } + //list(req,res); + } catch (Exception e) { + throw new ServletModuleException(e.toString()); + } + } + } diff --git a/source/mircoders/storage/DatabaseLinksImcs.java b/source/mircoders/storage/DatabaseLinksImcs.java index c3302966..63f6c687 100755 --- a/source/mircoders/storage/DatabaseLinksImcs.java +++ b/source/mircoders/storage/DatabaseLinksImcs.java @@ -1,9 +1,3 @@ -/* - * put your module comment here - * formatted with JxBeauty (c) johann.langhofer@nextra.at - */ - - package mircoders.storage; import java.lang.*; @@ -54,6 +48,156 @@ public class DatabaseLinksImcs extends Database } } + public String insert (Entity theEntity) throws StorageObjectException { + String returnId = "0"; + Connection con = null; + PreparedStatement pstmt = null; + //cache + invalidatePopupCache(); + try { + HashMap theEntityValues = theEntity.getValues(); + ArrayList streamedInput = theEntity.streamedInput(); + StringBuffer f = new StringBuffer(); + StringBuffer v = new StringBuffer(); + String aField, aValue; + boolean firstField = true; + // make sql-string + for (int i = 0; i < getFields().size(); i++) { + aField = (String)getFields().get(i); + if (!aField.equals(thePKeyName)) { + aValue = null; + // sonderfaelle + if (aField.equals("webdb_create")) { + aValue = "NOW()"; + } + else { + if (streamedInput != null && streamedInput.contains(aField)) { + aValue = "?"; + } + else { + if (theEntityValues.containsKey(aField)) { + if (aField.equals("to_parent_id")) { + aValue = StringUtil.quote((String)theEntityValues.get(aField)); + } else { + aValue = "'" + StringUtil.quote((String)theEntityValues.get(aField)) + "'"; + } + } + } + } + // wenn Wert gegeben, dann einbauen + if (aValue != null) { + if (firstField == false) { + f.append(","); + v.append(","); + } + else { + firstField = false; + } + f.append(aField); + v.append(aValue); + } + } + } // end for + // insert into db + StringBuffer sqlBuf = new StringBuffer("insert into ").append(theTable).append("(").append(f).append(") values (").append(v).append(")"); + String sql = sqlBuf.toString(); + theLog.printInfo("INSERT: " + sql); + con = getPooledCon(); + con.setAutoCommit(false); + pstmt = con.prepareStatement(sql); + if (streamedInput != null) { + for (int i = 0; i < streamedInput.size(); i++) { + String inputString = (String)theEntityValues.get(streamedInput.get(i)); + pstmt.setBytes(i + 1, inputString.getBytes()); + } + } + pstmt.execute(); + pstmt = con.prepareStatement(theAdaptor.getLastInsertSQL((Database)myselfDatabase)); + ResultSet rs = pstmt.executeQuery(); + rs.next(); + returnId = rs.getString(1); + theEntity.setId(returnId); + } catch (SQLException sqe) { + throwSQLException(sqe, "insert"); + } finally { + try { + con.setAutoCommit(true); + } catch (Exception e) { + ; + } + freeConnection(con, pstmt); + } + return returnId; + } + + public void update (Entity theEntity) throws StorageObjectException { + Connection con = null; + PreparedStatement pstmt = null; + ArrayList streamedInput = theEntity.streamedInput(); + HashMap theEntityValues = theEntity.getValues(); + String id = theEntity.getId(); + String aField; + StringBuffer fv = new StringBuffer(); + boolean firstField = true; + //cache + invalidatePopupCache(); + // build sql statement + for (int i = 0; i < getFields().size(); i++) { + aField = (String)metadataFields.get(i); + // only normal cases + if (!(aField.equals(thePKeyName) || aField.equals("webdb_create") || + aField.equals("webdb_lastchange") || (streamedInput != null && streamedInput.contains(aField)))) { + if (theEntityValues.containsKey(aField)) { + if (firstField == false) { + fv.append(", "); + } + else { + firstField = false; + } + if (aField.equals("to_parent_id")) { + fv.append(aField).append("=").append(StringUtil.quote((String)theEntityValues.get(aField))); + } else { + fv.append(aField).append("='").append(StringUtil.quote((String)theEntityValues.get(aField))).append("'"); + } + } + } + } + StringBuffer sql = new StringBuffer("update ").append(theTable).append(" set ").append(fv); + // exceptions + if (metadataFields.contains("webdb_lastchange")) { + sql.append(",webdb_lastchange=NOW()"); + } + if (streamedInput != null) { + for (int i = 0; i < streamedInput.size(); i++) { + sql.append(",").append(streamedInput.get(i)).append("=?"); + } + } + sql.append(" where id=").append(id); + theLog.printInfo("UPDATE: " + sql); + // execute sql + try { + con = getPooledCon(); + con.setAutoCommit(false); + pstmt = con.prepareStatement(sql.toString()); + if (streamedInput != null) { + for (int i = 0; i < streamedInput.size(); i++) { + String inputString = (String)theEntityValues.get(streamedInput.get(i)); + pstmt.setBytes(i + 1, inputString.getBytes()); + } + } + pstmt.executeUpdate(); + } catch (SQLException sqe) { + throwSQLException(sqe, "update"); + } finally { + try { + con.setAutoCommit(true); + } catch (Exception e) { + ; + } + freeConnection(con, pstmt); + } + } + /** * put your documentation comment here * @return diff --git a/templates-dist/de/linksimcs.template b/templates-dist/de/linksimcs.template index 30a3a6ed..233820ee 100755 --- a/templates-dist/de/linksimcs.template +++ b/templates-dist/de/linksimcs.template @@ -9,7 +9,7 @@
- + "${entity.id}""${id}"> @@ -17,19 +17,17 @@ @@ -37,16 +35,16 @@ @@ -54,8 +52,8 @@ diff --git a/templates-dist/de/linksimcslist.template b/templates-dist/de/linksimcslist.template index 3c7b0ecc..ae0d12bc 100755 --- a/templates-dist/de/linksimcslist.template +++ b/templates-dist/de/linksimcslist.template @@ -4,12 +4,14 @@ - +
Name: - + "${entity.title}""${title}">
Kontinent: - +
URL: - + "${entity.url}""${url}">
Sortierkriteríum:
Sprache:
+ @@ -18,10 +20,11 @@ - + bgcolor="#dddddd" > - + + -
Name + Parent Url Sortierpriorität  
${entry.title} ${entry.url}${entry.to_parent_id}${entry.url} ${entry.sortpriority} ${entry.to_language}  delete @@ -30,7 +33,7 @@
+ ${count} datensätze / anzeige von ${from} bis ${to}