KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openedit > repository > ContentItem


1 /*
2  * Created on Aug 1, 2003
3  *
4 /*
5 Copyright (c) 2003 eInnovation Inc. All rights reserved
6
7 This library is free software; you can redistribute it and/or modify it under the terms
8 of the GNU Lesser General Public License as published by the Free Software Foundation;
9 either version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU Lesser General Public License for more details.
14 */

15 package org.openedit.repository;
16
17 import java.io.InputStream JavaDoc;
18 import java.util.Date JavaDoc;
19
20 /**
21  * The ContentItem is a lot like a versioned network "file".
22  *
23  * @author Matt Avery, mavery@einnovation.com
24  */

25 public abstract class ContentItem
26 {
27
28     public final static String JavaDoc TYPE_EDITED = "edited";
29     public final static String JavaDoc TYPE_ADDED = "added";
30     public final static String JavaDoc TYPE_MOVED = "moved";
31     public final static String JavaDoc TYPE_COPIED = "copied";
32     public final static String JavaDoc TYPE_REMOVED = "removed";
33     public final static String JavaDoc TYPE_APPROVED = "approved";
34
35     protected String JavaDoc fieldAuthor;
36     protected String JavaDoc fieldMessage;
37     protected String JavaDoc fieldVersion;
38     protected String JavaDoc fieldType;
39     protected String JavaDoc fieldPath;
40     protected String JavaDoc fieldActualPath; //only used when content actually comes from another path
41
protected Date JavaDoc fieldLastModified;
42     protected long fieldLength = -1;
43     protected boolean fieldMakeVersion = true; //used when saving content
44

45     /**
46      * This path is relative.
47      *
48      * @return
49      */

50     public String JavaDoc getPath()
51     {
52         return fieldPath;
53     }
54     public void setPath( String JavaDoc path )
55     {
56         fieldPath = path;
57     }
58
59     /**
60      * If exists() == false, this method should return 1/1/1970 instead
61      * of null.
62      *
63      * @return
64      */

65     public Date JavaDoc lastModified()
66     {
67         return fieldLastModified;
68     }
69     protected void setLastModified(Date JavaDoc inDate)
70     {
71         fieldLastModified = inDate;
72     }
73     /**
74      * This will return the contents of the file this item points to *or*
75      * a listing of the path in XHTML if we are pointing to a "directory".
76      *
77      * @return An input stream of the content
78      * @throws RepositoryException
79      */

80     public abstract InputStream JavaDoc getInputStream() throws RepositoryException;
81     
82     public abstract boolean exists();
83     
84     public abstract boolean isFolder();
85     
86     public abstract boolean isWritable();
87     
88     //valid types are edited, added, removed
89

90     /**
91      * I would almost like to see this return something more structured than
92      * a String. For instance, I could see the Revision being used in conjunction
93      * to an issue tracking system which might have quite a lot of information in
94      * the "message" string. In that case, I would store this guy as an XML file.
95      *
96      * @return A meaningful message for this revision.
97      */

98     public String JavaDoc getAuthor()
99     {
100         return fieldAuthor;
101     }
102     public void setAuthor( String JavaDoc author )
103     {
104         fieldAuthor = author;
105     }
106
107     public String JavaDoc getMessage()
108     {
109         return fieldMessage;
110     }
111     public void setMessage( String JavaDoc message )
112     {
113         fieldMessage = message;
114     }
115     /**
116      * This could be changed to return an integer. Also, the field names could
117      * be shortened.
118      *
119      * @return
120      */

121     public String JavaDoc getType()
122     {
123         return fieldType;
124     }
125     public void setType( String JavaDoc type )
126     {
127         fieldType = type;
128     }
129     /**
130      * This is the one and only method of the "Versioned" interface. There
131      * also exists "VersionComparator" and "VersionFormat" classes that could
132      * be used in conjunction with this interface.
133      *
134      * @return The version String.
135      */

136     public String JavaDoc getVersion()
137     {
138         return fieldVersion;
139     }
140     public void setVersion( String JavaDoc version )
141     {
142         fieldVersion = version;
143     }
144     
145     /**
146      * Should this class make a version of the file when saving
147      * @return
148      */

149     public boolean isMakeVersion()
150     {
151         return fieldMakeVersion;
152     }
153     public void setMakeVersion(boolean inMakeVersion)
154     {
155         fieldMakeVersion = inMakeVersion;
156     }
157     /**
158      * @return
159      */

160     public long getLength()
161     {
162         return fieldLength;
163     }
164     public String JavaDoc getActualPath()
165     {
166         if( fieldActualPath == null)
167         {
168             return getPath();
169         }
170         return fieldActualPath;
171     }
172     public void setActualPath(String JavaDoc inActualPath)
173     {
174         fieldActualPath = inActualPath;
175     }
176 }
177
Popular Tags