KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > controllers > kernel > impl > simple > ComponentLogic


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23  
24 package org.infoglue.deliver.controllers.kernel.impl.simple;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Locale JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import org.apache.log4j.Logger;
35 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
36 import org.infoglue.cms.entities.content.ContentVO;
37 import org.infoglue.cms.entities.content.ContentVersion;
38 import org.infoglue.cms.entities.structure.SiteNodeVO;
39 import org.infoglue.cms.exception.SystemException;
40 import org.infoglue.cms.util.XMLHelper;
41 import org.infoglue.deliver.applications.actions.InfoGlueComponent;
42 import org.infoglue.deliver.applications.databeans.ComponentDeliveryContext;
43 import org.infoglue.deliver.applications.databeans.DeliveryContext;
44 import org.infoglue.deliver.util.NullObject;
45 import org.infoglue.deliver.applications.databeans.Slot;
46 import org.infoglue.deliver.applications.databeans.WebPage;
47 import org.infoglue.deliver.util.CacheController;
48 import org.infoglue.deliver.util.Support;
49 import org.w3c.dom.Document JavaDoc;
50 import org.w3c.dom.Element JavaDoc;
51 import org.w3c.dom.NodeList JavaDoc;
52
53 public class ComponentLogic
54 {
55     private final static Logger logger = Logger.getLogger(ComponentLogic.class.getName());
56
57     private TemplateController templateController = null;
58     private InfoGlueComponent infoGlueComponent = null;
59     private boolean useInheritance = true;
60     private boolean useEditOnSight = true;
61     private boolean threatFoldersAsContents = false;
62     private ComponentDeliveryContext componentDeliveryContext;
63     
64     public ComponentLogic(TemplateController templateController, InfoGlueComponent infoGlueComponent)
65     {
66         this.templateController = templateController;
67         this.infoGlueComponent = infoGlueComponent;
68         this.componentDeliveryContext = ComponentDeliveryContext.getComponentDeliveryContext(templateController.getDeliveryContext(), infoGlueComponent);
69         this.componentDeliveryContext.addUsedContent("content_" + infoGlueComponent.getContentId());
70     }
71     
72     /*
73     public void getDatabaseStatus(String debug)
74     {
75         try
76         {
77             this.templateController.getDatabaseStatus(debug);
78         }
79         catch(Exception e)
80         {
81             e.printStackTrace();
82         }
83     }
84     */

85
86     /**
87      * The method returns a list of ContentVO-objects that is children to the bound content of named binding on the siteNode sent in.
88      * The method is great for collection-pages on any site where you want to bind to a folder containing all contents to list.
89      * You can also state if the method should recurse into subfolders and how the contents should be sorted.
90      * The recursion only deals with three levels at the moment for performance-reasons.
91      *
92      * @param propertyName the name of the content binding property
93      * @param searchRecursive if true the search is made recursive
94      * @param sortAttribute the attribute to sort the resulting List
95      * @param sortOrder if desc sorting is descendend otherwise ascending.
96      * @return a List of ContentVO objects,
97      * @throws Exception if an error occures
98      */

99     public List JavaDoc getBoundFolderContents(String JavaDoc propertyName, boolean searchRecursive, String JavaDoc sortAttribute, String JavaDoc sortOrder) throws Exception JavaDoc
100     {
101         return getBoundFolderContents(propertyName, searchRecursive, sortAttribute, sortOrder, false);
102     }
103
104     /**
105      * The method returns a list of ContentVO-objects that is children to the bound content of named binding on the siteNode sent in.
106      * The method is great for collection-pages on any site where you want to bind to a folder containing all contents to list.
107      * You can also state if the method should recurse into subfolders and how the contents should be sorted.
108      * The recursion only deals with three levels at the moment for performance-reasons.
109      *
110      * @param propertyName the name of the content binding property
111      * @param searchRecursive if true the search is made recursive
112      * @param sortAttribute the attribute to sort the rsulting List
113      * @param sortOrder if desc sorting is descendend otherwise ascending.
114      * @param includeFolders true if the folders should be added to the List
115      * @return a List of ContentVO objects,
116      * @throws Exception if an error occures
117      */

118     public List JavaDoc getBoundFolderContents(String JavaDoc propertyName, boolean searchRecursive, String JavaDoc sortAttribute, String JavaDoc sortOrder, boolean includeFolders) throws Exception JavaDoc
119     {
120         List JavaDoc childContents = new ArrayList JavaDoc();
121         
122         //Map property = this.getComponentProperty(propertyName);
123
//if(property != null)
124
//{
125
Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, this.useInheritance);
126         if(property != null)
127         {
128             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
129             if(bindings.size() > 0)
130             {
131                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
132                 childContents = this.templateController.getChildContents(contentId, searchRecursive, sortAttribute, sortOrder, includeFolders);
133             }
134         }
135         
136         return childContents;
137     }
138
139     /**
140      * The method returns a list of ContentVO-objects that are related to the category of named binding on the siteNode sent in.
141      * The method is great for collection-pages on any site where you want to bind a category.
142      */

143     public List JavaDoc getBoundCategoryContents(String JavaDoc categoryAttribute, String JavaDoc typeAttribute) throws Exception JavaDoc
144     {
145         Map JavaDoc categoryComponent = getInheritedComponentProperty(infoGlueComponent, categoryAttribute, this.useInheritance);
146         Map JavaDoc attributeComponent = getInheritedComponentProperty(infoGlueComponent, typeAttribute, this.useInheritance);
147         if(categoryComponent != null && attributeComponent != null)
148         {
149             String JavaDoc attr = (String JavaDoc)attributeComponent.get("path");
150             Integer JavaDoc categoryId = getSingleBindingAsInteger(categoryComponent);
151             final List JavaDoc contentVersionsByCategory = templateController.getContentVersionsByCategory(categoryId, attr);
152             return contentVersionsByCategory;
153         }
154
155         return Collections.EMPTY_LIST;
156     }
157
158     private Integer JavaDoc getSingleBindingAsInteger(Map JavaDoc componentProperty)
159     {
160         List JavaDoc bindings = (List JavaDoc)componentProperty.get("bindings");
161         return (bindings.size() > 0)
162                     ? new Integer JavaDoc((String JavaDoc)bindings.get(0))
163                     : new Integer JavaDoc(0);
164     }
165
166     public String JavaDoc getAssetUrl(String JavaDoc propertyName) throws Exception JavaDoc
167     {
168         String JavaDoc assetUrl = "";
169
170         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, this.useInheritance);
171         if(property != null)
172         {
173             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
174             logger.info("bindings:" + bindings.size());
175             if(bindings.size() > 0)
176             {
177                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
178                 logger.info("contentId:" + contentId);
179                 assetUrl = templateController.getAssetUrl(contentId);
180             }
181         }
182         return assetUrl;
183     }
184     
185     public String JavaDoc getAssetUrl(String JavaDoc propertyName, boolean useInheritance) throws Exception JavaDoc
186     {
187         String JavaDoc assetUrl = "";
188
189         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
190         if(property != null)
191         {
192             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
193             logger.info("bindings:" + bindings.size());
194             if(bindings.size() > 0)
195             {
196                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
197                 logger.info("contentId:" + contentId);
198                 assetUrl = templateController.getAssetUrl(contentId);
199             }
200         }
201         return assetUrl;
202     }
203
204     public String JavaDoc getAssetUrl(String JavaDoc propertyName, String JavaDoc assetKey) throws Exception JavaDoc
205     {
206         String JavaDoc assetUrl = "";
207                 
208         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, this.useInheritance);
209         if(property != null)
210         {
211             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
212             if(bindings.size() > 0)
213             {
214                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
215                 assetUrl = templateController.getAssetUrl(contentId, assetKey);
216             }
217         }
218         return assetUrl;
219     }
220
221     public String JavaDoc getAssetUrl(String JavaDoc propertyName, String JavaDoc assetKey, boolean useInheritance) throws Exception JavaDoc
222     {
223         String JavaDoc assetUrl = "";
224                 
225         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
226         if(property != null)
227         {
228             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
229             if(bindings.size() > 0)
230             {
231                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
232                 assetUrl = templateController.getAssetUrl(contentId, assetKey);
233             }
234         }
235         return assetUrl;
236     }
237
238     public String JavaDoc getAssetThumbnailUrl(String JavaDoc propertyName, int width, int height) throws Exception JavaDoc
239     {
240         return getAssetThumbnailUrl(propertyName, width, height, this.useInheritance);
241     }
242     
243     public String JavaDoc getAssetThumbnailUrl(String JavaDoc propertyName, int width, int height, boolean useInheritance) throws Exception JavaDoc
244     {
245         String JavaDoc assetUrl = "";
246                 
247         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
248         if(property != null)
249         {
250             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
251             if(bindings.size() > 0)
252             {
253                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
254                 assetUrl = templateController.getAssetThumbnailUrl(contentId, width, height);
255             }
256         }
257         return assetUrl;
258     }
259
260     public String JavaDoc getAssetThumbnailUrl(String JavaDoc propertyName, String JavaDoc assetKey, int width, int height) throws Exception JavaDoc
261     {
262        return getAssetThumbnailUrl(propertyName, assetKey, width, height, this.useInheritance);
263     }
264     
265     public String JavaDoc getAssetThumbnailUrl(String JavaDoc propertyName, String JavaDoc assetKey, int width, int height, boolean useInheritance) throws Exception JavaDoc
266     {
267         String JavaDoc assetUrl = "";
268
269         try
270         {
271             Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
272             if(property != null)
273             {
274                 List JavaDoc bindings = (List JavaDoc)property.get("bindings");
275                 if(bindings.size() > 0)
276                 {
277                     Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
278                     assetUrl = templateController.getAssetThumbnailUrl(contentId, assetKey, width, height);
279                 }
280             }
281         }
282         catch(Exception JavaDoc e)
283         {
284             e.printStackTrace();
285         }
286         
287         return assetUrl;
288     }
289
290     public String JavaDoc getAssetThumbnailUrl(Integer JavaDoc contentId, int width, int height) throws Exception JavaDoc
291     {
292         String JavaDoc assetUrl = templateController.getAssetThumbnailUrl(contentId, width, height);
293         return assetUrl;
294     }
295
296     public String JavaDoc getAssetThumbnailUrl(Integer JavaDoc contentId, String JavaDoc assetKey, int width, int height) throws Exception JavaDoc
297     {
298         String JavaDoc assetUrl = templateController.getAssetThumbnailUrl(contentId, assetKey, width, height);
299         return assetUrl;
300     }
301
302     
303     public String JavaDoc getAssetUrl(Integer JavaDoc contentId, String JavaDoc assetKey)
304     {
305         String JavaDoc assetUrl = templateController.getAssetUrl(contentId, assetKey);
306
307         return assetUrl;
308     }
309     
310     public String JavaDoc getContentAttribute(String JavaDoc propertyName, String JavaDoc attributeName)
311     {
312         return getContentAttribute(propertyName, attributeName, !this.useEditOnSight, this.useInheritance);
313     }
314
315     public String JavaDoc getContentAttribute(String JavaDoc propertyName, String JavaDoc attributeName, boolean disableEditOnSight)
316     {
317         return getContentAttribute(propertyName, attributeName, disableEditOnSight, this.useInheritance);
318     }
319
320     /*
321     public String getContentAttribute(String propertyName, String attributeName)
322     {
323         String attributeValue = "";
324
325         Map property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
326         if(property != null)
327         {
328             List bindings = (List)property.get("bindings");
329             if(bindings.size() > 0)
330             {
331                 Integer contentId = new Integer((String)bindings.get(0));
332                 attributeValue = templateController.getContentAttribute(contentId, attributeName);
333             }
334         }
335
336         return attributeValue;
337     }
338     */

