KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
28  * Date: Jun 21, 2004 Time: 11:43:10 AM
29  * @author Sameer Charles
30  * @version 2.0
31  */

32 public final class PacketCollector {
33
34     /**
35      * Logger.
36      */

37     private static Logger log = Logger.getLogger(PacketCollector.class);
38
39     /**
40      * Utility class, don't instantiate.
41      */

42     private PacketCollector() {
43         // unused
44
}
45
46     public static Packet getPacket(HierarchyManager hm, String JavaDoc path, boolean recurse) {
47         Packet packet = new PacketImpl();
48         try {
49             Object JavaDoc 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); //$NON-NLS-1$
69
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