1 15 16 package org.jahia.services.pages; 17 18 import org.jahia.exceptions.JahiaException; 19 import org.jahia.services.version.EntryStateable; 20 import java.io.Serializable ; 21 22 35 class JahiaPageInfo implements PageInfoInterface, EntryStateable, Serializable { 36 private int mID; private int mSiteID; private int mParentID; private int mPageType; private String mTitle; private int mPageTemplateID; private String mRemoteURL; private int mPageLinkID; private String mCreator; private String mDoc; private int mCounter; private int mAclID; 49 private String mLanguageCode; 50 private int mVersionID; 51 private int mVersionStatus; 52 53 private int mTempParentID; private int mTempAclID; private int mTempPageType; private String mTempTitle; private int mTempPageTemplateID; private String mTempRemoteURL; private int mTempPageLinkID; 62 private boolean mDataChanged = false; 65 private int mHashCode = -1; 68 69 private static JahiaPagesDB mPageDB = JahiaPagesDB.getInstance (); 70 71 72 81 82 86 protected JahiaPageInfo (int ID, int jahiaID, int parentID, int pageType, 87 String title, int pageTemplateID, String remoteURL, 88 int pageLinkID, String creator, String doc, 89 int counter, int aclID, 90 int versionID, int versionStatus, String languageCode) { 91 mID = ID; 92 mSiteID = jahiaID; 93 mParentID = parentID; 94 mTitle = title; 95 mCreator = creator; 96 mDoc = doc; 97 mCounter = counter; 98 mAclID = aclID; 99 mPageType = pageType; 100 mPageTemplateID = pageTemplateID; 101 mVersionID = versionID; 102 mVersionStatus = versionStatus; 103 mLanguageCode = languageCode; 104 105 if (remoteURL == null) { 106 mRemoteURL = NO_REMOTE_URL; 107 } else { 108 mRemoteURL = remoteURL; 109 } 110 111 mPageLinkID = pageLinkID; 112 113 mTempParentID = mParentID; 115 mTempAclID = mAclID; 116 mTempPageType = mPageType; 117 mTempTitle = mTitle; 118 mTempPageTemplateID = pageTemplateID; 119 mTempRemoteURL = mRemoteURL; 120 mTempPageLinkID = mPageLinkID; 121 mDataChanged = false; 122 } 124 125 public boolean equals (Object obj) { 126 if (!(obj instanceof JahiaPageInfo)) { 127 return false; 128 } 129 JahiaPageInfo rightPageInfo = (JahiaPageInfo) obj; 130 return ((getID () == rightPageInfo.getID ()) && 131 (getWorkflowState () == rightPageInfo.getWorkflowState ()) && 132 (getVersionID () == rightPageInfo.getVersionID ()) && 133 (getLanguageCode ().equals (rightPageInfo.getLanguageCode ()))); 134 } 135 136 public int hashCode () { 137 if ((mDataChanged) || (mHashCode == -1)) { 138 StringBuffer buff = new StringBuffer (30); 139 buff.append(mID); 140 buff.append("_"); 141 buff.append(mVersionID); 142 buff.append("_"); 143 buff.append(mVersionStatus); 144 buff.append("_"); 145 buff.append(mLanguageCode); 146 mHashCode = buff.toString ().hashCode (); 147 } 148 return mHashCode; 149 } 150 151 157 public int getID () { 158 return mID; 159 } 160 161 167 public int getJahiaID () { 168 return mSiteID; 169 } 170 171 177 public int getParentID () { 178 return mParentID; 179 } 180 181 187 public int getPageTemplateID () { 188 return mPageTemplateID; 189 } 190 191 197 public String getTitle () { 198 return mTitle; 199 } 200 201 208 public String getCreator () { 209 return mCreator; 210 } 211 212 218 public String getDoc () { 219 return mDoc; 220 } 221 222 228 public int getCounter () { 229 return mCounter; 230 } 231 232 238 public int getAclID () { 239 return mAclID; 240 } 241 242 248 public int getPageType () { 249 return mPageType; 250 } 251 252 259 public String getRemoteURL () { 260 return mRemoteURL; 261 } 262 263 270 public int getPageLinkID () { 271 return mPageLinkID; 272 } 273 274 275 276 277 283 public synchronized void setTitle (String value) { 284 mTempTitle = value; 285 mDataChanged = true; 286 } 287 288 297 public synchronized void setPageType (int value) { 298 mTempPageType = value; 299 300 switch (value) { 301 case TYPE_LINK: 302 mTempRemoteURL = NO_REMOTE_URL; 305 break; 306 307 case TYPE_URL: 308 mTempPageLinkID = TERMINATION_PAGE_ID; 310 break; 311 312 case TYPE_DIRECT: 313 mTempRemoteURL = NO_REMOTE_URL; 316 mTempPageLinkID = TERMINATION_PAGE_ID; 317 break; 318 } 319 mDataChanged = true; 320 } 321 322 328 public synchronized void setParentID (int value) { 329 mTempParentID = value; 330 mDataChanged = true; 331 } 332 333 338 public synchronized void setAclID (int aclID) { 339 mTempAclID = aclID; 340 mDataChanged = true; 341 } 342 343 349 public synchronized void setRemoteURL (String value) { 350 mTempRemoteURL = value; 351 mTempPageType = TYPE_URL; 352 mTempPageLinkID = TERMINATION_PAGE_ID; 353 mDataChanged = true; 354 } 355 356 362 public synchronized void setRemoteURLWithoutType (String value) { 363 mTempRemoteURL = value; 364 mDataChanged = true; 365 } 366 367 373 public synchronized void setPageLinkID (int value) { 374 mTempPageLinkID = value; 375 mTempPageType = TYPE_LINK; 376 mTempRemoteURL = NO_REMOTE_URL; 377 mDataChanged = true; 378 } 379 380 381 388 public synchronized final void setPageTemplateID (int value) { 389 mTempPageTemplateID = value; 390 mDataChanged = true; 391 } 392 393 394 401 public synchronized void commitChanges () throws JahiaException 402 { 403 commitChanges(true); 404 } 405 406 415 public synchronized void commitChanges (boolean commitToDB) 416 throws JahiaException 417 { 418 if (mDataChanged) { 420 mParentID = mTempParentID; 422 mAclID = mTempAclID; 423 mPageType = mTempPageType; 424 mTitle = mTempTitle; 425 mPageTemplateID = mTempPageTemplateID; 426 mRemoteURL = mTempRemoteURL; 427 mPageLinkID = mTempPageLinkID; 428 if ( commitToDB ){ 429 mPageDB.updatePageInfo (this, mVersionID, mVersionStatus); 431 mDataChanged = false; 432 } 433 mRemoteURL = mTempRemoteURL; 434 mPageLinkID = mTempPageLinkID; 435 436 mPageDB.updatePageInfo (this, mVersionID, mVersionStatus); 438 mDataChanged = false; 439 } 440 } 441 442 446 public synchronized void incrementCounter () { 447 mCounter++; 448 mDataChanged = true; 449 } 450 451 463 protected JahiaPageInfo clonePageInfo (int aclID, int newParentID, 464 int pageID, String dateOfCreation) { 465 if (newParentID == -1) { 466 newParentID = mParentID; 467 } 468 return new JahiaPageInfo (pageID, mSiteID, newParentID, mPageType, 470 mTitle, mPageTemplateID, mRemoteURL, 471 mPageLinkID, mCreator, dateOfCreation, 472 mCounter, aclID, 473 mVersionID, mVersionStatus, mLanguageCode); 474 } 475 476 protected JahiaPageInfo clonePageInfo (int versionID, int versionStatus, 477 String languageCode) { 478 JahiaPageInfo newPageInfo = new JahiaPageInfo (mID, mSiteID, mParentID, mPageType, 479 mTitle, mPageTemplateID, mRemoteURL, 480 mPageLinkID, mCreator, mDoc, 481 mCounter, mAclID, versionID, versionStatus, 482 languageCode); 483 newPageInfo.mTempAclID = mTempAclID; 484 newPageInfo.mTempPageLinkID = mTempPageLinkID; 485 newPageInfo.mTempPageTemplateID = mTempPageTemplateID; 486 newPageInfo.mTempPageType= mTempPageType; 487 newPageInfo.mTempParentID = mTempParentID; 488 newPageInfo.mTempRemoteURL = mTempRemoteURL; 489 newPageInfo.mTempTitle = mTempTitle; 490 newPageInfo.mDataChanged = mDataChanged; 491 return newPageInfo; 492 } 493 494 public String getLanguageCode () { 495 return mLanguageCode; 496 } 497 498 public int getVersionID () { 499 return mVersionID; 500 } 501 502 public int getWorkflowState () { 503 return mVersionStatus; 504 } 505 506 public void setVersionID (int newVersionID) { 507 mVersionID = newVersionID; 508 mDataChanged = true; 509 } 510 511 public void setVersionStatus (int newVersionStatus) { 512 mVersionStatus = newVersionStatus; 513 mDataChanged = true; 514 } 515 516 public void setLanguageCode (String newLanguageCode) { 517 newLanguageCode = mLanguageCode; 518 mDataChanged = true; 519 } 520 521 public String toString () { 522 StringBuffer result = new StringBuffer (); 523 result.append ("JahiaPageInfo:\n"); 524 result.append (" id =" + mID + "\n"); 525 result.append (" siteID =" + mSiteID + "\n"); 526 result.append (" parentID=" + mParentID + "\n"); 527 result.append (" pageType=" + mPageType + "\n"); 528 result.append (" title=" + mTitle + "\n"); 529 result.append (" pageTemplateID=" + mPageTemplateID + "\n"); 530 result.append (" remoteURL=" + mRemoteURL + "\n"); 531 result.append (" pageLinkID=" + mPageLinkID + "\n"); 532 result.append (" creator=" + mCreator + "\n"); 533 result.append (" date of creation=" + mDoc + "\n"); 534 result.append (" counter=" + mCounter + "\n"); 535 result.append (" aclID=" + mAclID + "\n"); 536 result.append (" versionID=" + mVersionID + "\n"); 537 result.append (" versionStatus=" + mVersionStatus + "\n"); 538 result.append (" languageCode=" + mLanguageCode + "\n"); 539 return result.toString (); 540 } 541 542 } | Popular Tags |