KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > exchange > simple > SerializableContent


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.exchange.simple;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.core.ItemType;
17 import info.magnolia.cms.core.NodeData;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 import org.apache.log4j.Logger;
25
26
27 /**
28  * Date: Jun 21, 2004 Time: 11:42:04 AM
29  * @author Sameer Charles
30  * @version 2.0
31  */

32 public class SerializableContent implements Serializable JavaDoc {
33
34     /**
35      * Stable serialVersionUID.
36      */

37     private static final long serialVersionUID = 222L;
38
39     /**
40      * Logger.
41      */

42     private static Logger log = Logger.getLogger(SerializableContent.class);
43
44     /**
45      * NodeData collection.
46      */

47     protected ArrayList JavaDoc nodeDataCollection = new ArrayList JavaDoc();
48
49     /**
50      * Sub ContentNode collection.
51      */

52     protected ArrayList JavaDoc contentNodeCollection = new ArrayList JavaDoc();
53
54     /**
55      * Sub Content collection.
56      */

57     protected ArrayList JavaDoc contentCollection = new ArrayList JavaDoc();
58
59     protected SerializableMetaData metaData;
60
61     private String JavaDoc name;
62
63     private boolean recurse;
64
65     public SerializableContent() {
66     }
67
68     public SerializableContent(Content content) {
69         this.makeSerializable(content);
70     }
71
72     public SerializableContent(Content content, boolean recurse) {
73         this.recurse = recurse;
74         this.makeSerializable(content);
75     }
76
77     private void makeSerializable(Content content) {
78         this.setName(content.getName());
79         this.metaData = new SerializableMetaData(content.getMetaData());
80         this.addNodeDataList(content);
81         this.addContentNodeList(content, true);
82         if (this.recurse) {
83             this.addContentList(content, true);
84         }
85     }
86
87     public ArrayList JavaDoc getContentNodeCollection() {
88         return this.contentNodeCollection;
89     }
90
91     public ArrayList JavaDoc getContentCollection() {
92         return this.contentCollection;
93     }
94
95     public ArrayList JavaDoc getNodeDataCollection() {
96         return this.nodeDataCollection;
97     }
98
99     public SerializableMetaData getMetaData() {
100         return this.metaData;
101     }
102
103     public void setName(String JavaDoc value) {
104         this.name = value;
105     }
106
107     public String JavaDoc getName() {
108         return this.name;
109     }
110
111     protected void addNodeDataList(Content content) {
112         Collection JavaDoc children = content.getNodeDataCollection();
113         if (children == null) {
114             return;
115         }
116         Iterator JavaDoc childIterator = children.iterator();
117         while (childIterator.hasNext()) {
118             try {
119                 this.nodeDataCollection.add(new SerializableNodeData((NodeData) childIterator.next()));
120             }
121             catch (SerializationException se) {
122                 log.error(se.getMessage(), se);
123             }
124         }
125     }
126
127     protected void addContentNodeList(Content content, boolean recurse) {
128         Collection JavaDoc children = content.getChildren(ItemType.CONTENTNODE);
129         if (children == null) {
130             return;
131         }
132         Iterator JavaDoc childIterator = children.iterator();
133         while (childIterator.hasNext()) {
134             this.contentNodeCollection.add(new SerializableContentNode((Content) childIterator.next(), recurse));
135         }
136     }
137
138     protected void addContentList(Content content, boolean recurse) {
139         Collection JavaDoc children = content.getChildren(ItemType.CONTENT);
140         if (children == null) {
141             return;
142         }
143         Iterator JavaDoc childIterator = children.iterator();
144         while (childIterator.hasNext()) {
145             this.contentCollection.add(new SerializableContent((Content) childIterator.next(), recurse));
146         }
147     }
148 }
149
Popular Tags