|
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 |