1 13 package org.jahia.services.version; 14 15 import java.io.Serializable ; 16 17 18 19 23 24 public class ContentObjectEntryState implements EntryStateable, Comparable , Cloneable , Serializable 25 { 26 public static final int WORKFLOW_STATE_ACTIVE = 1; public static final int WORKFLOW_STATE_START_STAGING = 2; public static final int WORKFLOW_STATE_VERSIONING_DELETED = -1; public static final int WORKFLOW_STATE_VERSIONED = 0; 31 private int workflowState; 32 private int versionID; 33 private String languageCode; 34 35 public ContentObjectEntryState (int workflowState, int versionID, String languageCode) 36 { 37 this.workflowState = workflowState; 38 this.versionID = versionID; 39 this.languageCode = languageCode; 40 } 41 42 46 public ContentObjectEntryState (EntryStateable entryStateable) { 47 this.workflowState = entryStateable.getWorkflowState(); 48 this.versionID = entryStateable.getVersionID(); 49 this.languageCode = entryStateable.getLanguageCode(); 50 } 51 52 public int getWorkflowState() { return workflowState; } 53 public int getVersionID() { return versionID; } 54 public String getLanguageCode() { return languageCode; } 55 56 protected void setVersionID(int versionID) 57 { this.versionID = versionID; } 58 59 public boolean isActive() { return (workflowState==1)?true:false; } 60 public boolean isStaging() { return (workflowState>1)?true:false; } 61 public boolean isVersioning() { return (workflowState<1)?true:false; } 62 63 66 public boolean equals(Object cfv) 67 { 68 if (cfv instanceof ContentObjectEntryState) 69 { 70 if ((((ContentObjectEntryState)cfv).getWorkflowState()==this.workflowState) && 71 (((ContentObjectEntryState)cfv).getVersionID()==this.versionID) && 72 (((ContentObjectEntryState)cfv).getLanguageCode().equals(this.languageCode))) 73 return true; 74 } 75 return false; 76 } 77 78 89 public int compareTo(Object o) { 90 ContentObjectEntryState rightEntryState = (ContentObjectEntryState) o; 91 if (getWorkflowState() != rightEntryState.getWorkflowState()) { 92 Integer leftState = new Integer (getWorkflowState()); 93 Integer rightState = new Integer (rightEntryState.getWorkflowState()); 94 return leftState.compareTo(rightState); 95 } else { 96 if (getVersionID() != rightEntryState.getVersionID()) { 97 Integer leftVersionID = new Integer (getVersionID()); 99 Integer rightVersionID = new Integer (rightEntryState.getVersionID()); 100 return leftVersionID.compareTo(rightVersionID); 101 } else { 102 return getLanguageCode().compareTo(rightEntryState.getLanguageCode()); 104 } 105 } 106 } 107 108 111 public int hashCode() 112 { 113 return languageCode.hashCode()+versionID+workflowState+1237*workflowState; 114 } 115 116 public String toString() 117 { 118 StringBuffer buf = new StringBuffer ("[ENTRY:workFlowState="); 119 buf.append(getWorkflowState()); 120 buf.append(", versionID="); 121 buf.append(getVersionID()); 122 buf.append(", languageCode="); 123 buf.append(getLanguageCode()); 124 buf.append("]"); 125 return buf.toString(); 126 } 127 128 129 134 public static int getWorkflowState(int versionID){ 135 int ws = WORKFLOW_STATE_VERSIONED; 136 switch ( versionID ) 137 { 138 case -1 : return WORKFLOW_STATE_START_STAGING; 139 case 0 : return WORKFLOW_STATE_START_STAGING; 140 case 1 : return WORKFLOW_STATE_ACTIVE; 141 } 142 return ws; 143 } 144 145 152 public static ContentObjectEntryState getEntryState(int versionID, String languageCode){ 153 154 ContentObjectEntryState entryState = null; 155 int ws = WORKFLOW_STATE_VERSIONED; 156 int v = versionID; 157 158 switch ( versionID ) 159 { 160 case -1 : ws = WORKFLOW_STATE_START_STAGING; 161 v = 0; 162 break; 163 case 0 : ws = WORKFLOW_STATE_START_STAGING; 164 v = 0; 165 break; 166 case 1 : ws = WORKFLOW_STATE_ACTIVE; 167 v = 0; 168 } 169 return entryState = new ContentObjectEntryState(ws,v,languageCode); 170 } 171 172 public Object clone () { 173 ContentObjectEntryState clone = 174 new ContentObjectEntryState (this.getWorkflowState(), 175 this.getVersionID(), 176 this.getLanguageCode()); 177 return clone; 178 } 179 180 } 181 | Popular Tags |