Source code: com/obinary/cms/core/ContainerList.java
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-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11 *
12 * */
13
14
15
16
17
18 package com.obinary.cms.core;
19
20
21 import com.obinary.cms.util.ChildrenCollector;
22
23 import javax.jcr.Node;
24 import javax.jcr.ElementNotFoundException;
25 import javax.jcr.RepositoryException;
26 import java.util.Collection;
27 import java.util.ArrayList;
28
29
30
31 /**
32 * User: sameercharles
33 * Date: Apr 20, 2003
34 * Time: 11:00:12 AM
35 * @author Sameer Charles
36 * @version 1.0
37 */
38
39
40 public class ContainerList extends Content {
41
42
43 private Node workingNode;
44 private String name;
45 private Content containerList;
46
47
48
49 /**
50 * constructor
51 */
52 ContainerList() {
53
54 }
55
56
57 /**
58 * Package private constructor, gets existing <code>ContainerList</code> object
59 *
60 * @param workingNode parent <code>Node</code>
61 * @param containerListName name to be assigned
62 * @throws ElementNotFoundException
63 * @throws RepositoryException
64 */
65 ContainerList (Node workingNode, String containerListName) throws ElementNotFoundException, RepositoryException {
66 this.workingNode = workingNode;
67 this.name = containerListName;
68 this.containerList = new Content(this.workingNode, this.name);
69 this.node = this.containerList.node;
70 }
71
72
73
74 /**
75 * Package private constructor, creates new <code>ContainerList</code> object
76 *
77 * @param workingNode parent <code>Node</code>
78 * @param containerListName name to be assigned
79 * @param createNew creates a new container list
80 * @throws ElementNotFoundException
81 * @throws RepositoryException
82 */
83 ContainerList (Node workingNode, String containerListName, boolean createNew) throws ElementNotFoundException, RepositoryException {
84 this.workingNode = workingNode;
85 this.name = containerListName;
86 this.containerList = new Content(this.workingNode, this.name, false);
87 this.node = this.containerList.node;
88 }
89
90
91 /**
92 * <p>gets a Collection containing all clild nodes at the current level+1 level</p>
93 * @return Collection of content nodes
94 */
95 public Collection getChildren() {
96 Collection children = new ArrayList();
97 ChildrenCollector cc = new ChildrenCollector(children,true,false,1,ChildrenCollector.SIMPLE_NODE);
98 try {
99 cc.visit(this.node);
100 } catch (RepositoryException re) {re.printStackTrace(); }
101 return children;
102 }
103
104
105
106 /**
107 * @return Boolean, if sub node(s) exists
108 */
109 public boolean hasChildren() {
110 try {
111 return (this.getChildren().size() > 0);
112 } catch (Exception e) {return false;}
113 }
114
115
116 }