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 JahiaHomepageLink extends JahiaHomepage 34 { 35 private static String CLASS_NAME = JahiaHomepageLink.class.getName(); 36 37 private static final String PAGEID = "pageid"; 38 39 private JahiaHomepagesPersistance hpp; 40 41 42 53 JahiaHomepageLink( Integer id, 54 String name, 55 String descr, 56 Integer type, 57 String siteKey, 58 Hashtable props, 59 Integer aclID ){ 60 61 super(id,name,descr,type,siteKey,props,aclID); 62 } 63 64 65 71 public int getPageID(){ 72 Integer pageID = (Integer )props.get(PAGEID); 73 if ( pageID == null ){ 74 return -1; 75 } 76 return pageID.intValue(); 77 } 78 79 85 public void setPageID(int id){ 86 props.put(PAGEID,new Integer (id)); 87 } 88 89 94 void save() 95 throws JahiaException { 96 97 JahiaHomepagesPersistance.getInstance().save(this); 98 saveProperties(); 99 } 100 101 106 void delete() 107 throws JahiaException { 108 109 JahiaHomepagesPersistance.getInstance().delete(getID()); 110 deleteProperties(); 111 } 112 113 118 void loadProperties() throws JahiaException{ 119 120 if ( props == null ) 121 props = new Hashtable (); 122 123 String value = null; 124 125 value = JahiaHomepagesPersistance.getInstance().getProperty(this,PAGEID); 126 if ( value != null ){ 127 try { 128 props.put(PAGEID,new Integer (value)); 129 } catch ( Throwable t ){ 130 t.printStackTrace(); 131 } 132 } 133 } 134 135 140 void saveProperties() throws JahiaException{ 141 142 deleteProperties(); 143 144 String value = null; 145 146 value = Integer.toString(getPageID()); 147 if ( value != null ) 148 JahiaHomepagesPersistance.getInstance().addProperty(this,PAGEID,value); 149 150 } 151 152 157 void deleteProperties() throws JahiaException{ 158 159 JahiaHomepagesPersistance.getInstance().deleteProperties(this); 160 } 161 162 163 169 public String toString (){ 170 171 StringBuffer buff= new StringBuffer ("String rep. of a "); 172 buff.append(CLASS_NAME); 173 buff.append(" bean :\n"); 174 buff.append(" id :"); 175 buff.append(getID()); 176 return buff.toString(); 178 179 } 180 181 187 public Object clone (){ 188 189 Hashtable hash = null; 190 if ( getProperties() != null ){ 191 hash = new Hashtable (); 192 if ( props.get(PAGEID) != null ) 193 hash.put(PAGEID,new Integer (getPageID())); 194 } 195 196 JahiaHomepageLink clone = 197 new JahiaHomepageLink( new Integer (getID()), 198 getName(), 199 getDescr(), 200 new Integer (getType()), 201 getSiteKey(), 202 hash, 203 new Integer (getAclID()) ); 204 return clone; 205 } 206 207 208 } 209 | Popular Tags |