KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > rm > resources > publishing > WebPage


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

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 /**
35  * This class represents the definition of a page in Harmonise,
36  * defining what XML page template to use and which XSLT resource to use to publish
37  * a page of content.
38  *
39  * @author Michael Bell
40  * @version $Revision: 1.2 $
41  *
42  */

43 public class WebPage
44     extends AbstractChildObject
45     implements Editable, DataStoreObject {
46
47     //XML constants
48
public static final String JavaDoc TAG_PAGE = "Page";
49     public static final String JavaDoc TAG_HARMONISE = "HarmonisePage";
50     public static final String JavaDoc TAG_PAGETITLE = "PageTitle" ;
51     public static final String JavaDoc TAG_NAVIGATION = "Navigation" ;
52     public static final String JavaDoc TAG_EXTERNAL_LINK = "ExternalLink" ;
53     public static final String JavaDoc TAG_ANCILLARY_TEXT = "AncillaryText" ;
54     public static final String JavaDoc ATTRIB_PAGEID = "page_id" ;
55
56     //DB constants
57
private static final String JavaDoc TBL_PAGE = "page";
58     private static final String JavaDoc CLMN_TIMEOUT = "timeout";
59     private static final String JavaDoc CLMN_XML = "xml_id";
60     private static final String JavaDoc 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 JavaDoc m_sDocContent = "";
66
67     /**
68      * Constructs an empty object.
69      */

70     public WebPage() {
71         super();
72     }
73
74     /**
75      * Constructs a new object with an interface to the DB.
76      *
77      * @param con
78      *
79      */

80     public WebPage(AbstractDataStoreInterface con) {
81         super(con);
82     }
83
84     /**
85      * Standard constructor for a known object.
86      *
87      * @param con
88      * @param nPageId
89      *
90      */

91     public WebPage(AbstractDataStoreInterface con, int nPageId) {
92         super(con,nPageId);
93     }
94
95     /**
96      * Standard constructor for a historical object which may be historical.
97      *
98      * @param con
99      * @param nId
100      * @param bIsHistorical
101      *
102      */

103     public WebPage(
104         AbstractDataStoreInterface con,
105         int nId,
106         int nKey,
107         boolean bIsHistorical) {
108         super(con,nId,nKey,bIsHistorical);
109     }
110
111     /**
112      * Sets the <code>XMLResource</code> which determines the content to be presented
113      * in the display of this page..
114      *
115      * @param newDoc
116      */

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     /**
130      * Sets the <code>XSLResource</code> which will be used to transform the output of
131      * the processing of the <code>XMLResource</code> associated with this page definition.
132      *
133      * @param newDoc
134      */

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     /**
148      * Returns the <code>XMLResource</code> which determines the content to be presented
149      * in the display of this page.
150      *
151      *
152      * @return Page XML document
153      * @throws Exception
154      */

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     /**
179      * Returns the <code>XSLResource</code> that is to process the output of the processing
180      * on the <code>XMLResource</code> associated to this page definition.
181      *
182      * @return
183      * @throws Exception
184      */

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     /**
212      * Sets the timeout value associated to this page.
213      *
214      * @param nTimeout
215      */

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     /**
225      * Returns the timeout value associated to this webpage.
226      *
227      * @return
228      * @throws DataAccessException
229      */

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     /* (non-Javadoc)
245      * @see org.openharmonise.rm.resources.AbstractChildObject#getParentObjectClassName()
246      */

247     public String JavaDoc getParentObjectClassName() {
248         return WebPageGroup.class.getName();
249     }
250
251     /* (non-Javadoc)
252      * @see org.openharmonise.rm.resources.AbstractEditableObject#saveNonCoreData()
253      */

254     protected void saveNonCoreData() throws EditException {
255         //no non core data
256

257     }
258
259     /* (non-Javadoc)
260      * @see org.openharmonise.rm.dsi.DataStoreObject#getDBTableName()
261      */

262     public String JavaDoc getDBTableName() {
263         return TBL_PAGE;
264     }
265
266     /* (non-Javadoc)
267      * @see org.openharmonise.rm.publishing.Publishable#getTagName()
268      */

269     public String JavaDoc getTagName() {
270         return TAG_PAGE;
271     }
272
273     /* (non-Javadoc)
274      * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceJoinConditions(java.lang.String, boolean)
275      */

276     public JoinConditions getInstanceJoinConditions(
277         String JavaDoc sObjectTag,
278         boolean bIsOuter)
279         throws DataStoreException {
280         //nothing to do
281
return null;
282     }
283
284     /* (non-Javadoc)
285      * @see org.openharmonise.rm.dsi.DataStoreObject#getInstanceColumnRef(java.lang.String, boolean)
286      */

287     public ColumnRef getInstanceColumnRef(String JavaDoc sColumn, boolean bIsHist)
288         throws DataStoreException {
289         ColumnRef colref = null;
290
291         String JavaDoc 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     /*----------------------------------------------------------------------------
307     Protected Functions
308     -----------------------------------------------------------------------------*/

309
310     /* (non-Javadoc)
311      * @see org.openharmonise.rm.resources.AbstractEditableObject#addDataToSave(org.openharmonise.commons.dsi.dml.InsertStatement)
312      */

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     /* (non-Javadoc)
353      * @see org.openharmonise.rm.resources.AbstractObject#addColumnsToPopulateQuery(org.openharmonise.commons.dsi.dml.SelectStatement, boolean)
354      */

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     /* (non-Javadoc)
368      * @see org.openharmonise.rm.resources.AbstractObject#populateFromResultSetRow(java.sql.ResultSet, org.openharmonise.commons.dsi.dml.SelectStatement)
369      */

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