Source code: com/obinary/cms/core/Container.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 import com.obinary.cms.beans.ParagraphInfo;
23
24 import javax.jcr.*;
25 import java.util.Collection;
26 import java.util.ArrayList;
27
28
29
30 /**
31 * User: sameercharles
32 * Date: Apr 15, 2003
33 * Time: 11:00:20 AM
34 * @author Sameer Charles
35 * @version 1.0
36 */
37
38
39 public class Container extends ContainerList {
40
41
42 private Node workingNode;
43 private String name;
44 private Content container;
45
46
47
48
49
50 /**
51 * constructor
52 */
53 public Container () {
54
55 }
56
57
58
59 /**
60 * Package private constructor
61 *
62 * @param workingNode parent <code>Node</code>
63 * @param containerName name to retrieve
64 * @throws ElementNotFoundException
65 * @throws RepositoryException
66 */
67 Container (Node workingNode, String containerName) throws ElementNotFoundException, RepositoryException {
68 this.workingNode = workingNode;
69 this.name = containerName;
70 this.container = new Content(this.workingNode, this.name);
71 this.node = this.container.node;
72 }
73
74
75
76 /**
77 * constructor use to typecast node to Container
78 *
79 * @param node current <code>Node</code>
80 * @throws ElementNotFoundException
81 * @throws RepositoryException
82 */
83 public Container (Node node) throws ElementNotFoundException, RepositoryException {
84 this.node = node;
85 }
86
87
88
89 /**
90 * Package private constructor
91 *
92 * @param workingNode parent <code>Node</code>
93 * @param containerName name to be assigned
94 * @param createNew creates a new container
95 * @throws ElementNotFoundException
96 * @throws RepositoryException
97 */
98 Container (Node workingNode, String containerName, boolean createNew) throws ElementNotFoundException, RepositoryException {
99 this.workingNode = workingNode;
100 this.name = containerName;
101 this.container = new Content(this.workingNode, this.name, false, true);
102 this.node = this.container.node;
103 }
104
105
106
107 /**
108 * <p>gets a Collection containing all clild Atoms at the current level</p>
109 * @return Collection of Atoms
110 */
111 public Collection getChildren() {
112 Collection children = new ArrayList();
113 ChildrenCollector cc = new ChildrenCollector(children,false,true,1,ChildrenCollector.SIMPLE_NODE);
114 try {
115 cc.visit(this.node);
116 } catch (RepositoryException re) {re.printStackTrace(); }
117 return children;
118 }
119
120
121 /**
122 * @return Boolean, if sub node(s) exists
123 */
124 public boolean hasChildren() {
125 try {
126 return (this.getChildren().size() > 0);
127 } catch (Exception e) {return false;}
128 }
129
130
131 /**
132 *
133 * */
134 public String getTemplate() {
135 try {
136 String uuid = this.node.getProperty("UUID").getValue().getString();
137 return ParagraphInfo.getInfo(uuid).getTemplate();
138 } catch (Exception e) {return "";}
139 }
140
141 public String getX() {
142 return "=V=";
143 }
144
145 }