339     
340     public Integer JavaDoc getContentId(Map JavaDoc property)
341     {
342         Integer JavaDoc contentId = null;
343
344         if(property != null)
345         {
346             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
347             if(bindings.size() > 0)
348             {
349                 contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
350             }
351         }
352
353         return contentId;
354     }
355
356     public List JavaDoc getBoundContents(Map JavaDoc property)
357     {
358         List JavaDoc contents = new ArrayList JavaDoc();
359
360         if(property != null)
361         {
362             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
363             Iterator JavaDoc bindingsIterator = bindings.iterator();
364             while(bindingsIterator.hasNext())
365             {
366                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindingsIterator.next());
367                 contents.add(this.templateController.getContent(contentId));
368             }
369         }
370
371         return contents;
372     }
373
374     public Integer JavaDoc getSiteNodeId(Map JavaDoc property)
375     {
376         Integer JavaDoc siteNodeId = null;
377
378         if(property != null)
379         {
380             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
381             if(bindings.size() > 0)
382             {
383                 siteNodeId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
384             }
385         }
386
387         return siteNodeId;
388     }
389
390     public List JavaDoc getBoundPages(Map JavaDoc property)
391     {
392         List JavaDoc pages = new ArrayList JavaDoc();
393
394         if(property != null)
395         {
396             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
397             Iterator JavaDoc bindingsIterator = bindings.iterator();
398             while(bindingsIterator.hasNext())
399             {
400                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindingsIterator.next());
401                 SiteNodeVO siteNode = templateController.getSiteNode(siteNodeId);
402                 if(siteNode != null)
403                 {
404                     WebPage webPage = new WebPage();
405                     webPage.setSiteNodeId(siteNodeId);
406                     webPage.setLanguageId(templateController.getLanguageId());
407                     webPage.setContentId(null);
408                     webPage.setNavigationTitle(getPageNavTitle(siteNodeId));
409                     webPage.setMetaInfoContentId(siteNode.getMetaInfoContentId());
410                     webPage.setUrl(getPageUrl(siteNodeId));
411                     pages.add(webPage);
412                 }
413             }
414         }
415
416         return pages;
417     }
418
419     
420     public String JavaDoc getContentAttribute(String JavaDoc propertyName, String JavaDoc attributeName, boolean disableEditOnSight, boolean useInheritance)
421     {
422         String JavaDoc attributeValue = "";
423
424         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
425         if(property != null)
426         {
427             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
428             if(bindings.size() > 0)
429             {
430                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
431                 if(disableEditOnSight)
432                     attributeValue = templateController.getContentAttribute(contentId, attributeName, disableEditOnSight);
433                 else
434                     attributeValue = templateController.getContentAttribute(contentId, attributeName);
435             }
436         }
437
438         return attributeValue;
439     }
440
441     public String JavaDoc getContentAttribute(String JavaDoc propertyName, Integer JavaDoc languageId, String JavaDoc attributeName, boolean disableEditOnSight, boolean useInheritance)
442     {
443         String JavaDoc attributeValue = "";
444
445         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
446         if(property != null)
447         {
448             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
449             if(bindings.size() > 0)
450             {
451                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
452                 attributeValue = templateController.getContentAttribute(contentId, languageId, attributeName, disableEditOnSight);
453             }
454         }
455
456         return attributeValue;
457     }
458
459     public String JavaDoc getParsedContentAttribute(String JavaDoc propertyName, String JavaDoc attributeName)
460     {
461         return getParsedContentAttribute(propertyName, attributeName, !this.useEditOnSight, this.useInheritance);
462     }
463
464     public String JavaDoc getParsedContentAttribute(String JavaDoc propertyName, String JavaDoc attributeName, boolean disableEditOnSight, boolean useInheritance)
465     {
466         String JavaDoc attributeValue = "";
467
468         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
469         if(property != null)
470         {
471             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
472             if(bindings.size() > 0)
473             {
474                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
475                 attributeValue = templateController.getParsedContentAttribute(contentId, attributeName, disableEditOnSight);
476             }
477         }
478
479         return attributeValue;
480     }
481
482     public String JavaDoc getParsedContentAttribute(String JavaDoc propertyName, Integer JavaDoc languageId, String JavaDoc attributeName, boolean disableEditOnSight, boolean useInheritance)
483     {
484         String JavaDoc attributeValue = "";
485
486         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
487         if(property != null)
488         {
489             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
490             if(bindings.size() > 0)
491             {
492                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
493                 attributeValue = templateController.getParsedContentAttribute(contentId, languageId, attributeName, disableEditOnSight);
494             }
495         }
496
497         return attributeValue;
498     }
499
500     public List JavaDoc getFormAttributes(String JavaDoc propertyName, String JavaDoc attributeName)
501     {
502         List JavaDoc formAttributes = new ArrayList JavaDoc();
503
504         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, this.useInheritance);
505         if(property != null)
506         {
507             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
508             if(bindings.size() > 0)
509             {
510                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
511                 String JavaDoc formDefinition = templateController.getContentAttribute(contentId, attributeName, true);
512                 formAttributes = FormDeliveryController.getFormDeliveryController().getContentTypeAttributes(formDefinition);
513             }
514         }
515
516         return formAttributes;
517     }
518     
519     public String JavaDoc getPropertyValue(String JavaDoc propertyName) throws SystemException
520     {
521         return getPropertyValue(propertyName, true);
522     }
523
524     public String JavaDoc getPropertyValue(String JavaDoc propertyName, boolean useLangaugeFallback) throws SystemException
525     {
526         return getPropertyValue(propertyName, useLangaugeFallback, this.useInheritance);
527     }
528
529     public String JavaDoc getPropertyValue(String JavaDoc propertyName, boolean useLangaugeFallback, boolean useInheritance) throws SystemException
530     {
531         String JavaDoc propertyValue = "";
532
533         Locale JavaDoc locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(templateController.getDatabase(), templateController.getLanguageId());
534
535         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
536         if(property != null)
537         {
538             if(property != null)
539             {
540                 propertyValue = (String JavaDoc)property.get("path");
541                 if(propertyValue == null)
542                 {
543                     Iterator JavaDoc keysIterator = property.keySet().iterator();
544                     while(keysIterator.hasNext())
545                     {
546                         String JavaDoc key = (String JavaDoc)keysIterator.next();
547                     }
548                 }
549             }
550         }
551
552         return propertyValue;
553     }
554
555
556     
557     public String JavaDoc getPropertyValue(Integer JavaDoc siteNodeId, String JavaDoc propertyName, boolean useLangaugeFallback, boolean useInheritance) throws SystemException
558     {
559         String JavaDoc propertyValue = "";
560
561         Locale JavaDoc locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(templateController.getDatabase(), templateController.getLanguageId());
562
563         Map JavaDoc property = getInheritedComponentProperty(siteNodeId, this.infoGlueComponent, propertyName, useInheritance);
564         if(property != null)
565         {
566             if(property != null)
567             {
568                 propertyValue = (String JavaDoc)property.get("path");
569                 if(propertyValue == null)
570                 {
571                     Iterator JavaDoc keysIterator = property.keySet().iterator();
572                     while(keysIterator.hasNext())
573                     {
574                         String JavaDoc key = (String JavaDoc)keysIterator.next();
575                     }
576                 }
577             }
578         }
579
580         return propertyValue;
581     }
582
583
584     
585     public ContentVO getBoundContent(String JavaDoc propertyName)
586     {
587         return getBoundContent(propertyName, true);
588     }
589     
590     public ContentVO getBoundContent(String JavaDoc propertyName, boolean useInheritance)
591     {
592         ContentVO content = null;
593
594         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
595         if(property != null)
596         {
597             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
598             if(bindings.size() > 0)
599             {
600                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
601                 content = this.templateController.getContent(contentId);
602             }
603         }
604
605         return content;
606     }
607
608     public ContentVO getBoundContent(Integer JavaDoc siteNodeId, String JavaDoc propertyName, boolean useInheritance)
609     {
610         ContentVO content = null;
611
612         Map JavaDoc property = getInheritedComponentProperty(siteNodeId, this.infoGlueComponent, propertyName, useInheritance);
613         if(property != null)
614         {
615             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
616             if(bindings.size() > 0)
617             {
618                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
619                 content = this.templateController.getContent(contentId);
620             }
621         }
622
623         return content;
624     }
625
626     public Integer JavaDoc getBoundContentId(String JavaDoc propertyName)
627     {
628         return getBoundContentId(propertyName, true);
629     }
630     
631     public Integer JavaDoc getBoundContentId(String JavaDoc propertyName, boolean useInheritance)
632     {
633         Integer JavaDoc contentId = null;
634
635         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
636         if(property != null)
637         {
638             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
639             if(bindings.size() > 0)
640             {
641                 contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
642             }
643         }
644
645         return contentId;
646     }
647
648     public List JavaDoc getBoundContents(String JavaDoc propertyName)
649     {
650         return getBoundContents(propertyName, this.useInheritance);
651     }
652     
653     public List JavaDoc getBoundContents(String JavaDoc propertyName, boolean useInheritance)
654     {
655         List JavaDoc contents = new ArrayList JavaDoc();
656
657         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
658         if(property != null)
659         {
660             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
661             Iterator JavaDoc bindingsIterator = bindings.iterator();
662             while(bindingsIterator.hasNext())
663             {
664                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindingsIterator.next());
665                 contents.add(this.templateController.getContent(contentId));
666             }
667         }
668
669         return contents;
670     }
671     
672     public WebPage getBoundPage(String JavaDoc propertyName)
673     {
674         return getBoundPage(propertyName, this.useInheritance);
675     }
676     
677     /**
678      * This method returns a page bound to the component.
679      */

