Also apply the __toString fix to UserInfo
[cacert-mgr.git] / external / ZendFramework-1.9.5 / externals / dojo / demos / offline / editor / server / org / dojo / moxie / Document.java
1 package org.dojo.moxie;
2
3 import java.util.*;
4 import java.util.regex.*;
5
6 /**
7 @author Brad Neuberg, bkn3@columbia.edu
8 */
9 public class Document{
10 protected Integer id = null;
11 protected Integer origId = null;
12 protected String fileName = null;
13 protected long createdOn;
14 protected long lastUpdated;
15 protected String content = null;
16
17 /**
18 @param id The ID of this document; this can either be a positive
19 number if this document exists in the database; it can also be null
20 or negative to indicate that no database-assigned id exists yet.
21 @throws IllegalArgumentException Thrown if fileName,
22 createdOn, or lastUpdated are null or if fileName is invalid.
23 */
24 public Document(Integer id, String fileName, long createdOn,
25 long lastUpdated, String content)
26 throws MoxieException{
27 if(validFileName(fileName) == false){
28 throw new MoxieException("Invalid file name");
29 }
30
31 this.id = id;
32 this.fileName = fileName;
33 this.createdOn = createdOn;
34 this.lastUpdated = lastUpdated;
35 this.content = content;
36 }
37
38 public void setId(Integer Id){
39 this.id = id;
40 }
41
42 public Integer getId(){
43 return this.id;
44 }
45
46 public void setOrigId(Integer origId){
47 this.origId = origId;
48 }
49
50 public Integer getOrigId(){
51 return this.origId;
52 }
53
54 public void setFileName(String fileName){
55 this.fileName = fileName;
56 }
57
58 public String getFileName(){
59 return fileName;
60 }
61
62 public void setCreatedOn(long createdOn){
63 this.createdOn = createdOn;
64 }
65
66 public long getCreatedOn(){
67 return this.createdOn;
68 }
69
70 public void setLastUpdated(long lastUpdated){
71 this.lastUpdated = lastUpdated;
72 }
73
74 public long getLastUpdated(){
75 return this.lastUpdated;
76 }
77
78 public void setContent(String content){
79 this.content = content;
80 }
81
82 public String getContent(){
83 return content;
84 }
85
86 public String toString(){
87 StringBuffer results = new StringBuffer();
88 results.append("{");
89 results.append("id: " + this.id + ", ");
90 if(this.origId != null){
91 results.append("origID: " + this.origId + ", ");
92 }
93 results.append("fileName: '" + this.fileName + "', ");
94 results.append("createdOn: " + this.createdOn + ", ");
95 results.append("lastUpdated: " + this.lastUpdated + ", ");
96 results.append("content: '" + this.content + "'");
97 results.append("}");
98
99 return results.toString();
100 }
101
102 public static boolean validFileName(String fileName){
103 if(fileName == null || fileName.trim().equals("")){
104 return false;
105 }
106
107 return Pattern.matches("^[0-9A-Za-z_]*$", fileName);
108 }
109 }