|
From: Michael K. <ko...@us...> - 2004-03-30 13:21:49
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/portal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22484 Modified Files: PortalManagerImpl.java Log Message: Index: PortalManagerImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/portal/PortalManagerImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- PortalManagerImpl.java 30 Mar 2004 12:31:58 -0000 1.6 +++ PortalManagerImpl.java 30 Mar 2004 13:10:12 -0000 1.7 @@ -185,7 +185,7 @@ */ public PortalPage getPage(String pagePath, String pageName) { - if (pagePath == null) pagePath = "/"; + if (pagePath == null) pagePath = ""; if (pageName == null) pageName = "index.html"; PortalPage p = pageCache.getPage(pagePath, pageName); if (p == null) { @@ -432,22 +432,23 @@ */ public int getPageItemId(String pagePath, String pageName) { + // TBD: currently we store the path in the filename + // this will be changed when the category component is + // finished - then we will first query the categories for + // the path, then check all page items in the given categroy + // for the pageName ... + String key = pagePath+pageName; Integer itemid = (Integer)pageItemIdCache.get(key); if (itemid!=null) { return itemid.intValue(); } - // first get category for path - PortalFolder c = getPortalFolder(pagePath); - if (c == null) return 0; - - // and now look for a portalpage item that has the portalfolder - // category assigned - - // tbd - - if (itemid!=null) { + String sql = "select itemid from page_object_html where " + +"filename = '"+pagePath+pageName+"'"; + Map m = dbAccess.sqlQuerySingleRow(sql); + if (m!=null && m.get("itemid")!=null) { + itemid = (Integer)m.get("itemid"); pageItemIdCache.put(key, itemid); return itemid.intValue(); } @@ -466,16 +467,24 @@ Map result = new HashMap(); Map conditions = new HashMap(); conditions.put("itemid", new Integer(itemid)); - - // tbd - // result.put(lang, m.get("content")); - + List fields = new ArrayList(); + fields.add("lang"); + fields.add("content"); + fields.add("fullcontext"); + List l = dbAccess.sqlSelect("page_object_html", conditions, fields); + Iterator i = l.iterator(); + while (i.hasNext()) { + Map m = (Map)i.next(); + String lang = (String)m.get("lang"); + String fullcontext = (String)m.get("fullcontext"); + result.put(lang, m.get("content")); + } return result; } /** - * Create a new portalpage item with the given attributes + * */ public int createPage(String pagePath, String pageName, String lang, String title, String content, boolean fullcontext, @@ -487,18 +496,54 @@ pagePath += "/"; if (!pagePath.startsWith("/")) pagePath = "/"+pagePath; - - // check if the pagePath is created - PortalFolder c = getPortalFolder(pagePath); - if (c == null) - throw new CobricksException("portal", "nopath", ""); - - // check if page already exits - // tbd - - // create new item - - + // check if there are already items for this pagePath + // tbd: check in the category information + Map conditions = new HashMap(); + conditions.put("filename", pagePath+pageName); + List fields = new ArrayList(); + fields.add("itemid"); + fields.add("lang"); + List l = dbAccess.sqlSelect("page_object_html", conditions, fields); + Integer itemid = null; + boolean exists = false; + Iterator i = l.iterator(); + while (i.hasNext()) { + Map m = (Map)i.next(); + itemid = (Integer)m.get("itemid"); + String mlang = (String)m.get("lang"); + if (mlang.equals(lang)) { + exists = true; + break; + } + } + // update or insert new item + if (itemid == null) { + // create new item + // tbd: currently just create a new itemid for the page_object_html + // table ... but this should call the item manager + String sql = "select max(itemid)+1 as maxid from page_object_html"; + Map m = dbAccess.sqlQuerySingleRow(sql); + if (m!=null && m.get("maxid")!=null) { + itemid = (Integer)m.get("maxid"); + if (itemid.intValue()<1) + itemid = new Integer(1); + } else { + itemid = new Integer(1); + } + } + if (exists) { + Map attrs = new HashMap(); + attrs.put("content", content); + dbAccess.sqlUpdate("page_object_html", attrs, "itemid=" + +itemid.toString()+" and lang='"+lang+"'"); + } else { + Map attrs = new HashMap(); + attrs.put("itemid", itemid); + attrs.put("filename", pagePath+pageName); // tbd: only pageName + attrs.put("lang", lang); + attrs.put("content", content); + dbAccess.sqlInsert("page_object_html", attrs); + } String key = pagePath+pageName; pageItemIdCache.put(key, itemid); portalStats.addPageUpdate(pagePath, pageName); @@ -950,3 +995,6 @@ } + + + |