KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Locale JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.exolab.castor.jdo.Database;
34 import org.exolab.castor.jdo.OQLQuery;
35 import org.exolab.castor.jdo.QueryResults;
36 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController;
37 import org.infoglue.cms.entities.content.ContentVO;
38 import org.infoglue.cms.entities.content.ContentVersionVO;
39 import org.infoglue.cms.entities.management.Language;
40 import org.infoglue.cms.entities.management.LanguageVO;
41 import org.infoglue.cms.entities.management.Repository;
42 import org.infoglue.cms.entities.management.RepositoryLanguage;
43 import org.infoglue.cms.entities.management.impl.simple.LanguageImpl;
44 import org.infoglue.cms.entities.management.impl.simple.RepositoryImpl;
45 import org.infoglue.cms.entities.structure.SiteNode;
46 import org.infoglue.cms.entities.structure.SiteNodeVersion;
47 import org.infoglue.cms.entities.structure.impl.simple.SiteNodeImpl;
48 import org.infoglue.cms.exception.SystemException;
49 import org.infoglue.cms.security.InfoGluePrincipal;
50 import org.infoglue.cms.util.CmsPropertyHandler;
51 import org.infoglue.deliver.applications.databeans.DeliveryContext;
52 import org.infoglue.deliver.util.CacheController;
53
54
55 public class LanguageDeliveryController extends BaseDeliveryController
56 {
57     private final static Logger logger = Logger.getLogger(LanguageDeliveryController.class.getName());
58
59     /**
60      * Private constructor to enforce factory-use
61      */

62     
63     private LanguageDeliveryController()
64     {
65     }
66     
67     /**
68      * Factory method
69      */

70     
71     public static LanguageDeliveryController getLanguageDeliveryController()
72     {
73         return new LanguageDeliveryController();
74     }
75     
76     
77     /**
78      * This method return a LanguageVO
79      */

80     
81     public LanguageVO getLanguageVO(Database db, Integer JavaDoc languageId) throws SystemException, Exception JavaDoc
82     {
83         if(languageId == null || languageId.intValue() == 0)
84             return null;
85             
86         String JavaDoc key = "" + languageId;
87         logger.info("key:" + key);
88         LanguageVO languageVO = (LanguageVO)CacheController.getCachedObject("languageCache", key);
89         if(languageVO != null)
90         {
91             logger.info("There was an cached languageVO:" + languageVO);
92         }
93         else
94         {
95             Language language = (Language)getObjectWithId(LanguageImpl.class, languageId, db);
96                 
97             if(language != null)
98                 languageVO = language.getValueObject();
99             
100             CacheController.cacheObject("languageCache", key, languageVO);
101         }
102                 
103         return languageVO;
104     }
105
106     /**
107      * This method returns all languages for a certain repository.
108      *
109      * @param repositoryId
110      * @return
111      * @throws SystemException
112      * @throws Exception
113      */

114
115     public List JavaDoc getAvailableLanguagesForRepository(Database db, Integer JavaDoc repositoryId) throws SystemException, Exception JavaDoc
116     {
117         String JavaDoc key = "" + repositoryId + "_allLanguages";
118         logger.info("key:" + key);
119         List JavaDoc list = (List JavaDoc)CacheController.getCachedObject("languageCache", key);
120         if(list != null)
121         {
122             logger.info("There was an cached list:" + list);
123         }
124         else
125         {
126             list = new ArrayList JavaDoc();
127             
128             Repository repository = (Repository) getObjectWithId(RepositoryImpl.class, repositoryId, db);
129             if (repository != null)
130             {
131                 for (Iterator JavaDoc i = repository.getRepositoryLanguages().iterator();i.hasNext();)
132                 {
133                     RepositoryLanguage repositoryLanguage = (RepositoryLanguage) i.next();
134                     Language language = repositoryLanguage.getLanguage();
135                     if (language != null)
136                         list.add(language.getValueObject());
137                 }
138             }
139         
140             if(list.size() > 0)
141                 CacheController.cacheObject("languageCache", key, list);
142         }
143             
144         return list;
145     }
146     
147     /**
148      * This method returns the languages assigned to a respository.
149      */

150     
151     public List JavaDoc getAvailableLanguages(Database db, Integer JavaDoc siteNodeId) throws SystemException, Exception JavaDoc
152     {
153         logger.info("getAvailableLanguages for " + siteNodeId + " start.");
154
155         List JavaDoc languageVOList = new ArrayList JavaDoc();
156
157         logger.info("siteNodeId:" + siteNodeId);
158
159         SiteNode siteNode = (SiteNode)getObjectWithId(SiteNodeImpl.class, siteNodeId, db);
160             
161         if(siteNode != null)
162         {
163             Repository repository = siteNode.getRepository();
164             if(repository != null)
165             {
166                 logger.info("repository:" + repository.getName());
167
168                 Collection JavaDoc repositoryLanguages = repository.getRepositoryLanguages();
169                 logger.info("repositoryLanguages:" + repositoryLanguages.size());
170                 Iterator JavaDoc repositoryLanguagesIterator = repositoryLanguages.iterator();
171                 while(repositoryLanguagesIterator.hasNext())
172                 {
173                     RepositoryLanguage repositoryLanguage = (RepositoryLanguage)repositoryLanguagesIterator.next();
174                     Language language = repositoryLanguage.getLanguage();
175                     if(language != null)
176                     {
177                         logger.info("Adding " + language.getName() + " to the list of available languages");
178                         languageVOList.add(language.getValueObject());
179                     }
180                 }
181             }
182         }
183
184         logger.info("getAvailableLanguages for " + siteNodeId + " end.");
185
186         return languageVOList;
187     }
188
189
190     /**
191      * This method returns the master language.
192      * todo - add attribute on repositoryLanguage to be able to sort them... and then fetch the first
193      */

194     
195     public LanguageVO getMasterLanguage(Database db, String JavaDoc repositoryName) throws SystemException, Exception JavaDoc
196     {
197         Language language = null;
198
199         OQLQuery oql = db.getOQLQuery( "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.repositoryLanguages.repository.name = $1 ORDER BY l.repositoryLanguages.sortOrder, l.languageId");
200         oql.bind(repositoryName);
201         
202         QueryResults results = oql.execute(Database.ReadOnly);
203         
204         if (results.hasMore())
205         {
206             language = (Language)results.next();
207         }
208           
209         results.close();
210         oql.close();
211
212         return (language == null) ? null : language.getValueObject();
213     }
214     
215
216     /**
217      * This method returns the master language.
218      * todo - add attribute on repositoryLanguage to be able to sort them... and then fetch the first
219      */

220     
221     public LanguageVO getMasterLanguageForRepository(Database db, Integer JavaDoc repositoryId) throws SystemException, Exception JavaDoc
222     {
223         String JavaDoc languageKey = "" + repositoryId;
224         logger.info("languageKey in getMasterLanguageForRepository:" + languageKey);
225         LanguageVO languageVO = (LanguageVO)CacheController.getCachedObject("masterLanguageCache", languageKey);
226         if(languageVO != null)
227         {
228             logger.info("There was an cached master language:" + languageVO.getName());
229         }
230         else
231         {
232             OQLQuery oql = db.getOQLQuery( "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.repositoryLanguages.repository.repositoryId = $1 ORDER BY l.repositoryLanguages.sortOrder, l.languageId");
233             oql.bind(repositoryId);
234             
235             QueryResults results = oql.execute(Database.ReadOnly);
236             
237             if (results.hasMore())
238             {
239                 Language language = (Language)results.next();
240                 languageVO = language.getValueObject();
241             }
242             
243             results.close();
244             oql.close();
245
246             CacheController.cacheObject("masterLanguageCache", languageKey, languageVO);
247         }
248
249         return languageVO;
250     }
251
252     /**
253      * This method returns the master language.
254      * todo - add attribute on repositoryLanguage to be able to sort them... and then fetch the first
255      */

256     
257     public LanguageVO getMasterLanguageForRepository(Integer JavaDoc repositoryId, Database db) throws SystemException, Exception JavaDoc
258     {
259         LanguageVO languageVO = null;
260
261         String JavaDoc languageKey = "" + repositoryId;
262         logger.info("languageKey in getMasterLanguageForRepository:" + languageKey);
263         languageVO = (LanguageVO)CacheController.getCachedObject("masterLanguageCache", languageKey);
264         if(languageVO != null)
265         {
266             logger.info("There was an cached master language:" + languageVO.getName());
267         }
268         else
269         {
270             OQLQuery oql = db.getOQLQuery( "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.repositoryLanguages.repository.repositoryId = $1 ORDER BY l.repositoryLanguages.sortOrder, l.languageId");
271             oql.bind(repositoryId);
272             
273             QueryResults results = oql.execute(Database.ReadOnly);
274             
275             if (results.hasMore())
276             {
277                 Language language = (Language)results.next();
278                 languageVO = language.getValueObject();
279             }
280             
281             results.close();
282             oql.close();
283
284             CacheController.cacheObject("masterLanguageCache", languageKey, languageVO);
285         }
286
287         return languageVO;
288     }
289
290     
291     /**
292      * This method returns the master language.
293      * todo - add attribute on repositoryLanguage to be able to sort them... and then fetch the first
294      */

295     
296     public LanguageVO getMasterLanguageForSiteNode(Database db, Integer JavaDoc siteNodeId) throws SystemException, Exception JavaDoc
297     {
298         String JavaDoc languageKey = "siteNodeId_" + siteNodeId;
299         logger.info("languageKey in getMasterLanguageForSiteNode:" + languageKey);
300         LanguageVO languageVO = (LanguageVO)CacheController.getCachedObject("masterLanguageCache", languageKey);
301         if(languageVO != null)
302         {
303             logger.info("There was an cached master language:" + languageVO.getName());
304         }
305         else
306         {
307             SiteNode siteNode = (SiteNode)getObjectWithId(SiteNodeImpl.class, siteNodeId, db);
308             Integer JavaDoc repositoryId = siteNode.getRepository().getRepositoryId();
309             
310             OQLQuery oql = db.getOQLQuery( "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.repositoryLanguages.repository.repositoryId = $1 ORDER BY l.repositoryLanguages.sortOrder, l.languageId");
311             oql.bind(repositoryId);
312             
313             QueryResults results = oql.execute(Database.ReadOnly);
314             
315             if (results.hasMore())
316             {
317                 Language language = (Language)results.next();
318                 languageVO = language.getValueObject();
319             }
320             
321             results.close();
322             oql.close();
323
324             CacheController.cacheObject("masterLanguageCache", languageKey, languageVO);
325         }
326         
327         return languageVO;
328     }
329     
330
331     /**
332      * This method returns language with the languageCode sent in.
333      */

334     
335     public Locale JavaDoc getLocaleWithId(Database db, Integer JavaDoc languageId)
336     {
337         String JavaDoc key = "" + languageId;
338         logger.info("key:" + key);
339         Locale JavaDoc locale = (Locale JavaDoc)CacheController.getCachedObject("localeCache", key);
340         if(locale != null)
341         {
342             logger.info("There was an cached locale:" + locale);
343         }
344         else
345         {
346             locale = Locale.getDefault();
347             
348             if (languageId != null)
349             {
350                 try
351                 {
352                     LanguageVO languageVO = getLanguageVO(db, languageId);
353                     locale = new Locale JavaDoc(languageVO.getLanguageCode());
354                 }
355                 catch (Exception JavaDoc e)
356                 {
357                     logger.error("An error occurred in getLocaleWithId: getting locale with languageid:" + languageId + "," + e, e);
358                 }
359             }
360             
361             CacheController.cacheObject("localeCache", key, locale);
362         }
363         
364         return locale;
365     }
366
367     /**
368      * This method returns language with the languageCode sent in.
369      */

370     
371     public Locale JavaDoc getLocaleWithCode(String JavaDoc languageCode)
372     {
373         String JavaDoc key = "" + languageCode;
374         logger.info("key:" + key);
375         Locale JavaDoc locale = (Locale JavaDoc)CacheController.getCachedObject("localeCache", key);
376         if(locale != null)
377         {
378             logger.info("There was an cached locale:" + locale);
379         }
380         else
381         {
382             locale = Locale.getDefault();
383             
384             if (languageCode != null)
385             {
386                 try
387                 {
388                     locale = new Locale JavaDoc(languageCode);
389                 }
390                 catch (Exception JavaDoc e)
391                 {
392                     logger.error("An error occurred in getLocaleWithCode: getting locale with languageCode:" + languageCode + "," + e, e);
393                 }
394             }
395             
396             CacheController.cacheObject("localeCache", key, locale);
397         }
398         
399         return locale;
400     }
401
402
403     /**
404      * This method returns language with the languageCode sent in.
405      */

406     
407     public LanguageVO getLanguageWithCode(Database db, String JavaDoc languageCode) throws SystemException, Exception JavaDoc
408     {
409         String JavaDoc key = "" + languageCode;
410         logger.info("key:" + key);
411         LanguageVO languageVO = (LanguageVO)CacheController.getCachedObject("languageCache", key);
412         if(languageVO != null)
413         {
414             logger.info("There was an cached languageVO:" + languageVO);
415         }
416         else
417         {
418             Language language = null;
419     
420             OQLQuery oql = db.getOQLQuery( "SELECT l FROM org.infoglue.cms.entities.management.impl.simple.LanguageImpl l WHERE l.languageCode = $1");
421             oql.bind(languageCode);
422             
423             QueryResults results = oql.execute(Database.ReadOnly);
424             
425             if (results.hasMore())
426             {
427                 language = (Language)results.next();
428                 languageVO = language.getValueObject();
429             }
430             
431             results.close();
432             oql.close();
433
434             CacheController.cacheObject("languageCache", key, languageVO);
435         }
436         
437         return languageVO;
438     }
439
440
441     /**
442      * This method returns language with the languageCode sent in if it is allowed/supported in the current repository.
443      */

444     
445     public LanguageVO getLanguageIfRepositorySupportsIt(Database db, String JavaDoc languageCodes, Integer JavaDoc siteNodeId) throws SystemException, Exception JavaDoc
446     {
447         if (languageCodes == null) return null;
448         int index = Integer.MAX_VALUE;
449         int currentIndex = 0;
450         logger.info("Coming in with languageCodes:" + languageCodes);
451         
452         Language language = null;
453
454         SiteNode siteNode = (SiteNode)getObjectWithId(SiteNodeImpl.class, siteNodeId, db);
455         Repository repository = siteNode.getRepository();
456         if(repository != null)
457         {
458             Collection JavaDoc languages = repository.getRepositoryLanguages();
459             Iterator JavaDoc languageIterator = languages.iterator();
460             while(languageIterator.hasNext())
461             {
462                 RepositoryLanguage repositoryLanguage = (RepositoryLanguage)languageIterator.next();
463                 Language currentLanguage = repositoryLanguage.getLanguage();
464                 logger.info("CurrentLanguageCode:" + currentLanguage.getLanguageCode());
465                 currentIndex = languageCodes.toLowerCase().indexOf(currentLanguage.getLanguageCode().toLowerCase());
466                 if( currentIndex > -1 && currentIndex < index)
467                 {
468                     index = currentIndex;
469                     logger.info("Found the language in the list of supported languages for this site: " + currentLanguage.getName() + " - priority:" + index);
470                     language = currentLanguage;
471                     if (index==0) break; // Continue and try to find a better candidate unless index is 0 (first prio)
472
}
473             }
474         }
475
476         return (language == null) ? null : language.getValueObject();
477     }
478
479     /**
480      * This method returns language with the languageCode sent in if it is allowed/supported in the current repository.
481      */

482     
483     public LanguageVO getLanguageIfSiteNodeSupportsIt(Database db, String JavaDoc languageCodes, Integer JavaDoc siteNodeId, InfoGluePrincipal principal) throws SystemException, Exception JavaDoc
484     {
485         if (languageCodes == null)
486             return null;
487         
488         String JavaDoc key = "" + siteNodeId + "_" + languageCodes;
489         LanguageVO languageVO = (LanguageVO)CacheController.getCachedObject("siteNodeLanguageCache", key);
490         if(languageVO != null)
491             return languageVO;
492         
493         int index = Integer.MAX_VALUE;
494         int currentIndex = 0;
495         logger.info("Coming in with languageCodes:" + languageCodes);
496         
497         Language language = null;
498
499         SiteNode siteNode = (SiteNode)getObjectWithId(SiteNodeImpl.class, siteNodeId, db);
500                 
501         Repository repository = siteNode.getRepository();
502         if(repository != null)
503         {
504             Collection JavaDoc languages = repository.getRepositoryLanguages();
505             Iterator JavaDoc languageIterator = languages.iterator();
506             while(languageIterator.hasNext())
507             {
508                 RepositoryLanguage repositoryLanguage = (RepositoryLanguage)languageIterator.next();
509                 Language currentLanguage = repositoryLanguage.getLanguage();
510                 logger.info("CurrentLanguageCode:" + currentLanguage.getLanguageCode());
511                 
512                 NodeDeliveryController ndc = NodeDeliveryController.getNodeDeliveryController(siteNodeId, currentLanguage.getId(), new Integer JavaDoc(-1));
513                 
514                 currentIndex = languageCodes.toLowerCase().indexOf(currentLanguage.getLanguageCode().toLowerCase());
515                 if(getIsValidLanguage(db, ndc, siteNode, currentLanguage.getId()) && currentIndex > -1 && currentIndex < index)
516                 {
517                     index = currentIndex;
518                     logger.info("Found the language in the list of supported languages for this site: " + currentLanguage.getName() + " - priority:" + index);
519
520                     DeliveryContext deliveryContext = DeliveryContext.getDeliveryContext();
521                     ContentVO contentVO = ndc.getBoundContent(db, principal, siteNodeId, currentLanguage.getId(), false, BasicTemplateController.META_INFO_BINDING_NAME, deliveryContext);
522                     if(contentVO != null)
523                     {
524                         ContentVersionVO contentVersionVO = ContentDeliveryController.getContentDeliveryController().getContentVersionVO(db, siteNodeId, contentVO.getId(), currentLanguage.getId(), false, deliveryContext, principal);
525                         if(contentVersionVO != null)
526                         {
527                             language = currentLanguage;
528                             logger.info("Language now: " + language.getName());
529                         }
530                     }
531                     
532                     if (index==0) break; // Continue and try to find a better candidate unless index is 0 (first prio)
533
}
534             }
535         }
536
537         if(language != null)
538             CacheController.cacheObject("siteNodeLanguageCache", key, language.getValueObject());
539
540         logger.info("Returning language: " + language);
541         
542         return (language == null) ? null : language.getValueObject();
543     }
544
545  
546     /**
547      * This method returns language with the languageCode sent in if it is allowed/supported in the current repository.
548      */

549     
550     public LanguageVO getLanguageIfSiteNodeSupportsIt(Database db, Integer JavaDoc languageId, Integer JavaDoc siteNodeId) throws SystemException, Exception JavaDoc
551     {
552         if (languageId == null)
553             return null;
554
555         String JavaDoc key = "" + siteNodeId + "_" + languageId;
556         LanguageVO languageVO = (LanguageVO)CacheController.getCachedObject("siteNodeLanguageCache", key);
557         if(languageVO != null)
558             return languageVO;
559         
560         NodeDeliveryController ndc = NodeDeliveryController.getNodeDeliveryController(siteNodeId, languageId, new Integer JavaDoc(-1));
561
562         logger.info("Coming in with languageId:" + languageId);
563         
564         Language language = null;
565
566         SiteNode siteNode = (SiteNode)getObjectWithId(SiteNodeImpl.class, siteNodeId, db);
567
568         if(!getIsValidLanguage(db, ndc, siteNode, languageId))
569             return null;
570         
571         Repository repository = siteNode.getRepository();
572         if(repository != null)
573         {
574             Collection JavaDoc languages = repository.getRepositoryLanguages();
575             
576             Iterator JavaDoc languageIterator = languages.iterator();
577             while(languageIterator.hasNext())
578             {
579                 RepositoryLanguage repositoryLanguage = (RepositoryLanguage)languageIterator.next();
580                 Language currentLanguage = repositoryLanguage.getLanguage();
581                 logger.info("CurrentLanguage:" + currentLanguage.getId());
582                 if(currentLanguage.getId().intValue() == languageId.intValue())
583                 {
584                     logger.info("Found the language in the list of supported languages for this site: " + currentLanguage.getName());
585                     if(getIsValidLanguage(db, ndc, siteNode, currentLanguage.getId()))
586                     {
587                         language = currentLanguage;
588                         break;
589                     }
590                     /*
591                     DeliveryContext deliveryContext = DeliveryContext.getDeliveryContext();
592                     ContentVO contentVO = ndc.getBoundContent(db, principal, siteNodeId, currentLanguage.getId(), false, BasicTemplateController.META_INFO_BINDING_NAME, deliveryContext);
593                     if(contentVO != null)
594                     {
595                         ContentVersionVO contentVersionVO = ContentDeliveryController.getContentDeliveryController().getContentVersionVO(db, siteNodeId, contentVO.getId(), currentLanguage.getId(), false, deliveryContext, principal);
596                         if(contentVersionVO != null)
597                         {
598                             System.out.println("Found the language in the list of supported languages for this site: " + currentLanguage.getName());
599                             language = currentLanguage;
600                             break;
601                         }
602                     }
603                     */

604                 }
605             }
606         }
607         
608         if(language != null)
609             CacheController.cacheObject("siteNodeLanguageCache", key, language.getValueObject());
610
611         logger.info("Returning language: " + language);
612
613         return (language == null) ? null : language.getValueObject();
614     }
615
616     /**
617      * This method returns all languages available for a site node.
618      */

619     
620     public List JavaDoc getLanguagesForSiteNode(Database db, Integer JavaDoc siteNodeId, InfoGluePrincipal principal) throws SystemException, Exception JavaDoc
621     {
622         String JavaDoc key = "" + siteNodeId;
623         List JavaDoc languageVOList = (List JavaDoc)CacheController.getCachedObject("siteNodeLanguageCache", key);
624         if(languageVOList != null)
625             return languageVOList;
626         
627         logger.info("Coming in with siteNodeId:" + siteNodeId);
628         
629         languageVOList = new ArrayList JavaDoc();
630
631         SiteNode siteNode = (SiteNode)getObjectWithId(SiteNodeImpl.class, siteNodeId, db);
632                 
633         Repository repository = siteNode.getRepository();
634         if(repository != null)
635         {
636             Collection JavaDoc languages = repository.getRepositoryLanguages();
637             Iterator JavaDoc languageIterator = languages.iterator();
638             while(languageIterator.hasNext())
639             {
640                 RepositoryLanguage repositoryLanguage = (RepositoryLanguage)languageIterator.next();
641                 Language currentLanguage = repositoryLanguage.getLanguage();
642                 logger.info("CurrentLanguageCode:" + currentLanguage.getLanguageCode());
643                 
644                 NodeDeliveryController ndc = NodeDeliveryController.getNodeDeliveryController(siteNodeId, currentLanguage.getId(), new Integer JavaDoc(-1));
645                 
646                 if(getIsValidLanguage(db, ndc, siteNode, currentLanguage.getId()))
647                 {
648                     logger.info("Found the language in the list of supported languages for this site: " + currentLanguage.getName());
649                     languageVOList.add(currentLanguage.getValueObject());
650                 }
651             }
652         }
653
654         if(languageVOList != null)
655             CacheController.cacheObject("siteNodeLanguageCache", key, languageVOList);
656
657         logger.info("Returning languageVOList: " + languageVOList.size());
658         
659         return languageVOList;
660     }
661
662     
663     public boolean getIsValidLanguage(Database db, NodeDeliveryController ndc, SiteNode siteNode, Integer JavaDoc languageId) throws Exception JavaDoc
664     {
665         boolean isValidLanguage = true;
666         
667         SiteNodeVersion siteNodeVersion = ndc.getActiveSiteNodeVersion(siteNode.getId(), db);
668         Integer JavaDoc disabledLanguagesSiteNodeVersionId = ndc.getDisabledLanguagesSiteNodeVersionId(db, siteNode.getId());
669         logger.info("disabledLanguagesSiteNodeVersionId:" + disabledLanguagesSiteNodeVersionId);
670         
671         if(disabledLanguagesSiteNodeVersionId != null)
672         {
673             SiteNodeVersion disabledLanguagesSiteNodeVersion = SiteNodeVersionController.getController().getSiteNodeVersionWithId(disabledLanguagesSiteNodeVersionId, db);
674             
675             String JavaDoc disabledLanguagesString = CmsPropertyHandler.getPropertySetValue("siteNode_" + disabledLanguagesSiteNodeVersion.getValueObject().getSiteNodeId() + "_disabledLanguages");
676             logger.info("disabledLanguagesString:" + disabledLanguagesString);
677             
678             if(disabledLanguagesString != null && !disabledLanguagesString.equalsIgnoreCase(""))
679             {
680                 String JavaDoc[] disabledLanguagesStringArray = disabledLanguagesString.split(",");
681                 for(int i=0; i<disabledLanguagesStringArray.length; i++)
682                 {
683                     logger.info("languageId.intValue():" + languageId.intValue());
684                     logger.info("disabledLanguagesStringArray:" + disabledLanguagesStringArray);
685                     if(languageId.intValue() == new Integer JavaDoc(disabledLanguagesStringArray[i]).intValue())
686                     {
687                         isValidLanguage = false;
688                         logger.info("isValidLanguage:" + isValidLanguage);
689                         break;
690                     }
691                 }
692             }
693             
694         }
695         logger.info("languageId:" + languageId + " was valid:" + isValidLanguage);
696         
697         return isValidLanguage;
698     }
699
700     
701     
702 }
Popular Tags