680
681     public WebPage getBoundPage(String JavaDoc propertyName, boolean useInheritance)
682     {
683         WebPage webPage = null;
684
685         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
686         
687         if(property != null)
688         {
689             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
690             Iterator JavaDoc bindingsIterator = bindings.iterator();
691             if(bindingsIterator.hasNext())
692             {
693                 webPage = new WebPage();
694                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindingsIterator.next());
695                 SiteNodeVO siteNode = templateController.getSiteNode(siteNodeId);
696                 if(siteNode != null)
697                 {
698                     webPage.setSiteNodeId(siteNodeId);
699                     webPage.setLanguageId(templateController.getLanguageId());
700                     webPage.setContentId(null);
701                     webPage.setNavigationTitle(getPageNavTitle(siteNodeId));
702                     webPage.setMetaInfoContentId(siteNode.getMetaInfoContentId());
703                     webPage.setUrl(getPageUrl(siteNodeId));
704                 }
705             }
706         }
707
708         return webPage;
709     }
710
711     
712     public List JavaDoc getBoundPages(String JavaDoc propertyName)
713     {
714         return getBoundPages(propertyName, this.useInheritance);
715     }
716     
717     /**
718      * This method returns a list of pages bound to the component.
719      */

720
721     public List JavaDoc getBoundPages(String JavaDoc propertyName, boolean useInheritance)
722     {
723         List JavaDoc pages = new ArrayList JavaDoc();
724
725         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
726         
727         if(property != null)
728         {
729             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
730             Iterator JavaDoc bindingsIterator = bindings.iterator();
731             while(bindingsIterator.hasNext())
732             {
733                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindingsIterator.next());
734                 SiteNodeVO siteNode = templateController.getSiteNode(siteNodeId);
735                 if(siteNode != null)
736                 {
737                     WebPage webPage = new WebPage();
738                     webPage.setSiteNodeId(siteNodeId);
739                     webPage.setLanguageId(templateController.getLanguageId());
740                     webPage.setContentId(null);
741                     webPage.setNavigationTitle(getPageNavTitle(siteNodeId));
742                     webPage.setMetaInfoContentId(siteNode.getMetaInfoContentId());
743                     webPage.setUrl(getPageUrl(siteNodeId));
744                     pages.add(webPage);
745                 }
746             }
747         }
748
749         return pages;
750     }
751
752     /**
753      * This method returns a list of pages bound to the component.
754      */

755
756     public SiteNodeVO getBoundSiteNode(String JavaDoc propertyName, boolean useInheritance)
757     {
758         SiteNodeVO siteNodeVO = null;
759         
760         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
761         
762         if(property != null)
763         {
764             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
765             Iterator JavaDoc bindingsIterator = bindings.iterator();
766             if(bindingsIterator.hasNext())
767             {
768                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindingsIterator.next());
769                 siteNodeVO = templateController.getSiteNode(siteNodeId);
770             }
771         }
772
773         return siteNodeVO;
774     }
775
776     /**
777      * This method returns a list of pages bound to the component on the given siteNode.
778      */

779
780     public SiteNodeVO getBoundSiteNode(Integer JavaDoc targetSiteNodeId, String JavaDoc propertyName, boolean useInheritance)
781     {
782         SiteNodeVO siteNodeVO = null;
783         
784         Map JavaDoc property = getInheritedComponentProperty(targetSiteNodeId, this.infoGlueComponent, propertyName, useInheritance);
785         
786         if(property != null)
787         {
788             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
789             Iterator JavaDoc bindingsIterator = bindings.iterator();
790             if(bindingsIterator.hasNext())
791             {
792                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindingsIterator.next());
793                 siteNodeVO = templateController.getSiteNode(siteNodeId);
794             }
795         }
796
797         return siteNodeVO;
798     }
799
800     /**
801      * This method returns a list of childContents using inheritence as default.
802      */

803
804     public List JavaDoc getChildContents(String JavaDoc propertyName)
805     {
806         return getChildContents(propertyName, this.useInheritance, false, "id", "asc", false);
807     }
808     
809     /**
810      * This method returns a list of childcontents.
811      */

812
813     public List JavaDoc getChildContents(String JavaDoc propertyName, boolean useInheritance, boolean searchRecursive, String JavaDoc sortAttribute, String JavaDoc sortOrder, boolean includeFolders)
814     {
815         List JavaDoc childContents = new ArrayList JavaDoc();
816         
817         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
818         if(property != null)
819         {
820             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
821             Iterator JavaDoc bindingsIterator = bindings.iterator();
822             while(bindingsIterator.hasNext())
823             {
824                 Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindingsIterator.next());
825                 childContents.addAll(this.templateController.getChildContents(contentId, searchRecursive, sortAttribute, sortOrder, includeFolders));
826             }
827         }
828         return childContents;
829     }
830
831     
832     /**
833      * This method returns a list of childpages using inheritence as default.
834      */

835
836     public List JavaDoc getChildPages(String JavaDoc propertyName)
837     {
838         return getChildPages(propertyName, this.useInheritance);
839     }
840
841     public List JavaDoc getChildPages(String JavaDoc propertyName, boolean useInheritance)
842     {
843         return getChildPages(propertyName, useInheritance, false, false);
844     }
845
846     public List JavaDoc getChildPages(String JavaDoc propertyName, boolean useInheritance, boolean escapeHTML)
847     {
848         return getChildPages(propertyName, this.useInheritance, escapeHTML, false);
849     }
850
851     /**
852      * This method returns a list of childpages.
853      */

854
855     public List JavaDoc getChildPages(String JavaDoc propertyName, boolean useInheritance, boolean escapeHTML, boolean hideUnauthorizedPages)
856     {
857         List JavaDoc childPages = new ArrayList JavaDoc();
858         
859         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
860         if(property != null)
861         {
862             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
863             Iterator JavaDoc bindingsIterator = bindings.iterator();
864             while(bindingsIterator.hasNext())
865             {
866                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindingsIterator.next());
867                 childPages.addAll(getChildPages(siteNodeId));
868             }
869         }
870         return childPages;
871     }
872
873     
874     /**
875      * This method returns a list of childpages.
876      */

877
878     public List JavaDoc getChildPages(Integer JavaDoc siteNodeId)
879     {
880         List JavaDoc pages = templateController.getChildPages(siteNodeId);
881
882         Iterator JavaDoc pagesIterator = pages.iterator();
883         while(pagesIterator.hasNext())
884         {
885             WebPage webPage = (WebPage)pagesIterator.next();
886             webPage.setUrl(getPageUrl(webPage.getSiteNodeId()));
887         }
888     
889         return pages;
890     }
891
892     public String JavaDoc getPageUrl(String JavaDoc propertyName) throws Exception JavaDoc
893     {
894         return getPageUrl(propertyName, this.useInheritance);
895     }
896
897     public String JavaDoc getPageUrl(String JavaDoc propertyName, boolean useInheritance)
898     {
899         String JavaDoc pageUrl = "";
900
901         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
902         if(property != null)
903         {
904             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
905             if(bindings.size() > 0)
906             {
907                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
908                 pageUrl = this.getPageUrl(siteNodeId, templateController.getLanguageId(), templateController.getContentId());
909             }
910         }
911         
912         return pageUrl;
913     }
914     
915     public String JavaDoc getPageUrl(Integer JavaDoc siteNodeId)
916     {
917         String JavaDoc pageUrl = "";
918
919         pageUrl = this.getPageUrl(siteNodeId, templateController.getLanguageId(), null);
920
921         return pageUrl;
922     }
923
924     public String JavaDoc getPageUrl(String JavaDoc propertyName, Integer JavaDoc contentId)
925     {
926         return getPageUrl(propertyName, contentId, this.useInheritance);
927     }
928     
929     public String JavaDoc getPageUrl(String JavaDoc propertyName, Integer JavaDoc contentId, boolean useInheritance)
930     {
931         String JavaDoc pageUrl = "";
932
933         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
934         if(property != null)
935         {
936             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
937             if(bindings.size() > 0)
938             {
939                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
940                 pageUrl = this.getPageUrl(siteNodeId, templateController.getLanguageId(), contentId);
941             }
942         }
943
944         return pageUrl;
945     }
946
947     public String JavaDoc getPageUrl(String JavaDoc propertyName, Integer JavaDoc contentId, Integer JavaDoc languageId, boolean useInheritance)
948     {
949         String JavaDoc pageUrl = "";
950
951         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
952         if(property != null)
953         {
954             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
955             if(bindings.size() > 0)
956             {
957                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
958                 pageUrl = this.getPageUrl(siteNodeId, languageId, contentId);
959             }
960         }
961
962         return pageUrl;
963     }
964
965     /**
966      * This method calls an page and stores it as an digitalAsset - that way one can avoid having to
967      * serve javascript-files and css-files through InfoGlue. Not suitable for use if you have very dynamic
968      * css:es or scripts which includes logic depending on user info etc.. mostly usable if you have a static css
969      * or controls it on the pageCache parameters.
970      */

971      
972     public String JavaDoc getPageAsDigitalAssetUrl(String JavaDoc propertyName) throws Exception JavaDoc
973     {
974         return getPageAsDigitalAssetUrl(propertyName, this.useInheritance, "");
975     }
976
977     /**
978      * This method calls an page and stores it as an digitalAsset - that way one can avoid having to
979      * serve javascript-files and css-files through InfoGlue. Not suitable for use if you have very dynamic
980      * css:es or scripts which includes logic depending on user info etc.. mostly usable if you have a static css
981      * or controls it on the pageCache parameters.
982      */

