|
From: Andreas V. <a_...@us...> - 2004-04-18 21:54:16
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13672/src/org/cobricks/item Modified Files: ItemServlet.java Log Message: Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- ItemServlet.java 17 Apr 2004 17:33:00 -0000 1.7 +++ ItemServlet.java 18 Apr 2004 21:54:08 -0000 1.8 @@ -11,9 +11,11 @@ import org.cobricks.core.CobricksException; import java.io.PrintWriter; +import java.util.Collection; 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 java.text.DateFormat; @@ -79,7 +81,11 @@ this.addTarget("login", "performLogin", "", false); this.addTarget("createitem", "performCreateItem", "Create a new item"); this.addTarget("updateitem", "performUpdate", "Update an item"); - + this.addTarget("searchitem", "performSearch", "Search items"); + this.addTarget("xpathsearchitem", "performXPathSearch", + "Search items (XPath)"); + this.addTarget("itemdetails", "showItem", "Show details of an item"); + ComponentDirectory componentDirectory = coreManager.getComponentDirectory(); itemManager = @@ -224,6 +230,103 @@ return "fatalerror"; } } + + public final String performSearch(PortalRequest prequest, PrintWriter out) { + logger.debug("performSearch"); + + prequest.setContextObject("xPath", build(prequest)); + + // TBD statt xpath liste mit items hinterlegen + +// if (prequest.getRequestParameter("title_de").equals("fehler")) { +// return "error"; +// } + + return "success"; + } + + public final String performXPathSearch(PortalRequest prequest, + PrintWriter out) { + + //System.out.println(build(prequest)); + + String query = prequest.getRequestParameter("xPathQuery"); + //prequest.setContextObject("") + List items = this.itemManager.searchItems(query); + + prequest.setContextObject("searchform", Boolean.TRUE); + + if (items == null) { + prequest.setContextObject("errormessage", "The method searchItems " + + "encountered an error. Please check logging output for " + + "details."); + return "error"; + } + + prequest.setContextObject("itemlist", items); + return "success"; + } + + public final String showItem(PortalRequest prequest, PrintWriter out) { + Item item = null; + try { + int itemid = Integer.parseInt(prequest.getRequestParameter("itemid")); + item = this.itemManager.getItem(itemid); + } catch(NumberFormatException e) { + return "error"; + } catch(CobricksException e) { + return "error"; + } + prequest.setContextObject("item", item); + + return "success"; + } + + private String build(PortalRequest prequest) { + //Set errors = new HashSet(); // All errors are stored here + Set parameterNames = prequest.getRequestParameters().keySet(); + //Map result = new HashMap(); + StringBuffer result = new StringBuffer(); + + + if (parameterNames.isEmpty()) { + return null; + } + // Go through all request parameters + Iterator it = parameterNames.iterator(); + + // TBD: besser wieder reinnehmen? + // Ignore the first entry in the portal request because it's the + // searchItems command + //it.next(); + + while (it.hasNext()) { + String currentParam = (String) it.next(); + if (currentParam.startsWith("cmd")) { + continue; + } + + String input = (String) prequest.getRequestParameter(currentParam); + + // TBD date(time), cobricks types + if (!input.equals("")) { + if (input.matches("\\w+")) { + input = "'" + input + "'"; + } + result.append("/item[" + currentParam + "=" + input + "] and "); + } + + System.out.println(currentParam + input); + } + + // Delete the last 'and' + if (result.length() > 0) { + result.delete(result.length() - 5, result.length()); + } + + System.out.println(result.toString()); + return result.toString(); + } /** * This method builds a map of instantiated attributes out of the portal |
|
From: Andreas V. <a_...@us...> - 2004-04-22 09:35:57
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv612/src/org/cobricks/item Modified Files: ItemServlet.java Log Message: Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- ItemServlet.java 18 Apr 2004 21:54:08 -0000 1.8 +++ ItemServlet.java 22 Apr 2004 09:35:45 -0000 1.9 @@ -81,10 +81,9 @@ this.addTarget("login", "performLogin", "", false); this.addTarget("createitem", "performCreateItem", "Create a new item"); this.addTarget("updateitem", "performUpdate", "Update an item"); - this.addTarget("searchitem", "performSearch", "Search items"); + //this.addTarget("searchitem", "performSearch", "Search items"); this.addTarget("xpathsearchitem", "performXPathSearch", - "Search items (XPath)"); - this.addTarget("itemdetails", "showItem", "Show details of an item"); + "Search items (XPath)"); ComponentDirectory componentDirectory = coreManager.getComponentDirectory(); @@ -231,102 +230,115 @@ } } - public final String performSearch(PortalRequest prequest, PrintWriter out) { - logger.debug("performSearch"); - - prequest.setContextObject("xPath", build(prequest)); - - // TBD statt xpath liste mit items hinterlegen - -// if (prequest.getRequestParameter("title_de").equals("fehler")) { -// return "error"; -// } - - return "success"; - } +// public final String performSearch(PortalRequest prequest, PrintWriter out) { +// logger.debug("performSearch"); +// +// prequest.setContextObject("xPath", build(prequest)); +// +// // TBD statt xpath liste mit items hinterlegen +// +//// if (prequest.getRequestParameter("title_de").equals("fehler")) { +//// return "error"; +//// } +// +// return "success"; +// } + /** + * This method searches for items by calling the method searchItems(String) + * of the itemManager. + * The XPath-like query entered by the user is fetched and used as input + * for the searchItems(String) method. + * In case there was an error while performing the search an "errormessage" + * is set; otherwise a list with the found items is set. + * + * @param prequest The portal request this call comes from. + * @param out Not needed. + * @return "error" if the method searchItems(String) indicates an error; + * otherwise "success" + */ public final String performXPathSearch(PortalRequest prequest, PrintWriter out) { - //System.out.println(build(prequest)); - + // Get the query entered by the user and perform the search String query = prequest.getRequestParameter("xPathQuery"); - //prequest.setContextObject("") List items = this.itemManager.searchItems(query); - - prequest.setContextObject("searchform", Boolean.TRUE); - + + // In case there was an error while performing the search, set an + // errormessage if (items == null) { prequest.setContextObject("errormessage", "The method searchItems " + "encountered an error. Please check logging output for " + "details."); return "error"; } - + + // In case everything is ok, set the list of items prequest.setContextObject("itemlist", items); + return "success"; } - public final String showItem(PortalRequest prequest, PrintWriter out) { - Item item = null; - try { - int itemid = Integer.parseInt(prequest.getRequestParameter("itemid")); - item = this.itemManager.getItem(itemid); - } catch(NumberFormatException e) { - return "error"; - } catch(CobricksException e) { - return "error"; - } - prequest.setContextObject("item", item); - - return "success"; - } - - private String build(PortalRequest prequest) { - //Set errors = new HashSet(); // All errors are stored here - Set parameterNames = prequest.getRequestParameters().keySet(); - //Map result = new HashMap(); - StringBuffer result = new StringBuffer(); - - - if (parameterNames.isEmpty()) { - return null; - } - // Go through all request parameters - Iterator it = parameterNames.iterator(); - - // TBD: besser wieder reinnehmen? - // Ignore the first entry in the portal request because it's the - // searchItems command - //it.next(); - - while (it.hasNext()) { - String currentParam = (String) it.next(); - if (currentParam.startsWith("cmd")) { - continue; - } - - String input = (String) prequest.getRequestParameter(currentParam); - - // TBD date(time), cobricks types - if (!input.equals("")) { - if (input.matches("\\w+")) { - input = "'" + input + "'"; - } - result.append("/item[" + currentParam + "=" + input + "] and "); - } - - System.out.println(currentParam + input); - } - - // Delete the last 'and' - if (result.length() > 0) { - result.delete(result.length() - 5, result.length()); - } - - System.out.println(result.toString()); - return result.toString(); - } +// public final String showItem(PortalRequest prequest, PrintWriter out) { +// Item item = null; +// try { +// int itemid = Integer.parseInt(prequest.getRequestParameter("itemid")); +// item = this.itemManager.getItem(itemid); +// } catch(NumberFormatException e) { +// return "error"; +// } catch(CobricksException e) { +// return "error"; +// } +// prequest.setContextObject("item", item); +// +// return "success"; +// } + +// private String build(PortalRequest prequest) { +// //Set errors = new HashSet(); // All errors are stored here +// Set parameterNames = prequest.getRequestParameters().keySet(); +// //Map result = new HashMap(); +// StringBuffer result = new StringBuffer(); +// +// +// if (parameterNames.isEmpty()) { +// return null; +// } +// // Go through all request parameters +// Iterator it = parameterNames.iterator(); +// +// // TBD: besser wieder reinnehmen? +// // Ignore the first entry in the portal request because it's the +// // searchItems command +// //it.next(); +// +// while (it.hasNext()) { +// String currentParam = (String) it.next(); +// if (currentParam.startsWith("cmd")) { +// continue; +// } +// +// String input = (String) prequest.getRequestParameter(currentParam); +// +// // TBD date(time), cobricks types +// if (!input.equals("")) { +// if (input.matches("\\w+")) { +// input = "'" + input + "'"; +// } +// result.append("/item[" + currentParam + "=" + input + "] and "); +// } +// +// System.out.println(currentParam + input); +// } +// +// // Delete the last 'and' +// if (result.length() > 0) { +// result.delete(result.length() - 5, result.length()); +// } +// +// System.out.println(result.toString()); +// return result.toString(); +// } /** * This method builds a map of instantiated attributes out of the portal |
|
From: Stefan H. <ste...@us...> - 2004-05-21 11:31:48
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28076/src/org/cobricks/item Modified Files: ItemServlet.java Log Message: Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- ItemServlet.java 26 Apr 2004 14:05:50 -0000 1.10 +++ ItemServlet.java 21 May 2004 11:31:37 -0000 1.11 @@ -1,6 +1,7 @@ package org.cobricks.item; +import org.apache.commons.fileupload.*; import org.apache.log4j.Logger; import org.cobricks.core.ComponentDirectory; @@ -124,11 +125,46 @@ return "error"; } else { Item it = null; + String title=null; + String comment=null; String eMessage = "No further information avalaible."; + int size; + try { it = itemManager.createItem(attrs); + boolean isMultipart = FileUpload.isMultipartContent( + prequest.getHttpServletRequest()); + if (isMultipart){ + title=prequest.getRequestParameter("_fileTitle"); + comment=prequest.getRequestParameter("_fileComment"); + if(title==null||title.equalsIgnoreCase("")) + title="default_Title"; + if(comment==null) + comment=""; + DiskFileUpload dfUpload = new DiskFileUpload(); + List items = dfUpload. + parseRequest(prequest.getHttpServletRequest()); + Iterator iter = items.iterator(); + while (iter.hasNext()) { + FileItem item = (FileItem) iter.next(); + if (!item.isFormField()) { + String contentType = item.getContentType(); + size = (int) item.getSize(); + ItemAttachment ia=itemManager. + getItemAttachmentManager(). + createItemAttachment(it.getId(),title, + comment,contentType, size, null, 0,null); + byte[] data = item.get(); + itemManager.getItemAttachmentManager(). + storeAttachment(ia,data); + } + } + + } } catch (CobricksException e) { eMessage = e.getMessage(); + } catch (FileUploadException e) { + eMessage=e.getMessage(); } if (it != null) { |
|
From: Andreas V. <a_...@us...> - 2004-06-06 16:12:58
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30216/src/org/cobricks/item Modified Files: ItemServlet.java Log Message: Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- ItemServlet.java 2 Jun 2004 13:32:56 -0000 1.12 +++ ItemServlet.java 6 Jun 2004 16:12:49 -0000 1.13 @@ -81,6 +81,7 @@ this.addTarget("login", "performLogin", "", false); this.addTarget("createitem", "performCreateItem", "Create a new item"); this.addTarget("updateitem", "performUpdate", "Update an item"); + this.addTarget("deleteitem", "performDeletion", "Delete an item"); this.addTarget("xpathsearchitem", "performXPathSearch", "Search items (XPath)"); @@ -265,6 +266,35 @@ } /** + * This method deletes an item by calling the method deleteItem(int) of the + * itemManager. + * + * @param prequest The portal request this call comes from. + * @param out Not needed. + * @return "error" if there was an error while performing the + * itemdeletion; "success" otherwise + */ + public final String performDeletion(PortalRequest prequest, + PrintWriter out) { + + try { + // Get the itemid of the item to be deleted + String itemid = prequest.getRequestParameter("itemid"); + + prequest.setContextObject("itemid", itemid); + + int id = Integer.parseInt(itemid); + + // Delete the item + this.itemManager.deleteItem(id); + + return "success"; + } catch (Exception e) { + return "error"; + } + } + + /** * This method searches for items by calling the method searchItems(String) * of the itemManager. * The XPath-like query entered by the user is fetched and used as input |
|
From: Andreas V. <a_...@us...> - 2004-06-14 13:15:59
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1171/src/org/cobricks/item Modified Files: ItemServlet.java Log Message: Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- ItemServlet.java 6 Jun 2004 16:12:49 -0000 1.13 +++ ItemServlet.java 14 Jun 2004 13:15:49 -0000 1.14 @@ -281,15 +281,14 @@ // Get the itemid of the item to be deleted String itemid = prequest.getRequestParameter("itemid"); - prequest.setContextObject("itemid", itemid); - - int id = Integer.parseInt(itemid); + int id = Integer.parseInt(itemid.trim()); // Delete the item this.itemManager.deleteItem(id); return "success"; } catch (Exception e) { + logger.warn(e.getMessage(), e); return "error"; } } |
|
From: wus <wu...@us...> - 2005-07-12 07:56:23
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2356/src/org/cobricks/item Modified Files: ItemServlet.java Log Message: change itemManager als protected, so dass people can call the methods in portlet Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- ItemServlet.java 26 May 2005 13:58:54 -0000 1.29 +++ ItemServlet.java 12 Jul 2005 07:56:14 -0000 1.30 @@ -70,7 +70,7 @@ /** * The item manager is needed for doing actions in the back end structure */ - private ItemManager itemManager; + protected ItemManager itemManager; /** * Performs a login TBD |
|
From: wus <wu...@us...> - 2005-07-12 20:18:23
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8526/src/org/cobricks/item Modified Files: ItemServlet.java Log Message: change the itemManager back to private, and add a set method Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- ItemServlet.java 12 Jul 2005 07:56:14 -0000 1.30 +++ ItemServlet.java 12 Jul 2005 20:18:09 -0000 1.31 @@ -70,7 +70,7 @@ /** * The item manager is needed for doing actions in the back end structure */ - protected ItemManager itemManager; + private ItemManager itemManager; /** * Performs a login TBD @@ -713,4 +713,7 @@ } } + public void setItemManager(ItemManager im){ + this.itemManager=im; + } } |
|
From: Michael K. <ko...@us...> - 2005-08-10 13:50:38
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9202 Modified Files: ItemServlet.java Log Message: Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- ItemServlet.java 10 Aug 2005 13:34:56 -0000 1.33 +++ ItemServlet.java 10 Aug 2005 13:50:23 -0000 1.34 @@ -285,9 +285,11 @@ // check access rights PortalUser portalUser = prequest.getPortalUser(); + Map attrs = new HashMap(); + attrs.put("itemid", itemid); if (!userManager.getAccessControl(). checkPermission(portalUser.getUserId(), "item", - "update", "itemid="+itemid)) { + "update", attrs)) { prequest.setReturnCode(2000); return "noaccess"; } |
|
From: Michael K. <ko...@us...> - 2005-11-22 07:42:35
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18969/src/org/cobricks/item Modified Files: ItemServlet.java Log Message: Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- ItemServlet.java 22 Aug 2005 13:52:07 -0000 1.36 +++ ItemServlet.java 22 Nov 2005 07:42:27 -0000 1.37 @@ -12,6 +12,7 @@ package org.cobricks.item; +import java.io.File; import java.io.PrintWriter; import java.util.Date; import java.util.ArrayList; @@ -310,11 +311,34 @@ prequest.setReturnCode(2003); return "error"; } + + // check if there are uploaded files and store them in + // attributes or in the context + String tmps = prequest.getRequestParameter("uploadfileattrs"); + String tmpnames = prequest.getRequestParameter("uploadfilenames"); + Map attrsmap = new HashMap(); + if (tmps != null && tmps.length()>0) { + HttpServletRequest request = prequest.getHttpServletRequest(); + StringTokenizer st = new StringTokenizer(tmps, ","); + if (tmpnames == null) tmpnames = ""; + StringTokenizer st2 = new StringTokenizer(tmpnames, ","); + while (st.hasMoreTokens()) { + String aname = st.nextToken(); + String tmpname = null; + if (st2.hasMoreTokens()) tmpname = st2.nextToken(); + Object o = request.getAttribute(aname); + if (o != null && o instanceof FileItem) { + String uri = uploadFile((FileItem)o, tmpname); + attrsmap.put(aname, uri); + } + } + } + String reqICName = prequest.getRequestParameter("itemclass"); if (reqICName == null) reqICName = item.getOntologyClassName(); - Map changedAttrs = buildItemAttrsMap(prequest); + Map changedAttrs = buildItemAttrsMap(prequest, attrsmap); if (changedAttrs.containsKey("errors")) { logger.info("Errors encountered"); prequest.setContextObject("errors", @@ -621,10 +645,12 @@ * otherwise a Map with only one set containing DisplayError * objects is returned. */ - private Map buildItemAttrsMap(PortalRequest prequest) + private Map buildItemAttrsMap(PortalRequest prequest, Map attrsmap) { Set errors = new HashSet(); // All errors are stored here Set parameterNames = prequest.getRequestParameters().keySet(); + parameterNames.remove("uploadfileattrs"); + parameterNames.remove("uploadfilenames"); Map result = new HashMap(); // handle the item class attribute @@ -660,77 +686,24 @@ input = input + ";" + inputs[i]; } } - if (input == null) input = ""; - if (shouldProcessAttribute(currentParam, input, prequest)) { - // this attribute should be processed - Object attr = - OntologyHelper. - instantiateAttrExternal(input, - currentParam, - itemManager.getOntology(). - getClass(itemClassName, "item"), - coreManager, - dateTimeFormatter, dateFormatter); - if (attr instanceof DisplayError) { // attr is a single error - ((DisplayError)attr).setEnvironment(currentParam); - errors.add(attr); - } else if (attr instanceof Set - && ((Set) attr).iterator().next() - instanceof DisplayError) { - // attr has possibly multiple errors - Iterator it2 = ((Set) attr).iterator(); - while (it2.hasNext()) { - DisplayError next = (DisplayError) it2.next(); - next.setEnvironment(currentParam); - errors.add(next); - } - } else if (attr != null) { // Item was correctly 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 which is not covered with an - // error message. Looks like a greater problem. - logger.warn("cannot handle attribute: " + 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); - if (avalue != null && avalue.trim().length() > 0) { - Object attr = OntologyHelper. - instantiateAttrExternal(avalue, aname, - itemManager.getOntology(). - getClass(itemClassName, "item"), - coreManager, - dateTimeFormatter, - dateFormatter); - if (attr instanceof DisplayError) { - ((DisplayError) attr). - setEnvironment(aname - + ("CUSTOM")); - errors.add(attr); - } else if (attr != null) { - logger.debug("Instantiatiated custom attribute: " - + aname + attr.toString()); - result.put(aname, attr); - } else { - logger.info("Null returned while instantiating custom " - + "attribute: " + aname); - } - } - } // End of handling custom attributes + buildItemAttrsMap(currentParam, input, prequest, itemClassName, + dateTimeFormatter, dateFormatter, + result, errors); } // End of going through all attributes - // Do additional checks + + // go through all additional parameters (if any) + if (attrsmap != null) { + it = attrsmap.keySet().iterator(); + while (it.hasNext()) { + String aname = (String)it.next(); + String avalue = (String)attrsmap.get(aname); + buildItemAttrsMap(aname, avalue, prequest, itemClassName, + dateTimeFormatter, dateFormatter, + result, errors); + } + } + + // do additional checks Map additionalCheck = OntologyHelper. checkAttrsAgainstOntology(result, itemManager.getOntology(). getClass(itemClassName, "item"), @@ -748,6 +721,92 @@ } } + private Map buildItemAttrsMap(PortalRequest prequest) + { + return buildItemAttrsMap(prequest, null); + } + + private void buildItemAttrsMap(String currentParam, String input, + PortalRequest prequest, + String itemClassName, + DateFormat dateTimeFormatter, + DateFormat dateFormatter, + Map result, + Set errors) + { + if (input == null) input = ""; + if (shouldProcessAttribute(currentParam, input, prequest)) { + // this attribute should be processed + Object attr = + OntologyHelper. + instantiateAttrExternal(input, + currentParam, + itemManager.getOntology(). + getClass(itemClassName, "item"), + coreManager, + dateTimeFormatter, dateFormatter); + if (attr instanceof DisplayError) { // attr is a single error + ((DisplayError)attr).setEnvironment(currentParam); + errors.add(attr); + } else if (attr instanceof Set + && ((Set) attr).iterator().next() + instanceof DisplayError) { + // attr has possibly multiple errors + Iterator it2 = ((Set) attr).iterator(); + while (it2.hasNext()) { + DisplayError next = (DisplayError) it2.next(); + next.setEnvironment(currentParam); + errors.add(next); + } + } else if (attr != null) { // Item was correctly 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 which is not covered with an + // error message. Looks like a greater problem. + logger.warn("cannot handle attribute: " + 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); + if (avalue != null && avalue.trim().length() > 0) { + Object attr = OntologyHelper. + instantiateAttrExternal(avalue, aname, + itemManager.getOntology(). + getClass(itemClassName, "item"), + coreManager, + dateTimeFormatter, + dateFormatter); + if (attr instanceof DisplayError) { + ((DisplayError) attr). + setEnvironment(aname + + ("CUSTOM")); + errors.add(attr); + } else if (attr != null) { + logger.debug("Instantiatiated custom attribute: " + + aname + attr.toString()); + result.put(aname, attr); + } else { + logger.info("Null returned while instantiating custom " + + "attribute: " + aname); + } + } + } // End of handling custom attributes + } + + /** * This method decides whether a request parameter is used for further * processing (buildItemAttrsMap) or not. @@ -895,4 +954,54 @@ this.itemManager=im; } + + /** + * Get an uploaded file and store it in the upload directory + */ + protected String uploadFile(FileItem uploadfile, String fname) + { + String ufilename = uploadfile.getName(); + if (ufilename == null || ufilename.length()<1) return null; + String filesuffix = ufilename; + if (filesuffix!=null && filesuffix.length()>0) { + int pos = filesuffix.lastIndexOf("."); + if (pos >= 0) { + filesuffix = filesuffix.substring(pos); + } else { + filesuffix = ""; + } + } + + // fname is relative to webspace.dir ! + + String fnamefull = fname; + if (fnamefull.endsWith(File.separator)) { + fname += ufilename; + fnamefull += ufilename; + } + String pdirname = coreManager.getProperty("portal.webspace.dir"); + if (pdirname!=null && pdirname.length()>0) + fnamefull = pdirname + File.separator + fnamefull; + else + fnamefull = "." + File.separator + fnamefull; + int pos = fnamefull.lastIndexOf("."); + if (!(pos > -1 && pos > fnamefull.lastIndexOf(File.separator))) { + fnamefull = fnamefull + filesuffix; + fname = fname + filesuffix; + } + + logger.info("Saving uploaded file to "+fnamefull); + + File file = new File(fnamefull); + try { + uploadfile.write(file); + } catch (Exception e) { + logger.debug("Failed uploading file ... "+e.toString()); + return null; + } + + String uri = "/" + fname; + return uri; + } + } |
|
From: Michael K. <ko...@us...> - 2006-01-23 15:14:23
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/item In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7245 Modified Files: ItemServlet.java Log Message: corrected bug in creating annotations/ratings Index: ItemServlet.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/item/ItemServlet.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -d -r1.39 -r1.40 --- ItemServlet.java 16 Jan 2006 20:43:24 -0000 1.39 +++ ItemServlet.java 23 Jan 2006 15:14:11 -0000 1.40 @@ -250,14 +250,17 @@ String annTitle = prequest.getRequestParameter("_annTitle"); if (annTitle != null && annTitle.length()>0) { String lang = prequest.getRequestParameter("_lang"); - if (lang == null | lang.length()<1) + if (lang == null || lang.length()<1) lang = itemManager.getDefaultLanguage(); String annContent = prequest.getRequestParameter("_annContent"); int rating = 0; String ratingstring = prequest.getRequestParameter("_annRating"); - rating = Integer.parseInt(ratingstring); + logger.info("!!! parsing rating string:>"+ratingstring+"<"); + try { + rating = Integer.parseInt(ratingstring); + } catch (Exception e) { } ItemAnnotation ia = new ItemAnnotation(it.getId(), portalUser.getUserId(), lang, annTitle, annContent, rating); @@ -490,7 +493,9 @@ String content = prequest.getRequestParameter("content"); int rating = 0; String ratingstring = prequest.getRequestParameter("rating"); - rating = Integer.parseInt(ratingstring); + try { + rating = Integer.parseInt(ratingstring); + } catch (Exception e) { } ItemAnnotation ia = new ItemAnnotation(itemid, portalUser.getUserId(), lang, |