|
From: Andreas V. <a_...@us...> - 2004-03-16 18:21:07
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1062/src/org/cobricks/item Added Files: ItemAttachmentManager.java Log Message: --- NEW FILE: ItemAttachmentManager.java --- /* * Created on 03.02.2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package org.cobricks.item; import java.util.*; /** * @author Stefan * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class ItemAttachmentManager { private org.cobricks.core.db.DBAccess dbAccess; public ItemAttachmentManager(org.cobricks.core.db.DBAccess dbAccess) { this.dbAccess = dbAccess; } /** * uses the protected constructor from the class ItemAttachment * to create an ItemAttachment * @param itemid * @param itemaid * @param title * @param comment * @param mimetype * @param size * @param url * @param creatorid * @param creationtime * @return */ protected ItemAttachment createItemAttachment( int itemid, int itemaid, String title, String comment, String mimetype, int size, String url, int creatorid, Date creationtime) { ItemAttachment ia = new ItemAttachment( itemid, itemaid, title, comment, mimetype, size, url, creatorid, creationtime); return ia; } /** * returns the ItemAttachment, which belongs to the given item, * with the given attachmentid * @param item * @param attachmentid * @param itemCache * @return */ protected ItemAttachment getItemAttachment( Item item, int attachmentid, ItemCache itemCache) { ItemAttachment res; res = itemCache.getItem(item.getGlobalId()).getAttachment(attachmentid); if (res == null) { //search db for item HashMap conditions = new HashMap(); conditions.put("attachid", "" + attachmentid); conditions.put("itemid", "" + item.getLocalId()); List fields = new java.util.LinkedList(); fields.add("creatorid"); fields.add("creatoriontime"); fields.add("url"); fields.add("size"); fields.add("comment"); fields.add("name"); fields.add("mimetype"); List result = dbAccess.sqlSelect("item_attachment", conditions, fields, 1); if (result.isEmpty()) { //logger.info(("No ItemAttachment found for given Attachmentid" //+ attachmentid)); return null; } else { Map re = (Map) result.get(0); int creatorid = ((Integer) re.get("creatorid")).intValue(); Date creationtime = ((Date) re.get("creatoriontime")); String url = ((String) re.get("url")); int size = ((Integer) re.get("size")).intValue(); String comment = ((String) re.get("comment")); String name = ((String) re.get("name")); String mimetype = ((String) re.get("mimetype")); res = this.createItemAttachment( item.getLocalId(), attachmentid, name, comment, mimetype, size, url, creatorid, creationtime); } } return res; } /** * returns the ItemAttachment of the given attachmentid * @param attachmentid * @param itemCache * @return */ protected ItemAttachment getItemAttachment( int attachmentid, ItemCache itemCache) { ItemAttachment res; res = itemCache.searchAid(attachmentid); if (res == null) { //search db for item HashMap conditions = new HashMap(); conditions.put("attachid", "" + attachmentid); List fields = new java.util.LinkedList(); fields.add("itemid"); fields.add("creatorid"); fields.add("creatoriontime"); fields.add("url"); fields.add("size"); fields.add("comment"); fields.add("name"); fields.add("mimetype"); List result = dbAccess.sqlSelect("item_attachment", conditions, fields, 1); if (result.isEmpty()) { //logger.info(("No ItemAttachment found for given Attachmentid" //+ attachmentid)); return null; } else { Map re = (Map) result.get(0); int itemid = ((Integer) re.get("itemid")).intValue(); int creatorid = ((Integer) re.get("creatorid")).intValue(); Date creationtime = ((Date) re.get("creatoriontime")); String url = ((String) re.get("url")); int size = ((Integer) re.get("size")).intValue(); String comment = ((String) re.get("comment")); String name = ((String) re.get("name")); String mimetype = ((String) re.get("mimetype")); res = this.createItemAttachment( itemid, attachmentid, name, comment, mimetype, size, url, creatorid, creationtime); } } return res; } /** * returns the content of an attachment with given attachmentid in a byte[] * @param ia * @return */ protected byte[] getContent(ItemAttachment ia) { byte[] ba = new byte[ia.getSize()]; if (ia.getUrl() == null) { HashMap conditions = new HashMap(); conditions.put("attachid", "" + ia.getId()); List fields = new java.util.LinkedList(); fields.add("content"); List result = dbAccess.sqlSelect("item_attachcontent", conditions, fields, 1); if (result.isEmpty()); //logger.info("Content of ItemAttachment "+ia.getId() +"not found in db"); else { Map re = (Map) result.get(0); ba = ((byte[]) re.get("content")); //wie kommt content aus der Datenbank? } } else { } return ba; } protected void removeItemAttachment( Item item, ItemAttachment ia, ItemCache itemCache) { dbAccess.sqlDelete("item_attachment", ia.getId()); if (ia.getUrl() == null) { dbAccess.sqlDelete("item_attachcontent", ia.getId()); } else ; //delete in Filesystem itemCache.deleteAttachment(ia.getId()); //delete in Cache //delete in XMLDB? } protected void removeItemAttachment( Item item, int aid, ItemCache itemCache) { removeItemAttachment( item, this.getItemAttachment(item, aid, itemCache), itemCache); } protected void removeItemAttachment( int itemLocalID, ItemCache itemCache, ItemManager itemManager) { Item i = itemManager.getItem(itemLocalID); Iterator iterator = i.getAttachments().iterator(); while (iterator.hasNext()) { ItemAttachment temp = (ItemAttachment) iterator.next(); if (temp.getUrl() == null) dbAccess.sqlDelete("item_attachcontent", temp.getId()); else ; //delete in Filesystem dbAccess.sqlDelete("item_attachment", temp.getId()); } i.deleteAllAttachments(); itemCache.updateItem(i); } /** * @param ia */ public void updateItemAttachment(ItemAttachment ia) { ; } public void storeAttachment(ItemAttachment ia) { ; } } |