983     public String JavaDoc getPageAsDigitalAssetUrl(String JavaDoc propertyName, boolean useInheritance, String JavaDoc fileSuffix)
984     {
985         String JavaDoc pageUrl = "";
986
987         Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
988         if(property != null)
989         {
990             List JavaDoc bindings = (List JavaDoc)property.get("bindings");
991             if(bindings.size() > 0)
992             {
993                 Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
994                 pageUrl = this.getPageAsDigitalAssetUrl(siteNodeId, templateController.getLanguageId(), templateController.getContentId(), fileSuffix);
995             }
996         }
997         
998         return pageUrl;
999     }
1000
1001    /**
1002     * This method calls an page and stores it as an digitalAsset - that way one can avoid having to
1003     * serve javascript-files and css-files through InfoGlue. Not suitable for use if you have very dynamic
1004     * css:es or scripts which includes logic depending on user info etc.. mostly usable if you have a static css
1005     * or controls it on the pageCache parameters.
1006     */

1007    public String JavaDoc getPageAsDigitalAssetUrl(String JavaDoc propertyName, Integer JavaDoc languageId, Integer JavaDoc contentId, boolean useInheritance, String JavaDoc fileSuffix)
1008    {
1009        String JavaDoc pageUrl = "";
1010
1011        Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, useInheritance);
1012        if(property != null)
1013        {
1014            List JavaDoc bindings = (List JavaDoc)property.get("bindings");
1015            if(bindings.size() > 0)
1016            {
1017                Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
1018                pageUrl = this.getPageAsDigitalAssetUrl(siteNodeId, languageId, contentId, fileSuffix);
1019            }
1020        }
1021        
1022        return pageUrl;
1023    }
1024
1025    /**
1026     * This method calls an page and stores it as an digitalAsset - that way one can avoid having to
1027     * serve javascript-files and css-files through InfoGlue. Not suitable for use if you have very dynamic
1028     * css:es or scripts which includes logic depending on user info etc.. mostly usable if you have a static css
1029     * or controls it on the pageCache parameters.
1030     */

1031    public String JavaDoc getPageAsDigitalAssetUrl(Integer JavaDoc siteNodeId, Integer JavaDoc languageId, Integer JavaDoc contentId, String JavaDoc fileSuffix)
1032    {
1033        String JavaDoc pageUrl = this.templateController.getPageAsDigitalAssetUrl(siteNodeId, languageId, contentId, fileSuffix);
1034        
1035        return pageUrl;
1036    }
1037
1038
1039    public String JavaDoc getPageNavTitle(String JavaDoc propertyName)
1040    {
1041        String JavaDoc pageUrl = "";
1042
1043        Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, this.useInheritance);
1044        if(property != null)
1045        {
1046            List JavaDoc bindings = (List JavaDoc)property.get("bindings");
1047            if(bindings.size() > 0)
1048            {
1049                Integer JavaDoc siteNodeId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
1050                pageUrl = templateController.getPageNavTitle(siteNodeId);
1051            }
1052        }
1053        
1054        return pageUrl;
1055    }
1056    
1057    public List JavaDoc getRelatedPages(String JavaDoc propertyName, String JavaDoc attributeName)
1058    {
1059        List JavaDoc relatedPages = new ArrayList JavaDoc();
1060        
1061        Map JavaDoc property = getInheritedComponentProperty(this.infoGlueComponent, propertyName, this.useInheritance);
1062        if(property != null)
1063        {
1064            List JavaDoc bindings = (List JavaDoc)property.get("bindings");
1065            if(bindings.size() > 0)
1066            {
1067                Integer JavaDoc contentId = new Integer JavaDoc((String JavaDoc)bindings.get(0));
1068                relatedPages = templateController.getRelatedPages(contentId, attributeName);
1069            }
1070        }
1071        
1072        return relatedPages;
1073    }
1074    
1075    /**
1076     * This method gets a property from the component and if not found there checks in parent components.
1077     */

1078
1079    public Map JavaDoc getInheritedComponentProperty(InfoGlueComponent component, String JavaDoc propertyName, boolean useInheritance)
1080    {
1081        try
1082        {
1083            Map JavaDoc property1 = getComponentProperty(propertyName, useInheritance);
1084            if(property1 != null)
1085                return property1;
1086                
1087            Map JavaDoc property = (Map JavaDoc)component.getProperties().get(propertyName);
1088            InfoGlueComponent parentComponent = component.getParentComponent();
1089            //logger.info("parentComponent: " + parentComponent);
1090
while(property == null && parentComponent != null)
1091            {
1092                property = (Map JavaDoc)parentComponent.getProperties().get(propertyName);
1093                parentComponent = parentComponent.getParentComponent();
1094            }
1095            
1096            return property;
1097        }
1098        catch(Exception JavaDoc e)
1099        {
1100            e.printStackTrace();
1101        }
1102        
1103        return null;
1104    }
1105
1106    /**
1107     * This method gets a property from the component and if not found there checks in parent components.
1108     */

1109
1110    public Map JavaDoc getInheritedComponentProperty(Integer JavaDoc siteNodeId, InfoGlueComponent component, String JavaDoc propertyName, boolean useInheritance)
1111    {
1112        try
1113        {
1114            Map JavaDoc property1 = getComponentProperty(siteNodeId, propertyName, useInheritance);
1115            if(property1 != null)
1116                return property1;
1117            /*
1118            Map property = (Map)component.getProperties().get(propertyName);
1119            InfoGlueComponent parentComponent = component.getParentComponent();
1120            //logger.info("parentComponent: " + parentComponent);
1121            while(property == null && parentComponent != null)
1122            {
1123                property = (Map)parentComponent.getProperties().get(propertyName);
1124                parentComponent = parentComponent.getParentComponent();
1125            }
1126            */

1127            
1128            return null;
1129        }
1130        catch(Exception JavaDoc e)
1131        {
1132            e.printStackTrace();
1133        }
1134        
1135        return null;
1136    }
1137
1138    /**
1139     * This method gets a property from the component and if not found there checks in parent components.
1140     */

1141
1142    public List JavaDoc getInheritedComponentProperties(String JavaDoc propertyName, boolean useInheritance)
1143    {
1144        return getInheritedComponentProperties(this.templateController.getSiteNodeId(), propertyName, useInheritance);
1145    }
1146
1147    /**
1148     * This method gets a property from the component and if not found there checks in parent components.
1149     */

1150
1151    public List JavaDoc getInheritedComponentProperties(Integer JavaDoc siteNodeId, String JavaDoc propertyName, boolean useInheritance)
1152    {
1153        try
1154        {
1155            List JavaDoc properties = getComponentProperties(siteNodeId, propertyName, useInheritance);
1156            if(properties != null)
1157                return properties;
1158            
1159            return null;
1160        }
1161        catch(Exception JavaDoc e)
1162        {
1163            e.printStackTrace();
1164        }
1165        
1166        return null;
1167    }
1168
1169    /**
1170     * This method gets if a property is defined and available in the given page.
1171     */

1172
1173    public boolean getHasDefinedProperty(Integer JavaDoc siteNodeId, Integer JavaDoc languageId, String JavaDoc propertyName, boolean useInheritance)
1174    {
1175        Map JavaDoc property = getComponentProperty(siteNodeId, languageId, propertyName, useInheritance);
1176        
1177        return property == null ? false : true;
1178    }
1179
1180    
1181    /**
1182     * This method gets a property from the sitenode given and also looks recursively upwards.
1183     */

1184    
1185    public Map JavaDoc getComponentProperty(Integer JavaDoc siteNodeId, Integer JavaDoc languageId, String JavaDoc propertyName, boolean useInheritance)
1186    {
1187        Map JavaDoc componentProperty = getComponentProperty(siteNodeId, languageId, propertyName);
1188        SiteNodeVO parentSiteNodeVO = this.templateController.getParentSiteNode(siteNodeId);
1189        while(componentProperty == null && useInheritance && parentSiteNodeVO != null)
1190        {
1191            componentProperty = getComponentProperty(parentSiteNodeVO.getId(), languageId, propertyName);
1192            parentSiteNodeVO = this.templateController.getParentSiteNode(parentSiteNodeVO.getId());
1193        }
1194        
1195        return componentProperty;
1196    }
1197
1198        
1199    /**
1200     * This method gets a property from the sitenode given .
1201     */

