1 16 package org.jahia.services.homepages; 17 18 import java.util.Hashtable ; 19 20 import org.jahia.exceptions.JahiaException; 21 22 23 33 public final class JahiaHomepageCopy extends JahiaHomepage 34 { 35 private static String CLASS_NAME = JahiaHomepageCopy.class.getName(); 36 37 private static final String PAGEID = "pageid"; 39 40 private static final String USER_REF = "user_ref"; 42 43 private static final String GROUP_REF = "group_ref"; 45 46 private static final String PARENT_PAGEID = "parent_pageid"; 48 49 private static final String COPY_DEPTH = "copy_depth"; 51 52 private JahiaHomepagesPersistance hpp; 53 54 55 66 JahiaHomepageCopy( Integer id, 67 String name, 68 String descr, 69 Integer type, 70 String siteKey, 71 Hashtable props, 72 Integer aclID ){ 73 74 super(id,name,descr,type,siteKey,props,aclID); 75 } 76 77 78 84 public int getPageID(){ 85 Integer pageID = (Integer )props.get(PAGEID); 86 if ( pageID == null ){ 87 return -1; 88 } 89 return pageID.intValue(); 90 } 91 92 98 public void setPageID(int id){ 99 props.put(PAGEID,new Integer (id)); 100 } 101 102 108 public String getUserRef(){ 109 return (String )props.get(USER_REF); 110 } 111 112 118 public void setUserRef(String userKey) throws JahiaException{ 119 props.put(USER_REF,userKey); 120 } 121 122 128 public String getGroupRef(){ 129 return (String )props.get(GROUP_REF); 130 } 131 132 138 public void setGroupRef(String groupKey) throws JahiaException{ 139 props.put(GROUP_REF,groupKey); 140 } 141 142 148 public int getParentPageID(){ 149 Integer id = (Integer )props.get(PARENT_PAGEID); 150 if ( id == null ){ 151 return -1; 152 } 153 return id.intValue(); 154 } 155 156 162 public void setParentPageID(int pageID) throws JahiaException{ 163 props.put(PARENT_PAGEID,new Integer (pageID)); 164 } 165 166 173 public int getCopyDepth(){ 174 Integer depth = (Integer )props.get(COPY_DEPTH); 175 if ( depth == null ){ 176 return -1; 177 } 178 return depth.intValue(); 179 } 180 181 190 public void setCopyDepth(int depth) throws JahiaException{ 191 if ( depth < 0 ){ 192 throw new JahiaException( CLASS_NAME+".setCopyDepth()", 193 "Copy depth value must be bigger or equals to 0", 194 JahiaException.DATA_ERROR, 195 JahiaException.ERROR_SEVERITY); 196 } 197 198 props.put(COPY_DEPTH,new Integer (depth)); 199 } 200 201 206 void save() 207 throws JahiaException { 208 209 JahiaHomepagesPersistance.getInstance().save(this); 210 saveProperties(); 211 } 212 213 218 void delete() 219 throws JahiaException { 220 221 JahiaHomepagesPersistance.getInstance().delete(getID()); 222 deleteProperties(); 223 } 224 225 230 void loadProperties() throws JahiaException{ 231 232 if ( props == null ) 233 props = new Hashtable (); 234 235 String value = null; 236 237 value = JahiaHomepagesPersistance.getInstance().getProperty(this,USER_REF); 238 if ( value != null ) 239 props.put(USER_REF,value); 240 241 value = JahiaHomepagesPersistance.getInstance().getProperty(this,GROUP_REF); 242 if ( value != null ) 243 props.put(GROUP_REF,value); 244 245 value = JahiaHomepagesPersistance.getInstance().getProperty(this,PAGEID); 246 if ( value != null ){ 247 try { 248 props.put(PAGEID,new Integer (value)); 249 } catch ( Throwable t ){ 250 t.printStackTrace(); 251 } 252 } 253 254 value = JahiaHomepagesPersistance.getInstance().getProperty(this,PARENT_PAGEID); 255 if ( value != null ){ 256 try { 257 props.put(PARENT_PAGEID,new Integer (value)); 258 } catch ( Throwable t ){ 259 t.printStackTrace(); 260 } 261 } 262 263 value = JahiaHomepagesPersistance.getInstance().getProperty(this,COPY_DEPTH); 264 if ( value != null ){ 265 try { 266 props.put(COPY_DEPTH,new Integer (value)); 267 } catch ( Throwable t ){ 268 t.printStackTrace(); 269 } 270 } 271 272 } 273 274 279 void saveProperties() throws JahiaException{ 280 281 deleteProperties(); 282 283 String value = null; 284 285 value = getUserRef(); 286 if ( value != null ) 287 JahiaHomepagesPersistance.getInstance().addProperty(this,USER_REF,value); 288 289 value = getGroupRef(); 290 if ( value != null ) 291 JahiaHomepagesPersistance.getInstance().addProperty(this,GROUP_REF,value); 292 293 value = Integer.toString(getPageID()); 294 if ( value != null ) 295 JahiaHomepagesPersistance.getInstance().addProperty(this,PAGEID,value); 296 297 value = Integer.toString(getParentPageID()); 298 if ( value != null ) 299 JahiaHomepagesPersistance.getInstance().addProperty(this,PARENT_PAGEID,value); 300 301 value = Integer.toString(getCopyDepth()); 302 if ( value != null ) 303 JahiaHomepagesPersistance.getInstance().addProperty(this,COPY_DEPTH,value); 304 305 } 306 307 312 void deleteProperties() throws JahiaException{ 313 314 JahiaHomepagesPersistance.getInstance().deleteProperties(this); 315 } 316 317 318 324 public String toString (){ 325 326 StringBuffer buff= new StringBuffer ("String rep. of a "); 327 buff.append(CLASS_NAME); 328 buff.append(" bean :\n"); 329 buff.append(" id :"); 330 buff.append(getID()); 331 return buff.toString(); 333 334 } 335 336 342 public Object clone (){ 343 344 Hashtable hash = null; 345 if ( getProperties() != null ){ 346 hash = new Hashtable (); 347 if ( props.get(PAGEID) != null ) 348 hash.put(PAGEID,new Integer (getPageID())); 349 if ( props.get(PARENT_PAGEID) != null ) 350 hash.put(PARENT_PAGEID,new Integer (getParentPageID())); 351 if ( props.get(COPY_DEPTH) != null ) 352 hash.put(COPY_DEPTH,new Integer (getCopyDepth())); 353 if ( props.get(USER_REF) != null ) 354 hash.put(USER_REF,getUserRef()); 355 if ( props.get(GROUP_REF) != null ) 356 hash.put(GROUP_REF,getGroupRef()); 357 358 } 359 360 JahiaHomepageCopy clone = 361 new JahiaHomepageCopy( new Integer (getID()), 362 getName(), 363 getDescr(), 364 new Integer (getType()), 365 getSiteKey(), 366 hash, 367 new Integer (getAclID()) ); 368 return clone; 369 } 370 371 372 } 373 | Popular Tags |