1 13 package info.magnolia.cms.exchange.simple; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.core.HierarchyManager; 17 import info.magnolia.cms.core.ItemType; 18 import info.magnolia.cms.core.NodeData; 19 import info.magnolia.exchange.Packet; 20 import info.magnolia.exchange.PacketIOException; 21 22 import javax.jcr.RepositoryException; 23 24 import org.apache.log4j.Logger; 25 26 27 32 public final class PacketCollector { 33 34 37 private static Logger log = Logger.getLogger(PacketCollector.class); 38 39 42 private PacketCollector() { 43 } 45 46 public static Packet getPacket(HierarchyManager hm, String path, boolean recurse) { 47 Packet packet = new PacketImpl(); 48 try { 49 Object content = null; 50 if (hm.isPage(path)) { 51 Content page = hm.getContent(path); 52 content = new SerializableContent(page, recurse); 53 } 54 else if (hm.isNodeType(path, ItemType.CONTENTNODE)) { 55 Content contentNode = hm.getContent(path); 56 content = new SerializableContentNode(contentNode, recurse); 57 } 58 else if (hm.isNodeData(path)) { 59 NodeData nodeData = hm.getNodeData(path); 60 try { 61 content = new SerializableNodeData(nodeData); 62 } 63 catch (SerializationException se) { 64 log.error(se.getMessage(), se); 65 } 66 } 67 else { 68 log.error("Unknown object type OR path does not exist for - " + path); return packet; 70 } 71 packet.getBody().setBody(content); 72 } 73 catch (RepositoryException re) { 74 log.error(re.getMessage(), re); 75 } 76 catch (PacketIOException pe) { 77 log.error(pe.getMessage(), pe); 78 } 79 return packet; 80 } 81 } 82 | Popular Tags |