1202 
1203    public Map JavaDoc getComponentProperty(Integer JavaDoc siteNodeId, Integer JavaDoc languageId, String JavaDoc propertyName)
1204    {
1205        try
1206        {
1207            List JavaDoc contentVersionIdList = new ArrayList JavaDoc();
1208
1209            String JavaDoc componentPropertiesXML = getPageComponentsString(this.templateController, siteNodeId, languageId, new Integer JavaDoc(-1), contentVersionIdList);
1210            logger.info("componentPropertiesXML:" + componentPropertiesXML);
1211            
1212            String JavaDoc key = "" + siteNodeId + "_" + languageId + "_" + propertyName;
1213            //Map property = (Map)CacheController.getCachedObjectFromAdvancedCache("componentPropertyCache", key);
1214
Object JavaDoc propertyCandidate = CacheController.getCachedObjectFromAdvancedCache("componentPropertyCache", key);
1215            //System.out.println("propertyCandidate for key " + key + "=" + propertyCandidate);
1216
Map JavaDoc property = null;
1217                
1218            if(propertyCandidate != null)
1219            {
1220                if(propertyCandidate instanceof NullObject)
1221                    property = null;
1222                else
1223                    property = (Map JavaDoc)propertyCandidate;
1224                    
1225                //logger.info("There was an cached content attribute:" + attribute);
1226
//System.out.println("Returning cached property for key " + key);
1227
}
1228            else
1229            {
1230                logger.info("Have to fetch property from XML...:" + key);
1231            
1232                //HashMap property = null;
1233

1234                if(componentPropertiesXML != null && componentPropertiesXML.length() > 0)
1235                {
1236                    Document JavaDoc document = XMLHelper.readDocumentFromByteArray(componentPropertiesXML.getBytes("UTF-8"));
1237                    String JavaDoc propertyXPath = "//component/properties/property[@name='" + propertyName + "']";
1238                    //logger.info("propertyXPath:" + propertyXPath);
1239
NodeList JavaDoc anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), propertyXPath);
1240                    //logger.info("*********************************************************anl:" + anl.getLength());
1241

1242                    for(int i=0; i < anl.getLength(); i++)
1243                    {
1244                        Element JavaDoc propertyElement = (Element JavaDoc)anl.item(i);
1245    
1246                        String JavaDoc name = propertyElement.getAttribute("name");
1247                        String JavaDoc type = propertyElement.getAttribute("type");
1248                        String JavaDoc entity = propertyElement.getAttribute("entity");
1249                        boolean isMultipleBinding = new Boolean JavaDoc(propertyElement.getAttribute("multiple")).booleanValue();
1250                        
1251                        String JavaDoc value = null;
1252                        
1253                        if(type.equalsIgnoreCase("textfield") || type.equalsIgnoreCase("textarea") || type.equalsIgnoreCase("select"))
1254                        {
1255                            value = propertyElement.getAttribute("path");
1256    
1257                            Locale JavaDoc locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(templateController.getDatabase(), languageId);
1258    
1259                            if(propertyElement.hasAttribute("path_" + locale.getLanguage()))
1260                                value = propertyElement.getAttribute("path_" + locale.getLanguage());
1261                        }
1262                        
1263                        property = new HashMap JavaDoc();
1264                        property.put("name", name);
1265                        property.put("path", value);
1266                        property.put("type", type);
1267                        
1268                        List JavaDoc bindings = new ArrayList JavaDoc();
1269                        NodeList JavaDoc bindingNodeList = propertyElement.getElementsByTagName("binding");
1270                        //logger.info("bindingNodeList:" + bindingNodeList.getLength());
1271
for(int j=0; j < bindingNodeList.getLength(); j++)
1272                        {
1273                            Element JavaDoc bindingElement = (Element JavaDoc)bindingNodeList.item(j);
1274                            String JavaDoc entityName = bindingElement.getAttribute("entity");
1275                            String JavaDoc entityId = bindingElement.getAttribute("entityId");
1276                            //logger.info("Binding found:" + entityName + ":" + entityId);
1277
if(entityName.equalsIgnoreCase("Content"))
1278                            {
1279                                //logger.info("Content added:" + entityName + ":" + entityId);
1280
bindings.add(entityId);
1281                            }
1282                            else
1283                            {
1284                                //logger.info("SiteNode added:" + entityName + ":" + entityId);
1285
bindings.add(entityId);
1286                            }
1287                        }
1288    
1289                        property.put("bindings", bindings);
1290                    }
1291                    
1292                    if(property != null && contentVersionIdList.size() > 0)
1293                    {
1294                        ////System.out.println("Caching property: " + contentVersionIdList.get(0) + ":" + property);
1295

1296                        Integer JavaDoc contentVersionId = (Integer JavaDoc)contentVersionIdList.get(0);
1297                        if(contentVersionId != null)
1298                        {
1299                            ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(contentVersionId, this.templateController.getDatabase());
1300                            logger.info("Caching property:" + key);
1301                            CacheController.cacheObjectInAdvancedCache("componentPropertyCache", key, property, new String JavaDoc[]{"contentVersion_" + contentVersionId, "content_" + contentVersion.getValueObject().getContentId()}, true);
1302                        }
1303                    }
1304                }
1305            }
1306            
1307            return property;
1308        }
1309        catch(Exception JavaDoc e)
1310        {
1311            e.printStackTrace();
1312        }
1313        
1314        return null;
1315    }
1316
1317    /**
1318     * This method returns a url to the given page. The url is composed of siteNode, language and content
1319     * TODO - temporary dev solution
1320     */

1321
1322    public String JavaDoc getPageUrl(Integer JavaDoc siteNodeId, Integer JavaDoc languageId, Integer JavaDoc contentId)
1323    {
1324        String JavaDoc pageUrl = this.templateController.getPageUrl(siteNodeId, languageId, contentId);
1325        
1326        return pageUrl;
1327    }
1328
1329        
1330    public String JavaDoc getPageNavTitle(Integer JavaDoc siteNodeId)
1331    {
1332        String JavaDoc navTitle = "";
1333
1334        navTitle = templateController.getPageNavTitle(siteNodeId);
1335    
1336        return navTitle;
1337    }
1338    
1339    
1340    /**
1341     * This method fetches the component named component property. If not available on the current page metainfo we go up recursive.
1342     */

1343    
1344    private Map JavaDoc getComponentProperty(String JavaDoc propertyName, boolean useInheritance) throws Exception JavaDoc
1345    {
1346        Map JavaDoc property = (Map JavaDoc)this.infoGlueComponent.getProperties().get(propertyName);
1347        
1348        if(useInheritance)
1349        {
1350            try
1351            {
1352                NodeDeliveryController nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(this.templateController.getSiteNodeId(), this.templateController.getLanguageId(), this.templateController.getContentId());
1353            
1354                SiteNodeVO parentSiteNodeVO = nodeDeliveryController.getSiteNode(templateController.getDatabase(), this.templateController.getSiteNodeId()).getValueObject();
1355                while(property == null && parentSiteNodeVO != null)
1356                {
1357                    property = getInheritedComponentProperty(this.templateController, parentSiteNodeVO.getId(), this.templateController.getLanguageId(), this.templateController.getContentId(), this.infoGlueComponent.getId(), propertyName);
1358                    
1359                    SiteNodeVO newParentSiteNodeVO = nodeDeliveryController.getParentSiteNode(templateController.getDatabase(), parentSiteNodeVO.getId());
1360                
1361                    if(newParentSiteNodeVO == null)
1362                    {
1363                        Integer JavaDoc parentRepositoryId = this.templateController.getParentRepositoryId(parentSiteNodeVO.getRepositoryId());
1364                        logger.info("parentRepositoryId:" + parentRepositoryId);
1365                        if(parentRepositoryId != null)
1366                        {
1367                            newParentSiteNodeVO = this.templateController.getRepositoryRootSiteNode(parentRepositoryId);
1368                        }
1369                    }
1370                    
1371                    parentSiteNodeVO = newParentSiteNodeVO;
1372                }
1373            }
1374            catch(Exception JavaDoc e)
1375            {
1376                e.printStackTrace();
1377            }
1378        }
1379
1380        //logger.info("Done..." + propertyName);
1381

1382        return property;
1383    }
1384
1385    /**
1386     * This method fetches the component named component property. If not available on the sent in page metainfo we go up recursive.
1387     */

1388    
1389    private Map JavaDoc getComponentProperty(Integer JavaDoc siteNodeId, String JavaDoc propertyName, boolean useInheritance) throws Exception JavaDoc
1390    {
1391        //Map property = (Map)this.infoGlueComponent.getProperties().get(propertyName);
1392
//logger.info("property1:" + property);
1393
Map JavaDoc property = getInheritedComponentProperty(this.templateController, siteNodeId, this.templateController.getLanguageId(), this.templateController.getContentId(), this.infoGlueComponent.getId(), propertyName);
1394        
1395        if(useInheritance)
1396        {
1397            try
1398            {
1399                NodeDeliveryController nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(siteNodeId, this.templateController.getLanguageId(), this.templateController.getContentId());
1400            
1401                SiteNodeVO parentSiteNodeVO = nodeDeliveryController.getSiteNode(templateController.getDatabase(), siteNodeId).getValueObject();
1402                while(property == null && parentSiteNodeVO != null)
1403                {
1404                    property = getInheritedComponentProperty(this.templateController, parentSiteNodeVO.getId(), this.templateController.getLanguageId(), this.templateController.getContentId(), this.infoGlueComponent.getId(), propertyName);
1405                    
1406                    SiteNodeVO newParentSiteNodeVO = nodeDeliveryController.getParentSiteNode(templateController.getDatabase(), parentSiteNodeVO.getId());
1407                
1408                    if(newParentSiteNodeVO == null)
1409                    {
1410                        Integer JavaDoc parentRepositoryId = this.templateController.getParentRepositoryId(parentSiteNodeVO.getRepositoryId());
1411                        logger.info("parentRepositoryId:" + parentRepositoryId);
1412                        if(parentRepositoryId != null)
1413                        {
1414                            newParentSiteNodeVO = this.templateController.getRepositoryRootSiteNode(parentRepositoryId);
1415                        }
1416                    }
1417                    
1418                    parentSiteNodeVO = newParentSiteNodeVO;
1419                }
1420            }
1421            catch(Exception JavaDoc e)
1422            {
1423                e.printStackTrace();
1424            }
1425        }
1426
1427        //logger.info("Done..." + propertyName);
1428

1429        return property;
1430    }
1431
1432    
1433    /**
1434     * This method gets a component property from the parent to the current recursively until found.
1435     */

