001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/api/src/java/org/theospi/portfolio/shared/model/TechnicalMetadata.java $
003: * $Id:TechnicalMetadata.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.theospi.portfolio.shared.model;
021:
022: import java.util.Date;
023:
024: import org.sakaiproject.content.api.ContentResource;
025: import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
026: import org.sakaiproject.entity.api.EntityPropertyTypeException;
027: import org.sakaiproject.metaobj.shared.model.Agent;
028: import org.sakaiproject.metaobj.shared.model.Id;
029: import org.sakaiproject.metaobj.shared.model.MimeType;
030: import org.sakaiproject.metaobj.shared.model.Type;
031: import org.sakaiproject.time.api.Time;
032:
033: /**
034: * Created by IntelliJ IDEA.
035: * User: John Ellis
036: * Date: Jul 27, 2005
037: * Time: 6:09:44 PM
038: * To change this template use File | Settings | File Templates.
039: */
040: public class TechnicalMetadata {
041: private Id id;
042: private Type type;
043: private String name;
044: private Date lastModified;
045: private Date creation;
046: private long size;
047: private MimeType mimeType;
048: private Agent owner;
049:
050: public TechnicalMetadata(Id id, ContentResource resource,
051: Agent owner) {
052: this .id = id;
053: this .name = resource.getProperties().getProperty(
054: resource.getProperties().getNamePropDescription());
055: this .size = resource.getContentLength();
056: mimeType = new MimeType(resource.getContentType());
057:
058: lastModified = getDate(resource, resource.getProperties()
059: .getNamePropModifiedDate());
060: creation = getDate(resource, resource.getProperties()
061: .getNamePropCreationDate());
062: this .owner = owner;
063: }
064:
065: protected Date getDate(ContentResource resource, String propName) {
066: try {
067: Time time = resource.getProperties().getTimeProperty(
068: propName);
069: return new Date(time.getTime());
070: } catch (EntityPropertyNotDefinedException e) {
071: return null;
072: } catch (EntityPropertyTypeException e) {
073: throw new RuntimeException(e);
074: }
075: }
076:
077: /**
078: * @return Returns the creation.
079: */
080: public Date getCreation() {
081: return creation;
082: }
083:
084: /**
085: * @param creation The creation to set.
086: */
087: public void setCreation(Date creation) {
088: this .creation = creation;
089: }
090:
091: /**
092: * @return Returns the lastModified.
093: */
094: public Date getLastModified() {
095: return lastModified;
096: }
097:
098: /**
099: * @param lastModified The lastModified to set.
100: */
101: public void setLastModified(Date lastModified) {
102: this .lastModified = lastModified;
103: }
104:
105: /**
106: * @return Returns the mimeType.
107: */
108: public MimeType getMimeType() {
109: return mimeType;
110: }
111:
112: /**
113: * @param mimeType The mimeType to set.
114: */
115: public void setMimeType(MimeType mimeType) {
116: this .mimeType = mimeType;
117: }
118:
119: /**
120: * @return Returns the name.
121: */
122: public String getName() {
123: return name;
124: }
125:
126: /**
127: * @param name The name to set.
128: */
129: public void setName(String name) {
130: this .name = name;
131: }
132:
133: /**
134: * @return Returns the size.
135: */
136: public long getSize() {
137: return size;
138: }
139:
140: /**
141: * @param size The size to set.
142: */
143: public void setSize(long size) {
144: this .size = size;
145: }
146:
147: /**
148: * @return Returns the type.
149: */
150: public Type getType() {
151: return type;
152: }
153:
154: /**
155: * @param type The type to set.
156: */
157: public void setType(Type type) {
158: this .type = type;
159: }
160:
161: public Id getId() {
162: return id;
163: }
164:
165: public void setId(Id id) {
166: this .id = id;
167: }
168:
169: public Agent getOwner() {
170: return owner;
171: }
172:
173: public void setOwner(Agent owner) {
174: this.owner = owner;
175: }
176:
177: }
|