KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > version > RevisionEntry


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12

13 package org.jahia.services.version;
14
15 import java.util.HashMap JavaDoc;
16 import java.util.StringTokenizer JavaDoc;
17
18 import org.jahia.content.ObjectKey;
19
20 public class RevisionEntry implements EntryStateable, Comparable JavaDoc{
21
22     public static final String JavaDoc REVISION_TITLE = "RevisionTitle";
23
24     private ContentObjectEntryState entryState;
25     private ObjectKey objectKey;
26
27     // Additional Properties, mostly for display purpose
28
private HashMap JavaDoc properties = new HashMap JavaDoc();
29
30     /**
31      *
32      * @param entryState
33      * @param objectKey
34      */

35     public RevisionEntry(ContentObjectEntryState entryState,
36                               ObjectKey objectKey){
37         this.entryState = entryState;
38         this.objectKey = objectKey;
39     }
40
41     public String JavaDoc getLanguageCode(){
42         return entryState.getLanguageCode();
43     }
44
45     public int getVersionID(){
46         return entryState.getVersionID();
47     }
48
49     public int getWorkflowState(){
50         return entryState.getWorkflowState();
51     }
52
53     public ContentObjectEntryState getEntryState(){
54         return entryState;
55     }
56
57     public ObjectKey getObjectKey(){
58         return objectKey;
59     }
60
61     public void setProperty(Object JavaDoc name, Object JavaDoc val ){
62         this.properties.put(name,val);
63     }
64
65     public Object JavaDoc getProperty(Object JavaDoc name){
66         return this.properties.get(name);
67     }
68
69     /**
70      * Returns :
71      * objectKey.toString()
72      * + "_" + entryState.getWorkflowState()
73      * + "_" + entryState.getVersionID()
74      * + "_" + entryState.getLanguageCode()
75      * @return
76      */

77     public String JavaDoc toString(){
78         StringBuffer JavaDoc buff = new StringBuffer JavaDoc(objectKey.toString());
79         buff.append("_");
80         buff.append(entryState.getWorkflowState());
81         buff.append("_");
82         buff.append(entryState.getVersionID());
83         buff.append("_");
84         buff.append(entryState.getLanguageCode());
85         return buff.toString();
86     }
87
88     /**
89      * Ignore language codes equality.
90      * Compare the revision on the objectkey, the workflow_state and the version_id
91      * attributes.
92      *
93      * @param object
94      * @return
95      */

96     public boolean equals(Object JavaDoc object){
97
98         RevisionEntry revisionEntry = (RevisionEntry)object;
99         if ( revisionEntry == null ){
100             return false;
101         }
102
103         if ( !this.entryState.equals(revisionEntry.getEntryState()) ){
104             return false;
105         }
106         return (getObjectKey().equals(revisionEntry.getObjectKey()));
107     }
108
109     public int hashCode(){
110         StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
111         buff.append(getObjectKey());
112         buff.append("_");
113         buff.append(this.getVersionID());
114         buff.append("_");
115         buff.append(this.getWorkflowState());
116         return buff.toString().hashCode();
117     }
118     /**
119      *
120      * @param revisionEntryKey
121      * @return
122      */

123     public static RevisionEntry getRevisionEntry(String JavaDoc revisionEntryKey){
124
125         RevisionEntry revisionEntry = null;
126         try {
127             StringTokenizer JavaDoc strToken = new StringTokenizer JavaDoc(revisionEntryKey, "_");
128             String JavaDoc objType = "";
129             String JavaDoc objID = "";
130             String JavaDoc w = "";
131             String JavaDoc v = "";
132             String JavaDoc l = "";
133
134             if (strToken.countTokens()==5) {
135                 objType = strToken.nextToken();
136                 objID = strToken.nextToken();
137                 w = strToken.nextToken();
138                 v = strToken.nextToken();
139                 l = strToken.nextToken();
140                 ContentObjectEntryState entryState =
141                         new ContentObjectEntryState(Integer.parseInt(w),
142                         Integer.parseInt(v),l);
143                 revisionEntry =
144                         new RevisionEntry(entryState,
145                         ObjectKey.getInstance(objType + "_" + objID));
146             }
147         } catch ( Throwable JavaDoc t ){
148             //t.printStackTrace();
149
}
150         return revisionEntry;
151     }
152
153     /**
154      * To do
155      * @param o
156      * @return
157      */

158     public int compareTo(Object JavaDoc o) {
159         return 1;
160     }
161 }
162
Popular Tags