1436     
1437    private Map JavaDoc getInheritedComponentProperty(TemplateController templateController, Integer JavaDoc siteNodeId, Integer JavaDoc languageId, Integer JavaDoc contentId, Integer JavaDoc componentId, String JavaDoc propertyName) throws Exception JavaDoc
1438    {
1439        List JavaDoc contentVersionIdList = new ArrayList JavaDoc();
1440
1441        //logger.info("Checking for property " + propertyName + " on siteNodeId " + siteNodeId);
1442
String JavaDoc inheritedPageComponentsXML = getPageComponentsString(templateController, siteNodeId, languageId, contentId, contentVersionIdList);
1443        //logger.info("inheritedPageComponentsXML:" + inheritedPageComponentsXML);
1444

1445        String JavaDoc key = "inherited_" + siteNodeId + "_" + languageId + "_" + componentId + "_" + propertyName;
1446        Object JavaDoc propertyCandidate = CacheController.getCachedObjectFromAdvancedCache("componentPropertyCache", key);
1447        //System.out.println("propertyCandidate for key " + key + "=" + propertyCandidate);
1448
Map JavaDoc property = null;
1449            
1450        if(propertyCandidate != null)
1451        {
1452            if(propertyCandidate instanceof NullObject)
1453                property = null;
1454            else
1455                property = (Map JavaDoc)propertyCandidate;
1456                
1457            //logger.info("There was an cached content attribute:" + attribute);
1458
//System.out.println("Returning cached property for key " + key);
1459
}
1460        else
1461        {
1462            logger.info("Checking for property " + propertyName + " on siteNodeId " + siteNodeId);
1463
1464            ////System.out.println("Have to fetch property from XML...:" + contentVersionIdList.size());
1465

1466            //HashMap property = null;
1467

1468            if(inheritedPageComponentsXML != null && inheritedPageComponentsXML.length() > 0)
1469            {
1470                Document JavaDoc document = XMLHelper.readDocumentFromByteArray(inheritedPageComponentsXML.getBytes("UTF-8"));
1471                String JavaDoc propertyXPath = "//component[@id=" + componentId + "]/properties/property[@name='" + propertyName + "']";
1472                //logger.info("propertyXPath:" + propertyXPath);
1473
//logger.info("propertyXPath:" + propertyXPath);
1474
NodeList JavaDoc anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), propertyXPath);
1475                //logger.info("*********************************************************anl:" + anl.getLength());
1476

1477                //If not found on the same component id - let's check them all and use the first we find.
1478
if(anl == null || anl.getLength() == 0)
1479                {
1480                    String JavaDoc globalPropertyXPath = "//component/properties/property[@name='" + propertyName + "'][1]";
1481                    //logger.info("globalPropertyXPath:" + globalPropertyXPath);
1482
//logger.info("globalPropertyXPath:" + globalPropertyXPath);
1483
anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), globalPropertyXPath);
1484                    //logger.info("anl:" + anl.getLength());
1485
//logger.info("*********************************************************anl:" + anl.getLength());
1486
}
1487                
1488                for(int i=0; i < anl.getLength(); i++)
1489                {
1490                    Element JavaDoc propertyElement = (Element JavaDoc)anl.item(i);
1491                    //logger.info(XMLHelper.serializeDom(propertyElement, new StringBuffer()));
1492
//logger.info("YES - we read the property...");
1493

1494                    String JavaDoc name = propertyElement.getAttribute("name");
1495                    String JavaDoc type = propertyElement.getAttribute("type");
1496                    String JavaDoc entity = propertyElement.getAttribute("entity");
1497                    boolean isMultipleBinding = new Boolean JavaDoc(propertyElement.getAttribute("multiple")).booleanValue();
1498                    
1499                    //logger.info("name:" + name);
1500
//logger.info("type:" + type);
1501
//logger.info("entity:" + entity);
1502
//logger.info("isMultipleBinding:" + isMultipleBinding);
1503

1504                    //logger.info("name:" + name);
1505
//logger.info("type:" + type);
1506
//logger.info("entity:" + entity);
1507
//logger.info("isMultipleBinding:" + isMultipleBinding);
1508

1509                    String JavaDoc value = null;
1510                    
1511                    if(type.equalsIgnoreCase("textfield") || type.equalsIgnoreCase("textarea") || type.equalsIgnoreCase("select"))
1512                    {
1513                        value = propertyElement.getAttribute("path");
1514    
1515                        Locale JavaDoc locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(templateController.getDatabase(), languageId);
1516                        //System.out.println("locale:" + languageId + ":" + locale.getDisplayLanguage());
1517
Locale JavaDoc masterLocale = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(templateController.getDatabase(), siteNodeId).getLocale();
1518                        //System.out.println("masterLocale:" + masterLocale.getDisplayLanguage());
1519

1520                        if(propertyElement.hasAttribute("path_" + locale.getLanguage()))
1521                            value = propertyElement.getAttribute("path_" + locale.getLanguage());
1522
1523                        if((value == null || value.equals("")) && propertyElement.hasAttribute("path_" + masterLocale.getLanguage()))
1524                            value = propertyElement.getAttribute("path_" + masterLocale.getLanguage());
1525                    }
1526                    else
1527                    {
1528                        value = getComponentPropertyValue(inheritedPageComponentsXML, componentId, languageId, name);
1529                    }
1530                    
1531                    
1532                    property = new HashMap JavaDoc();
1533                    property.put("name", name);
1534                    //property.put("path", "Inherited");
1535
property.put("path", value);
1536                    property.put("type", type);
1537                    
1538                    List JavaDoc bindings = new ArrayList JavaDoc();
1539                    NodeList JavaDoc bindingNodeList = propertyElement.getElementsByTagName("binding");
1540                    //logger.info("bindingNodeList:" + bindingNodeList.getLength());
1541
for(int j=0; j < bindingNodeList.getLength(); j++)
1542                    {
1543                        Element JavaDoc bindingElement = (Element JavaDoc)bindingNodeList.item(j);
1544                        String JavaDoc entityName = bindingElement.getAttribute("entity");
1545                        String JavaDoc entityId = bindingElement.getAttribute("entityId");
1546                        //logger.info("Binding found:" + entityName + ":" + entityId);
1547
if(entityName.equalsIgnoreCase("Content"))
1548                        {
1549                            //logger.info("Content added:" + entityName + ":" + entityId);
1550
bindings.add(entityId);
1551                        }
1552                        else
1553                        {
1554                            //logger.info("SiteNode added:" + entityName + ":" + entityId);
1555
bindings.add(entityId);
1556                        }
1557                    }
1558    
1559                    property.put("bindings", bindings);
1560                }
1561            }
1562            
1563            //System.out.println("property:" + property);
1564
if(property != null && contentVersionIdList.size() > 0)
1565            {
1566                Integer JavaDoc contentVersionId = (Integer JavaDoc)contentVersionIdList.get(0);
1567                if(contentVersionId != null)
1568                {
1569                    ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(contentVersionId, this.templateController.getDatabase());
1570                    //System.out.println("Caching property: " + contentVersionIdList.get(0) + ":" + property);
1571
CacheController.cacheObjectInAdvancedCache("componentPropertyCache", key, property, new String JavaDoc[]{"contentVersion_" + contentVersionId, "content_" + contentVersion.getValueObject().getContentId()}, true);
1572                }
1573            }
1574            else
1575            {
1576                //System.out.println("contentVersionIdList.size():" + contentVersionIdList.size());
1577
if(property == null && contentVersionIdList.size() > 0)
1578                {
1579                    Integer JavaDoc contentVersionId = (Integer JavaDoc)contentVersionIdList.get(0);
1580                    //System.out.println("contentVersionId: " + contentVersionId);
1581
if(contentVersionId != null)
1582                    {
1583                        ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(contentVersionId, this.templateController.getDatabase());
1584                        //System.out.println("Caching property: " + contentVersionIdList.get(0) + ": NullObject");
1585
CacheController.cacheObjectInAdvancedCache("componentPropertyCache", key, new NullObject(), new String JavaDoc[]{"contentVersion_" + contentVersionId, "content_" + contentVersion.getValueObject().getContentId()}, true);
1586                    }
1587                    else
1588                    {
1589                        //System.out.println("Caching property without content versions: NullObject for key " + key);
1590
CacheController.cacheObjectInAdvancedCache("componentPropertyCache", key, new NullObject(), new String JavaDoc[]{}, false);
1591                    }
1592                }
1593                else
1594                {
1595                    //System.out.println("Caching property without content versions: NullObject for key " + key);
1596
CacheController.cacheObjectInAdvancedCache("componentPropertyCache", key, new NullObject(), new String JavaDoc[]{}, false);
1597                }
1598            }
1599        }
1600                
1601        return property;
1602    }
1603
1604
1605    /**
1606     * This method fetches the components named component property. If not available on the sent in page metainfo we go up recursive.
1607     */

1608    
1609    private List JavaDoc getComponentProperties(Integer JavaDoc siteNodeId, String JavaDoc propertyName, boolean useInheritance) throws Exception JavaDoc
1610    {
1611        List JavaDoc properties = getInheritedComponentProperties(this.templateController, siteNodeId, this.templateController.getLanguageId(), this.templateController.getContentId(), this.infoGlueComponent.getId(), propertyName);
1612        
1613        if(useInheritance)
1614        {
1615            try
1616            {
1617                NodeDeliveryController nodeDeliveryController = NodeDeliveryController.getNodeDeliveryController(siteNodeId, this.templateController.getLanguageId(), this.templateController.getContentId());
1618            
1619                SiteNodeVO parentSiteNodeVO = nodeDeliveryController.getSiteNode(templateController.getDatabase(), siteNodeId).getValueObject();
1620                while(properties == null || properties.size() == 0 && parentSiteNodeVO != null)
1621                {
1622                    properties = getInheritedComponentProperties(this.templateController, parentSiteNodeVO.getId(), this.templateController.getLanguageId(), this.templateController.getContentId(), this.infoGlueComponent.getId(), propertyName);
1623                    
1624                    SiteNodeVO newParentSiteNodeVO = nodeDeliveryController.getParentSiteNode(templateController.getDatabase(), parentSiteNodeVO.getId());
1625                
1626                    if(newParentSiteNodeVO == null)
1627                    {
1628                        Integer JavaDoc parentRepositoryId = this.templateController.getParentRepositoryId(parentSiteNodeVO.getRepositoryId());
1629                        logger.info("parentRepositoryId:" + parentRepositoryId);
1630                        if(parentRepositoryId != null)
1631                        {
1632                            newParentSiteNodeVO = this.templateController.getRepositoryRootSiteNode(parentRepositoryId);
1633                        }
1634                    }
1635                    
1636                    parentSiteNodeVO = newParentSiteNodeVO;
1637                }
1638            }
1639            catch(Exception JavaDoc e)
1640            {
1641                e.printStackTrace();
1642            }
1643        }
1644
1645        return properties;
1646    }
1647
1648    
1649    /**
1650     * This method gets a component property from the parent to the current recursively until found.
1651     */

