001: /*
002: * Created on Aug 1, 2003
003: *
004: /*
005: Copyright (c) 2003 eInnovation Inc. All rights reserved
006:
007: This library is free software; you can redistribute it and/or modify it under the terms
008: of the GNU Lesser General Public License as published by the Free Software Foundation;
009: either version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
012: without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
013: See the GNU Lesser General Public License for more details.
014: */
015: package org.openedit.repository;
016:
017: import java.io.InputStream;
018: import java.util.Date;
019:
020: /**
021: * The ContentItem is a lot like a versioned network "file".
022: *
023: * @author Matt Avery, mavery@einnovation.com
024: */
025: public abstract class ContentItem {
026:
027: public final static String TYPE_EDITED = "edited";
028: public final static String TYPE_ADDED = "added";
029: public final static String TYPE_MOVED = "moved";
030: public final static String TYPE_COPIED = "copied";
031: public final static String TYPE_REMOVED = "removed";
032: public final static String TYPE_APPROVED = "approved";
033:
034: protected String fieldAuthor;
035: protected String fieldMessage;
036: protected String fieldVersion;
037: protected String fieldType;
038: protected String fieldPath;
039: protected String fieldActualPath; //only used when content actually comes from another path
040: protected Date fieldLastModified;
041: protected long fieldLength = -1;
042: protected boolean fieldMakeVersion = true; //used when saving content
043:
044: /**
045: * This path is relative.
046: *
047: * @return
048: */
049: public String getPath() {
050: return fieldPath;
051: }
052:
053: public void setPath(String path) {
054: fieldPath = path;
055: }
056:
057: /**
058: * If exists() == false, this method should return 1/1/1970 instead
059: * of null.
060: *
061: * @return
062: */
063: public Date lastModified() {
064: return fieldLastModified;
065: }
066:
067: public long getLastModified() {
068: if (fieldLastModified != null) {
069: return fieldLastModified.getTime();
070: }
071: return 0;
072: }
073:
074: protected void setLastModified(Date inDate) {
075: fieldLastModified = inDate;
076: }
077:
078: /**
079: * This will return the contents of the file this item points to *or*
080: * a listing of the path in XHTML if we are pointing to a "directory".
081: *
082: * @return An input stream of the content
083: * @throws RepositoryException
084: */
085: public abstract InputStream getInputStream()
086: throws RepositoryException;
087:
088: public abstract boolean exists();
089:
090: public abstract boolean isFolder();
091:
092: public abstract boolean isWritable();
093:
094: //valid types are edited, added, removed
095:
096: /**
097: * I would almost like to see this return something more structured than
098: * a String. For instance, I could see the Revision being used in conjunction
099: * to an issue tracking system which might have quite a lot of information in
100: * the "message" string. In that case, I would store this guy as an XML file.
101: *
102: * @return A meaningful message for this revision.
103: */
104: public String getAuthor() {
105: return fieldAuthor;
106: }
107:
108: public void setAuthor(String author) {
109: fieldAuthor = author;
110: }
111:
112: public String getMessage() {
113: return fieldMessage;
114: }
115:
116: public void setMessage(String message) {
117: fieldMessage = message;
118: }
119:
120: /**
121: * This could be changed to return an integer. Also, the field names could
122: * be shortened.
123: *
124: * @return
125: */
126: public String getType() {
127: return fieldType;
128: }
129:
130: public void setType(String type) {
131: fieldType = type;
132: }
133:
134: /**
135: * This is the one and only method of the "Versioned" interface. There
136: * also exists "VersionComparator" and "VersionFormat" classes that could
137: * be used in conjunction with this interface.
138: *
139: * @return The version String.
140: */
141: public String getVersion() {
142: return fieldVersion;
143: }
144:
145: public void setVersion(String version) {
146: fieldVersion = version;
147: }
148:
149: /**
150: * Should this class make a version of the file when saving
151: * @return
152: */
153: public boolean isMakeVersion() {
154: return fieldMakeVersion;
155: }
156:
157: public void setMakeVersion(boolean inMakeVersion) {
158: fieldMakeVersion = inMakeVersion;
159: }
160:
161: /**
162: * @return
163: */
164: public long getLength() {
165: return fieldLength;
166: }
167:
168: public String getActualPath() {
169: if (fieldActualPath == null) {
170: return getPath();
171: }
172: return fieldActualPath;
173: }
174:
175: public void setActualPath(String inActualPath) {
176: fieldActualPath = inActualPath;
177: }
178: }
|