1 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 ; 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 24 import org.apache.log4j.Logger; 25 26 27 32 public class SerializableContent implements Serializable { 33 34 37 private static final long serialVersionUID = 222L; 38 39 42 private static Logger log = Logger.getLogger(SerializableContent.class); 43 44 47 protected ArrayList nodeDataCollection = new ArrayList (); 48 49 52 protected ArrayList contentNodeCollection = new ArrayList (); 53 54 57 protected ArrayList contentCollection = new ArrayList (); 58 59 protected SerializableMetaData metaData; 60 61 private String 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 getContentNodeCollection() { 88 return this.contentNodeCollection; 89 } 90 91 public ArrayList getContentCollection() { 92 return this.contentCollection; 93 } 94 95 public ArrayList getNodeDataCollection() { 96 return this.nodeDataCollection; 97 } 98 99 public SerializableMetaData getMetaData() { 100 return this.metaData; 101 } 102 103 public void setName(String value) { 104 this.name = value; 105 } 106 107 public String getName() { 108 return this.name; 109 } 110 111 protected void addNodeDataList(Content content) { 112 Collection children = content.getNodeDataCollection(); 113 if (children == null) { 114 return; 115 } 116 Iterator 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 children = content.getChildren(ItemType.CONTENTNODE); 129 if (children == null) { 130 return; 131 } 132 Iterator 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 children = content.getChildren(ItemType.CONTENT); 140 if (children == null) { 141 return; 142 } 143 Iterator childIterator = children.iterator(); 144 while (childIterator.hasNext()) { 145 this.contentCollection.add(new SerializableContent((Content) childIterator.next(), recurse)); 146 } 147 } 148 } 149
| Popular Tags
|