1 16 package org.jahia.services.homepages; 17 18 19 import java.util.Hashtable ; 20 21 import org.jahia.exceptions.JahiaException; 22 23 24 33 public final class JahiaHomepageNew extends JahiaHomepage 34 { 35 private static String CLASS_NAME = JahiaHomepageNew.class.getName(); 36 37 private static final String TEMPLATE = "template"; 39 40 private static final String PARENT_PAGEID = "parent_pageid"; 42 43 private JahiaHomepagesPersistance hpp; 44 45 46 57 JahiaHomepageNew( Integer id, 58 String name, 59 String descr, 60 Integer type, 61 String siteKey, 62 Hashtable props, 63 Integer aclID ){ 64 65 super(id,name,descr,type,siteKey,props,aclID); 66 } 67 68 74 public int getParentPageID(){ 75 Integer id = (Integer )props.get(PARENT_PAGEID); 76 if ( id == null ){ 77 return -1; 78 } 79 return id.intValue(); 80 } 81 82 88 public void setParentPageID(int pageID) throws JahiaException{ 89 props.put(PARENT_PAGEID,new Integer (pageID)); 90 } 91 92 98 public int getTemplateID(){ 99 Integer id = (Integer )props.get(TEMPLATE); 100 if ( id == null ){ 101 return -1; 102 } 103 return id.intValue(); 104 } 105 106 112 public void setTemplateID(int id) throws JahiaException{ 113 props.put(TEMPLATE,new Integer (id)); 114 } 115 116 121 void save() 122 throws JahiaException { 123 124 JahiaHomepagesPersistance.getInstance().save(this); 125 saveProperties(); 126 } 127 128 133 void delete() 134 throws JahiaException { 135 136 JahiaHomepagesPersistance.getInstance().delete(getID()); 137 deleteProperties(); 138 } 139 140 145 void loadProperties() throws JahiaException{ 146 147 if ( props == null ) 148 props = new Hashtable (); 149 150 String value = null; 151 152 value = JahiaHomepagesPersistance.getInstance().getProperty(this,TEMPLATE); 153 if ( value != null ){ 154 try { 155 props.put(TEMPLATE,new Integer (value)); 156 } catch ( Throwable t ){ 157 t.printStackTrace(); 158 } 159 } 160 161 value = JahiaHomepagesPersistance.getInstance().getProperty(this,PARENT_PAGEID); 162 if ( value != null ){ 163 try { 164 props.put(PARENT_PAGEID,new Integer (value)); 165 } catch ( Throwable t ){ 166 t.printStackTrace(); 167 } 168 } 169 170 } 171 172 177 void saveProperties() throws JahiaException{ 178 179 deleteProperties(); 180 181 String value = null; 182 183 value = Integer.toString(getTemplateID()); 184 if ( value != null ) 185 JahiaHomepagesPersistance.getInstance().addProperty(this,TEMPLATE,value); 186 187 value = Integer.toString(getParentPageID()); 188 if ( value != null ) 189 JahiaHomepagesPersistance.getInstance().addProperty(this,PARENT_PAGEID,value); 190 191 } 192 193 198 void deleteProperties() throws JahiaException{ 199 200 JahiaHomepagesPersistance.getInstance().deleteProperties(this); 201 } 202 203 209 public String toString (){ 210 211 StringBuffer buff= new StringBuffer ("String rep. of a "); 212 buff.append(CLASS_NAME); 213 buff.append(" bean :\n"); 214 buff.append(" id :"); 215 buff.append(getID()); 216 return buff.toString(); 218 219 } 220 221 227 public Object clone (){ 228 229 Hashtable hash = null; 230 if ( getProperties() != null ){ 231 hash = new Hashtable (); 232 if ( props.get(PARENT_PAGEID) != null ) 233 hash.put(PARENT_PAGEID,new Integer (getParentPageID())); 234 if ( props.get(TEMPLATE) != null ) 235 hash.put(TEMPLATE,new Integer (getTemplateID())); 236 237 } 238 239 JahiaHomepageNew clone = 240 new JahiaHomepageNew( new Integer (getID()), 241 getName(), 242 getDescr(), 243 new Integer (getType()), 244 getSiteKey(), 245 hash, 246 new Integer (getAclID()) ); 247 return clone; 248 } 249 250 251 } 252 | Popular Tags |