Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17236/src/org/cobricks/item Modified Files: ItemManagerDB.java Item.java ItemManagerImpl.java ItemManager.java ItemServlet.java ItemPresenter.java ItemAttrs.java Log Message: Index: ItemManagerDB.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemManagerDB.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ItemManagerDB.java 2 Mar 2004 17:58:10 -0000 1.6 --- ItemManagerDB.java 6 Mar 2004 21:35:04 -0000 1.7 *************** *** 14,17 **** --- 14,18 ---- */ import org.cobricks.core.db.DBAccess; + import org.cobricks.core.CobricksException; import org.cobricks.item.xmldb.XMLDBAccess; *************** *** 146,154 **** * @param newItem The new item (the one which has changed) * @param itemclass The item class which correspond to this item */ protected final void updateAttributeXMLDB(String name, Item oldItem, Item newItem, OntologyClass itemclass) throws XMLDBException { ! String xpath = "/item[globalid='" + newItem.getGlobalId() + "']"; //ItemAttrs.buildXPathForAttribute(name, oldItem.getGlobalId()); --- 147,157 ---- * @param newItem The new item (the one which has changed) * @param itemclass The item class which correspond to this item + * @throws XMLDBException Is thrown in case there were major problems + * while updating (so that the calling method can try a failsafe update). */ protected final void updateAttributeXMLDB(String name, Item oldItem, Item newItem, OntologyClass itemclass) throws XMLDBException { ! String xpath = "/item[itemid='" + newItem.getLocalId() + "']"; //ItemAttrs.buildXPathForAttribute(name, oldItem.getGlobalId()); *************** *** 167,172 **** */ protected final void storeItemXMLDB(Item item) { ! this.xmlDBAccess.insertDocument(item.getItemAsXML(false, false), ! String.valueOf(item.getLocalId())); } /** --- 170,186 ---- */ protected final void storeItemXMLDB(Item item) { ! try { ! this.xmlDBAccess.insertDocument(item.getItemAsXML(false, false), ! String.valueOf(item.getLocalId())); ! } catch (CobricksException e) { ! if (e.getExceptionId().equals("3001")) { ! logger.warn("Offline-Exception"); ! //TBD: Offline Error handling? ! } ! //TBD ! } catch (XMLDBException e) { ! logger.warn("Error during storing", e); ! } ! } /** *************** *** 305,310 **** protected final void performSafeUpdateXMLDB(Item item) { logger.info("Performing safe update for item: " + item.getLocalId()); ! this.xmlDBAccess.updateWholeDocument(item.getItemAsXML(false, false), ! String.valueOf(item.getLocalId())); } --- 319,331 ---- protected final void performSafeUpdateXMLDB(Item item) { logger.info("Performing safe update for item: " + item.getLocalId()); ! try { ! this.xmlDBAccess.updateWholeDocument(item.getItemAsXML(false, false), ! String.valueOf(item.getLocalId())); ! } catch (XMLDBException e) { ! logger.warn("Fatal problem while trying safe update", e); ! } catch (CobricksException e) { ! logger.warn("Can't update - db offline"); ! } ! } Index: Item.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/Item.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Item.java 2 Mar 2004 17:57:41 -0000 1.6 --- Item.java 6 Mar 2004 21:35:04 -0000 1.7 *************** *** 60,64 **** this.xmlEncoding = itemManager.getXMLEncoding(); ! HashMap attrs = itemManager.extractFromXML(xml); if (attrs == null) { --- 60,64 ---- this.xmlEncoding = itemManager.getXMLEncoding(); ! Map attrs = itemManager.extractFromXML(xml); if (attrs == null) { *************** *** 274,284 **** attrs.remove("globalid"); } - if ((attrs.get("itemclass") != null) && - (attrs.get("itemclass") instanceof String)) { - this.itemclass = (String) attrs.get("itemclass"); - attrs.remove("itemclass"); } ! */ this.attrs = attrs; } --- 274,284 ---- attrs.remove("globalid"); } + */ + if ((attrs.get("itemclass") != null) + && (attrs.get("itemclass") instanceof String)) { + this.itemclass = (String) attrs.remove("itemclass"); } ! this.attrs = attrs; } Index: ItemManagerImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemManagerImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ItemManagerImpl.java 2 Mar 2004 17:58:26 -0000 1.6 --- ItemManagerImpl.java 6 Mar 2004 21:35:04 -0000 1.7 *************** *** 2,6 **** package org.cobricks.item; ! import org.apache.log4j.*; import org.cobricks.category.Category; --- 2,6 ---- package org.cobricks.item; ! import org.apache.log4j.Logger; import org.cobricks.category.Category; *************** *** 30,44 **** import org.xml.sax.SAXException; ! import java.io.*; ! ! import java.lang.reflect.Constructor; ! ! import java.net.URI; import java.sql.Timestamp; - import java.text.DateFormat; ! import java.util.*; import javax.xml.parsers.DocumentBuilder; --- 30,49 ---- import org.xml.sax.SAXException; ! import java.io.File; ! import java.io.BufferedInputStream; ! import java.io.ByteArrayInputStream; import java.sql.Timestamp; import java.text.DateFormat; ! import java.util.Map; ! import java.util.Set; ! import java.util.ArrayList; ! import java.util.HashMap; ! import java.util.HashSet; ! import java.util.Iterator; ! import java.util.List; ! import java.util.LinkedList; ! import java.util.Properties; import javax.xml.parsers.DocumentBuilder; *************** *** 57,61 **** --- 62,72 ---- public class ItemManagerImpl extends ComponentManagerAdaptor implements ItemManager { + /** + * Standard logger. + */ private static Logger logger = Logger.getLogger(ItemManagerImpl.class); + /** + * All tables in the relational data base. + */ private static final String[] DB_REL_ALL_TABLES = { *************** *** 63,69 **** "item_attrsitem", "item_attrsuser", "item_title", "item_content", }; ! static String COMP_NAME = "Cobricks-2 Item Manager"; ! static String COMP_VERSION = "V0.1 (Jul. 2003)"; ! private static int DEFAULT_CACHE_SIZE = 50; /** --- 74,89 ---- "item_attrsitem", "item_attrsuser", "item_title", "item_content", }; ! /** ! * Component name ! */ ! private static final String COMP_NAME = "Cobricks-2 Item Manager"; ! /** ! * Component version ! */ ! private static final String COMP_VERSION = "V0.1 (Jul. 2003)"; ! /** ! * The default value for the item cache - used in case no property is found ! */ ! private static final int DEFAULT_CACHE_SIZE = 50; /** *************** *** 73,87 **** /** * What attributes are used for permission checking? Maybe this will be ! * defined in the ontology? * TBD */ ! private static final String [] PERMISSION_ATTRIBUTES = {"creator","category"}; ! ! protected String defaultLanguage = "en"; private Ontology ontology; private CoreManager coreManager; ! Map itemObjects = null; private ItemCache itemCache; ! //private XMLDBAccess xmlDBAccess; private ItemManagerDB itemManagerDB; /** --- 93,122 ---- /** * What attributes are used for permission checking? Maybe this will be ! * defined in the ontology? * TBD */ ! private static final String [] PERMISSION_ATTRIBUTES = {"creator", ! "category"}; ! /** ! * Default language entry. Used for item attributes that are multi language ! */ ! private String defaultLanguage = "en"; ! /** ! * Ontology information about items ! */ private Ontology ontology; + /** + * Reference to the core manager. + */ private CoreManager coreManager; ! //Map itemObjects = null; ! /** ! * Itemcache is a map - based cache structure ! */ private ItemCache itemCache; ! ! /** ! * All database handling is done via the item manager db - adapter. ! */ private ItemManagerDB itemManagerDB; /** *************** *** 90,102 **** */ private String javaEncoding = "UTF-8"; ! /** * This has to be equivalent with the java setting. (Sometimes java encoding * names differ from xml encoding names). */ - private String xmlEncoding = "UTF-8"; - //private org.cobricks.item.xmldb.XMLDBAccess xmlDB; /** --- 125,135 ---- */ private String javaEncoding = "UTF-8"; ! /** * This has to be equivalent with the java setting. (Sometimes java encoding * names differ from xml encoding names). */ private String xmlEncoding = "UTF-8"; /** *************** *** 106,127 **** super(); } ! ! public String getComponentName() { return COMP_NAME; } ! public String getComponentVersion() { return COMP_VERSION; } ! public String getDefaultLanguage() { return defaultLanguage; } /** ! * */ ! public void init(String componentId, String managerId, ! Properties properties, CoreManager coreManager, DBAccess dbAccess) throws Exception { super.init(componentId, managerId, properties, coreManager, dbAccess); --- 139,171 ---- super(); } ! /** ! * @see org.cobricks.core.ComponentManagerInterface#getComponentName() ! */ ! public final String getComponentName() { return COMP_NAME; } + /** + * @see org.cobricks.core.ComponentManagerInterface#getComponentVersion() + */ ! public final String getComponentVersion() { return COMP_VERSION; } ! /** ! * @see org.cobricks.item.ItemManager#getDefaultLanguage() ! */ ! ! public final String getDefaultLanguage() { return defaultLanguage; } /** ! * @see org.cobricks.core.ComponentManagerInterface#init(java.lang.String, java.lang.String, java.util.Properties, org.cobricks.core.CoreManager, org.cobricks.core.db.DBAccess) */ ! public final void init(String componentId, String managerId, ! Properties properties, ! CoreManager coreManager, ! DBAccess dbAccess) throws Exception { super.init(componentId, managerId, properties, coreManager, dbAccess); *************** *** 186,190 **** + componentId + File.separator + "dbxml" + File.separator + "item.xml"); ! /*xmlDBAccess = new XMLDBAccess(properties); xmlDBAccess.init("item", (String) --- 230,234 ---- + componentId + File.separator + "dbxml" + File.separator + "item.xml"); ! /*xmlDBAccess = new XMLDBAccess(properties); xmlDBAccess.init("item", (String) *************** *** 193,205 **** + "item.xml"); */ Thread init = new Thread((Runnable) xmlDBAccess , "init"); - init.start(); ! this.itemManagerDB = new ItemManagerDB(this, coreManager.getDBAccess(), xmlDBAccess); ! if (properties.getProperty("item.java.file.encoding") != null){ this.javaEncoding = properties.getProperty("item.java.file.encoding"); } ! if (properties.getProperty("item.xml.encoding")!= null){ this.xmlEncoding = properties.getProperty("item.xml.encoding"); } --- 237,248 ---- + "item.xml"); */ Thread init = new Thread((Runnable) xmlDBAccess , "init"); init.start(); ! this.itemManagerDB = new ItemManagerDB(this, coreManager.getDBAccess(), xmlDBAccess); ! if (properties.getProperty("item.java.file.encoding") != null) { this.javaEncoding = properties.getProperty("item.java.file.encoding"); } ! if (properties.getProperty("item.xml.encoding")!= null) { this.xmlEncoding = properties.getProperty("item.xml.encoding"); } *************** *** 207,227 **** } ! public Ontology getOntology() { return ontology; } private Item getItemFromCache(int itemLocalId) { logger.info("getItemFrom Cache(int)"); - return itemCache.getItem(itemLocalId); } private Item getItemFromCache(String itemGlobalId) { logger.info("getItemFrom Cache (String based)"); return itemCache.getItem(itemGlobalId); } ! public Item getItem(int itemLocalId) { Item res = this.getItemFromCache(itemLocalId); --- 250,284 ---- } ! protected final Ontology getOntology() { return ontology; } + /** + * This method retries an item out of the local cache. + * @param itemLocalId Needed to find the item. + * @return The item in case it is in the cache, null otherwise + */ private Item getItemFromCache(int itemLocalId) { logger.info("getItemFrom Cache(int)"); return itemCache.getItem(itemLocalId); } + /** + * This method retries an item out of the local cache. + * @param itemGlobalId Needed to find the item. + * @return The item in case it is in the cache, null otherwise + */ private Item getItemFromCache(String itemGlobalId) { + //TBD get out of cache with global id - still needed? logger.info("getItemFrom Cache (String based)"); return itemCache.getItem(itemGlobalId); } + ! /** ! * @see org.cobricks.item.ItemManager#getItem(int) ! */ ! public final Item getItem(int itemLocalId) { Item res = this.getItemFromCache(itemLocalId); *************** *** 237,241 **** } ! public Item getItem(String itemid) { Item res = this.getItemFromCache(itemid); --- 294,301 ---- } ! /** ! * @see org.cobricks.item.ItemManager#getItem(java.lang.String) ! */ ! public final Item getItem(String itemid) { Item res = this.getItemFromCache(itemid); *************** *** 262,271 **** --- 322,344 ---- } + /** + * @see org.cobricks.item.ItemManager#addItemAnnotation(org.cobricks.item. + * Item, + * org.cobricks.item.ItemAnnotation) + */ public void addItemAnnotation(Item item, ItemAnnotation iann) { } + /** + * @see org.cobricks.item.ItemManager#addItemAttachment(org.cobricks.item. + * Item, + * org.cobricks.item.ItemAttachment) + */ public void addItemAttachment(Item item, ItemAttachment ia) { } + /** + * @see org.cobricks.item.ItemManager#createItem(java.util.Map) + */ public final Item createItem(Map attrs) { //I. Handle the two item ids *************** *** 350,354 **** public Item createItemFromXML(String xml) { ! HashMap attrs = this.extractFromXML(xml); return this.createItem(attrs); --- 423,427 ---- public Item createItemFromXML(String xml) { ! Map attrs = this.extractFromXML(xml); return this.createItem(attrs); *************** *** 1214,1218 **** * @return HashMap filled with extracted Objects from xml */ ! public HashMap extractFromXML(String xml) { logger.debug("extractFromXML"); --- 1287,1291 ---- * @return HashMap filled with extracted Objects from xml */ ! public Map extractFromXML(String xml) { logger.debug("extractFromXML"); Index: ItemManager.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ItemManager.java 29 Feb 2004 12:03:26 -0000 1.2 --- ItemManager.java 6 Mar 2004 21:35:04 -0000 1.3 *************** *** 1,30 **** ! /** ! * ! * @author mic...@ac... ! * @version $ $ ! * ! * Copyright (c) 2003 Michael Koch, mic...@ac... ! */ package org.cobricks.item; ! import java.util.*; import org.cobricks.core.ComponentManagerInterface; - import org.cobricks.core.util.LogUtil; - import org.cobricks.core.Ontology; - ! public interface ItemManager extends ComponentManagerInterface ! { ! public String getDefaultLanguage(); ! ! public Item getItem(int itemid); ! public Item createItem(Map attrs) ;// minimum: typeid, title_de, publisherid ! public Item createItem(Map attrs, String userid); // check access rights ! public Item getItem(String globalid); public Item getItem(String globalid, String userid); // check access rights public List searchItems(String xpath); //List of Items --- 1,73 ---- ! package org.cobricks.item; ! import java.util.Map; ! import java.util.List; import org.cobricks.core.ComponentManagerInterface; ! //import org.cobricks.core.Ontology; ! /** ! * ! * @author mic...@ac..., ma...@in... ! * @version $ $ ! * ! * Copyright (c) 2003 Michael Koch, mic...@ac... ! */ ! public interface ItemManager extends ComponentManagerInterface { ! /** ! * This method returns the default language; the default language is used in all ! * mutli language attributes if no language is specified. ! * @return An ISO 639-1 language identifier (two letters) of the default language ! * used. ! */ ! String getDefaultLanguage(); ! /** ! * This method is used to get an item out of the backend structure. ! * In case caching is activated, at first a lookup in the cache is performed. ! * If this succeeds, the item will be returned out of the cache. If it fails, ! * the item will be retrieved out of the persistent structure (data base). ! * @param itemid The local id of the item to get. ! * @return An instance of item in case it was found, the null pointer other ! * wise. ! */ + Item getItem(int itemid); + /** + * This method creates a new item object: At first the data is inserted into + * the persistent storage and then instantiated and (if activated) inserted + * into the cache and then returned. + * <i> Important: Because no user is supplied, anonymous will be used </i> + * In case some of the submitted attributes are not valid (according to the + * item ontology) this method tries at first to correct the attributes and if + * this fails, the still invalid attributes are discarded. + * If required attributes are missing, the item won't be created. + * @param attrs Map containing all attributes. All attributes must have the + * correct Java type (according to the item ontology). + * There are some attributes that get a special handling: The ids are + * discarded in the create method (reason: they have to be assigned by the + * system). Second, an attribute named itemclass is necessary to assign the + * correct item ontology class. If none is submitted, the default will be + * used: "item". + * Multi language attributes: The attribute name has to be aname_lang (lang + * as two letters, e.g. en). If the default language attribute value is set + * the _lang can be omitted. + * @return The item which was stored in the database, null if an error + * occurred. + */ + Item createItem(Map attrs); // minimum: typeid, title_de, publisherid + /** + * The same as getItem(int), but with additional user information - access + * right checking with given user id. + * @see ItemManager#getItem(int) + * @param attrs The attributes for the new item + * @param userid Needed to check access rights. + * @return newly instantiated item or null if an error occurs. + */ + Item createItem(Map attrs, String userid); // check access rights ! Item getItem(String globalid); public Item getItem(String globalid, String userid); // check access rights public List searchItems(String xpath); //List of Items *************** *** 52,57 **** public int getLocalIdForGlobalId(String globalid); // get HashMap of Objects from xml-input ! public HashMap extractFromXML(String xml); ! public Ontology getOntology(); /** --- 95,100 ---- public int getLocalIdForGlobalId(String globalid); // get HashMap of Objects from xml-input ! public Map extractFromXML(String xml); ! //public Ontology getOntology(); /** Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ItemServlet.java 2 Mar 2004 17:59:05 -0000 1.3 --- ItemServlet.java 6 Mar 2004 21:35:04 -0000 1.4 *************** *** 1,12 **** ! /** ! * ! * @author mic...@co... ! * @version $ $ ! * ! * Copyright (c) 2003 Michael Koch, mic...@co... ! */ package org.cobricks.item; ! import org.apache.log4j.*; import org.cobricks.core.ComponentDirectory; --- 1,6 ---- ! package org.cobricks.item; ! import org.apache.log4j.Logger; import org.cobricks.core.ComponentDirectory; *************** *** 16,45 **** import org.cobricks.portal.PortalUser; ! import java.io.*; ! ! import java.net.URL; ! ! import java.util.*; ! import javax.servlet.*; ! import javax.servlet.http.*; public class ItemServlet extends PortalServletAdaptor { ! static Logger logger = Logger.getLogger(ItemServlet.class); ! protected ItemManager itemManager; /** ! * */ ! public void performLogin(HttpServletRequest request, ! HttpServletResponse response, PrintWriter out, PortalUser user) { logger.info(">>>>>>>>perfomLogin()!!!!!"); } /** ! * */ ! public void init(ServletConfig config) throws ServletException { super.init(config); --- 10,72 ---- import org.cobricks.portal.PortalUser; ! import java.io.PrintWriter; ! import java.util.HashMap; ! import java.util.HashSet; ! import java.util.Iterator; ! import java.util.Map; ! import java.util.Set; + import javax.servlet.ServletConfig; + import javax.servlet.ServletException; + import javax.servlet.http.HttpServletRequest; + import javax.servlet.http.HttpServletResponse; + /** + * + * @author mic...@co..., ma...@in... + * @version $ $ + * + * Copyright (c) 2003 Michael Koch, mic...@co... + */ public class ItemServlet extends PortalServletAdaptor { ! /** ! * This array contains all regex which are not used (directly) for building ! * the ItemAttrsMap ! */ ! private static final String [] FILTERED_ATTRIBUTE_NAMES = { ! "cmd.*", "_.*", ".*_lang", "DD.MM.YY HH:MM", "itemid", "globalid" }; ! /** ! * standard logger ! */ ! private static Logger logger = Logger.getLogger(ItemServlet.class); ! /** ! * the item manager is needed for doing actions in the back end structure ! */ ! private ItemManager itemManager; /** ! * Performs a login TBD ! * @param request TBD ! * @param response TBD ! * @param out TBD ! * @param user TBD */ ! ! public final void performLogin(HttpServletRequest request, ! HttpServletResponse response, ! PrintWriter out, ! PortalUser user) { logger.info(">>>>>>>>perfomLogin()!!!!!"); } /** ! * Initializes the presenter: adding targets, initializing item manager ! * @param config Needed to run init method in PortalServletAdaptor ! * @throws ServletException Is thrown in case init method of ! * PortalServerletAdaptor throws this exception */ ! public final void init(ServletConfig config) throws ServletException { ! super.init(config); *************** *** 57,60 **** --- 84,102 ---- } } + /** + * This method performs item creation out of the request parameter. The + * request parameter must have a special format: + * if a custom itemclass is desired there must be a parameter itemclass + * with a correct item class name. + * All cmd.* are ignored. + * Multi-language attributes: parameter name1 = attribute name + * parameter value1 = attribute value; parameter name2 = attribute name + + * "_lang"; parameter value2=language + * @param prequest Portalrequest to gather the data to create a new item + * @param out Is not used. + * @return "error": In case there are errors, also a context object named + * errors is set (a Set of InputErrors). "success" If everything is o.k., + * a context object named "createdItem" is set (Item object). + */ public final String performCreateItem(PortalRequest prequest, *************** *** 66,69 **** --- 108,112 ---- prequest.setContextObject("errors", attrs.get("errors")); out.write(attrs.get("errors").toString()); + // Set the itemclass in the velocity context, //because the select itemclass is an extra form and is overwritten *************** *** 90,93 **** --- 133,137 ---- } } + /** * This method performs a standard update. It does <b>no</b> handling of *************** *** 95,98 **** --- 139,149 ---- * task, this handling is completely done by the front end structure (item * presenter / templates). It only detects changes of item classes. + * The request parameter must have a special format: + * If a custom itemclass is desired there must be a parameter itemclass + * with a correct item class name. + * All cmd.* are ignored. + * Multi-language attributes: parameter name1 = attribute name + * parameter value1 = attribute value; parameter name2 = attribute name + + * "_lang"; parameter value2=language * @param prequest The portal request this call comes from. * @param out Not needed. *************** *** 100,119 **** * there were illegal attributes, success if everything was o.k. */ - public final String performUpdate(PortalRequest prequest, PrintWriter out) { //Object itemObject = prequest.getVelocityContext().get("item"); String itemid = prequest.getRequestParameter("itemid"); Item item = null; try { item = itemManager.getItem(Integer.parseInt(itemid)); } catch (Exception e) { - //TBD out.write("Fatal: Could'nt find item to update."); ! return null; } - if (item !=null) { //This object must not be null /invalid - //Item item = (Item) itemObject; ! if (item.getItemClass().equals(prequest.getRequestParameter( "itemclass"))) { // There was no change in the item class, go ahead with updating --- 151,180 ---- * there were illegal attributes, success if everything was o.k. */ public final String performUpdate(PortalRequest prequest, PrintWriter out) { //Object itemObject = prequest.getVelocityContext().get("item"); String itemid = prequest.getRequestParameter("itemid"); Item item = null; + try { item = itemManager.getItem(Integer.parseInt(itemid)); } catch (Exception e) { out.write("Fatal: Could'nt find item to update."); ! Set errors = new HashSet(); ! errors.add(new InputError("INTERNAL_PRESENTER_ERROR")); ! prequest.setContextObject("errors", errors); ! return "error"; } ! if (item != null) { //This object must not be null /invalid ! logger.debug("old:" + item.getItemClass() + "new:" + ! prequest.getRequestParameter("itemclass")); ! String previousItemClassName = ! prequest.getRequestParameter("_previousitemclass"); ! if (previousItemClassName == null ! || previousItemClassName.length() == 0) { ! previousItemClassName = item.getItemClass(); ! } ! //Item item = (Item) itemObject; ! if (previousItemClassName.equals(prequest.getRequestParameter( "itemclass"))) { // There was no change in the item class, go ahead with updating *************** *** 129,132 **** --- 190,195 ---- } else { item.setFromMap(changedAttrs); + item.setItemClass( + prequest.getRequestParameter("itemclassname")); itemManager.updateItem(item); *************** *** 134,139 **** --- 197,204 ---- } } else { // There was a change in itemclass --> this has to be managed + //by the item presenter / frontend before. prequest.setContextObject("oldItemClass", item.getItemClass()); + return "changedItemClass"; } *************** *** 142,145 **** --- 207,211 ---- } } + /** * This method builds a map of instantiated attributes out of the portal *************** *** 147,162 **** * In case major errors occurred (wrong user input) only a map with one * set named errors is returned. ! * @param pRequest The portal request. Needed to get the parameters. * @return Map of instantiated attributes in case everything is o.k., other * wise a map only with one set containing InputError objects is returned. */ ! ! private Map buildItemAttrsMap(PortalRequest pRequest) { Set errors = new HashSet(); ! Set parameterNames = pRequest.getRequestParameters().keySet(); Map result = new HashMap(); ! String itemClassName = (String) pRequest.getRequestParameter("itemclass"); ! pRequest.setContextObject("itemclass", itemClassName); logger.debug("ic: " + itemClassName); // (String) tmp.remove("itemclass"); Iterator it = parameterNames.iterator(); --- 213,229 ---- * In case major errors occurred (wrong user input) only a map with one * set named errors is returned. ! * @param prequest The portal request. Needed to get the parameters. * @return Map of instantiated attributes in case everything is o.k., other * wise a map only with one set containing InputError objects is returned. */ ! private Map buildItemAttrsMap(PortalRequest prequest) { Set errors = new HashSet(); ! Set parameterNames = prequest.getRequestParameters().keySet(); Map result = new HashMap(); ! String itemClassName = ! (String) prequest.getRequestParameter("itemclass"); ! prequest.setContextObject("itemclass", itemClassName); logger.debug("ic: " + itemClassName); + // (String) tmp.remove("itemclass"); Iterator it = parameterNames.iterator(); *************** *** 164,178 **** while (it.hasNext()) { String currentParam = (String) it.next(); ! String input = (String) pRequest.getRequestParameter(currentParam); ! if (!currentParam.matches("cmd.*") && !currentParam.matches(".*_lang") ! && (input != null) ! && (input.length() > 0) ! && !ItemPresenter.DATE_FORMAT.equals(input)) { logger.debug(currentParam); Object attr = ItemAttrs.instantiateAttribute(this.itemManager, input, ! currentParam, itemClassName); if (attr instanceof InputError) { //attr is a single error --- 231,242 ---- while (it.hasNext()) { String currentParam = (String) it.next(); ! String input = (String) prequest.getRequestParameter(currentParam); ! if (this.processAttribute(currentParam, input, prequest)) { logger.debug(currentParam); Object attr = ItemAttrs.instantiateAttribute(this.itemManager, input, ! currentParam, itemClassName); if (attr instanceof InputError) { //attr is a single error *************** *** 180,211 **** errors.add(attr); } else if (attr instanceof Set ! && ((Set) attr).iterator().next() instanceof InputError) { //attr has possibly mutliple errors Iterator it2 = ((Set) attr).iterator(); while (it2.hasNext()) { InputError next = (InputError) it2.next(); ! next.setEnvironment(currentParam); ! errors.add(next); } } else if (attr != null) { //it was correct instantiated ! //important: There is no isMultiLanguage-check here. ! //we trust in the front end structure that it is not possible ! //to add wrong language settings. ! if (pRequest.getRequestParameter(currentParam + ! "_lang") == null) { //no multiple language result.put(currentParam, attr); } else { //Multiple language ! result.put(currentParam + "_" + ! pRequest.getRequestParameter(currentParam + "_lang"), ! attr); } } else { //something went wrong that is not covered with an //error message. Looks like a greater problem. logger.warn("can't handle: " + currentParam); } } } if (errors.isEmpty()) { // Everything is fine. return result; } else { //There were user errors... Return only the errors. --- 244,296 ---- errors.add(attr); } else if (attr instanceof Set ! && ((Set) attr).iterator().next() instanceof InputError) { //attr has possibly mutliple errors Iterator it2 = ((Set) attr).iterator(); + while (it2.hasNext()) { InputError next = (InputError) it2.next(); ! next.setEnvironment(currentParam); ! errors.add(next); } } else if (attr != null) { //it was correct instantiated ! ! if (prequest.getRequestParameter(currentParam + "_lang") ! == null) { //no multiple language result.put(currentParam, attr); } else { //Multiple language ! result.put(currentParam + "_" ! + prequest.getRequestParameter(currentParam ! + "_lang"), attr); } } else { //something went wrong that is not covered with an + //error message. Looks like a greater problem. logger.warn("can't handle: " + currentParam); } + } else if (currentParam.matches("_customAname.*")) { + //process custom attributes + String number = currentParam.substring( + currentParam.lastIndexOf("_"), + currentParam.length()); + String aname = prequest.getRequestParameter(currentParam); + String avalue = prequest.getRequestParameter("_customAvalue" + + number); + logger.debug("Handle custom attribute: " + aname + ":" + avalue + + " cust#" + number); + if (avalue != null && avalue.trim().length() > 0) { + Object attr = ItemAttrs.instantiateAttribute(this.itemManager, + avalue, aname, itemClassName); + if (attr instanceof InputError) { + ((InputError) attr).setEnvironment(aname); + errors.add(attr); + } else { + result.put(aname, attr); + } + } } } if (errors.isEmpty()) { // Everything is fine. + return result; } else { //There were user errors... Return only the errors. *************** *** 216,218 **** --- 301,323 ---- } } + + private boolean processAttribute(String aname, + String input, + PortalRequest prequest) { + boolean process = //should this attribute be processed? Every test is + //a show stopper. + (prequest.getRequestParameter("_subDel_" + aname) != null + && prequest.getRequestParameter("_subDel_" + + aname).equals("delete")); + + int i = 0; + while (process && i < FILTERED_ATTRIBUTE_NAMES.length) { + //if one of the filter matches, set process to false + process = !aname.matches(FILTERED_ATTRIBUTE_NAMES[i]); + i++; } + if (process) { + process = (input != null && input.length() > 0); + } + return process; + } } Index: ItemPresenter.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemPresenter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ItemPresenter.java 2 Mar 2004 17:58:53 -0000 1.3 --- ItemPresenter.java 6 Mar 2004 21:35:04 -0000 1.4 *************** *** 56,59 **** --- 56,60 ---- }; private static String[] LONG_DATATYPES = { "xml" }; + private static String[] UNCHANGED_ATTRIBUTES = {"itemid", "globalid", "creator", "creationtime", "updater", "creationtime"}; protected static String DATE_FORMAT = "DD.MM.YY HH:MM"; private Map errors; *************** *** 76,80 **** (ItemManager) coreManager.getComponentDirectory().getManager("itemManager"); this.coreManager = coreManager; ! ontology = itemManager.getOntology(); File file = new File((String) properties.get("configdir") + File.separator + "org.cobricks.item" + File.separator --- 77,81 ---- (ItemManager) coreManager.getComponentDirectory().getManager("itemManager"); this.coreManager = coreManager; ! ontology = ((ItemManagerImpl)itemManager).getOntology(); File file = new File((String) properties.get("configdir") + File.separator + "org.cobricks.item" + File.separator *************** *** 107,116 **** public String printAttrInput(String itemClass, String aname, ! String requestVal, int rows, int cols) { String result = ""; OntologyClassAttr oca = this.ontology.getClass(itemClass).getAttribute(aname); OntologyDataType odat = oca.getOntologyDataType(); ! String defaultVal = oca.getDefault(); if (rows == -1) { --- 108,123 ---- public String printAttrInput(String itemClass, String aname, ! String requestVal, int rows, int cols, boolean readonly) { String result = ""; OntologyClassAttr oca = this.ontology.getClass(itemClass).getAttribute(aname); + if(oca.isMultiLanguage()){ + aname = aname.split("_")[0]; + } OntologyDataType odat = oca.getOntologyDataType(); ! String defaultVal = null; ! if(requestVal != null && requestVal.length() > 0){ ! defaultVal = oca.getDefault(); ! } if (rows == -1) { *************** *** 120,128 **** } } } if (!oca.getValues().isEmpty()) { //There are possible values ! result += ("<select name=\"" + aname + "\" size=\"1\">\n"); ! List options = oca.getValues(); Iterator it = options.iterator(); --- 127,142 ---- } } + if((requestVal != null) && ((requestVal.length() > MAX_NUMBER_COLS) + || (requestVal.matches("\n")))){ + rows = 10; + } } if (!oca.getValues().isEmpty()) { //There are possible values ! result += "<select name=\"" + aname + "\" size=\"1\""; ! if(readonly){ ! result += " disabled=\"disabled\""; ! } ! result += ">\n"; List options = oca.getValues(); Iterator it = options.iterator(); *************** *** 141,156 **** result += (">" + next + "</option>\n"); } ! ! result += "</select>"; } else if (odat.getTypeName().equals("boolean")) { ! result += ("<input type=\"checkbox\" name=\"" + aname + "\" value=" + "\"true\""); - if (((defaultVal != null) && defaultVal.equals("true")) || ((requestVal != null) && requestVal.equals("true"))) { result += " checked=\"checked\""; } ! ! result += "/>"; } else if (odat.getTypeName().equals("datetime")) { result += ("<input name=\"" + aname + "\" type=\"text\" size=\"" --- 155,190 ---- result += (">" + next + "</option>\n"); } ! result += "<option value=\"\">no value</option></select>"; } else if (odat.getTypeName().equals("boolean")) { ! result += ("<input type=\"radio\" name=\"" + aname + "\" value=" + "\"true\""); if (((defaultVal != null) && defaultVal.equals("true")) || ((requestVal != null) && requestVal.equals("true"))) { result += " checked=\"checked\""; } ! if(readonly){ ! result += " readonly=\"redonly\""; ! } ! result += "> true</input>\n"; ! result += ("<input type=\"radio\" name=\"" + aname + "\" value=" ! + "\"false\""); ! if (((defaultVal != null) && defaultVal.equals("false")) ! || ((requestVal != null) && requestVal.equals("false"))) { ! result += " checked=\"checked\""; ! } ! if(readonly){ ! result += " readonly=\"redonly\""; ! } ! result += "> false</input>\n"; ! result += ("<input type=\"radio\" name=\"" + aname + "\" value=" ! + "\"\""); ! if ((requestVal != null) && (requestVal == "")) { ! result += " checked=\"checked\""; ! } ! if(readonly){ ! result += " readonly=\"redonly\""; ! } ! result += "> no value</input>"; ! } else if (odat.getTypeName().equals("datetime")) { result += ("<input name=\"" + aname + "\" type=\"text\" size=\"" *************** *** 164,168 **** result += (" value=\"" + DATE_FORMAT + "\""); } ! result += "/>"; } else if ((rows <= 1)) { --- 198,204 ---- result += (" value=\"" + DATE_FORMAT + "\""); } ! if(readonly){ ! result += " readonly=\"redonly\""; ! } result += "/>"; } else if ((rows <= 1)) { *************** *** 174,178 **** return printAttrInput(itemClass, aname, requestVal, rows, ! MAX_NUMBER_COLS); } else { result += (" size=\"" + odat.getMaxLength() --- 210,214 ---- return printAttrInput(itemClass, aname, requestVal, rows, ! MAX_NUMBER_COLS, readonly); } else { result += (" size=\"" + odat.getMaxLength() *************** *** 188,197 **** result += (" value=\"" + defaultVal + "\""); } ! result += "/>"; } else { result += ("<textarea name=\"" + aname + "\" cols=\"" + cols ! + "\" rows=\"" + rows + "\">"); ! if ((requestVal != null) && (requestVal.length() > 0)) { result += requestVal; --- 224,238 ---- result += (" value=\"" + defaultVal + "\""); } ! if(readonly){ ! result += " readonly=\"redonly\""; ! } result += "/>"; } else { result += ("<textarea name=\"" + aname + "\" cols=\"" + cols ! + "\" rows=\"" + rows + "\""); ! if(readonly){ ! result += "\" readonly=\"redonly\""; ! } ! result += ">"; if ((requestVal != null) && (requestVal.length() > 0)) { result += requestVal; *************** *** 199,206 **** result += defaultVal; } - result += "</textarea>"; } - return result; } --- 240,245 ---- *************** *** 208,212 **** public String printDescription(String icname, String aname, String lang) { String desc = null; ! if (aname == null) { desc = ontology.getClass(icname).getDescription(lang); --- 247,252 ---- public String printDescription(String icname, String aname, String lang) { String desc = null; ! try{ ! if (aname == null) { desc = ontology.getClass(icname).getDescription(lang); *************** *** 215,218 **** --- 255,259 ---- ontology.getClass(icname).getAttribute(aname).getDescription(lang); } + }catch(Exception e){} if (desc == null) { *************** *** 224,237 **** public String printMultiLangDropDown(String icname, String aname, ! String defaultLang) { String result = ""; ! if (this.ontology.getClass(icname).getAttribute(aname).isMultiLanguage()) { ! result += ("<select name=\"" + aname + "_lang\" size=1>\n"); for (int i = 0; i < LANGUAGES.length; i++) { result += ("<option value=\"" + LANGUAGES[i][0] + "\""); ! if (LANGUAGES[i][0].equals(defaultLang)) { result += " selected=\"selected\""; } --- 265,298 ---- public String printMultiLangDropDown(String icname, String aname, ! String defaultLang, String requestLang) { String result = ""; + String[] temp = aname.split("_"); + String attrName = temp[0]; + String lang = ""; + if(temp.length > 1){ + lang += temp[1]; + defaultLang = ""; + requestLang = ""; + } + if((requestLang != null) && (requestLang.length() > 0)){ + defaultLang = ""; + } ! try{ ! OntologyClass ic = this.ontology.getClass(icname); ! OntologyClassAttr ica = ic.getAttribute(attrName); ! if (ica.isMultiLanguage()) { ! result += ("<select name=\"" + attrName + "_lang\" size=1>\n"); for (int i = 0; i < LANGUAGES.length; i++) { result += ("<option value=\"" + LANGUAGES[i][0] + "\""); ! if(LANGUAGES[i][0].equals(lang)){ ! result += " selected=\"selected\""; ! } ! else if ((requestLang != null) && (LANGUAGES[i][0].equals(requestLang))) { ! result += " selected=\"selected\""; ! } ! else if (LANGUAGES[i][0].equals(defaultLang)) { result += " selected=\"selected\""; } *************** *** 242,245 **** --- 303,309 ---- result += "</select>"; } + }catch(Exception e){ + e.printStackTrace(); + } return result; *************** *** 247,254 **** public String printItemClassesDropDown(String selectName, ! String defaultClassName, String selectedClassName) { String result = ! "<select name=\"" + selectName ! + "\" onChange=\"form.submit()\" size=\"1\">\n"; Collection classes = this.ontology.getClasses(); Iterator iter = classes.iterator(); --- 311,318 ---- public String printItemClassesDropDown(String selectName, ! String defaultClassName, String selectedClassName, boolean submit) { String result = ! "<select name=\"" + selectName + "\""; if(submit){ ! result += " onChange=\"form.submit()\""; } result += " size=\"1\">\n"; Collection classes = this.ontology.getClasses(); Iterator iter = classes.iterator(); *************** *** 289,294 **** } ! public Set getAttributeNames(String itemClassName) { ! OntologyClass oc = ontology.getClass(itemClassName); if ((oc == null) --- 353,358 ---- } ! public Set getAttributeNames(final String itemClassName) { ! final OntologyClass oc = ontology.getClass(itemClassName); if ((oc == null) *************** *** 307,320 **** } ! public Set removeAttributeDuplicates(Set attributes, String toRemove) { ! attributes.removeAll(getAttributeNames(toRemove)); ! ! return attributes; } ! public Set getCommonAttributes(Set attributes1, Set attributes2) { ! attributes1.retainAll(attributes2); ! ! return attributes1; } --- 371,407 ---- } ! public Set removeAttributeDuplicates(final Set attributes, final String toRemove) { ! Iterator iter = attributes.iterator(); ! Set result = new HashSet(); ! Set remove = this.getAttributeNames(toRemove); ! while(iter.hasNext()){ ! String temp = (String)iter.next(); ! if(!remove.contains(temp)){ ! result.add(temp); ! } ! } ! return result; ! } ! ! public Set removeUnchangedAttributes(Set attributes){ ! Set result = new HashSet(attributes); ! for(int i=0; i< UNCHANGED_ATTRIBUTES.length; i++){ ! if(result.contains(UNCHANGED_ATTRIBUTES[i])){ ! result.add(UNCHANGED_ATTRIBUTES[i]); ! } ! } ! return result; } ! public Set getCommonAttributes(final Set attributes1, final Set attributes2) { ! Iterator iter = attributes1.iterator(); ! Set result = new HashSet(); ! while(iter.hasNext()){ ! String temp = (String)iter.next(); ! if(attributes2.contains(temp)){ ! result.add(temp); ! } ! } ! return result; } *************** *** 330,334 **** public Item getItem(String itemID) { - logger.debug("Try to get item with itemid=" + itemID); Item item = null; --- 417,420 ---- *************** *** 343,353 **** } - public String printItemIDInput(String itemID, int cols) { - String result = - "<input name=\"itemid\" type=\"text\" size=\"" + cols - + "\" value=\"" + itemID + "\" readonly=\"readonly\"/>"; - - return result; - } public String printStateInput(String itemClass, String selected) { --- 429,432 ---- *************** *** 376,379 **** --- 455,486 ---- } + public String printNewAttrInput(String aname, String requestVal, int cols){ + String result = "<input name=\"" + aname + "\" type=\"text\" size=\"" + cols + "\""; + if((requestVal != null) && (requestVal.length() > 0)){ + result += " value=\"" + requestVal + "\""; + } + result += "/>"; + return result; + } + + public String printRadioSubDel(String aname, String defaultVal){ + String result = "<input type=\"radio\" name=\"_subDel_" + aname + "\" value=\"delete\""; + if(defaultVal.equals("delete")){ + result += "checked=\"checked\""; } + result += "> Delete attribute</input></br><input type=\"radio\" name=\"_subDel_" + aname + "\" value=\"submit\""; if(defaultVal.equals("submit")){ + result += "checked=\"checked\""; + } + result += "> Maintain attribute</input>"; + return result; + } + + public String concat(String s1, String s2){ + return s1 + s2; + } + + public String getDateFormat(){ + return DATE_FORMAT; + } + private Map loadErrorInfos(File file) { Map result = new HashMap(); Index: ItemAttrs.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemAttrs.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ItemAttrs.java 2 Mar 2004 17:57:57 -0000 1.6 --- ItemAttrs.java 6 Mar 2004 21:35:04 -0000 1.7 *************** *** 768,772 **** + lang + "']/"; } else { ! xp = "/item[globalid='" + localid + "']/" + aname + "/"; } --- 768,772 ---- + lang + "']/"; } else { ! xp = "/item[itemid='" + localid + "']/" + aname + "/"; } *************** *** 1034,1038 **** String aname, String itemClassName) { OntologyClassAttr oca = ! getItemClass(im.getOntology(), itemClassName).getAttribute(aname); OntologyDataType ontType; --- 1034,1039 ---- String aname, String itemClassName) { OntologyClassAttr oca = ! getItemClass(((ItemManagerImpl) im).getOntology(), ! itemClassName).getAttribute(aname); OntologyDataType ontType; *************** *** 1288,1303 **** HashSet set = new HashSet(); String[] tokenized = input.split(COLLECTION_SEPARATOR); ! for (int i = 0; i < tokenized.length; i++) { Object temp = handleInt(tokenized[i], ontType.getCollectionElementType()); ! if (temp != null) { set.add(temp); } } ! if (!set.isEmpty()) { return set; } else { return null; --- 1289,1309 ---- HashSet set = new HashSet(); String[] tokenized = input.split(COLLECTION_SEPARATOR); ! HashSet errors = new HashSet(); for (int i = 0; i < tokenized.length; i++) { Object temp = handleInt(tokenized[i], ontType.getCollectionElementType()); ! if (!(temp instanceof InputError)) { set.add(temp); + } else { + ((InputError) temp).setFurtherInfo("Integer:" + tokenized[i]); + errors.add(temp); } } ! if (errors.isEmpty() && !set.isEmpty()) { return set; + } else if (!errors.isEmpty()) { + return errors; } else { return null; *************** *** 1309,1314 **** return null; } else { //int (->Integer) ! ! return Integer.valueOf(input); } } --- 1315,1323 ---- return null; } else { //int (->Integer) ! try { Integer res = Integer.valueOf(input); ! return res; ! } catch (Exception e) { ! return new InputError("ILLEGAL_INTEGER"); ! } } } |