KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > control > Tree


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.control;
14
15 import info.magnolia.cms.beans.config.ContentRepository;
16 import info.magnolia.cms.beans.config.Template;
17 import info.magnolia.cms.core.Content;
18 import info.magnolia.cms.core.ContentHandler;
19 import info.magnolia.cms.core.HierarchyManager;
20 import info.magnolia.cms.core.ItemType;
21 import info.magnolia.cms.core.MetaData;
22 import info.magnolia.cms.core.NodeData;
23 import info.magnolia.cms.core.Path;
24 import info.magnolia.cms.exchange.simple.Syndicator;
25 import info.magnolia.cms.gui.misc.Spacer;
26 import info.magnolia.cms.security.Authenticator;
27 import info.magnolia.cms.security.SessionAccessControl;
28 import info.magnolia.cms.util.MetaDataUtil;
29 import info.magnolia.cms.util.NodeDataUtil;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collection JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35
36 import javax.jcr.PropertyType;
37 import javax.jcr.RepositoryException;
38 import javax.jcr.Value;
39 import javax.servlet.http.HttpServletRequest JavaDoc;
40
41 import org.apache.commons.lang.StringUtils;
42 import org.apache.log4j.Logger;
43
44
45 /**
46  * @author Vinzenz Wyser
47  * @version 2.0
48  */

