|
From: Michael K. <ko...@us...> - 2006-02-10 11:36:25
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/portal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11203 Modified Files: MultipartFilter.java PortalManager.java PortalManagerImpl.java PortalPage.java PortalPresenter.java PortalServlet.java PortalServletAdaptor.java PortalStats.java itemontology.xml Added Files: PortalCache.java PortalObject.java PortalObjectFile.java Removed Files: PageCache.java Log Message: changed web object support in Portal Component to make binary objects possible Index: PortalManager.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/portal/PortalManager.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- PortalManager.java 2 Feb 2006 11:39:26 -0000 1.19 +++ PortalManager.java 10 Feb 2006 11:36:15 -0000 1.20 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2005 Cobricks Group. All rights reserved. + * Copyright (c) 2003-2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software @@ -45,23 +45,31 @@ throws PortalCompletedException; public void printPage(PortalRequest portalRequest, PrintWriter out); - public PortalPage getPage(String pagePath, String pageName); - public PortalPage getPage(int itemid); + public PortalObject getObject(String pagePath, String pageName); + public PortalObject getObject(int itemid); - public int getPageItemId(String pagePath, String pageName); + public void saveFileToFilesystem(String pagepath, String pagename, + byte barr[]); + + public int getObjectItemId(String pagePath, String pageName); - public int createPage(String pagePath, String pageName, - Map attrs, User creator) + public int createObject(String pagePath, String pageName, + Map attrs, User creator) throws CobricksException; - public void updatePage(int itemid, Map attrs, User updater) + public void updateObject(int itemid, Map attrs, User updater) throws CobricksException; - public void deletePage(int itemid, String lang, User user) + public void deleteObject(int itemid, String lang, User user) throws CobricksException; public PortalStats getPortalStats(); + public void storeBinary(int itemid, String filename, String lang, + byte barr[]); + public String[] getBinaryLangs(int itemid); + public byte[] getBinary(int itemid, String lang, StringBuffer fname); + public List getPageUpdateHistory(int itemid, Date fromdate); public void addPageUpdateHistory(int itemid, int userid, String hostname, Date accdate); @@ -79,7 +87,7 @@ public void deleteFolder(int cid, User user) throws CobricksException; - public List searchPages(String searchExp, boolean searchInTitle); + public List searchObjects(String searchExp, boolean searchInTitle); public void writeLogEntry(String userlogin, String msg); Index: PortalStats.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/portal/PortalStats.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- PortalStats.java 14 Oct 2004 05:52:12 -0000 1.6 +++ PortalStats.java 10 Feb 2006 11:36:15 -0000 1.7 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003 Cobricks Group. All rights reserved. + * Copyright (c) 2003-2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software @@ -16,7 +16,7 @@ import java.net.URL; import java.util.*; -import org.apache.log4j.*; +import org.apache.log4j.Logger; import org.cobricks.core.CoreManager; import org.cobricks.core.ComponentDirectory; Index: itemontology.xml =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/portal/itemontology.xml,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- itemontology.xml 1 Feb 2006 20:36:21 -0000 1.18 +++ itemontology.xml 10 Feb 2006 11:36:15 -0000 1.19 @@ -1,6 +1,6 @@ <itemontology> -<class name="portalpage" parent="item" javaclassname="org.cobricks.portal.PortalPage"> +<class name="portalobject" parent="item" javaclassname="org.cobricks.portal.PortalObject"> <description lang="de">Portalobjekt</description> <attr name="name" type="string(30)"/> <attr name="mimetype" type="string(20)"/> @@ -10,15 +10,19 @@ <attr name="readroles" type="string[]" /> <attr name="writeroles" type="string[]" /> </class> - -<class name="portalpagehtml" parent="portalpage"> + +<class name="portalfile" parent="portalobject" javaclassname="org.cobricks.portal.PortalObjectFile"> +<description lang="de">Portalobjekt</description> +</class> + +<class name="portalpage" parent="portalobject" javaclassname="org.cobricks.portal.PortalPage"> <description lang="de">Portalseite</description> <attr name="fullcontext" type="boolean"> <default>true</default> </attr> </class> -<class name="wikipage" parent="portalpagehtml"> +<class name="wikipage" parent="portalpage"> <description lang="de">Wikiseite</description> <attr name="content" type="text" multilanguage="true" versioned="true" /> </class> Index: PortalServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/portal/PortalServlet.java,v retrieving revision 1.45 retrieving revision 1.46 diff -u -d -r1.45 -r1.46 --- PortalServlet.java 2 Feb 2006 17:18:00 -0000 1.45 +++ PortalServlet.java 10 Feb 2006 11:36:15 -0000 1.46 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2005 Cobricks Group. All rights reserved. + * Copyright (c) 2003-2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.net.URL; +import java.net.URLConnection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -109,6 +110,8 @@ this.addTarget("create", "performCreatePage", "", false); this.addTarget("update", "performUpdatePage", "", false); this.addTarget("delete", "performDeletePage", "", false); + this.addTarget("createbin", "performCreateObj", "", false); + this.addTarget("updatebin", "performUpdateObj", "", false); this.addTarget("createfolder", "performCreateFolder", "", false); this.addTarget("updatefolder", "performUpdateFolder", "", false); this.addTarget("deletefolder", "performDeleteFolder", "", false); @@ -329,17 +332,17 @@ attrs.put("fullcontext", fullcontext); } - //Set the itemclass + // Set the itemclass String itemclass = prequest.getRequestParameter("itemclass"); if(itemclass == null) { - itemclass = "portalpagehtml"; + itemclass = "portalpage"; } attrs.put("itemclass", itemclass); try { int itemid = - portalManager.createPage(pagepath, pagename, attrs, - portalUser.getUser()); + portalManager.createObject(pagepath, pagename, attrs, + portalUser.getUser()); String hostname = request.getRemoteHost(); if (hostname == null) @@ -378,7 +381,7 @@ } try { - portalManager.deletePage(itemid, lang, portalUser.getUser()); + portalManager.deleteObject(itemid, lang, portalUser.getUser()); } catch (Exception e) { logger.error(LogUtil.ex("Failed deleting page.", e)); prequest.setReturnCode(2102); @@ -413,7 +416,7 @@ HttpServletRequest request = prequest.getHttpServletRequest(); - PortalPage page = portalManager.getPage(itemid); + PortalObject page = portalManager.getObject(itemid); Map attrs = new HashMap(); String lang[] = prequest.getRequestParameterValues("plang"); @@ -487,7 +490,7 @@ } else { attrs.put("newContentVersion", "false"); } - portalManager.updatePage(itemid, attrs, portalUser.getUser()); + portalManager.updateObject(itemid, attrs, portalUser.getUser()); String hostname = request.getRemoteHost(); if (hostname == null) @@ -508,6 +511,188 @@ /** * */ + public String performCreateObj(PortalRequest prequest, PrintWriter out) + throws PortalCompletedException + { + logger.debug("performCreateBin()"); + + // check access rights + PortalUser portalUser = prequest.getPortalUser(); + if (!userManager.getAccessControl().checkPermission(portalUser + .getUserId(), "page", "create", null)) { + prequest.setReturnCode(2000); + return "noaccess"; + } + + // get the uploaded file + HttpServletRequest request = prequest.getHttpServletRequest(); + Object upload = request.getAttribute("_file"); + if (upload == null) { + logger.warn("no file uploaded"); + prequest.setReturnCode(2101); + return "error"; + } + if (!(upload instanceof FileItem)) { + logger.warn("no file uploaded - "+upload.getClass().getName()); + prequest.setReturnCode(2101); + return "error"; + } + + FileItem uploadFile = (FileItem)upload; + String contentType = uploadFile.getContentType(); + int size = (int)uploadFile.getSize(); + byte[] data = uploadFile.get(); + + // get mandatory parameters from HTTP request + String pagepath = prequest.getRequestParameter("ppath"); + String pagename = prequest.getRequestParameter("pname"); + String uploadFileName = uploadFile.getName(); + String mimetype = + URLConnection.guessContentTypeFromName(uploadFileName); + logger.info("!!! filename="+uploadFileName+", mime="+mimetype); + if (pagename == null || pagename.trim().length()<1) { + pagename = uploadFileName; + } + else if (pagename.indexOf(".")<1) { + String tmps = uploadFile.getName(); + int pos = tmps.lastIndexOf("."); + if (pos >= 0) { + pagename += tmps.substring(pos); + } + } + String lang = prequest.getRequestParameter("plang"); + + // get optional parameters from HTTP request + String storedb = prequest.getRequestParameter("storedb"); + + if (storedb != null) { + // store the binary object in the database + // and create an item for it + Map attrs = new HashMap(); + attrs.put("mimetype", mimetype); + attrs.put("title", pagename); + // set the itemclass + String itemclass = prequest.getRequestParameter("itemclass"); + if(itemclass == null) { + itemclass = "portalfile"; + } + attrs.put("itemclass", itemclass); + try { + int itemid = + portalManager.createObject(pagepath, pagename, attrs, + portalUser.getUser()); + // store object + if (itemid > 0) { + logger.info("!!! storing "+data.length+" bytes"); + portalManager.storeBinary(itemid, pagename, lang, data); + } + + String hostname = request.getRemoteHost(); + if (hostname == null) + hostname = request.getRemoteAddr(); + portalManager. + addPageUpdateHistory(itemid, portalUser.getUserId(), + hostname, new Date()); + } catch (Exception e) { + logger.error(LogUtil.ex("Failed creating object.", e)); + prequest.setReturnCode(2101); + return "error"; + } + } else { + // store the binary object as file in the webspace + portalManager.saveFileToFilesystem(pagepath, pagename, data); + } + + prequest.setReturnCode(1101); + return "success"; + } + + + /** + * + */ + public String performUpdateObj(PortalRequest prequest, PrintWriter out) + throws PortalCompletedException + { + logger.debug("performUpdateBin()"); + + // check access rights + PortalUser portalUser = prequest.getPortalUser(); + if (!userManager.getAccessControl().checkPermission(portalUser + .getUserId(), "page", "update", null)) { + prequest.setReturnCode(2000); + return "noaccess"; + } + + // get the uploaded file + HttpServletRequest request = prequest.getHttpServletRequest(); + Object upload = request.getAttribute("_file"); + if (upload == null) { + logger.warn("no file uploaded"); + prequest.setReturnCode(2101); + return "error"; + } + if (!(upload instanceof FileItem)) { + logger.warn("no file uploaded - "+upload.getClass().getName()); + prequest.setReturnCode(2101); + return "error"; + } + + FileItem uploadFile = (FileItem)upload; + String contentType = uploadFile.getContentType(); + int size = (int)uploadFile.getSize(); + byte[] data = uploadFile.get(); + + // get mandatory parameters from HTTP request + String itemidstring = prequest.getRequestParameter("itemid"); + int itemid = 0; + try { + itemid = Integer.parseInt(itemidstring); + } catch (Exception e) { } + String pagename = prequest.getRequestParameter("pname"); + if (pagename == null || pagename.trim().length()<1) { + pagename = uploadFile.getName(); + } + else if (pagename.indexOf(".")<1) { + String tmps = uploadFile.getName(); + int pos = tmps.lastIndexOf("."); + if (pos >= 0) { + pagename += tmps.substring(pos+1); + } + } + String lang = prequest.getRequestParameter("plang"); + + // store the binary object in the database + // and update the item for it + Map attrs = new HashMap(); + try { + // TBD + + // store object + if (itemid > 0) { + portalManager.storeBinary(itemid, pagename, lang, data); + } + + String hostname = request.getRemoteHost(); + if (hostname == null) + hostname = request.getRemoteAddr(); + portalManager. + addPageUpdateHistory(itemid, portalUser.getUserId(), + hostname, new Date()); + } catch (Exception e) { + logger.error(LogUtil.ex("Failed updating object.", e)); + prequest.setReturnCode(2101); + return "error"; + } + + prequest.setReturnCode(1101); + return "success"; + } + + + /** + * + */ public String performCreateFolder(PortalRequest prequest, PrintWriter out) throws PortalCompletedException { Index: MultipartFilter.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/portal/MultipartFilter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- MultipartFilter.java 2 Feb 2006 11:39:26 -0000 1.3 +++ MultipartFilter.java 10 Feb 2006 11:36:15 -0000 1.4 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2005 Cobricks Group. All rights reserved. + * Copyright (c) 2003-2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software @@ -30,7 +30,7 @@ import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUpload; import org.apache.commons.fileupload.FileUploadException; -import org.apache.log4j.*; +import org.apache.log4j.Logger; import org.cobricks.core.util.LogUtil; --- NEW FILE: PortalCache.java --- /* * Copyright (c) 2004-2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software * License, either version 1.0 of the License, or (at your option) any * later version (see www.cobricks.org). * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. */ package org.cobricks.portal; import java.util.HashMap; import java.util.Map; import java.util.Iterator; import org.apache.log4j.Logger; /** * Class for caching PortalObject objects. * * @author mic...@ac... * @version $Date: 2006/02/10 11:36:15 $ */ public class PortalCache { static Logger logger = Logger.getLogger(PortalCache.class); Map pathCache = null; Map itemidCache = null; boolean active = true; /** * */ public PortalCache() { pathCache = new HashMap(); itemidCache = new HashMap(); } public void inactivate() { active = false; } public PortalObject getObject(String path, String name) { if (!active) return null; String key = path+"/"+name; return (PortalObject)pathCache.get(key); } public PortalObject getObject(int itemid) { if (!active) return null; // tbd: when this works with the itemmanager, then rely on // itemmanager cache ... return (PortalObject)itemidCache.get(new Integer(itemid)); } public void setObject(PortalObject p) { if (!active) return; String key = p.getPagePath()+"/"+p.getPageName(); pathCache.put(key, p); if (p.getId()>0) { itemidCache.put(new Integer(p.getId()), p); } // page objects cache garbage collection int cacheSize = pathCache.size(); if (cacheSize % 10 == 0) logger.info("Portal objects cache size is "+cacheSize); if (cacheSize > 500) { logger.info("Portal objects cache size is bigger than limit (" +cacheSize+")"); int toDelete = cacheSize - 300; Iterator iter = pathCache.keySet().iterator(); for (int i=0; i<toDelete; i++) { Object key2 = iter.next(); pathCache.remove(key2); } logger.info("Portal objects cache reduced to "+pathCache.size() +" entries"); } } public void removeObject(int itemid) { if (!active) return; itemidCache.remove(new Integer(itemid)); } /** * Clear the cache */ public void clear() { pathCache = new HashMap(); itemidCache = new HashMap(); } } Index: PortalPresenter.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/portal/PortalPresenter.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- PortalPresenter.java 2 Feb 2006 11:39:26 -0000 1.35 +++ PortalPresenter.java 10 Feb 2006 11:36:15 -0000 1.36 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2005 Cobricks Group. All rights reserved. + * Copyright (c) 2003-2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software @@ -193,7 +193,13 @@ pageName = filename; } } - PortalPage page = portalManager.getPage(pagePath, pageName); + PortalObject o = portalManager.getObject(pagePath, pageName); + if (!(o instanceof PortalPage)) { + logger.warn("Wrong type of portal object for " + +pagePath+pageName); + return ""; + } + PortalPage page = (PortalPage)o; Map pc = page.getStringPageContent(lang); if (pc == null || pc.size()<1) return ""; @@ -370,17 +376,22 @@ /** * Return a PortalPage object by the itemid which is given as String */ - public PortalPage getPage(String itemid) + public PortalObject getObject(String itemid) { int id = 0; try { id = Integer.parseInt(itemid); - return portalManager.getPage(id); + return portalManager.getObject(id); } catch (Exception e) { } return null; } + public PortalObject getPage(String itemid) + { + return getObject(itemid); + } + /** * Print some header information for html pages. This function * will be called in the Velocity header files. @@ -415,10 +426,11 @@ { StringBuffer sb = new StringBuffer(""); String lang = portalRequest.getPageLang(); - PortalPage page = portalManager.getPage(portalRequest.getPagePath(), - portalRequest.getPageName()); - if (page!=null) { - List languages = page.getLanguages(); + PortalObject page = portalManager. + getObject(portalRequest.getPagePath(), + portalRequest.getPageName()); + if (page!=null && (page instanceof PortalPage)) { + List languages = ((PortalPage)page).getLanguages(); ListIterator i = languages.listIterator(); while (i.hasNext()) { String tmps = (String)i.next(); @@ -662,7 +674,7 @@ public final String printOption(String label, String labelval, String val) { StringBuffer result = - new StringBuffer("<option value=\"" + labelval + "\">"); + new StringBuffer("<option value=\"" + labelval + "\""); if (labelval.equals(val)) { result.append(" selected=\"true\""); } --- NEW FILE: PortalObject.java --- /* * Copyright (c) 2003-2006 Cobricks Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted under the terms of the Cobricks Software * License, either version 1.0 of the License, or (at your option) any * later version (see www.cobricks.org). * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. */ package org.cobricks.portal; import java.io.File; import java.net.URLConnection; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.log4j.Logger; import org.cobricks.core.CoreManager; import org.cobricks.core.util.LogUtil; import org.cobricks.user.User; /** * Class for storing portal objects. The class is derived from Item, * since web objects are a special class of item (if they are stored in * the database). If the web object is not available in the database * the itemid in the object will be 0. * * @author mic...@ac... * @version $Date: 2006/02/10 11:36:15 $ */ public class PortalObject extends org.cobricks.item.Item { static Logger logger = Logger.getLogger(PortalObject.class); String pageName = null; String pagePath = null; Set pagePaths = null; String mimetype = null; Map pageTitles = new HashMap(); // lang - pagetitle String possibleLangs[] = {"de","en","fr","en","es"}; /** * */ public PortalObject() { super(); } public PortalObject(String pagePath, String pageName, String defaultLang) { super(); if (defaultLang!=null) this.defaultLanguage = defaultLang; this.pagePath = pagePath; if (pagePath == null) pagePath = "/"; this.pageName = pageName; setMimeTypeFromPageName(pageName); this.initAttrs(); } /** * */ public void postInit() { String mtype = (String)getAttribute("mimetype"); if (mtype != null) { mimetype = mtype; } String name = (String)getAttribute("name"); if (name != null) { pageName = name; if (mimetype == null) setMimeTypeFromPageName(name); } } public void postInit(CoreManager coreManager) { String mtype = (String)getAttribute("mimetype"); if (mtype != null) { mimetype = mtype; } String name = (String)getAttribute("name"); if (name != null) { pageName = name; if (mimetype == null) setMimeTypeFromPageName(name); } pagePaths = new HashSet(); Set folders = (Set)getAttribute("folders"); Iterator i = folders.iterator(); while (i.hasNext()) { Object o = i.next(); if (o instanceof Integer) { PortalManager portalManager = (PortalManager) coreManager. getComponentDirectory().getManager("portalManager"); o = portalManager.getPortalFolder(((Integer)o).intValue()); } PortalFolder pf = (PortalFolder)o; String path = pf.getPath(); pagePaths.add(path); pagePath = path; } } /** * */ public String[] getPagePaths() { String[] result = new String[pagePaths.size()]; Iterator it = pagePaths.iterator(); for (int i=0; i<pagePaths.size(); i++) { result[i] = (String)it.next(); } return result; } public String getPagePath() { if (pagePath == null) { if (pagePaths != null) pagePath = (String)(pagePaths.iterator().next()); } return pagePath; } public void addPagePath(String pagePath) { this.pagePaths.add(pagePath); if (this.pagePath == null) this.pagePath = pagePath; } public void removePagePath(String pagePath) { this.pagePaths.remove(pagePath); if (this.pagePath != null) { if (this.pagePath.equals(pagePath)) { this.pagePath = null; } } } public String getPageName() { if (pageName == null) { pageName = getAttributeAsString("name"); } return pageName; } public void setPageName(String pageName) { this.pageName = pageName; setAttribute("name", pageName); if (this.mimetype == null) setMimeTypeFromPageName(pageName); } public String getMimeType() { return mimetype; } public void setMimeTypeFromPageName(String pageName) { if (mimetype!=null) return; this.mimetype = getMimeTypeFromPageName(pageName); } static public String getMimeTypeFromPageName(String pageName) { String mimetype = URLConnection.guessContentTypeFromName(pageName); // guessContentTypeFromName() did not return a result, we use // simple suffix heuristics if (mimetype == null) { mimetype = "text/html"; String suffix = ""; int pos = pageName.lastIndexOf("."); if (pos > -1) { suffix = pageName.substring(pos+1); suffix = suffix.toLowerCase(); suffix = suffix.trim(); if (suffix.equals("html")) { mimetype = "text/html"; } if (suffix.equals("htm")) { mimetype = "text/html"; } if (suffix.equals("txt")) { mimetype = "text/plain"; } if (suffix.equals("css")) { mimetype = "text/css"; } if (suffix.equals("xml")) { mimetype = "text/xml"; } if (suffix.equals("rdf")) { mimetype = "text/rdf"; } if (suffix.equals("csv")) { mimetype = "text/csv"; } } } return mimetype; } public void setMimeType(String mimetype) { this.mimetype = mimetype; } public String getTitle(String lang) { String title = getAttributeAsString("title_" + lang); // if the page wasn't found in the requested language // check whether there exists a title in another language if (title == null || title.equals("")) { Iterator i = pageTitles.keySet().iterator(); if (i.hasNext()) { String la = (String) i.next(); title = (String) pageTitles.get(la); } } return title; } public void setTitle(String lang, String title) { lang = lang.toLowerCase(); this.setAttribute("title_"+lang,title); pageTitles.put(lang, title); } public Object getPageContent(String lang) { return null; } public void updateFromMap(Map map) { super.updateFromMap(map); initAttrs(); } /** * Ini... [truncated message content] |