001: /**********************************************************************************
002: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/api/src/java/org/theospi/portfolio/shared/model/Node.java $
003: * $Id:Node.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.io.InputStream;
023:
024: import org.sakaiproject.content.api.ContentResource;
025: import org.sakaiproject.exception.ServerOverloadException;
026: import org.sakaiproject.metaobj.shared.model.Agent;
027: import org.sakaiproject.metaobj.shared.model.Id;
028: import org.sakaiproject.metaobj.shared.model.MimeType;
029:
030: public class Node {
031:
032: private Id id;
033: private String name;
034: private String displayName;
035: private TechnicalMetadata technicalMetadata;
036: private MimeType mimeType;
037: private String externalUri;
038: private String fileType;
039: private ContentResource resource;
040: private boolean hasCopyright = false;
041:
042: public Node(Id id, ContentResource resource, Agent owner) {
043: this .resource = resource;
044: this .id = id;
045: name = resource.getProperties().getProperty(
046: resource.getProperties().getNamePropDisplayName());
047: displayName = name;
048:
049: //check for copyright
050: hasCopyright = Boolean.getBoolean(resource.getProperties()
051: .getProperty(
052: resource.getProperties()
053: .getNamePropCopyrightAlert()));
054:
055: externalUri = resource.getUrl();
056: mimeType = new MimeType(resource.getContentType());
057: String propName = resource.getProperties()
058: .getNamePropStructObjType();
059: String saType = resource.getProperties().getProperty(propName);
060: fileType = (saType != null && !saType.equals("")) ? saType
061: : "fileArtifact";
062:
063: setTechnicalMetadata(new TechnicalMetadata(id, resource, owner));
064: }
065:
066: /**
067: * @return Returns the externalUri.
068: */
069: public String getExternalUri() {
070: return externalUri;
071: }
072:
073: /**
074: * @return Returns the externalUri.
075: */
076: public String getFixedExternalUri() {
077: return externalUri.replaceAll(" ", "%20");
078: }
079:
080: /**
081: * @param externalUri The externalUri to set.
082: */
083: public void setExternalUri(String externalUri) {
084: this .externalUri = externalUri;
085: }
086:
087: /**
088: * @return Returns the mimeType.
089: */
090: public MimeType getMimeType() {
091: return mimeType;
092: }
093:
094: /**
095: * @param mimeType The mimeType to set.
096: */
097: public void setMimeType(MimeType mimeType) {
098: this .mimeType = mimeType;
099: }
100:
101: /**
102: * @return Returns the name.
103: */
104: public String getName() {
105: return name;
106: }
107:
108: /**
109: * @param name The name to set.
110: */
111: public void setName(String name) {
112: this .name = name;
113: }
114:
115: /**
116: * @return Returns the displayName.
117: */
118: public String getDisplayName() {
119: return displayName;
120: }
121:
122: /**
123: * @param displayName The displayName to set.
124: */
125: public void setDisplayName(String displayName) {
126: this .displayName = displayName;
127: }
128:
129: /**
130: * @return Returns the technicalMetadata.
131: */
132: public TechnicalMetadata getTechnicalMetadata() {
133: return technicalMetadata;
134: }
135:
136: /**
137: * @param technicalMetadata The technicalMetadata to set.
138: */
139: public void setTechnicalMetadata(TechnicalMetadata technicalMetadata) {
140: this .technicalMetadata = technicalMetadata;
141: }
142:
143: public Id getId() {
144: return id;
145: }
146:
147: public void setId(Id id) {
148: this .id = id;
149: }
150:
151: public InputStream getInputStream() {
152: try {
153: return resource.streamContent();
154: } catch (ServerOverloadException e) {
155: throw new RuntimeException(e);
156: }
157: }
158:
159: public ContentResource getResource() {
160: return resource;
161: }
162:
163: public String getFileType() {
164: return fileType;
165: }
166:
167: public void setFileType(String fileType) {
168: this .fileType = fileType;
169: }
170:
171: public boolean isHasCopyright() {
172: return hasCopyright;
173: }
174:
175: public void setHasCopyright(boolean hasCopyright) {
176: this.hasCopyright = hasCopyright;
177: }
178:
179: }
|