01: package org.sakaiproject.metaobj.shared.mgt;
02:
03: import org.jdom.Element;
04: import org.sakaiproject.content.api.ContentResource;
05: import org.sakaiproject.time.api.Time;
06: import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
07: import org.sakaiproject.entity.api.EntityPropertyTypeException;
08:
09: import java.util.Date;
10:
11: /**
12: * Created by IntelliJ IDEA.
13: * User: johnellis
14: * Date: Feb 10, 2007
15: * Time: 11:36:29 AM
16: * To change this template use File | Settings | File Templates.
17: */
18: public class ContentHostingUtil {
19:
20: public static Element createRepoNode(ContentResource contentResource) {
21: Element repositoryNode;
22: repositoryNode = new Element("repositoryNode");
23:
24: Date created = getDate(contentResource, contentResource
25: .getProperties().getNamePropCreationDate());
26: if (created != null) {
27: repositoryNode.addContent(createNode("created", created
28: .toString()));
29: }
30:
31: Date modified = getDate(contentResource, contentResource
32: .getProperties().getNamePropModifiedDate());
33: if (modified != null) {
34: repositoryNode.addContent(createNode("modified", modified
35: .toString()));
36: }
37: return repositoryNode;
38: }
39:
40: public static Element createNode(String name, String value) {
41: Element newNode = new Element(name);
42: newNode.addContent(value);
43: return newNode;
44: }
45:
46: public static Date getDate(ContentResource resource, String propName) {
47: try {
48: Time time = resource.getProperties().getTimeProperty(
49: propName);
50: return new Date(time.getTime());
51: } catch (EntityPropertyNotDefinedException e) {
52: return null;
53: } catch (EntityPropertyTypeException e) {
54: throw new RuntimeException(e);
55: }
56: }
57:
58: }
|