KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openedit > repository > filesystem > StringItem


1 /*
2  * Created on Aug 8, 2004
3  */

4 package org.openedit.repository.filesystem;
5
6 import java.io.ByteArrayInputStream JavaDoc;
7 import java.io.InputStream JavaDoc;
8 import java.util.Date JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.openedit.repository.ContentItem;
13 import org.openedit.repository.RepositoryException;
14
15
16 /**
17  * @author Matthew Avery, mavery@einnovation.com
18  */

19 public class StringItem extends ContentItem
20 {
21     protected String JavaDoc fieldContent;
22     protected String JavaDoc fieldOutputEncoding;
23     protected boolean fieldWritable = true;
24     private static final Log log = LogFactory.getLog(StringItem.class);
25     
26     public StringItem( String JavaDoc inPath, String JavaDoc inContent, String JavaDoc inEncoding )
27     {
28         //fieldLastModified = new Date();
29
if ( inContent == null)
30         {
31             inContent = "";
32         }
33         fieldContent = inContent;
34         fieldPath = inPath;
35         fieldOutputEncoding = inEncoding;
36     }
37     /**
38      *
39      */

40     public StringItem()
41     {
42     }
43     public void setLastModified(Date JavaDoc inDate)
44     {
45         super.setLastModified(inDate);
46     }
47
48     public InputStream JavaDoc getInputStream() throws RepositoryException
49     {
50         if ( getOutputEncoding() == null)
51         {
52             log.error("Encoding not defined");
53             return new ByteArrayInputStream JavaDoc(getContent().getBytes());
54         }
55         try
56         {
57             return new ByteArrayInputStream JavaDoc(getContent().getBytes(getOutputEncoding()));
58         } catch ( Exception JavaDoc ex)
59         {
60             log.error(ex);
61             throw new RepositoryException(ex);
62         }
63     }
64
65     public boolean exists()
66     {
67         return getContent() != null;
68     }
69
70     public boolean isFolder()
71     {
72         return false;
73     }
74     /**
75      * We use the StringItem to make changes and save them back again
76      */

77     public boolean isWritable()
78     {
79         return fieldWritable;
80     }
81
82
83     public String JavaDoc getContent()
84     {
85         return fieldContent;
86     }
87     public void setContent( String JavaDoc content )
88     {
89         fieldContent = content;
90     }
91     protected void setWritable(boolean inWritable)
92     {
93         fieldWritable = inWritable;
94     }
95     public String JavaDoc getOutputEncoding()
96     {
97         return fieldOutputEncoding;
98     }
99     public void setOutputEncoding(String JavaDoc inOutputEncoding)
100     {
101         fieldOutputEncoding = inOutputEncoding;
102     }
103 }
104
Popular Tags