1652     
1653    private List JavaDoc getInheritedComponentProperties(TemplateController templateController, Integer JavaDoc siteNodeId, Integer JavaDoc languageId, Integer JavaDoc contentId, Integer JavaDoc componentId, String JavaDoc propertyName) throws Exception JavaDoc
1654    {
1655        List JavaDoc contentVersionIdList = new ArrayList JavaDoc();
1656        
1657        //logger.info("Checking for property " + propertyName + " on siteNodeId " + siteNodeId);
1658
String JavaDoc inheritedPageComponentsXML = getPageComponentsString(templateController, siteNodeId, languageId, contentId, contentVersionIdList);
1659        //logger.info("inheritedPageComponentsXML:" + inheritedPageComponentsXML);
1660

1661        String JavaDoc key = "all_" + siteNodeId + "_" + languageId + "_" + propertyName;
1662        List JavaDoc properties = (List JavaDoc)CacheController.getCachedObjectFromAdvancedCache("componentPropertyCache", key);
1663        
1664        if(properties != null)
1665        {
1666            //logger.info("There was an cached content attribute:" + attribute);
1667
////System.out.println("Returning cached property...");
1668
}
1669        else
1670        {
1671            properties = new ArrayList JavaDoc();
1672            
1673            ////System.out.println("Have to fetch property from XML...:" + contentVersionIdList.size());
1674

1675            //HashMap property = null;
1676

1677            if(inheritedPageComponentsXML != null && inheritedPageComponentsXML.length() > 0)
1678            {
1679                Document JavaDoc document = XMLHelper.readDocumentFromByteArray(inheritedPageComponentsXML.getBytes("UTF-8"));
1680                
1681                String JavaDoc globalPropertyXPath = "//component/properties/property[@name='" + propertyName + "']";
1682                //logger.info("globalPropertyXPath:" + globalPropertyXPath);
1683
//logger.info("globalPropertyXPath:" + globalPropertyXPath);
1684
NodeList JavaDoc anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), globalPropertyXPath);
1685                //logger.info("anl:" + anl.getLength());
1686
//logger.info("*********************************************************anl:" + anl.getLength());
1687

1688                for(int i=0; i < anl.getLength(); i++)
1689                {
1690                    Element JavaDoc propertyElement = (Element JavaDoc)anl.item(i);
1691                    //logger.info(XMLHelper.serializeDom(propertyElement, new StringBuffer()));
1692
//logger.info("YES - we read the property...");
1693

1694                    String JavaDoc name = propertyElement.getAttribute("name");
1695                    String JavaDoc type = propertyElement.getAttribute("type");
1696                    String JavaDoc entity = propertyElement.getAttribute("entity");
1697                    boolean isMultipleBinding = new Boolean JavaDoc(propertyElement.getAttribute("multiple")).booleanValue();
1698                    
1699                    //logger.info("name:" + name);
1700
//logger.info("type:" + type);
1701
//logger.info("entity:" + entity);
1702
//logger.info("isMultipleBinding:" + isMultipleBinding);
1703

1704                    String JavaDoc value = null;
1705                    
1706                    if(type.equalsIgnoreCase("textfield") || type.equalsIgnoreCase("textarea") || type.equalsIgnoreCase("select"))
1707                    {
1708                        value = propertyElement.getAttribute("path");
1709    
1710                        Locale JavaDoc locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(templateController.getDatabase(), languageId);
1711    
1712                        if(propertyElement.hasAttribute("path_" + locale.getLanguage()))
1713                            value = propertyElement.getAttribute("path_" + locale.getLanguage());
1714                    }
1715                    else
1716                    {
1717                        value = getComponentPropertyValue(propertyElement, languageId, name);
1718                    }
1719                    /*
1720                    //System.out.println("name:" + name);
1721                    //System.out.println("type:" + type);
1722                    //System.out.println("entity:" + entity);
1723                    //System.out.println("value:" + value);
1724                    //System.out.println("isMultipleBinding:" + isMultipleBinding);
1725                    */

1726                    Map JavaDoc property = new HashMap JavaDoc();
1727                    property.put("name", name);
1728                    property.put("path", value);
1729                    property.put("type", type);
1730                    
1731                    List JavaDoc bindings = new ArrayList JavaDoc();
1732                    NodeList JavaDoc bindingNodeList = propertyElement.getElementsByTagName("binding");
1733                    //logger.info("bindingNodeList:" + bindingNodeList.getLength());
1734
for(int j=0; j < bindingNodeList.getLength(); j++)
1735                    {
1736                        Element JavaDoc bindingElement = (Element JavaDoc)bindingNodeList.item(j);
1737                        String JavaDoc entityName = bindingElement.getAttribute("entity");
1738                        String JavaDoc entityId = bindingElement.getAttribute("entityId");
1739                        //logger.info("Binding found:" + entityName + ":" + entityId);
1740
if(entityName.equalsIgnoreCase("Content"))
1741                        {
1742                            //logger.info("Content added:" + entityName + ":" + entityId);
1743
bindings.add(entityId);
1744                        }
1745                        else
1746                        {
1747                            //logger.info("SiteNode added:" + entityName + ":" + entityId);
1748
bindings.add(entityId);
1749                        }
1750                    }
1751    
1752                    property.put("bindings", bindings);
1753
1754                    properties.add(property);
1755                }
1756            }
1757            
1758            if(properties != null && contentVersionIdList.size() > 0)
1759            {
1760                ////System.out.println("Caching property: " + contentVersionIdList.get(0) + ":" + property);
1761

1762                Integer JavaDoc contentVersionId = (Integer JavaDoc)contentVersionIdList.get(0);
1763                ////System.out.println("contentVersionId:" + contentVersionId);
1764
if(contentVersionId != null)
1765                {
1766                    ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(contentVersionId, this.templateController.getDatabase());
1767                    CacheController.cacheObjectInAdvancedCache("componentPropertyCache", key, properties, new String JavaDoc[]{"contentVersion_" + contentVersionId, "content_" + contentVersion.getValueObject().getContentId()}, true);
1768                }
1769            }
1770
1771        }
1772        
1773        return properties;
1774    }
1775
1776    /**
1777     * This method fetches the template-string.
1778     */

1779    
1780    private String JavaDoc getComponentPropertiesString(TemplateController templateController, Integer JavaDoc siteNodeId, Integer JavaDoc languageId, Integer JavaDoc contentId) throws SystemException, Exception JavaDoc
1781    {
1782        String JavaDoc template = null;
1783        
1784        try
1785        {
1786            template = templateController.getContentAttribute(contentId, "ComponentStructure", true);
1787
1788            if(template == null)
1789                throw new SystemException("There was no component properties bound to this page which makes it impossible to render.");
1790        }
1791        catch(Exception JavaDoc e)
1792        {
1793            logger.error(e.getMessage(), e);
1794            throw e;
1795        }
1796
1797        return template;
1798    }
1799    
1800    
1801    /**
1802     * This method returns a value for a property if it's set. The value is collected in the
1803     * properties for the page.
1804     */

1805    
1806    private String JavaDoc getComponentPropertyValue(String JavaDoc componentXML, Integer JavaDoc componentId, Integer JavaDoc languageId, String JavaDoc name) throws Exception JavaDoc
1807    {
1808        String JavaDoc value = "Undefined";
1809        
1810        Locale JavaDoc locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(templateController.getDatabase(), languageId);
1811
1812        Document JavaDoc document = XMLHelper.readDocumentFromByteArray(componentXML.getBytes("UTF-8"));
1813        String JavaDoc componentXPath = "//component[@id=" + componentId + "]/properties/property[@name='" + name + "']";
1814        //logger.info("componentXPath:" + componentXPath);
1815
NodeList JavaDoc anl = org.apache.xpath.XPathAPI.selectNodeList(document.getDocumentElement(), componentXPath);
1816        for(int i=0; i < anl.getLength(); i++)
1817        {
1818            Element JavaDoc property = (Element JavaDoc)anl.item(i);
1819            
1820            String JavaDoc id = property.getAttribute("type");
1821            String JavaDoc path = property.getAttribute("path");
1822            
1823            if(property.hasAttribute("path_" + locale.getLanguage()))
1824                path = property.getAttribute("path_" + locale.getLanguage());
1825            
1826            value = path;
1827        }
1828
1829        
1830        return value;
1831    }
1832
1833    /**
1834     * This method returns a value for a property if it's set. The value is collected in the
1835     * properties for the page.
1836     */

1837    
1838    private String JavaDoc getComponentPropertyValue(Element JavaDoc property, Integer JavaDoc languageId, String JavaDoc name) throws Exception JavaDoc
1839    {
1840        String JavaDoc value = "Undefined";
1841        
1842        Locale JavaDoc locale = LanguageDeliveryController.getLanguageDeliveryController().getLocaleWithId(templateController.getDatabase(), languageId);
1843
1844        String JavaDoc id = property.getAttribute("type");
1845        String JavaDoc path = property.getAttribute("path");
1846        
1847        if(property.hasAttribute("path_" + locale.getLanguage()))
1848            path = property.getAttribute("path_" + locale.getLanguage());
1849        
1850        value = path;
1851        
1852        return value;
1853    }
1854
1855    /**
1856     * This method returns all components which are on slots under the current component.
1857     */

1858    
1859    public List JavaDoc getChildComponents()
1860    {
1861        return getChildComponents(this.getInfoGlueComponent(), null);
1862    }
1863    
1864    /**
1865     * This method returns all components which are on a given slots under the current component.
1866     */

1867    
1868    public List JavaDoc getChildComponents(String JavaDoc slotId)
1869    {
1870        return getChildComponents(this.getInfoGlueComponent(), slotId);
1871    }
1872    
1873    /**
1874     * This method returns all components which are on slots under the current component.
1875     */

1876    
1877    public List JavaDoc getChildComponents(InfoGlueComponent component, String JavaDoc slotId)
1878    {
1879        List JavaDoc childComponents = new ArrayList JavaDoc();
1880        
1881        List JavaDoc slotList = component.getSlotList();
1882        
1883        Iterator JavaDoc slotListIterator = slotList.iterator();
1884        while(slotListIterator.hasNext())
1885        {
1886            Slot slot = (Slot)slotListIterator.next();
1887            if(slotId == null || slotId.equalsIgnoreCase(slot.getId()))
1888            {
1889                childComponents.addAll(slot.getComponents());
1890            }
1891        }
1892        
1893        return childComponents;
1894    }
1895    
1896    /**
1897     * This method fetches the pageComponent structure from the metainfo content.
1898     */

