1 package com.sri.emo.controller;
2
3 import com.jcorporate.expresso.core.controller.ErrorCollection;
4 import com.jcorporate.expresso.core.db.DBException;
5 import com.sri.emo.dbobj.Node;
6
7 /***
8 * @author Michael Rimov
9 * @version 1.0
10 */
11 public class NodeCloner {
12 final Node src;
13
14 final String title;
15
16 public NodeCloner(Node sourceNode, String newTitle) {
17 super();
18 src = sourceNode;
19 title = newTitle;
20 }
21
22 public Node cloneAsOrphan(final ErrorCollection validationErrors) throws DBException {
23 validate(validationErrors);
24 if (validationErrors.size() > 0) {
25 return null;
26 } else {
27 return src.cloneOrphan(title);
28 }
29 }
30
31 public Node cloneAsSibling(final ErrorCollection validationErrors) throws DBException {
32 validate(validationErrors);
33 if (validationErrors.size() > 0) {
34 return null;
35 } else {
36 return src.cloneSibling(title);
37 }
38 }
39
40
41 protected void validate(ErrorCollection toPopulate) throws DBException {
42
43 Node titleSearch = new Node();
44 titleSearch.setNodeTitle(title);
45
46 if (titleSearch.find()) {
47 toPopulate.addError("Duplicate title not allowed. Please choose something different.");
48 }
49
50 }
51
52
53 }