1 19 package org.openharmonise.rm.resources.publishing; 20 21 import java.sql.*; 22 23 import org.openharmonise.commons.cache.*; 24 import org.openharmonise.commons.dsi.*; 25 import org.openharmonise.commons.dsi.dml.*; 26 import org.openharmonise.rm.*; 27 import org.openharmonise.rm.dsi.*; 28 import org.openharmonise.rm.factory.*; 29 import org.openharmonise.rm.resources.*; 30 import org.openharmonise.rm.resources.lifecycle.*; 31 import org.openharmonise.rm.resources.xml.*; 32 33 34 43 public class WebPage 44 extends AbstractChildObject 45 implements Editable, DataStoreObject { 46 47 public static final String TAG_PAGE = "Page"; 49 public static final String TAG_HARMONISE = "HarmonisePage"; 50 public static final String TAG_PAGETITLE = "PageTitle" ; 51 public static final String TAG_NAVIGATION = "Navigation" ; 52 public static final String TAG_EXTERNAL_LINK = "ExternalLink" ; 53 public static final String TAG_ANCILLARY_TEXT = "AncillaryText" ; 54 public static final String ATTRIB_PAGEID = "page_id" ; 55 56 private static final String TBL_PAGE = "page"; 58 private static final String CLMN_TIMEOUT = "timeout"; 59 private static final String CLMN_XML = "xml_id"; 60 private static final String CLMN_XSL = "xsl_id"; 61 62 private int m_nTimeout = -1; 63 private CachePointer m_XML = null; 64 private CachePointer m_XSL = null; 65 private String m_sDocContent = ""; 66 67 70 public WebPage() { 71 super(); 72 } 73 74 80 public WebPage(AbstractDataStoreInterface con) { 81 super(con); 82 } 83 84 91 public WebPage(AbstractDataStoreInterface con, int nPageId) { 92 super(con,nPageId); 93 } 94 95 103 public WebPage( 104 AbstractDataStoreInterface con, 105 int nId, 106 int nKey, 107 boolean bIsHistorical) { 108 super(con,nId,nKey,bIsHistorical); 109 } 110 111 117 public void setXML(XMLResource xml) throws PopulateException { 118 if (isPopulated() == true && m_XML.equals(xml) == false) { 119 setIsChanged(true); 120 } 121 122 try { 123 m_XML = CacheHandler.getInstance(m_dsi).getCachePointer(xml); 124 } catch (CacheException e) { 125 throw new PopulateException(e.getLocalizedMessage(),e); 126 } 127 } 128 129 135 public void setXSL(XSLResource xsl) throws PopulateException { 136 if (isPopulated() == true && m_XSL.equals(xsl) == false) { 137 setIsChanged(true); 138 } 139 140 try { 141 m_XSL = CacheHandler.getInstance(m_dsi).getCachePointer(xsl); 142 } catch (CacheException e) { 143 throw new PopulateException(e.getLocalizedMessage(),e); 144 } 145 } 146 147 155 public XMLResource getXML() throws DataAccessException { 156 if (isPopulated() == false) { 157 try { 158 populateFromDatabase(); 159 } catch (PopulateException e) { 160 throw new DataAccessException( 161 "Error occured populating object", 162 e); 163 } 164 } 165 166 XMLResource xml = null; 167 try { 168 if(m_XML != null) { 169 xml = (XMLResource) m_XML.getObject(); 170 } 171 } catch (CacheException e) { 172 throw new DataAccessException(e.getLocalizedMessage(),e); 173 } 174 175 return xml; 176 } 177 178 185 public XSLResource getXSL() throws DataAccessException { 186 if (isPopulated() == false) { 187 try { 188 populateFromDatabase(); 189 } catch (PopulateException e) { 190 throw new DataAccessException( 191 "Error occured populating object", 192 e); 193 } 194 } 195 196 XSLResource xsl = null; 197 try { 198 if(m_XSL != null) { 199 xsl = (XSLResource) m_XSL.getObject(); 200 } 201 202 } catch (CacheException e) { 203 throw new DataAccessException( 204 e.getLocalizedMessage(), 205 e); 206 } 207 208 return xsl; 209 } 210 211 216 public void setTimeout(int nTimeout) { 217 if (isPopulated() == true && m_nTimeout != nTimeout) { 218 setIsChanged(true); 219 } 220 221 m_nTimeout = nTimeout; 222 } 223 224 230 public int getTimeout() throws DataAccessException { 231 if (isPopulated() == false) { 232 try { 233 populateFromDatabase(); 234 } catch (PopulateException e) { 235 throw new DataAccessException( 236 "Error occured populating object", 237 e); 238 } 239 } 240 241 return m_nTimeout; 242 } 243 244 247 public String getParentObjectClassName() { 248 return WebPageGroup.class.getName(); 249 } 250 251 254 protected void saveNonCoreData() throws EditException { 255 257 } 258 259 262 public String getDBTableName() { 263 return TBL_PAGE; 264 } 265 266 269 public String getTagName() { 270 return TAG_PAGE; 271 } 272 273 276 public JoinConditions getInstanceJoinConditions( 277 String sObjectTag, 278 boolean bIsOuter) 279 throws DataStoreException { 280 return null; 282 } 283 284 287 public ColumnRef getInstanceColumnRef(String sColumn, boolean bIsHist) 288 throws DataStoreException { 289 ColumnRef colref = null; 290 291 String sTable = getTableName(bIsHist); 292 293 if (sColumn.equals(CLMN_XML) == true) { 294 colref = new ColumnRef(sTable, CLMN_XML, ColumnRef.NUMBER); 295 } else if (sColumn.equals(CLMN_XSL) == true) { 296 colref = new ColumnRef(sTable, CLMN_XSL, ColumnRef.NUMBER); 297 } else if (sColumn.equals(CLMN_TIMEOUT) == true) { 298 colref = new ColumnRef(sTable, CLMN_TIMEOUT, ColumnRef.NUMBER); 299 } else { 300 colref = super.getInstanceColumnRef(sColumn, bIsHist); 301 } 302 303 return colref; 304 } 305 306 309 310 313 protected void addDataToSave(InsertStatement insert) 314 throws DataStoreException { 315 316 boolean bIsHist = isHistorical(); 317 318 try { 319 if(m_XML != null) { 320 321 int nXMLId = getXML().getId(); 322 323 if(nXMLId > 0) { 324 insert.addColumnValue( 325 getInstanceColumnRef(CLMN_XML, bIsHist), 326 nXMLId); 327 } 328 } 329 330 if(m_XSL != null) { 331 332 int nXSLId = getXSL().getId(); 333 334 if(nXSLId > 0) { 335 insert.addColumnValue( 336 getInstanceColumnRef(CLMN_XSL, bIsHist), 337 nXSLId); 338 } 339 340 } 341 } catch (DataAccessException e) { 342 throw new DataStoreException(e.getLocalizedMessage(),e); 343 } 344 345 insert.addColumnValue( 346 getInstanceColumnRef(CLMN_TIMEOUT, bIsHist), 347 m_nTimeout); 348 349 super.addDataToSave(insert); 350 } 351 352 355 protected void addColumnsToPopulateQuery( 356 SelectStatement select, 357 boolean bIsHist) 358 throws DataStoreException { 359 360 select.addSelectColumn(getInstanceColumnRef(CLMN_XML, bIsHist)); 361 select.addSelectColumn(getInstanceColumnRef(CLMN_XSL, bIsHist)); 362 select.addSelectColumn(getInstanceColumnRef(CLMN_TIMEOUT, bIsHist)); 363 364 super.addColumnsToPopulateQuery(select, bIsHist); 365 } 366 367 370 protected void populateFromResultSetRow(ResultSet rs, SelectStatement select) 371 throws PopulateException { 372 int nTemp = -1; 373 374 try { 375 boolean bIsHist = isHistorical(); 376 ColumnRef colref = ColumnRefCache.getInstance().getColumnRef(this,CLMN_XML,bIsHist); 377 if (select.containsSelectColumn(colref) == true) { 378 nTemp = rs.getInt(select.getResultSetIndex(colref)); 379 380 if (m_XML != null) { 381 382 int nXMLId = ((AbstractObject)m_XML.getObject()).getId(); 383 384 if(nXMLId != nTemp) { 385 setIsChanged(true); 386 } 387 388 } else if (m_XML == null && nTemp > 0) { 389 390 391 XMLResource xml = 392 (XMLResource) HarmoniseObjectFactory.instantiateHarmoniseObject( 393 m_dsi, 394 XMLResource.class.getName(), 395 nTemp); 396 397 m_XML = CacheHandler.getInstance(m_dsi).getCachePointer(xml); 398 } 399 } 400 401 colref = ColumnRefCache.getInstance().getColumnRef(this,CLMN_XSL,bIsHist); 402 if (select.containsSelectColumn(colref) == true) { 403 nTemp = rs.getInt(select.getResultSetIndex(colref)); 404 405 if (m_XSL != null) { 406 int nXSLId = ((AbstractObject)m_XSL.getObject()).getId(); 407 408 if(nXSLId != nTemp) { 409 setIsChanged(true); 410 } 411 } else if (m_XSL == null && nTemp > 0) { 412 XSLResource xsl = 413 (XSLResource) HarmoniseObjectFactory.instantiateHarmoniseObject( 414 m_dsi, 415 XSLResource.class.getName(), 416 nTemp); 417 418 m_XSL = CacheHandler.getInstance(m_dsi).getCachePointer(xsl); 419 } 420 } 421 422 colref = ColumnRefCache.getInstance().getColumnRef(this,CLMN_TIMEOUT,bIsHist); 423 if (select.containsSelectColumn(colref) == true) { 424 nTemp = rs.getInt(select.getResultSetIndex(colref)); 425 426 if (m_nTimeout > 0 && m_nTimeout != nTemp) { 427 setIsChanged(true); 428 } else { 429 m_nTimeout = nTemp; 430 } 431 } 432 } catch (HarmoniseFactoryException e) { 433 throw new PopulateException( 434 "Error occured getting object from factory", 435 e); 436 } catch (SQLException e) { 437 throw new PopulateException( 438 "Error occured getting data from resultset", 439 e); 440 } catch (CacheException e) { 441 throw new PopulateException("Cache error",e); 442 } 443 444 super.populateFromResultSetRow(rs, select); 445 } 446 447 } | Popular Tags |