49 public class Tree extends ControlSuper {
50
51     public static final String JavaDoc DOCROOT = "/admindocroot/controls/tree/"; //$NON-NLS-1$
52

53     // todo: global; where?
54
public static final String JavaDoc ICONDOCROOT = "/admindocroot/icons/16/"; //$NON-NLS-1$
55

56     public static final int ACTION_MOVE = 0;
57
58     public static final int ACTION_COPY = 1;
59
60     public static final int ACTION_ACTIVATE = 2;
61
62     public static final int ACTION_DEACTIVATE = 3;
63
64     public static final int PASTETYPE_ABOVE = 0;
65
66     public static final int PASTETYPE_BELOW = 1;
67
68     public static final int PASTETYPE_SUB = 2;
69
70     public static final int PASTETYPE_LAST = 3;
71
72     /**
73      * Logger.
74      */

75     private static Logger log = Logger.getLogger(Tree.class);
76
77     private String JavaDoc repository;
78     
79     private String JavaDoc pathOpen;
80
81     private String JavaDoc pathCurrent;
82
83     private String JavaDoc pathSelected;
84
85     private int indentionWidth = 15;
86
87     private List JavaDoc itemTypes = new ArrayList JavaDoc();
88
89     private int height = 400;
90
91     private String JavaDoc iconPage = ICONDOCROOT + "document_plain_earth.gif"; //$NON-NLS-1$
92

93     private String JavaDoc iconContentNode = ICONDOCROOT + "cubes.gif"; //$NON-NLS-1$
94

95     private String JavaDoc iconNodeData = ICONDOCROOT + "cube_green.gif"; //$NON-NLS-1$
96

97     private String JavaDoc iconOndblclick;
98
99     private String JavaDoc shifterExpand = DOCROOT + "shifter_EXPAND.gif"; //$NON-NLS-1$
100

101     private String JavaDoc shifterCollaspe = DOCROOT + "shifter_COLLAPSE.gif"; //$NON-NLS-1$
102

103     private String JavaDoc shifterEmpty = DOCROOT + "shifter_EMPTY.gif"; //$NON-NLS-1$
104

105     private boolean drawShifter = true;
106
107     private String JavaDoc javascriptTree = "mgnlTreeControl"; //$NON-NLS-1$
108

109     private List JavaDoc columns = new ArrayList JavaDoc();
110
111     // private List menuItems = new ArrayList();
112
private ContextMenu menu;
113
114     private boolean snippetMode = true;
115
116     private String JavaDoc columnResizer = DOCROOT + "columnResizer.gif"; //$NON-NLS-1$
117

118     private boolean browseMode;
119
120     /**
121      * Constructor.
122      * @param name name of the tree (name of the treehandler)
123      * @param repository name of the repository (i.e. "website", "users")
124      * @param request
125      */

126     public Tree(String JavaDoc name, String JavaDoc repository, HttpServletRequest JavaDoc request) {
127         this.setName(name);
128         this.setRepository(repository);
129         this.setRequest(request);
130         this.setMenu(new ContextMenu(this.getJavascriptTree()));
131     }
132     
133     /**¬
134      * Constructor: the name of the tree is the same as the name of the repository
135      * @param repository
136      * @param request
137      * @deprecated use Tree(name, repository, request) instead
138      */

139     public Tree(String JavaDoc repository, HttpServletRequest JavaDoc request) {
140         this(repository, repository, request);
141     }
142     
143     
144
145     public void setRepository(String JavaDoc s) {
146         this.repository = s;
147     }
148
149     public String JavaDoc getRepository() {
150         return this.repository;
151     }
152
153     public void setPathOpen(String JavaDoc s) {
154         this.pathOpen = s;
155     }
156
157     public String JavaDoc getPathOpen() {
158         return this.pathOpen;
159     }
160
161     /**
162      * Sets which path will be selected (and opened - overwrites pathOpen).
163      * @param s
164      */

165     public void setPathSelected(String JavaDoc s) {
166         if (StringUtils.isNotEmpty(s)) {
167             this.setPathOpen(StringUtils.substringBeforeLast(s, "/")); //$NON-NLS-1$
168
}
169         this.pathSelected = s;
170     }
171
172     public String JavaDoc getPathSelected() {
173         return this.pathSelected;
174     }
175
176     public String JavaDoc getPath() {
177         if (super.getPath() != null) {
178             return super.getPath();
179         }
180
181         return ("/"); //$NON-NLS-1$
182
}
183
184     protected void setPathCurrent(String JavaDoc s) {
185         this.pathCurrent = s;
186     }
187
188     protected String JavaDoc getPathCurrent() {
189         return this.pathCurrent;
190     }
191
192     public void setIndentionWidth(int i) {
193         this.indentionWidth = i;
194     }
195
196     public int getIndentionWidth() {
197         return this.indentionWidth;
198     }
199
200     public List JavaDoc getItemTypes() {
201         return this.itemTypes;
202     }
203
204     /**
205      * Add a itemType to the itemTypes that will be shown in this branch.
206      * @param s itemType (one of: ItemType.NT_CONTENT, ItemType.NT_CONTENTNODE, ItemType.NT_NODEDATA)
207      */

208     public void addItemType(String JavaDoc s) {
209         this.itemTypes.add(s);
210     }
211
212     /**
213      * Add a itemType to the itemTypes that will be shown in this branch.
214      * @param s itemType (one of: ItemType.CONTENT, ItemType.CONTENTNODE)
215      */

216     public void addItemType(ItemType s) {
217         this.itemTypes.add(s.getSystemName());
218     }
219
220     /**
221      * Set the icon of pages.
222      * @param src source of the image
223      */

224     public void setIconPage(String JavaDoc src) {
225         this.iconPage = src;
226     }
227
228     public String JavaDoc getIconPage() {
229         return this.iconPage;
230     }
231
232     /**
233      * Set the icon of content nodes.
234      * @param src source of the image
235      */

236     public void setIconContentNode(String JavaDoc src) {
237         this.iconContentNode = src;
238     }
239
240     public String JavaDoc getIconContentNode() {
241         return this.iconContentNode;
242     }
243
244     /**
245      * Set the icon of node data.
246      * @param src source of the image
247      */

248     public void setIconNodeData(String JavaDoc src) {
249         this.iconNodeData = src;
250     }
251
252     public String JavaDoc getIconNodeData() {
253         return this.iconNodeData;
254     }
255
256     /**
257      * Set the double click event of the icon.
258      * @param s javascriopt method
259      */

260     public void setIconOndblclick(String JavaDoc s) {
261         this.iconOndblclick = s;
262     }
263
264     public String JavaDoc getIconOndblclick() {
265         return this.iconOndblclick;
266     }
267
268     /**
269      * Set the shifter image (expand branch). "_EXPAND" in file name will be replaced by "_COLLAPSE" after expanding
270      * e.g. myShifterIcon_EXPAND.gif
271      * @param src source of the image
272      */

273     public void setShifterExpand(String JavaDoc src) {
274         this.shifterExpand = src;
275     }
276
277     public String JavaDoc getShifterExpand() {
278         return this.shifterExpand;
279     }
280
281     /**
282      * Set the shifter image (collapse branch). "_COLLAPSE" in file name will be replaced by "_EXPAND" after collapsing
283      * e.g. myShifterIcon_COLLAPSE.gif
284      * @param src source of the image
285      */

286     public void setShifterCollapse(String JavaDoc src) {
287         this.shifterCollaspe = src;
288     }
289
290     public String JavaDoc getShifterCollapse() {
291         return this.shifterCollaspe;
292     }
293
294     /**
295      * Set the shifter image when no children are available (not expandable). "_EMPTY" in the file name will be replaced
296      * when children are available e.g. myShifterIcon_EMPTY.gif
297      * @param src source of the image
298      */

299     public void setShifterEmpty(String JavaDoc src) {
300         this.shifterEmpty = src;
301     }
302
303     public String JavaDoc getShifterEmpty() {
304         return this.shifterEmpty;
305     }
306
307     public void setDrawShifter(boolean b) {
308         this.drawShifter = b;
309     }
310
311     public boolean getDrawShifter() {
312         return this.drawShifter;
313     }
314
315     public void setHeight(int i) {
316         this.height = i;
317     }
318
319     public int getHeight() {
320         return this.height;
321     }
322
323     /**
324      * Set the columns (for pages and content nodes only).
325      * @param al list of TreeColumns
326      */

327     public void setColums(List JavaDoc al) {
328         this.columns = al;
329     }
330
331     public List JavaDoc getColumns() {
332         return this.columns;
333     }
334
335     public TreeColumn getColumns(int col) {
336         return (TreeColumn) this.getColumns().get(col);
337     }
338
339     public void addColumn(TreeColumn tc) {
340         this.getColumns().add(tc);
341     }
342
343     /**
344      * Set the name of the javascript tree object.
345      * @param variableName
346      */

347     public void setJavascriptTree(String JavaDoc variableName) {
348         this.javascriptTree = variableName;
349         this.menu.setName(variableName + "Menu"); //$NON-NLS-1$
350
}
351
352     public String JavaDoc getJavascriptTree() {
353         return this.javascriptTree;
354     }
355
356     /**
357      * Sets if only a snippet (requested branch) shall be returnde or including the surounding html (tree header, js/css
358      * links etc).
359      * @param b true: snippet only
360      */

361     public void setSnippetMode(boolean b) {
362         this.snippetMode = b;
363     }
364
365     public boolean getSnippetMode() {
366         return this.snippetMode;
367     }
368
369     // @todo: set size of column resizer gif and pass it to js object
370
public void setColumnResizer(String JavaDoc src) {
371         this.columnResizer = src;
372     }
373
374     public String JavaDoc getColumnResizer() {
375         return this.columnResizer;
376     }
377
378     public void deleteNode(String JavaDoc parentPath, String JavaDoc label) {
379         try {
380             HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository() );
381             Content parentNode = hm.getContent(parentPath);
382             String JavaDoc path;
383             if (!parentPath.equals("/")) { //$NON-NLS-1$
384
path = parentPath + "/" + label; //$NON-NLS-1$
385
}
386             else {
387                 path = "/" + label; //$NON-NLS-1$
388
}
389             this.deActivateNode(path);
390             parentNode.delete(label);
391             parentNode.save();
392         }
393         catch (Exception JavaDoc e) {
394             log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
395
}
396     }
397
398     public void deleteNode(String JavaDoc path) {
399         try {
400             String JavaDoc parentPath = StringUtils.substringBeforeLast(path, "/"); //$NON-NLS-1$
401
String JavaDoc label = StringUtils.substringAfterLast(path, "/"); //$NON-NLS-1$
402
deleteNode(parentPath, label);
403         }
404         catch (Exception JavaDoc e) {
405             log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
406
}
407     }
408
409     public void createNode(String JavaDoc itemType) {
410         this.createNode("untitled", itemType); //$NON-NLS-1$
411
}
412
413     public void createNode(String JavaDoc label, String JavaDoc itemType) {
414         try {
415             HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository());
416             Content parentNode = hm.getContent(this.getPath());
417             String JavaDoc slash = "/"; //$NON-NLS-1$
418
boolean isRoot = false;
419             if (this.getPath().equals("/")) { //$NON-NLS-1$
420
isRoot = true;
421                 slash = StringUtils.EMPTY;
422             }
423             if (hm.isExist(this.getPath() + slash + label)) {
424                 // todo: bugfix getUniqueLabel???
425
if (!isRoot) {
426                     label = Path.getUniqueLabel(hm, this.getPath(), label);
427                 }
428                 else {
429                     label = Path.getUniqueLabel(hm, StringUtils.EMPTY, label);
430                 }
431             }
432             if (itemType.equals(ItemType.NT_NODEDATA)) {
433                 parentNode.createNodeData(label);
434             }
435             else {
436                 Content newNode;
437                 if (itemType.equals(ItemType.CONTENT.getSystemName())) {
438                     newNode = parentNode.createContent(label);
439                 }
440                 else {
441                     newNode = parentNode.createContent(label, ItemType.CONTENTNODE);
442                 }
443                 newNode.getMetaData().setAuthorId(Authenticator.getUserId(this.getRequest()));
444                 newNode.getMetaData().setCreationDate();
445                 newNode.getMetaData().setModificationDate();
446                 newNode.getMetaData().setSequencePosition();
447                 // todo: default template
448
// now tmp: first template of list is taken...
449
if (this.getRepository().equals(ContentRepository.WEBSITE)
450                     && itemType.equals(ItemType.CONTENT.getSystemName())) {
451                     Iterator JavaDoc templates = Template.getAvailableTemplates(SessionAccessControl.getAccessManager(this
452                         .getRequest(), ContentRepository.CONFIG));
453                     while (templates.hasNext()) {
454                         Template template = (Template) templates.next();
455                         newNode.getMetaData().setTemplate(template.getName());
456                         break;
457                     }
458                 }
459             }
460             parentNode.save();
461         }
462         catch (Exception JavaDoc e) {
463             log.error(e.getMessage(), e);
464         }
465     }
466
467     public String JavaDoc saveNodeData(String JavaDoc nodeDataName, String JavaDoc value, boolean isMeta) {
468         String JavaDoc returnValue = StringUtils.EMPTY;
469         try {
470             HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository() );
471             Content page = hm.getContent(this.getPath());
472             if (!isMeta) {
473                 NodeData node;
474                 int type = PropertyType.STRING;
475                 if (!page.getNodeData(nodeDataName).isExist()) {
476                     node = page.createNodeData(nodeDataName);
477                 }
478                 else {
479                     node = page.getNodeData(nodeDataName);
480                     type = node.getType();
481                 }
482                 // todo: share with Contorol.Save
483
switch (type) {
484                     case PropertyType.STRING:
485                         node.setValue(value);
486                         break;
487                     case PropertyType.BOOLEAN:
488                         if (value.equals("true")) { //$NON-NLS-1$
489
node.setValue(true);
490                         }
491                         else {
492                             node.setValue(false);
493                         }
494                         break;
495                     case PropertyType.DOUBLE:
496                         try {
497                             node.setValue(Double.valueOf(value).doubleValue());
498                         }
499                         catch (Exception JavaDoc e) {
500                             node.setValue(0);
501                         }
502                         break;
503                     case PropertyType.LONG:
504                         try {
505                             node.setValue(Long.valueOf(value).longValue());
506                         }
507                         catch (Exception JavaDoc e) {
508                             node.setValue(0);
509                         }
510                         break;
511                     case PropertyType.DATE:
512                         // todo
513
break;
514                 }
515                 page.updateMetaData(this.getRequest());
516                 page.save();
517                 returnValue = new NodeDataUtil(node).getValueString();
518             }
519             else {
520                 page.getMetaData().setProperty(nodeDataName, value);
521                 page.updateMetaData(this.getRequest());
522                 page.save();
523                 returnValue = new MetaDataUtil(page).getPropertyValueString(nodeDataName);
524             }
525         }
526         catch (Exception JavaDoc e) {
527             log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
528
}
529         return returnValue;
530     }
531
532     public String JavaDoc saveNodeDataType(String JavaDoc nodeDataName, int type) {
533         try {
534             HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository());
535             Content page = hm.getContent(this.getPath());
536             Value value = null;
537             if (page.getNodeData(nodeDataName).isExist()) {
538                 value = page.getNodeData(nodeDataName).getValue();
539                 page.deleteNodeData(nodeDataName);
540             }
541             NodeData node = page.createNodeData(nodeDataName);
542             if (value != null) {
543                 switch (type) {
544                     case PropertyType.STRING:
545                         node.setValue(value.getString());
546                         break;
547                     case PropertyType.BOOLEAN:
548                         if (value != null && value.getBoolean()) {
549                             node.setValue(true);
550                         }
551                         else {
552                             node.setValue(false);
553                         }
554                         break;
555                     case PropertyType.DOUBLE:
556                         try {
557                             node.setValue(value.getDouble());
558                         }
559                         catch (Exception JavaDoc e) {
560                             node.setValue(0);
561                         }
562                         break;
563                     case PropertyType.LONG:
564                         try {
565                             node.setValue(value.getLong());
566                         }
567                         catch (Exception JavaDoc e) {
568                             node.setValue(0);
569                         }
570                         break;
571                     case PropertyType.DATE:
572                         // todo
573
break;
574                 }
575             }
576             page.updateMetaData(this.getRequest());
577             page.save();
578             return PropertyType.nameFromValue(page.getNodeData(nodeDataName).getType());
579             // return PropertyType.nameFromValue(node.getType());
580
}
581         catch (Exception JavaDoc e) {
582             log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
583
}
584         return StringUtils.EMPTY;
585     }
586
587     public String JavaDoc pasteNode(String JavaDoc pathOrigin, String JavaDoc pathSelected, int pasteType, int action) {
588         // todo: proper doc
589
// todo: ??? generic -> RequestInterceptor.java
590
// move and copy of nodes works as copy/cut - paste (remaining of the very first prototype)
591
// "Copy node" copies a node to the "clipboard" (clipboard object of the js tree object)
592
// "Move node" copies a node to the "clipboard", setting clipboardMethod "cut"
593
// select a node after copy or cut triggers Tree.pasteNode
594
// action: clipboardMethod (copy or move)
595
// pasteType: above, below, last position, as sub node
596
boolean move = false;
597         if (action == ACTION_MOVE) {
598             move = true;
599         }
600         String JavaDoc label = StringUtils.substringAfterLast(pathOrigin, "/"); //$NON-NLS-1$
601
String JavaDoc slash = "/"; //$NON-NLS-1$
602
if (pathSelected.equals("/")) { //$NON-NLS-1$
603
slash = StringUtils.EMPTY;
604         }
605         String JavaDoc destination = pathSelected + slash + label;
606         if (pasteType == PASTETYPE_SUB && action != ACTION_COPY && destination.equals(pathOrigin)) {
607             // drag node to parent node: move to last position
608
pasteType = PASTETYPE_LAST;
609         }
610         if (pasteType == PASTETYPE_SUB) {
611             destination = pathSelected + slash + label;
612             Content touchedContent = this.copyMoveNode(pathOrigin, destination, move);
613             if (touchedContent == null) {
614                 return StringUtils.EMPTY;
615             }
616             return touchedContent.getHandle();
617
618         }
619         else if (pasteType == PASTETYPE_LAST) {
620             // LAST only available for sorting inside the same directory
621
try {
622                 HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository());
623                 Content touchedContent = hm.getContent(pathOrigin);
624                 touchedContent.getMetaData().setSequencePosition();
625                 return touchedContent.getHandle();
626             }
627             catch (RepositoryException re) {
628                 return StringUtils.EMPTY;
629             }
630         }
631         else {
632             try {
633                 HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository());
634                 // PASTETYPE_ABOVE | PASTETYPE_BELOW
635

636                 String JavaDoc pathSelectedParent = StringUtils.substringBeforeLast(pathSelected, "/"); //$NON-NLS-1$
637
String JavaDoc pathOriginParent = StringUtils.substringBeforeLast(pathOrigin, "/"); //$NON-NLS-1$
638
if (StringUtils.isEmpty(pathSelectedParent)) {
639                     slash = StringUtils.EMPTY;
640                     pathSelectedParent = "/"; //$NON-NLS-1$
641
}
642                 if (StringUtils.isEmpty(pathOriginParent)) {
643                     pathOriginParent = "/"; //$NON-NLS-1$
644
}
645                 Content touchedContent = null;
646                 // *
647
// (copy node) or (move node if source and destination differ in parent directory)
648
if (action == ACTION_COPY || !pathSelectedParent.equals(pathOriginParent)) {
649                     destination = pathSelectedParent + slash + label;
650                     touchedContent = this.copyMoveNode(pathOrigin, destination, move);
651                 }
652                 else {
653                     // sort only (move inside the same directory)
654
touchedContent = hm.getContent(pathOrigin);
655                 }
656                 Content parentContent = hm.getContent(pathSelectedParent);
657                 Content selectedContent = hm.getContent(pathSelected);
658
659                 // *
660
// set sequence position (average of selected and above resp. below)
661
// todo: !!!!!!!!
662
// how to find out type of node?
663

664                 String JavaDoc selectedType = ItemType.NT_NODEDATA;
665                 String JavaDoc touchedType = ItemType.NT_NODEDATA;
666                 Iterator JavaDoc it1 = parentContent.getChildren(ItemType.CONTENT, ContentHandler.SORT_BY_SEQUENCE).iterator();
667                 while (it1.hasNext()) {
668                     Content c = (Content) it1.next();
669                     if (c.getHandle().equals(selectedContent.getHandle())) {
670                         selectedType = ItemType.CONTENT.getSystemName();
671                     }
672                     if (c.getHandle().equals(touchedContent.getHandle())) {
673                         touchedType = ItemType.CONTENT.getSystemName();
674                     }
675                 }
676                 Iterator JavaDoc it2 = parentContent
677                     .getChildren(ItemType.CONTENTNODE, ContentHandler.SORT_BY_SEQUENCE)
678                     .iterator();
679                 while (it2.hasNext()) {
680                     Content c = (Content) it2.next();
681                     if (c.getHandle().equals(selectedContent.getHandle())) {
682                         selectedType = ItemType.CONTENTNODE.getSystemName();
683                     }
684                     if (c.getHandle().equals(touchedContent.getHandle())) {
685                         touchedType = ItemType.CONTENTNODE.getSystemName();
686                     }
687                 }
688                 if (touchedType.equals(ItemType.NT_NODEDATA)) {
689                     return StringUtils.EMPTY; // sorting not possible
690
}
691                 long posSelected = selectedContent.getMetaData().getSequencePosition();
692                 long posAbove = 0;
693                 long posBelow = 0;
694                 long posFirst = 0;
695                 Iterator JavaDoc it = parentContent.getChildren(touchedType, ContentHandler.SORT_BY_SEQUENCE).iterator();
696                 boolean first = true;
697                 while (it.hasNext()) {
698                     Content c = (Content) it.next();
699                     if (first) {
700                         posFirst = c.getMetaData().getSequencePosition();
701                         first = false;
702                     }
703                     if (c.getHandle().equals(selectedContent.getHandle())) {
704                         if (it.hasNext()) {
705                             Content nextC = (Content) it.next();
706                             posBelow = nextC.getMetaData().getSequencePosition();
707                         }
708                         break;
709                     }
710
711                     posAbove = c.getMetaData().getSequencePosition();
712
713                 }
714                 if (!touchedType.equals(selectedType)) {
715                     if (touchedType.equals(ItemType.CONTENTNODE.getSystemName())
716                         && selectedType.equals(ItemType.CONTENT.getSystemName())) {
717                         // move at first position
718
// (tried to move a content node around a page)
719
pasteType = PASTETYPE_ABOVE;
720                         posAbove = posFirst;
721                     }
722                     else {
723                         // move to last position
724
// (tried to move a page around a content node or node data
725
// tried to move a content around a node data
726
pasteType = PASTETYPE_BELOW;
727                         posBelow = 0;
728                     }
729                 }
730                 long posTouched;
731                 if (pasteType == PASTETYPE_ABOVE) {
732                     if (posAbove == 0) {
733                         posTouched = posSelected - (MetaData.SEQUENCE_POS_COEFFICIENT * 1000); // first position in
734
}
735                     // directory ->
736
// 1000*coefficient
737
// above first
738
else {
739                         posTouched = (posAbove + posSelected) / 2;
740                     }
741                 }
742                 else {
743                     if (posBelow == 0) {
744                         posTouched = 0; // last position in directory -> timestamp (passing 0)
745
}
746                     else {
747                         posTouched = (posBelow + posSelected) / 2;
748                     }
749                 }
750                 touchedContent.getMetaData().setSequencePosition(posTouched);
751                 touchedContent.updateMetaData(this.getRequest());
752                 touchedContent.save();
753                 return touchedContent.getHandle();
754             }
755             catch (RepositoryException re) {
756                 return StringUtils.EMPTY;
757             }
758         }
759     }
760
761     public Content copyMoveNode(String JavaDoc source, String JavaDoc destination, boolean move) {
762         // todo: ??? generic -> RequestInterceptor.java
763
try {
764             HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository());
765             if (hm.isExist(destination)) {
766                 String JavaDoc parentPath = StringUtils.substringBeforeLast(destination, "/"); //$NON-NLS-1$
767
String JavaDoc label = StringUtils.substringAfterLast(destination, "/"); //$NON-NLS-1$
768
label = Path.getUniqueLabel(hm, parentPath, label);
769                 destination = parentPath + "/" + label; //$NON-NLS-1$
770
}
771             if (move) {
772                 if (destination.indexOf(source + "/") == 0) { //$NON-NLS-1$
773
// todo: disable this possibility in javascript
774
// move source into destinatin not possible
775
return null;
776                 }
777                 this.deActivateNode(source);
778                 try {
779                     hm.moveTo(source, destination);
780                 }
781                 catch (Exception JavaDoc e) {
782                     // try to move below node data
783
return null;
784                 }
785             }
786             else {
787                 // copy
788
hm.copyTo(source, destination);
789             }
790             SessionAccessControl.invalidateUser(this.getRequest());
791             Content newContent = hm.getContent(destination);
792             try {
793                 newContent.updateMetaData(this.getRequest());
794                 newContent.getMetaData().setSequencePosition();
795                 newContent.getMetaData(MetaData.ACTIVATION_INFO).setUnActivated();
796             }
797             catch (Exception JavaDoc e) {
798                 log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
799
}
800             newContent.save();
801             return newContent;
802         }
803         catch (Exception JavaDoc e) {
804             log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
805
}
806         return null;
807     }
808
809     public void moveNode(String JavaDoc source, String JavaDoc destination) {
810         this.copyMoveNode(source, destination, true);
811     }
812
813     public void copyNode(String JavaDoc source, String JavaDoc destination) {
814         this.copyMoveNode(source, destination, false);
815     }
816
817     public String JavaDoc renameNode(String JavaDoc newLabel) {
818         String JavaDoc returnValue = StringUtils.EMPTY;
819         try {
820             HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository());
821             String JavaDoc parentPath = StringUtils.substringBeforeLast(this.getPath(), "/"); //$NON-NLS-1$
822
newLabel = Path.getValidatedLabel(newLabel);
823             String JavaDoc dest = parentPath + "/" + newLabel; //$NON-NLS-1$
824
if (hm.isExist(dest)) {
825                 newLabel = Path.getUniqueLabel(hm, parentPath, newLabel);
826                 dest = parentPath + "/" + newLabel; //$NON-NLS-1$
827
}
828
829             this.deActivateNode(this.getPath());
830
831             if (log.isInfoEnabled()) {
832                 log.info("Moving node from " + this.getPath() + " to " + dest); //$NON-NLS-1$ //$NON-NLS-2$
833
}
834             if (hm.isNodeData(this.getPath())) {
835                 Content parentPage = hm.getContent(parentPath);
836                 NodeData newNodeData = parentPage.createNodeData(newLabel);
837                 NodeData existingNodeData = hm.getNodeData(this.getPath());
838                 newNodeData.setValue(existingNodeData.getString());
839                 existingNodeData.delete();
840                 dest = parentPath;
841             }
842             else {
843                 // we can't rename a node. we must move
844
// we must place the node at the same position
845
Content current = hm.getContent(this.getPath());
846                 Content parent = current.getParent();
847                 String JavaDoc placedBefore = null;
848                 for (Iterator JavaDoc iter = parent.getChildren(current.getNodeType().getName()).iterator(); iter.hasNext();) {
849                     Content child = (Content) iter.next();
850                     if (child.getHandle().equals(this.getPath())) {
851                         if (iter.hasNext()) {
852                             child = (Content) iter.next();
853                             placedBefore = child.getName();
854                         }
855                     }
856                 }
857
858                 hm.moveTo(this.getPath(), dest);
859
860                 // now set at the same place as before
861
if (placedBefore != null) {
862                     parent.orderBefore(newLabel, placedBefore);
863                 }
864             }
865             SessionAccessControl.invalidateUser(this.getRequest());
866             Content newPage = hm.getContent(dest);
867             returnValue = newLabel;
868             newPage.updateMetaData(this.getRequest());
869             newPage.save();
870         }
871         catch (Exception JavaDoc e) {
872             log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
873
}
874         return returnValue;
875     }
876
877     public void activateNode(String JavaDoc path, boolean recursive) {
878         // todo: ??? generic -> RequestInterceptor.java
879
try {
880             HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository());
881             Content c = null;
882             if (hm.isPage(path)) {
883                 c = hm.getContent(path);
884             }
885             else {
886                 c = hm.getContent(path);
887             }
888             Syndicator syndicator = new Syndicator(this.getRequest());
889             if (recursive) {
890                 deepActivate(syndicator, c, hm);
891             }
892             else {
893                 syndicator.activate(this.getRepository(), StringUtils.EMPTY, path, recursive);
894             }
895         }
896         catch (Exception JavaDoc e) {
897             log.error(e.getMessage(), e);
898         }
899     }
900
901     private void deepActivate(Syndicator syndicator, Content content, HierarchyManager hm) {
902         try {
903             syndicator.activate(this.getRepository(), StringUtils.EMPTY, content.getHandle(), false);
904             Collection JavaDoc children = content.getChildren();
905             if (children != null) {
906                 Iterator JavaDoc it = children.iterator();
907                 while (it.hasNext()) {
908                     deepActivate(syndicator, (Content) it.next(), hm);
909                 }
910             }
911         }
912         catch (Exception JavaDoc e) {
913             log.error(e.getMessage(), e);
914         }
915     }
916
917     public void deActivateNode(String JavaDoc path) {
918         try {
919             Syndicator syndicator = new Syndicator(this.getRequest());
920             syndicator.deActivate(this.getRepository(), path);
921         }
922         catch (Exception JavaDoc e) {
923             log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
924
}
925     }
926
927     public String JavaDoc getHtml() {
928         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
929         if (!this.getSnippetMode()) {
930             html.append(this.getHtmlHeader());
931         }
932         this.setPathCurrent(this.getPath());
933         html.append(this.getHtmlChildren());
934         if (!this.getSnippetMode()) {
935             html.append(this.getHtmlFooter());
936         }
937         return html.toString();
938     }
939
940     public String JavaDoc getHtmlHeader() {
941
942         StringBuffer JavaDoc html = new StringBuffer JavaDoc();
943
944         // write css definitions
945
// @todo style is not valid in body!
946
html.append("<style type=\"text/css\">"); //$NON-NLS-1$
947
int numberOfColumns = this.getColumns().size();
948         if (numberOfColumns == 0) {
949             numberOfColumns = 1;
950         }
951         for (int i = 0; i < numberOfColumns; i++) {
952             html.append("." + this.getJavascriptTree() + "CssClassColumn" + i); //$NON-NLS-1$ //$NON-NLS-2$
953
html.append("\n{position:absolute;left:0px;clip:rect(0 0 100 0);cursor:default;}\n"); //$NON-NLS-1$
954
}
955         html.append("</style>\n\n"); //$NON-NLS-1$
956

957         // resizer
958
html.append("<div id=\"" //$NON-NLS-1$
959
+ this.getJavascriptTree() + "_ColumnResizerDiv\" style=\"position:absolute;top:-50px;z-index:500;\">"); //$NON-NLS-1$
960
for (int i = 1; i < this.getColumns().size(); i++) {
961             // div around image: ie and safari do not allow drag of images
962
// todo: fix bad behaviour in mozilla: resizer "turns blue" when selecting
963
html.append("<div onmousedown=\"" //$NON-NLS-1$
964
+ this.getJavascriptTree() + ".dragColumnStart(this," //$NON-NLS-1$
965
+ i + ");\" id=\"" //$NON-NLS-1$
966
+ this.getJavascriptTree() + "ColumnResizer" //$NON-NLS-1$
967
+ i + "\" style=\"position:relative;left:-1000px;background-image:url(" //$NON-NLS-1$
968
+ this.getRequest().getContextPath() + this.getColumnResizer() + ");display:inline;\">"); //$NON-NLS-1$
969
// use resizer gif to get exact size
970
html.append("<img SRC=\"" //$NON-NLS-1$
971
+ this.getRequest().getContextPath()
972                 + this.getColumnResizer()
973                 + "\" alt=\"\" style=\"visibility:hidden;\" />"); //$NON-NLS-1$
974
html.append("</div>"); //$NON-NLS-1$
975
}
976         html.append("</div>"); //$NON-NLS-1$
977
// column header
978
html.append("<div id=\"" //$NON-NLS-1$
979
+ this.getJavascriptTree() + "_ColumnHeader\" style=\"position:absolute;top:-50px;z-index:480;\">"); //$NON-NLS-1$
980
for (int i = 0; i < this.getColumns().size(); i++) {
981             TreeColumn tc = this.getColumns(i);
982             html.append("<span class=\"mgnlTreeColumn " //$NON-NLS-1$
983
+ this.getJavascriptTree() + "CssClassColumn" //$NON-NLS-1$
984
+ i + "\"><span class=\"mgnlTreeHeader\">" //$NON-NLS-1$
985
+ tc.getTitle() + "<!-- ie --></span></span>"); //$NON-NLS-1$
986
}
987         html.append("</div>"); //$NON-NLS-1$
988

989         html.append("<div id=\"" //$NON-NLS-1$
990
+ this.getJavascriptTree()
991             + "_ColumnResizerLine\" style=\"position:absolute;top:0px;left:-100px;visibility:hidden;width:1px;height:" //$NON-NLS-1$
992
+ this.getHeight()
993             + "px;background-color:#333333;z-index:490;\"></div>"); //$NON-NLS-1$
994
html.append("<div id=\"" //$NON-NLS-1$
995
+ this.getJavascriptTree() + "_" //$NON-NLS-1$
996
+ this.getPath() + "_DivMain\" onclick=\"" //$NON-NLS-1$
997
+ this.getJavascriptTree() + ".mainDivReset();\" oncontextmenu=\"" //$NON-NLS-1$
998
+ this.getJavascriptTree() + ".menuShow(event);return false;\" class=\"mgnlTreeDiv\" style=\"height:" //$NON-NLS-1$
999
+ this.getHeight() + "px;\">"); //$NON-NLS-1$
1000
html.append(Spacer.getHtml(8, 8));
1001        // html.append("<div id=\""+this.getJavascriptTree()+"_"+this.getPath()+"_DivSub\" style=\"display:none;\">";
1002
html.append("<div id=\"" + this.getJavascriptTree() + "_" + this.getPath() + "_DivSub\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1003
return html.toString();
1004    }
1005
1006    public String JavaDoc getHtmlFooter() {
1007        StringBuffer JavaDoc html = new StringBuffer JavaDoc();
1008        html.append("</div>"); //$NON-NLS-1$
1009
boolean permissionWrite = true;
1010        try {
1011            HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository());
1012            Content root = hm.getContent(this.getPath());
1013            permissionWrite = root.isGranted(info.magnolia.cms.security.Permission.WRITE);
1014        }
1015        catch (RepositoryException e) {
1016            log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
1017
}
1018
1019        // lineInter: line between nodes, to allow set cursor between nodes
1020
// line to place a very last position
1021
String JavaDoc lineId = this.getJavascriptTree() + "_" + this.getPath() + "_LineInter"; //$NON-NLS-1$ //$NON-NLS-2$
1022

1023        html.append("<div id=\"" //$NON-NLS-1$
1024
+ lineId + "\" class=\"mgnlTreeLineInter mgnlLineEnabled\" onmouseover=\"" //$NON-NLS-1$
1025
+ this.javascriptTree + ".moveNodeHighlightLine('" //$NON-NLS-1$
1026
+ lineId + "');\" onmouseout=\"" //$NON-NLS-1$
1027
+ this.javascriptTree + ".moveNodeResetLine('" //$NON-NLS-1$
1028
+ lineId + "');\" onmousedown=\"" //$NON-NLS-1$
1029
+ this.javascriptTree + ".pasteNode('" //$NON-NLS-1$
1030
+ this.getPath() + "'," //$NON-NLS-1$
1031
+ Tree.PASTETYPE_SUB + "," //$NON-NLS-1$
1032
+ Boolean.toString(permissionWrite) + ",'" //$NON-NLS-1$
1033
+ lineId + "');\" ></div>"); //$NON-NLS-1$
1034

1035        html.append(new Hidden(this.getJavascriptTree() + "_" + this.getPath() + "_PermissionWrite", Boolean //$NON-NLS-1$ //$NON-NLS-2$
1036
.toString(permissionWrite), false).getHtml());
1037        html.append("</div>"); //$NON-NLS-1$
1038
// address bar
1039
String JavaDoc pathOpen = this.getPathOpen();
1040        if (pathOpen == null) {
1041            pathOpen = StringUtils.EMPTY;
1042        }
1043
1044        html.append(Spacer.getHtml(3, 3));
1045        html.append("\n\n\n\n\n\n\n\n<input id=\"" //$NON-NLS-1$
1046
+ this.getJavascriptTree()
1047            + "AddressBar\" type=\"text\" onkeydown=\"if (mgnlIsKeyEnter(event)) " //$NON-NLS-1$
1048
+ this.getJavascriptTree()
1049            + ".expandNode(this.value);\" class=\"mgnlDialogControlEdit\" style=\"width:100%;\" value=\"" //$NON-NLS-1$
1050
+ pathOpen
1051            + "\" />\n\n\n\n"); //$NON-NLS-1$
1052

1053        // shadow for moving pages
1054
html.append("<div id=\""); //$NON-NLS-1$
1055
html.append(this.getJavascriptTree());
1056        html.append("_MoveShadow\" "); //$NON-NLS-1$
1057
html.append("style=\"position:absolute;top:0px;left:0px;visibility:hidden;background-color:#fff;\"></div>"); //$NON-NLS-1$
1058

1059        // "move denied"
1060
html.append("<img SRC=\"" //$NON-NLS-1$
1061
+ this.getRequest().getContextPath()
1062            + Tree.DOCROOT
1063            + "move_denied.gif\" id=\"" //$NON-NLS-1$
1064
+ this.getJavascriptTree()
1065            + "_MoveDenied\" style=\"position:absolute;top:0px;left:0px;visibility:hidden;\" />"); //$NON-NLS-1$
1066
// initialize js tree object
1067
html.append("<script type=\"text/javascript\">"); //$NON-NLS-1$
1068
html.append("var " //$NON-NLS-1$
1069
+ this.getJavascriptTree() + "=new mgnlTree('" //$NON-NLS-1$
1070
+ this.getRepository() + "','" //$NON-NLS-1$
1071
+ this.getPath() + "','" //$NON-NLS-1$
1072
+ this.getJavascriptTree() + "'," //$NON-NLS-1$
1073
+ this.getHeight() + "," //$NON-NLS-1$
1074
+ "'" + this.getName() + "',"
1075            + this.isBrowseMode() + ");"); //$NON-NLS-1$
1076

1077        // add columns to tree object
1078
for (int i = 0; i < this.getColumns().size(); i++) {
1079            TreeColumn tc = this.getColumns(i);
1080            html.append(this.getJavascriptTree() + ".columns[" //$NON-NLS-1$
1081
+ i + "]=new mgnlTreeColumn(" //$NON-NLS-1$
1082
+ tc.getWidth() + ",'" //$NON-NLS-1$
1083
+ tc.getHtmlEdit() + "','" //$NON-NLS-1$
1084
+ tc.getName() + "'," //$NON-NLS-1$
1085
+ tc.getIsMeta() + "," //$NON-NLS-1$
1086
+ tc.getIsLabel() + "," //$NON-NLS-1$
1087
+ tc.getIsNodeDataValue() + "," //$NON-NLS-1$
1088
+ tc.getIsNodeDataType() + ");"); //$NON-NLS-1$
1089
}
1090        html.append("mgnlTreeControls['" + this.getJavascriptTree() + "']=" + this.getJavascriptTree() + ";\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1091
// js is not run on remote request
1092
html.append(this.getJavascriptTree() + ".selectNode('" + this.getPathSelected() + "');"); //$NON-NLS-1$ //$NON-NLS-2$
1093
html.append("</script>"); //$NON-NLS-1$
1094

1095        // contextmenu
1096
if (menu.getMenuItems().size() != 0) {
1097            html.append(menu.getHtml());
1098        }
1099
1100        // register menu
1101
html.append("<script>" + this.getJavascriptTree() + ".menu = " + menu.getName() + "</script>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1102

1103        return html.toString();
1104    }
1105
1106    public String JavaDoc getHtmlBranch() {
1107        return StringUtils.EMPTY;
1108    }
1109
1110    public String JavaDoc getHtmlChildren() {
1111        StringBuffer JavaDoc html = new StringBuffer JavaDoc();
1112        HierarchyManager hm = SessionAccessControl.getHierarchyManager(this.getRequest(), this.getRepository());
1113        Content parentNode = null;
1114        try {
1115            parentNode = hm.getContent(this.getPathCurrent());
1116            // loop the children of the different item types
1117
for (int i = 0; i < this.getItemTypes().size(); i++) {
1118                String JavaDoc type = (String JavaDoc) this.getItemTypes().get(i);
1119                html.append(this.getHtmlChildrenOfOneType(parentNode, type));
1120            }
1121        }
1122        catch (RepositoryException e) {
1123            log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
1124
}
1125        return html.toString();
1126    }
1127
1128    public String JavaDoc getHtmlChildrenOfOneType(Content parentNode, String JavaDoc itemType) {
1129        StringBuffer JavaDoc html = new StringBuffer JavaDoc();
1130        try {
1131            // todo: parentNode - level of this.getPath
1132
int left = (parentNode.getLevel()) * this.getIndentionWidth();
1133            Iterator JavaDoc it;
1134            if (itemType.equalsIgnoreCase(ItemType.NT_NODEDATA)) {
1135                it = parentNode.getNodeDataCollection().iterator();
1136            }
1137            else {
1138                it = parentNode.getChildren(itemType, ContentHandler.SORT_BY_SEQUENCE).iterator();
1139            }
1140            while (it.hasNext()) {
1141                Object JavaDoc o = it.next();
1142                Content c = null;
1143                NodeData d = null;
1144                String JavaDoc handle = StringUtils.EMPTY;
1145                String JavaDoc name = StringUtils.EMPTY;
1146                boolean hasSub = false;
1147                boolean showSub = false;
1148                boolean isActivated = false;
1149                boolean permissionWrite = false;
1150                boolean permissionWriteParent = false;
1151                if (itemType.equals(ItemType.NT_NODEDATA)) {
1152                    d = (NodeData) o;
1153                    handle = d.getHandle();
1154                    name = d.getName();
1155
1156                    if (d.isGranted(info.magnolia.cms.security.Permission.WRITE)) {
1157                        permissionWrite = true;
1158                    }
1159                }
1160                else {
1161                    c = (Content) o;
1162
1163                    handle = c.getHandle();
1164                    if (this.getColumns().size() == 0) {
1165                        name = c.getName();
1166                    }
1167                    else {
1168                        this.getColumns(0).setWebsiteNode(c);
1169                        name = this.getColumns(0).getHtml();
1170                    }
1171                    if (c.isGranted(info.magnolia.cms.security.Permission.WRITE)) {
1172                        permissionWrite = true;
1173                    }
1174                    if (c.getAncestor(c.getLevel() - 1).isGranted(info.magnolia.cms.security.Permission.WRITE)) {
1175                        permissionWriteParent = true;
1176                    }
1177                    isActivated = c.getMetaData(MetaData.ACTIVATION_INFO).getIsActivated();
1178                    for (int i = 0; i < this.getItemTypes().size(); i++) {
1179                        String JavaDoc type = (String JavaDoc) this.getItemTypes().get(i);
1180                        int size = 0;
1181                        if (type.equalsIgnoreCase(ItemType.NT_NODEDATA)) {
1182                            size = c.getNodeDataCollection().size();
1183                        }
1184                        else {
1185                            size = c.getChildren(type).size();
1186                        }
1187                        if (size > 0) {
1188                            hasSub = true;
1189                            if (this.getPathOpen() != null
1190                                && (this.getPathOpen().indexOf(handle + "/") == 0 || this.getPathOpen().equals(handle))) { //$NON-NLS-1$
1191
showSub = true;
1192                            }
1193                            break;
1194                        }
1195                    }
1196                }
1197                
1198                // get next if this node is not shown
1199
if(!showNode(c, d, itemType)){
1200                    continue;
1201                }
1202                
1203                String JavaDoc icon = getIcon(c, d, itemType);
1204                
1205                String JavaDoc idPre = this.javascriptTree + "_" + handle; //$NON-NLS-1$
1206
String JavaDoc jsHighlightNode = this.javascriptTree + ".nodeHighlight(this,'" //$NON-NLS-1$
1207
+ handle + "'," //$NON-NLS-1$
1208
+ Boolean.toString(permissionWrite) + ");"; //$NON-NLS-1$
1209
String JavaDoc jsResetNode = this.javascriptTree + ".nodeReset(this,'" + handle + "');"; //$NON-NLS-1$ //$NON-NLS-2$
1210
String JavaDoc jsSelectNode = this.javascriptTree + ".selectNode('" //$NON-NLS-1$
1211
+ handle + "'," //$NON-NLS-1$
1212
+ Boolean.toString(permissionWrite) + ",'" //$NON-NLS-1$
1213
+ itemType + "');"; //$NON-NLS-1$
1214
String JavaDoc jsExpandNode;
1215                if (this.getDrawShifter()) {
1216                    jsExpandNode = this.javascriptTree + ".expandNode('" + handle + "');"; //$NON-NLS-1$ //$NON-NLS-2$
1217
}
1218                else {
1219                    jsExpandNode = jsSelectNode;
1220                }
1221                String JavaDoc jsHighlightLine = this.javascriptTree + ".moveNodeHighlightLine('" + idPre + "_LineInter');"; //$NON-NLS-1$ //$NON-NLS-2$
1222
String JavaDoc jsResetLine = this.javascriptTree + ".moveNodeResetLine('" + idPre + "_LineInter');"; //$NON-NLS-1$ //$NON-NLS-2$
1223

1224                int maskWidth = left;
1225                if (maskWidth < 1) {
1226                    maskWidth = 1;
1227                }
1228
1229                // lineInter: line between nodes, to allow set cursor between nodes
1230
// try to avoid blank images, setting js actions on divs should be ok
1231
if (permissionWriteParent) {
1232                    html.append("<div id=\"" //$NON-NLS-1$
1233
+ idPre + "_LineInter\" class=\"mgnlTreeLineInter mgnlLineEnabled\" onmouseover=\"" //$NON-NLS-1$
1234
+ jsHighlightLine + "\" onmouseout=\"" //$NON-NLS-1$
1235
+ jsResetLine + "\" onmousedown=\"" //$NON-NLS-1$
1236
+ this.javascriptTree + ".pasteNode('" //$NON-NLS-1$
1237
+ handle + "'," //$NON-NLS-1$
1238
+ Tree.PASTETYPE_ABOVE + ",true);\" ></div>"); //$NON-NLS-1$
1239
}
1240                else {
1241                    html.append("<div id=\"" //$NON-NLS-1$
1242
+ idPre + "_LineInter\" class=\"mgnlTreeLineInter mgnlLineDisabled\"></div>"); //$NON-NLS-1$
1243
}
1244
1245                html.append("<div id=\"" //$NON-NLS-1$
1246
+ idPre + "_DivMain\" style=\"position:relative;top:0;left:0;width:100%;height:18px;\">"); //$NON-NLS-1$
1247
html.append("&nbsp;"); // do not remove! //$NON-NLS-1$
1248
int paddingLeft = left;
1249                if (paddingLeft < 0) {
1250                    paddingLeft = 0;
1251                }
1252                html.append("<span id=\"" //$NON-NLS-1$
1253
+ idPre + "_Column0Outer\" class=\"mgnlTreeColumn " //$NON-NLS-1$
1254
+ this.javascriptTree + "CssClassColumn0\" style=\"padding-left:" //$NON-NLS-1$
1255
+ paddingLeft + "px;\">"); //$NON-NLS-1$
1256
if (this.getDrawShifter()) {
1257                    String JavaDoc shifter = StringUtils.EMPTY;
1258                    if (hasSub) {
1259                        if (showSub) {
1260                            if (this.getShifterCollapse() != null) {
1261                                shifter = this.getShifterCollapse();
1262                            }
1263                        }
1264                        else {
1265                            if (this.getShifterExpand() != null) {
1266                                shifter = this.getShifterExpand();
1267                            }
1268                        }
1269                    }
1270                    else {
1271                        if (this.getShifterEmpty() != null) {
1272                            shifter = this.getShifterEmpty();
1273                        }
1274                    }
1275                    if (StringUtils.isNotEmpty(shifter)) {
1276                        html.append("<img id=\"" //$NON-NLS-1$
1277
+ idPre + "_Shifter\" onmousedown=\"" //$NON-NLS-1$
1278
+ this.javascriptTree + ".shifterDown('" //$NON-NLS-1$
1279
+ handle + "');\" onmouseout=\"" //$NON-NLS-1$
1280
+ this.javascriptTree + ".shifterOut();\" class=\"mgnlTreeShifter\" SRC=\"" //$NON-NLS-1$
1281
+ this.getRequest().getContextPath() + shifter + "\" />"); //$NON-NLS-1$
1282
}
1283                }
1284                html.append("<span id=" //$NON-NLS-1$
1285
+ idPre + "_Name onmouseover=\"" //$NON-NLS-1$
1286
+ jsHighlightNode + "\" onmouseout=\"" //$NON-NLS-1$
1287
+ jsResetNode + "\" onmousedown=\"" //$NON-NLS-1$
1288
+ jsSelectNode + this.javascriptTree + ".pasteNode('" //$NON-NLS-1$
1289
+ handle + "'," //$NON-NLS-1$
1290
+ Tree.PASTETYPE_SUB + "," //$NON-NLS-1$
1291
+ permissionWrite + ");\">"); //$NON-NLS-1$
1292
if (StringUtils.isNotEmpty(icon)) {
1293                    html.append("<img id=\"" //$NON-NLS-1$
1294
+ idPre + "_Icon\" class=\"mgnlTreeIcon\" SRC=\"" //$NON-NLS-1$
1295
+ this.getRequest().getContextPath() + icon + "\" onmousedown=\"" //$NON-NLS-1$
1296
+ jsExpandNode + "\""); //$NON-NLS-1$
1297
if (this.getIconOndblclick() != null) {
1298                        html.append(" ondblclick=\"" + this.getIconOndblclick() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
1299
}
1300                    html.append(" />"); //$NON-NLS-1$
1301
}
1302                String JavaDoc dblclick = StringUtils.EMPTY;
1303                if (permissionWrite && StringUtils.isNotEmpty(this.getColumns(0).getHtmlEdit())) {
1304                    dblclick = " ondblclick=\"" + this.javascriptTree + ".editNodeData(this,'" + handle + "',0);\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1305
}
1306                html.append("<span class=\"mgnlTreeText\" id=\"" + idPre + "_Column0Main\"" + dblclick + ">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1307
html.append(name);
1308                html.append("</span></span></span>"); //$NON-NLS-1$
1309
html.append(new Hidden(idPre + "_PermissionWrite", Boolean.toString(permissionWrite), false).getHtml()); //$NON-NLS-1$
1310
html.append(new Hidden(idPre + "_ItemType", itemType, false).getHtml()); //$NON-NLS-1$
1311
html.append(new Hidden(idPre + "_IsActivated", Boolean.toString(isActivated), false).getHtml()); //$NON-NLS-1$
1312
for (int i = 1; i < this.getColumns().size(); i++) {
1313                    String JavaDoc str = StringUtils.EMPTY;
1314                    TreeColumn tc = this.getColumns(i);
1315                    if (!itemType.equals(ItemType.NT_NODEDATA)) {
1316                        // content node ItemType.NT_CONTENTNODE and ItemType.NT_CONTENT
1317
if (!tc.getIsNodeDataType() && !tc.getIsNodeDataValue()) {
1318                            tc.setWebsiteNode(c);
1319                            tc.setId(handle);
1320                            str = tc.getHtml();
1321                        }
1322                    }
1323                    else {
1324                        NodeDataUtil util = new NodeDataUtil(d);
1325                        if (tc.getIsNodeDataType()) {
1326                            str = util.getTypeName(d.getType());
1327                        }
1328                        else if (tc.getIsNodeDataValue()) {
1329                            str = util.getValueString();
1330                        }
1331                        if (StringUtils.isEmpty(str)) {
1332                            str = TreeColumn.EMPTY;
1333                        }
1334                        tc.setName(name); // workaround, will be passed to js TreeColumn object
1335
}
1336                    tc.setEvent("onmouseover", jsHighlightNode, true); //$NON-NLS-1$
1337
tc.setEvent("onmouseout", jsResetNode, true); //$NON-NLS-1$
1338
tc.setEvent("onmousedown", jsSelectNode, true); //$NON-NLS-1$
1339
html.append("<span class=\"mgnlTreeColumn " //$NON-NLS-1$
1340
+ this.javascriptTree + "CssClassColumn" //$NON-NLS-1$
1341
+ i + "\"><span id=\"" //$NON-NLS-1$
1342
+ idPre + "_Column" //$NON-NLS-1$
1343
+ i + "Main\"" //$NON-NLS-1$
1344
+ tc.getHtmlCssClass() + tc.getHtmlEvents());
1345                    if (permissionWrite && StringUtils.isNotEmpty(tc.getHtmlEdit())) {
1346                        html.append(" ondblclick=\"" //$NON-NLS-1$
1347
+ this.javascriptTree + ".editNodeData(this,'" //$NON-NLS-1$
1348
+ handle + "'," //$NON-NLS-1$
1349
+ i + ");\""); //$NON-NLS-1$
1350
}
1351                    html.append(">" + str + "</span></span>"); //$NON-NLS-1$ //$NON-NLS-2$
1352
}
1353                html.append("</div>"); //$NON-NLS-1$
1354
String JavaDoc display = "none"; //$NON-NLS-1$
1355
if (showSub) {
1356                    display = "block"; //$NON-NLS-1$
1357
}
1358                html.append("<div id=\"" + idPre + "_DivSub\" style=\"display:" + display + ";\">"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1359
if (hasSub) {
1360                    if (showSub) {
1361                        String JavaDoc pathRemaining = this.getPathOpen().substring(this.getPathCurrent().length());
1362                        if (pathRemaining.length() > 0) {
1363                            // get rid of first slash (/people/franz -> people/franz)
1364
String JavaDoc slash = "/"; //$NON-NLS-1$
1365
if (this.getPathCurrent().equals("/")) { //$NON-NLS-1$
1366
// first slash already removed
1367
slash = StringUtils.EMPTY; // no slash needed between pathCurrent and nextChunk
1368
}
1369                            else {
1370                                pathRemaining = pathRemaining.substring(1);
1371                            }
1372                            String JavaDoc nextChunk = StringUtils.substringBefore(pathRemaining, "/"); //$NON-NLS-1$
1373

1374                            String JavaDoc pathNext = this.getPathCurrent() + slash + nextChunk;
1375                            this.setPathCurrent(pathNext);
1376                            html.append(this.getHtmlChildren());
1377                        }
1378                    }
1379                }
1380                html.append("</div>\n"); //$NON-NLS-1$
1381
}
1382        }
1383        catch (RepositoryException e) {
1384            log.debug("Exception caught: " + e.getMessage(), e); //$NON-NLS-1$
1385
}
1386        return html.toString();
1387    }
1388
1389
1390    /**
1391     * Override to make special exclusions. The current nodedata or node is passed.
1392     * @param node
1393     * @param nodedata
1394     * @param itemType
1395     * @return true if the node is shown
1396     */

1397    private boolean showNode(Content node, NodeData nodedata, String JavaDoc itemType) {
1398        return true;
1399    }
1400
1401    /**
1402     * The current nodedata or node is passed
1403     * @param nodedata can be null
1404     * @param node can be null
1405     * @param itemType
1406     * @return the icon
1407     */

1408    protected String JavaDoc getIcon(Content node, NodeData nodedata, String JavaDoc itemType) {
1409        String JavaDoc icon = null;
1410        if (itemType.equals(ItemType.CONTENT.getSystemName())) {
1411            icon = this.getIconPage();
1412        }
1413        else if (itemType.equals(ItemType.CONTENTNODE.getSystemName())) {
1414            icon = this.getIconContentNode();
1415        }
1416        else if (itemType.equals(ItemType.NT_NODEDATA)) {
1417            icon = this.getIconNodeData();
1418        }
1419        return icon;
1420    }
1421
1422    /**
1423     * @param menuNewFolder
1424     */

1425    public void addMenuItem(ContextMenuItem item) {
1426        menu.addMenuItem(item);
1427    }
1428
1429    /**
1430     * Add a separator line between menu items.
1431     */

1432    public void addSeparator() {
1433        menu.addMenuItem(null);
1434    }
1435
1436    protected ContextMenu getMenu() {
1437        return this.menu;
1438    }
1439
1440    protected void setMenu(ContextMenu menu) {
1441        this.menu = menu;
1442    }
1443
1444    
1445    /**
1446     * @return Returns the browseMode.
1447     */

1448    public boolean isBrowseMode() {
1449        return browseMode;
1450    }
1451
1452    
1453    /**
1454     * @param browseMode The browseMode to set.
1455     */

1456    public void setBrowseMode(boolean browseMode) {
1457        this.browseMode = browseMode;
1458    }
1459
1460}
1461
Popular Tags