1899        
1900    protected String JavaDoc getPageComponentsString(TemplateController templateController, Integer JavaDoc siteNodeId, Integer JavaDoc languageId, Integer JavaDoc contentId, List JavaDoc usedContentVersionId) throws SystemException, Exception JavaDoc
1901    {
1902        String JavaDoc cacheName = "componentEditorCache";
1903        String JavaDoc cacheKey = "pageComponentString_" + siteNodeId + "_" + languageId + "_" + contentId;
1904        String JavaDoc versionKey = cacheKey + "_contentVersionId";
1905        String JavaDoc cachedPageComponentsString = (String JavaDoc)CacheController.getCachedObject(cacheName, cacheKey);
1906        Integer JavaDoc contentVersionId = (Integer JavaDoc)CacheController.getCachedObjectFromAdvancedCache("contentVersionCache", versionKey);
1907        
1908        if(cachedPageComponentsString != null)
1909        {
1910            ////System.out.println("Returning cachedPageComponentsString..");
1911
if(usedContentVersionId != null)
1912                usedContentVersionId.add(contentVersionId);
1913            
1914            return cachedPageComponentsString;
1915        }
1916        
1917        String JavaDoc pageComponentsString = null;
1918        
1919        ContentVO contentVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getBoundContent(templateController.getDatabase(), templateController.getPrincipal(), siteNodeId, languageId, true, "Meta information", templateController.getDeliveryContext());
1920        
1921        if(contentVO == null)
1922            throw new SystemException("There was no Meta Information bound to this page which makes it impossible to render.");
1923        
1924        Integer JavaDoc masterLanguageId = LanguageDeliveryController.getLanguageDeliveryController().getMasterLanguageForSiteNode(templateController.getDatabase(), siteNodeId).getId();
1925        pageComponentsString = templateController.getContentAttributeWithReturningId(contentVO.getContentId(), masterLanguageId, "ComponentStructure", true, usedContentVersionId);
1926        
1927        if(pageComponentsString == null)
1928            throw new SystemException("There was no Meta Information bound to this page which makes it impossible to render.");
1929                    
1930        logger.info("pageComponentsString: " + pageComponentsString);
1931    
1932        CacheController.cacheObject(cacheName, cacheKey, pageComponentsString);
1933        if(usedContentVersionId != null && usedContentVersionId.size() > 0)
1934        {
1935            Integer JavaDoc tempContentVersionId = (Integer JavaDoc)usedContentVersionId.get(0);
1936            ContentVersion contentVersion = ContentVersionController.getContentVersionController().getContentVersionWithId(tempContentVersionId, this.templateController.getDatabase());
1937            //System.out.println("contentVersion:" + contentVersion.getValueObject().getId());
1938
CacheController.cacheObjectInAdvancedCache("contentVersionCache", versionKey, tempContentVersionId, new String JavaDoc[]{"contentVersion_" + tempContentVersionId, "content_" + contentVersion.getValueObject().getContentId()}, true);
1939        }
1940        
1941        return pageComponentsString;
1942    }
1943
1944
1945    /**
1946     * This method fetches the template-string.
1947     */

1948    /*
1949    private String getPageComponentsString(TemplateController templateController, Integer siteNodeId, Integer languageId, Integer contentId) throws SystemException, Exception
1950    {
1951        String template = null;
1952        
1953        try
1954        {
1955            ContentVO contentVO = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, contentId).getBoundContent(templateController.getPrincipal(), siteNodeId, languageId, true, "Meta information");
1956
1957            if(contentVO == null)
1958                throw new SystemException("There was no metainformation bound to this page which makes it impossible to render.");
1959            
1960            template = templateController.getContentAttribute(contentVO.getContentId(), "ComponentStructure", true);
1961            //logger.info(template);
1962            if(template == null)
1963                throw new SystemException("There was no metainformation bound to this page which makes it impossible to render.");
1964        }
1965        catch(Exception e)
1966        {
1967            logger.error(e.getMessage(), e);
1968            throw e;
1969        }
1970
1971        return template;
1972    }
1973    */

1974
1975    /**
1976     * @return Returns the infoGlueComponent.
1977     */

1978    
1979    public InfoGlueComponent getInfoGlueComponent()
1980    {
1981        return infoGlueComponent;
1982    }
1983
1984    public boolean getUseInheritance()
1985    {
1986        return useInheritance;
1987    }
1988    
1989    public void setUseInheritance(boolean useInheritance)
1990    {
1991        this.useInheritance = useInheritance;
1992    }
1993    
1994    public boolean getUseEditOnSight()
1995    {
1996        return useEditOnSight;
1997    }
1998    
1999    public void setUseEditOnSight(boolean useEditOnSight)
2000    {
2001        this.useEditOnSight = useEditOnSight;
2002    }
2003    
2004    public boolean getThreatFoldersAsContents()
2005    {
2006        return threatFoldersAsContents;
2007    }
2008    
2009    public void setThreatFoldersAsContents(boolean threatFoldersAsContents)
2010    {
2011        this.threatFoldersAsContents = threatFoldersAsContents;
2012        this.templateController.setThreatFoldersAsContents(threatFoldersAsContents);
2013    }
2014    
2015    /**
2016     * Returns ComponentDeliveryContext
2017     * @return the ComponentDeliveryContext
2018     */

2019    public ComponentDeliveryContext getComponentDeliveryContext()
2020    {
2021        return componentDeliveryContext;
2022    }
2023    
2024
2025    /**
2026     * Returns a map value from a content attribute bound by a propertie. This
2027     * method is good for global labels and translations, instead of having
2028     * property files on disk you have them in the cms.
2029     * @param propertyName a bound content
2030     * @param attributeName a attribute in the content
2031     * @param keyName keyname in the propertyu, the text should be formed as a
2032     * standard java property file (key=val)
2033     * @return The value of the keyname in the content attribute or empty string
2034     * if none found.
2035     * @author Per Jonsson - per.jonsson@it-huset.se
2036     */

2037    public String JavaDoc getContentAttributeMapValue( String JavaDoc propertyName, String JavaDoc attributeName, String JavaDoc keyName )
2038    {
2039        String JavaDoc mapValue = "";
2040        try
2041        {
2042            mapValue = (String JavaDoc)Support.convertTextToProperties(
2043                    getContentAttribute( propertyName, attributeName, true, true ) ).get( keyName );
2044        }
2045        catch ( Exception JavaDoc e )
2046        {
2047            logger.error( "An error occurred trying to get getContentAttributeMapValue ( " + propertyName +", " + attributeName + ", " + keyName + " ) ; "+ e.getMessage(), e );
2048        }
2049        if ( mapValue == null )
2050        {
2051            mapValue = "";
2052        }
2053        return mapValue;
2054    }
2055
2056    /**
2057     * Renders a text to a PNG file, the preferences of the text rendering is
2058     * taken from the deliver.properties. ie. fontrender.fontName=Arial
2059     * @param text The text to render
2060     * @return an asseturl to the rendered text or an empty string if something
2061     * went wrong
2062     * @author Per Jonsson - per.jonsson@it-huset.se
2063     */

2064    public String JavaDoc getRenderedTextUrl( String JavaDoc text )
2065    {
2066        return templateController.getRenderedTextUrl( text, null );
2067    }
2068
2069    /**
2070     * Renders a text to a PNG file, the preferences of the text rendering is
2071     * taken from the bound component content of the property. The content is
2072     * iterated and extract all matching properties. ie. fontName, fontsize etc.
2073     * @param fontConfigPropertyName name of the bound component with font render
2074     * properties. If null property is ignored.
2075     * @param text the text to render.
2076     * @return an asseturl to the rendered text or an empty string if something
2077     * went wrong
2078     * @author Per Jonsson - per.jonsson@it-huset.se
2079     */

2080    public String JavaDoc getRenderedTextUrl( String JavaDoc fontConfigPropertyName, String JavaDoc text )
2081    {
2082        return getRenderedTextUrl( fontConfigPropertyName, text, (Map JavaDoc)null );
2083    }
2084
2085    /**
2086     * Renders a text to a PNG file, the preferences of the text rendering is
2087     * taken from the bound component content of the property. The content is
2088     * iterated and extract all matching properties. ie. fontName, fontsize etc.
2089     * @param propertyName name of the bound component with font render
2090     * properties. If null property is ignored.
2091     * @param text the text to render
2092     * @param renderAttributes render attributes in a commaseparated string ie.
2093     * "fontname=Arial,fontsize=12" to override the bound content
2094     * preferences
2095     * @return an asseturl to the rendered text or an empty string if something
2096     * went wrong
2097     * @author Per Jonsson - per.jonsson@it-huset.se
2098     */

2099    public String JavaDoc getRenderedTextUrl( String JavaDoc fontConfigPropertyName, String JavaDoc text, String JavaDoc renderAttributes )
2100    {
2101        return getRenderedTextUrl( fontConfigPropertyName, text, Support.convertTextToMap( renderAttributes, "=", "," ) );
2102    }
2103
2104    /**
2105     * Renders a text to a PNG file, the preferences of the text rendering is
2106     * taken from the bound component content of the property. The content is
2107     * iterated and extract all matching properties. ie. fontName, fontsize etc.
2108     * @param propertyName name of the bound component with font render
2109     * properties. If null property is ignored.
2110     * @param text the text to render
2111     * @param renderAttributes render attributes in a commaseparated string ie.
2112     * "fontname=Arial,fontsize=12" to override the bound content
2113     * preferences
2114     * @return an asseturl to the rendered text or an empty string if something
2115     * went wrong
2116     * @author Per Jonsson - per.jonsson@it-huset.se
2117     */

2118    public String JavaDoc getRenderedTextUrl( String JavaDoc fontConfigPropertyName, String JavaDoc text, Map JavaDoc renderAttributes )
2119    {
2120        String JavaDoc assetUrl = "";
2121        try
2122        {
2123            Map JavaDoc property = getInheritedComponentProperty( this.infoGlueComponent, fontConfigPropertyName, true );
2124            if ( property != null )
2125            {
2126                List JavaDoc bindings = (List JavaDoc)property.get( "bindings" );
2127                if ( bindings.size() > 0 )
2128                {
2129                    Integer JavaDoc contentId = new Integer JavaDoc( (String JavaDoc)bindings.get( 0 ) );
2130                    assetUrl = templateController.getRenderedTextUrl( contentId, text, renderAttributes );
2131                }
2132            }
2133            else
2134            {
2135                assetUrl = templateController.getRenderedTextUrl( text, renderAttributes );
2136            }
2137
2138        }
2139        catch ( Exception JavaDoc e )
2140        {
2141            logger.error( "An error occurred trying to get getRenderedTextUrl As ImageUrl:" + e.getMessage(), e );
2142        }
2143
2144        return assetUrl;
2145    }
2146}
Popular Tags