summaryrefslogtreecommitdiff
path: root/external/ZendFramework-1.9.5/externals/dojo/demos/offline/editor/server/org/dojo/moxie/Document.java
blob: 1f5b455cbd70217336bc4a7364117fe25c007eeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package org.dojo.moxie;

import java.util.*;
import java.util.regex.*;

/**
	@author Brad Neuberg, bkn3@columbia.edu
*/
public class Document{
	protected Integer id = null;
	protected Integer origId = null;
	protected String fileName = null;
	protected long createdOn;
	protected long lastUpdated;
	protected String content = null;
	
	/**
		@param id The ID of this document; this can either be a positive
		number if this document exists in the database; it can also be null
		or negative to indicate that no database-assigned id exists yet.
		@throws IllegalArgumentException Thrown if fileName,
		createdOn, or lastUpdated are null or if fileName is invalid.
	*/
	public Document(Integer id, String fileName, long createdOn,
					long lastUpdated, String content)
								throws MoxieException{
		if(validFileName(fileName) == false){
			throw new MoxieException("Invalid file name");
		}
		
		this.id = id;
		this.fileName = fileName;
		this.createdOn = createdOn;
		this.lastUpdated = lastUpdated;
		this.content = content;
	}
	
	public void setId(Integer Id){
		this.id = id;
	}
	
	public Integer getId(){
		return this.id;
	}
	
	public void setOrigId(Integer origId){
		this.origId = origId;
	}
	
	public Integer getOrigId(){
		return this.origId;
	}
	
	public void setFileName(String fileName){
		this.fileName = fileName;
	}
	
	public String getFileName(){
		return fileName;
	}
	
	public void setCreatedOn(long createdOn){
		this.createdOn = createdOn;
	}
	
	public long getCreatedOn(){
		return this.createdOn;
	}
	
	public void setLastUpdated(long lastUpdated){
		this.lastUpdated = lastUpdated;
	}
	
	public long getLastUpdated(){
		return this.lastUpdated;
	}
	
	public void setContent(String content){
		this.content = content;
	}
	
	public String getContent(){
		return content;
	}
	
	public String toString(){
		StringBuffer results = new StringBuffer();
		results.append("{");
		results.append("id: " + this.id + ", ");
		if(this.origId != null){
			results.append("origID: " + this.origId + ", ");
		}
		results.append("fileName: '" + this.fileName + "', ");
		results.append("createdOn: " + this.createdOn + ", ");
		results.append("lastUpdated: " + this.lastUpdated + ", ");
		results.append("content: '" + this.content + "'");
		results.append("}");
		
		return results.toString();
	}
	
	public static boolean validFileName(String fileName){
		if(fileName == null || fileName.trim().equals("")){
			return false;
		}
		
		return Pattern.matches("^[0-9A-Za-z_]*$", fileName); 
	}
}