|
From: Philipp H. <p-...@us...> - 2006-06-02 12:04:49
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/discussion In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv30569/src/org/cobricks/discussion Modified Files: DiscussionManagerImpl.java itemontology.xml OrderComparator.java ChronologicalPostingComparator.java properties.txt DiscussionPresenter.java Log Message: Bugfixes in Topic Display and WYSIWYG Editor for Disucssion Forms (FCKeditor) Index: itemontology.xml =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/discussion/itemontology.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- itemontology.xml 30 May 2006 14:48:06 -0000 1.4 +++ itemontology.xml 2 Jun 2006 12:04:44 -0000 1.5 @@ -3,6 +3,12 @@ <class name="discussion_topic" parent="item"> <description lang="en">Topic in the discussion component</description> <attr name="parent_cat" type="category(discussion_forum)" /> +<attr name="priority" type="string"> + <default>normal</default> + <value>normal</value> + <value>important</value> + <value>announcement</value> +</attr> </class> <class name="discussion_posting" parent="item"> @@ -11,6 +17,7 @@ <attr name="topicId" type="item(discussion_topic)" /> <attr name="parent" type="item(discussion_posting)" /> <attr name="ip" type="string" /> +<attr name="name" type="string(30)" /> <attr name="email" type="string" /> </class> Index: ChronologicalPostingComparator.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/discussion/ChronologicalPostingComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ChronologicalPostingComparator.java 30 May 2006 14:48:06 -0000 1.1 +++ ChronologicalPostingComparator.java 2 Jun 2006 12:04:44 -0000 1.2 @@ -9,8 +9,10 @@ public class ChronologicalPostingComparator implements Comparator { - private static Logger logger = Logger.getLogger(ChronologicalPostingComparator.class); + private static Logger logger = Logger + .getLogger(ChronologicalPostingComparator.class); private boolean reverse = false; + public ChronologicalPostingComparator() { super(); @@ -24,22 +26,56 @@ public int compare(Object o1, Object o2) { + // the not null value comes first than the null value + if (o1 == null) + { + if (o2 == null) + { + return 0; + } else + { + return 1; + } + } else if (o2 == null) + { + return -1; + } + int return_val = 0; - if (o1 instanceof Item && o2 instanceof Item) + Object dateObj1 = null; + Object dateObj2 = null; + if (o1 instanceof Item) { Item i1 = (Item) o1; + dateObj1 = i1.getAttribute("creationtime"); + + } + if (o2 instanceof Item) + { Item i2 = (Item) o2; - Object dateObj1 = i1.getAttribute("creationtime"); - Object dateObj2 = i2.getAttribute("creationtime"); - if(dateObj1 instanceof Timestamp && - dateObj2 instanceof Timestamp && - dateObj1 != null && - dateObj2 != null){ - return_val = ((Timestamp)dateObj1).compareTo((Timestamp)dateObj2); - } + dateObj2 = i2.getAttribute("creationtime"); + } - - if(reverse){ + if (o1 instanceof Posting) + { + Posting i1 = (Posting) o1; + dateObj1 = i1.getAttribute("creationtime"); + + } + if (o2 instanceof Posting) + { + Posting i2 = (Posting) o2; + dateObj2 = i2.getAttribute("creationtime"); + + } + if (dateObj1 instanceof Timestamp && dateObj2 instanceof Timestamp + && dateObj1 != null && dateObj2 != null) + { + return_val = ((Timestamp) dateObj1).compareTo((Timestamp) dateObj2); + } + + if (reverse) + { return_val *= -1; } return return_val; Index: OrderComparator.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/discussion/OrderComparator.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- OrderComparator.java 30 May 2006 14:48:06 -0000 1.1 +++ OrderComparator.java 2 Jun 2006 12:04:44 -0000 1.2 @@ -4,11 +4,18 @@ import org.apache.log4j.Logger; import org.cobricks.category.Category; +import org.cobricks.item.Item; +/** + * Sorts Collections of Categories or Items with their "order" attribute.<br/> + * If one of them has no "order" attribute it is after the ohne with the "order" attribute. + * + * @author Philipp Hemmer + */ public class OrderComparator implements Comparator { private static Logger logger = Logger.getLogger(OrderComparator.class); - + public int compare(Object o1, Object o2) { // the not null value comes first than the null value @@ -26,50 +33,69 @@ return -1; } // the object from type Category come first than the other objects - if (o1 instanceof Category) + + Object order1 = null; + Object order2 = null; + + if (o1 instanceof Category && o2 instanceof Category) { - if (o2 instanceof Category) + order1 = ((Category) o1).getAttribute("order"); + order2 = ((Category) o2).getAttribute("order"); + } + if (o1 instanceof Item && o2 instanceof Item) + { + order1 = ((Item) o1).getAttribute("order"); + order2 = ((Item) o2).getAttribute("order"); + } + + if (order1 == null) + { + if (order2 == null) { - int i1 = 0; - int i2 = 0; - Object order1 =((Category) o1).getAttribute("order"); - Object order2 =((Category) o2).getAttribute("order"); - - // if one of the Categories has no order it comes last - if (order1 == null) - { - if (order2 == null) - { - return 0; - } else - { - return 1; - } - } else if (order2 == null) - { - return -1; - } - if (order1 instanceof String) - { - i1 = Integer.parseInt((String) order1); - }else if(order1 instanceof Integer){ - i1 = ((Integer)order1).intValue(); - } - if (order2 instanceof String) - { - i2 = Integer.parseInt((String) order2); - }else if(order2 instanceof Integer){ - i2 = ((Integer)order2).intValue(); - } - return i1 - i2; - }else { - return -1; + return 0; + } else + { + return 1; } - }else if (o2 instanceof Category) + } else if (order2 == null) { - return 1; + return -1; + } + + int i1 = 0; + int i2 = 0; + + // if one of the Categories has no order it comes last + if (order1 == null) + { + if (order2 == null) + { + return 0; + } else + { + return 1; + } + } else if (order2 == null) + { + return -1; } - return 0; - } + if (order1 instanceof String) + { + logger.debug("order is returned as String"); + i1 = Integer.parseInt((String) order1); + } else if (order1 instanceof Integer) + { + logger.debug("order is returned as Integer"); + i1 = ((Integer) order1).intValue(); + } + if (order2 instanceof String) + { + i2 = Integer.parseInt((String) order2); + } else if (order2 instanceof Integer) + { + i2 = ((Integer) order2).intValue(); + } + return i1 - i2; + } } Index: properties.txt =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/discussion/properties.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- properties.txt 30 May 2006 14:48:06 -0000 1.3 +++ properties.txt 2 Jun 2006 12:04:44 -0000 1.4 @@ -62,7 +62,7 @@ org.cobricks.discussion.settings.forum_view.choice2=list org.cobricks.discussion.settings.forum_view.choice3=hybrid -org.cobricks.discussion.settings.tree_sorting=chronologic +org.cobricks.discussion.settings.tree_sorting=news_on_top org.cobricks.discussion.settings.tree_sorting.descr=how the tree view is sorted<br/>chronologic: first the old then the new topics<br/>news_on_top: in every level of the tree the newes topic is on top org.cobricks.discussion.settings.tree_sorting.choice1=chronologic org.cobricks.discussion.settings.tree_sorting.choice2=news_on_top Index: DiscussionManagerImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/discussion/DiscussionManagerImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- DiscussionManagerImpl.java 30 May 2006 14:48:06 -0000 1.3 +++ DiscussionManagerImpl.java 2 Jun 2006 12:04:44 -0000 1.4 @@ -14,6 +14,7 @@ import org.cobricks.category.Category; import org.cobricks.category.CategoryManager; import org.cobricks.core.CobricksException; +import org.cobricks.core.ComponentEvent; import org.cobricks.core.ComponentManagerAdaptor; import org.cobricks.core.CoreManager; import org.cobricks.core.Ontology; @@ -122,6 +123,9 @@ accesshandler.init(coreManager, dbAccess); accessControl.registerAccessHandler(accesshandler); + // + coreManager.registerEventListener("category","create"); + //if no discussion data is present create default discussion_categorie, forum, topic and postings Map attrs = new HashMap(); attrs.put("categoryclass", "discussion_category"); @@ -129,12 +133,25 @@ //everything in the component is unter the categories, if there are no categories //there are no valid other data from the discussion component if(cats.size() == 0){ - logger.debug("no discussion data is present, fill will default data"); + logger.debug("no discussion data is present, fill with default data"); insertDefaultData(); } logger.info("discussionManager initialized"); } + public void processEvent(ComponentEvent event) + { + //test listener + logger.debug("event="+event); + logger.debug("event.getSourceComponentId()="+event.getSourceComponentId()); + logger.debug("event.getDomain()="+event.getDomain()); + logger.debug("event.getAction()="+event.getAction()); + logger.debug("event.getObjectId()="+event.getObjectId()); + logger.debug("event.getObjectType()="+event.getObjectType()); + logger.debug("event.getClass().getName()="+event.getClass().getName()); + + } + private void insertDefaultData() { GregorianCalendar cal = new GregorianCalendar(1979, 4, 12, 12, 00); @@ -796,6 +813,7 @@ attrs.put("topicId", new Integer(guestbook_topic.getLocalId())); // attrs.put("parent", new Integer(question2.getLocalId())); attrs.put("ip", "127.0.0.1"); + attrs.put("name", "Hans Mustermann"); attrs.put("email", "name_(at)_host.de"); try @@ -822,6 +840,7 @@ attrs.put("topicId", new Integer(guestbook_topic.getLocalId())); // attrs.put("parent", new Integer(question2.getLocalId())); attrs.put("ip", "127.0.0.1"); + attrs.put("name", "Hans Mustermann"); attrs.put("email", "name_(at)_host.de"); try Index: DiscussionPresenter.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/discussion/DiscussionPresenter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- DiscussionPresenter.java 30 May 2006 14:48:06 -0000 1.3 +++ DiscussionPresenter.java 2 Jun 2006 12:04:44 -0000 1.4 @@ -244,7 +244,7 @@ logger.debug("in getPostings with topicId=" + tId + ", type=" + type + ", view=" + view + ", postingId=" + postingId + ", start_index=" + start_index + ", display_count=" - + display_count +", cut_tree="+cut_tree); + + display_count + ", cut_tree=" + cut_tree); int topicId = -1; int startId = -1; int start = -1; @@ -266,8 +266,11 @@ } // if count == 1 only one Posting is returned, the startposting or the // topic - if (cut_tree && type.equalsIgnoreCase("Forum")) + if (cut_tree && type.equalsIgnoreCase("Forum") + && view.equalsIgnoreCase("tree")) { + logger + .debug("cut_tree und 'forum' only List with Item from postingId or topicId"); if (startId > 0) { return itemManager.searchItems("/item/itemid=" + postingId); @@ -286,14 +289,17 @@ { if (postings.size() > 1) { - // something wrong, cause FAQ has only one posting + logger + .warn("something wrong, cause FAQ should have only one posting"); } else { + logger.debug("faq with one posting"); Item topic; try { topic = itemManager.getItem(topicId); postings.add(0, topic); + logger.debug("add topic at position 0"); } catch (CobricksException e) { logger.error("error with getting topic item"); @@ -313,7 +319,16 @@ logger .debug("getPostings for Forum (view='list')in chronological order"); Collections - .sort(postings, new ChronologicalPostingComparator()); + .sort(postings, new ChronologicalPostingComparator());// insert topic + Item topic; + try + { + topic = itemManager.getItem(topicId); + postings.add(0, topic); + } catch (CobricksException e) + { + logger.warn("error with getting topic item"); + } } else if (view.equalsIgnoreCase("tree") || view.equalsIgnoreCase("hybrid")) { @@ -336,7 +351,21 @@ { Collections.sort(postings, new TreePostingComparator()); } - /* + // insert topic + Item topic; + try + { + topic = itemManager.getItem(topicId); + Posting p = new Posting(topic, 0); + if (startId == -1){ + p.setMarked(true); + } + postings.add(0, p); + } catch (CobricksException e) + { + logger.warn("error with getting topic item"); + } + // mark or cut the posting(tree) or subtree (hybrid) int indent = -1; List cuted_list = null; @@ -348,7 +377,7 @@ for (Iterator iter = postings.iterator(); iter.hasNext();) { Posting posting = (Posting) iter.next(); - if (indent > -1) + if (indent > -1 || startId == -1) { if (posting.getIndent() > indent) { @@ -368,14 +397,13 @@ { indent = posting.getIndent(); posting.setMarked(true); - logger.debug("start posting found and marked"); if (cut_tree) { cuted_list.add(posting); } if (view.equalsIgnoreCase("tree")) - { - // only mark the startId + { + // only mark the start posting break; } } @@ -384,17 +412,24 @@ { postings = cuted_list; } - */ - } - Item topic; - try - { - topic = itemManager.getItem(topicId); - postings.add(0, new Posting(topic, 0)); - } catch (CobricksException e) - { - logger.error("error with getting topic item"); + //normalize indent + Object first = postings.get(0); + if (first instanceof Posting) + { + int first_indent = ((Posting) first).getIndent(); + if(first_indent > 0){ + for (Iterator iter = postings.iterator(); iter + .hasNext();) + { + Posting posting = (Posting) iter.next(); + posting.setIndent(posting.getIndent()-first_indent); + } + } + } } + logger.debug("after type specific code, postings.size()=" + + postings.size()); + } return postings; @@ -463,29 +498,35 @@ */ private Map createSortingMap(List postings) { + logger.debug("createSortingMap"); Map return_map = new HashMap(); for (Iterator iter = postings.iterator(); iter.hasNext();) { Item item = (Item) iter.next(); int id = item.getLocalId(); Timestamp time = (Timestamp) item.getAttribute("creationtime"); - Timestamp value = (Timestamp) return_map.get(String.valueOf(id)); - if (value != null && time.after(value)) + if (value == null || time.after(value)) { + logger.debug("put new key in map for item: key=" + id + + ", value=" + time); return_map.put(String.valueOf(id), time); } else { + logger.debug("next item "); continue; } Integer parent_id = (Integer) item.getAttribute("parent"); while (parent_id != null && parent_id.intValue() > 0) { + logger.debug("item has parent"); Timestamp parentTime = (Timestamp) return_map.get(parent_id .toString()); if (parentTime == null || time.after(parentTime)) { + logger.debug("put new key in map for parents: key=" + id + + ", value=" + time); return_map.put(parent_id.toString(), time); } else { @@ -508,12 +549,16 @@ public String getViewFromRequest(PortalRequest pRequest) { Cookie[] cookies = pRequest.getHttpServletRequest().getCookies(); - for (int i = 0; i < cookies.length; i++) + if (cookies != null) { - if (cookies[i].getName().equalsIgnoreCase("discussion_view")) + for (int i = 0; i < cookies.length; i++) { - logger.debug("view from cookie value=" + cookies[i].getValue()); - return cookies[i].getValue(); + if (cookies[i].getName().equalsIgnoreCase("discussion_view")) + { + logger.debug("view from cookie value=" + + cookies[i].getValue()); + return cookies[i].getValue(); + } } } if (pRequest.getRequestParameter("view") != null) @@ -526,6 +571,7 @@ .debug("view from settings, value=" + coreManager .getProperty("org.cobricks.discussion.settings.forum_view")); + return coreManager .getProperty("org.cobricks.discussion.settings.forum_view"); } |