View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.portal.service.portal;
35  
36  import fr.paris.lutece.portal.business.XmlContent;
37  import fr.paris.lutece.portal.business.page.Page;
38  import fr.paris.lutece.portal.business.page.PageHome;
39  import fr.paris.lutece.portal.business.portalcomponent.PortalComponentHome;
40  import fr.paris.lutece.portal.business.portlet.Portlet;
41  import fr.paris.lutece.portal.business.portlet.PortletHome;
42  import fr.paris.lutece.portal.business.style.ModeHome;
43  import fr.paris.lutece.portal.business.stylesheet.StyleSheet;
44  import fr.paris.lutece.portal.service.cache.CacheService;
45  import fr.paris.lutece.portal.service.cache.CacheableService;
46  import fr.paris.lutece.portal.service.content.ContentService;
47  import fr.paris.lutece.portal.service.content.PageData;
48  import fr.paris.lutece.portal.service.datastore.DatastoreService;
49  import fr.paris.lutece.portal.service.html.XmlTransformerService;
50  import fr.paris.lutece.portal.service.includes.PageInclude;
51  import fr.paris.lutece.portal.service.includes.PageIncludeService;
52  import fr.paris.lutece.portal.service.message.SiteMessageException;
53  import fr.paris.lutece.portal.service.page.IPageService;
54  import fr.paris.lutece.portal.service.plugin.PluginService;
55  import fr.paris.lutece.portal.service.security.LuteceUser;
56  import fr.paris.lutece.portal.service.security.SecurityService;
57  import fr.paris.lutece.portal.service.spring.SpringContextService;
58  import fr.paris.lutece.portal.service.template.AppTemplateService;
59  import fr.paris.lutece.portal.service.util.AppPathService;
60  import fr.paris.lutece.portal.service.util.AppPropertiesService;
61  import fr.paris.lutece.portal.web.constants.Markers;
62  import fr.paris.lutece.portal.web.constants.Parameters;
63  import fr.paris.lutece.portal.web.l10n.LocaleService;
64  import fr.paris.lutece.util.html.HtmlTemplate;
65  import fr.paris.lutece.util.xml.XmlUtil;
66  
67  import org.apache.commons.lang.StringUtils;
68  
69  import java.util.ArrayList;
70  import java.util.Collection;
71  import java.util.HashMap;
72  import java.util.List;
73  import java.util.Locale;
74  import java.util.Map;
75  import java.util.Properties;
76  
77  import javax.servlet.http.HttpServletRequest;
78  
79  
80  /**
81   * This class provides methods to build the pages of the portal and manage the
82   * cache
83   */
84  public final class PortalService
85  {
86      ////////////////////////////////////////////////////////////////////////////
87      // Constants
88      private static final int PORTAL_COMPONENT_PAGE_PATH_ID = 5;
89  
90      // Properties
91      private static final String PROPERTY_HOME_PAGE_HEADER = "home.page.header.mode";
92      private static final String PROPERTY_INTERNAL_PAGE_HEADER = "internal.page.header.mode";
93      private static final String PROPERTY_PAGE_TOOLS_MENU = "page.tools.menu.mode";
94      private static final String PROPERTY_PORTAL_FOOTER = "page.portal.footer.mode";
95      private static final String PROPERTY_PATH_ON_ROOT = "lutece.root.path";
96      private static final String PROPERTY_ENCODING = "lutece.encoding";
97      private static final String PROPERTY_ENCODING_DEFAULT = "UTF-8";
98  
99      // Datastore keys
100     private static final String KEY_SITE_NAME = "portal.site.site_property.name";
101     private static final String KEY_WEBMASTER_EMAIL = "portal.site.site_property.email";
102 
103     // Templates
104     private static final String TEMPLATE_PAGE_FRAMESET = "skin/site/page_frameset.html";
105     private static final String TEMPLATE_HOME_PAGE_HEADER = "skin/site/page_header_home.html";
106     private static final String TEMPLATE_INTERNAL_PAGE_HEADER = "skin/site/page_header_internal.html";
107     private static final String TEMPLATE_PAGE_TOOLS_MENU = "skin/site/page_menu_tools.html";
108     private static final String TEMPLATE_PAGE_PATH = "skin/site/page_path.html";
109     private static final String TEMPLATE_PORTAL_FOOTER = "skin/site/portal_footer.html";
110 
111     // Markers
112     private static final String MARKER_TARGET = "target";
113     private static final String MARKER_PAGE_DATA = "data";
114     private static final String PLUGIN_EXTEND_NAME = "extend";
115     private static final String PLUGIN_CONTACT_NAME = "contact";
116     private static final String MARK_IS_EXTEND_INSTALLED = "isExtendInstalled";
117     private static final String MARK_IS_CONTACT_INSTALLED = "isContactInstalled";
118     private static final String MARK_LUTECE_USER = "lutece_user";
119     private static final String TARGET_TOP = "target='_top'";
120     private static final String BOOKMARK_BASE_URL = "@base_url@";
121 
122     // Added in v1.3
123     private static final int MODE_NORMAL = 0;
124     private static final int MODE_ADMIN = 1;
125     private static final String PARAMETER_SITE_PATH = "site-path";
126 
127     // Content Service registry
128     private static Map<String, ContentService> _mapContentServicesRegistry = new HashMap<String, ContentService>(  );
129     private static IPageService _pageService = (IPageService) SpringContextService.getBean( "pageService" );
130 
131     /**
132      * Private Constructor
133      */
134     private PortalService(  )
135     {
136     }
137 
138     /**
139      * Reset the cache
140      * @deprecated use CacheService.resetCaches()
141      */
142     @Deprecated
143     public static void resetCache(  )
144     {
145         CacheService.resetCaches(  );
146     }
147 
148     /**
149      * Analyzes request's parameters to find the ContentService that should
150      * handle the request
151      *
152      * @param request The HTTP request
153      * @return ContentService that should handle the request
154      */
155     public static ContentService getInvokedContentService( HttpServletRequest request )
156     {
157         for ( ContentService cs : getContentServicesList(  ) )
158         {
159             if ( cs.isInvoked( request ) )
160             {
161                 return cs;
162             }
163         }
164 
165         return null;
166     }
167 
168     /**
169      * Registers a new ContentService
170      * @param strName The name
171      * @param cs The ContentService
172      */
173     public static void registerContentService( String strName, ContentService cs )
174     {
175         _mapContentServicesRegistry.put( strName, cs );
176     }
177 
178     /**
179      * Returns all registered Content services
180      *
181      * @return A collection containing all registered Content services
182      */
183     public static Collection<ContentService> getContentServicesList(  )
184     {
185         return _mapContentServicesRegistry.values(  );
186     }
187 
188     /**
189      * Registers a new CacheableService
190      * @deprecated Use CacheService.registerCacheableService( String strName,
191      *             CacheableService cs ) instead
192      * @param strName The name
193      * @param cs The CacheableService
194      */
195     @Deprecated
196     public static void registerCacheableService( String strName, CacheableService cs )
197     {
198         CacheService.registerCacheableService( strName, cs );
199     }
200 
201     /**
202      * Returns all registered Cacheable services
203      * @deprecated Use CacheService.getCacheableServicesList() instead
204      *
205      * @return A collection containing all registered Cacheable services
206      */
207     @Deprecated
208     public static Collection<CacheableService> getCacheableServicesList(  )
209     {
210         return CacheService.getCacheableServicesList(  );
211     }
212 
213     /**
214      * Returns the identifier of the root page of the portal read in the
215      * lutece.properties file
216      *
217      * @return The identifier of the root page
218      */
219     public static int getRootPageId(  )
220     {
221         return AppPropertiesService.getPropertyInt( "lutece.page.root", 1 );
222     }
223 
224     /**
225      * Return the default page of the portal (the home page)
226      * @param request The request
227      * @param nMode the mode id
228      * @return default page as a String
229      * @throws SiteMessageException occurs when a site message need to be
230      *             displayed
231      */
232     public static String getDefaultPage( HttpServletRequest request, int nMode )
233         throws SiteMessageException
234     {
235         return _pageService.getPage( String.valueOf( getRootPageId(  ) ), nMode, request );
236     }
237 
238     /**
239      * Return the xml content of the pages contained in the list specified in
240      * parameter
241      *
242      * @param listPages The pages list
243      * @return the xml code for the content page
244      */
245     public static String getXmlPagesList( Collection<Page> listPages )
246     {
247         StringBuffer strXml = new StringBuffer(  );
248         strXml.append( XmlUtil.getXmlHeader(  ) );
249         XmlUtil.beginElement( strXml, XmlContent.TAG_CHILD_PAGES_LIST );
250 
251         for ( Page page : listPages )
252         {
253             XmlUtil.beginElement( strXml, XmlContent.TAG_PAGE );
254             XmlUtil.addElement( strXml, XmlContent.TAG_PAGE_ID, page.getId(  ) );
255             XmlUtil.addElementHtml( strXml, XmlContent.TAG_PAGE_NAME, page.getName(  ) );
256             XmlUtil.endElement( strXml, XmlContent.TAG_PAGE );
257         }
258 
259         XmlUtil.endElement( strXml, XmlContent.TAG_CHILD_PAGES_LIST );
260 
261         return strXml.toString(  );
262     }
263 
264     ////////////////////////////////////////////////////////////////////////////
265     // pages builder
266 
267     /**
268      * Returns the html code which represents the page content
269      * @param data The structure which contains the informations about the page
270      * @param nMode The mode in which displaying the page : normal or
271      *            administration
272      * @param request The request
273      * @return The html code of a page
274      */
275     public static String buildPageContent( PageData data, int nMode, HttpServletRequest request )
276     {
277         return buildPageContent( getRootPageId(  ), data, nMode, request );
278     }
279 
280     /**
281      * Returns the html code which represents the page content
282      * @param nCurrentPageId the current page id
283      * @param data The structure which contains the informations about the page
284      * @param nMode The mode in which displaying the page : normal or
285      *            administration
286      * @param request The request
287      * @return The html code of a page
288      */
289     public static String buildPageContent( int nCurrentPageId, PageData data, int nMode, HttpServletRequest request )
290     {
291         Locale locale = null;
292         HashMap<String, Object> model = new HashMap<String, Object>(  );
293         LuteceUser user = null;
294         String strWebmasterEmail = DatastoreService.getDataValue( KEY_WEBMASTER_EMAIL, "" );
295         model.put( Markers.WEBMASTER_EMAIL, strWebmasterEmail );
296 
297         if ( request != null )
298         {
299             locale = LocaleService.getUserSelectedLocale( request );
300             user = SecurityService.getInstance(  ).getRegisteredUser( request );
301             if ( nMode != MODE_ADMIN) 
302             {
303             	  model.put( MARK_LUTECE_USER, user );
304             }
305         }
306 
307         List<PageInclude> listIncludes = PageIncludeService.getIncludes(  );
308 
309         for ( PageInclude pic : listIncludes )
310         {
311             pic.fillTemplate( model, data, nMode, request );
312         }
313 
314         String strHeader = ( data.isHomePage(  ) )
315             ? AppPropertiesService.getProperty( PROPERTY_HOME_PAGE_HEADER + nMode, TEMPLATE_HOME_PAGE_HEADER )
316             : AppPropertiesService.getProperty( PROPERTY_INTERNAL_PAGE_HEADER + nMode, TEMPLATE_INTERNAL_PAGE_HEADER );
317         HtmlTemplate tHeader = AppTemplateService.getTemplate( strHeader, locale, model );
318 
319         String strFooter = AppPropertiesService.getProperty( PROPERTY_PORTAL_FOOTER + nMode, TEMPLATE_PORTAL_FOOTER );
320         String strToolsMenu = AppPropertiesService.getProperty( PROPERTY_PAGE_TOOLS_MENU + nMode,
321                 TEMPLATE_PAGE_TOOLS_MENU );
322         model.put( MARK_IS_CONTACT_INSTALLED, isContactActivated(  ) );
323 
324         HtmlTemplate tFooter = AppTemplateService.getTemplate( strFooter, locale, model );
325 
326         HtmlTemplate tToolsMenu = AppTemplateService.getTemplate( strToolsMenu, locale, model );
327         model.put( Markers.PAGE_HEADER, tHeader.getHtml(  ) );
328         model.put( MARKER_PAGE_DATA, data );
329         model.put( Markers.PAGE_NAME, ( data.getName(  ) == null ) ? "" : data.getName(  ) );
330         model.put( Markers.PAGE_CONTENT, ( data.getContent(  ) == null ) ? "" : data.getContent(  ) );
331         model.put( Markers.PAGE_PATH, ( data.getPagePath(  ) == null ) ? "" : data.getPagePath(  ) );
332         model.put( Markers.PAGE_TOOLS_MENU, tToolsMenu.getHtml(  ) );
333         model.put( Markers.PAGE_ID, nCurrentPageId );
334         
335         model.put( Markers.PAGE_FOOTER, tFooter.getHtml(  ) );
336 
337         String strBaseUrl = ( request != null ) ? AppPathService.getBaseUrl( request ) : ""; // request could be null (method called by daemons or batch)
338 
339         // for link service
340         model.put( Markers.WEBAPP_PATH_FOR_LINKSERVICE, strBaseUrl );
341         model.put( Markers.BASE_URL, strBaseUrl );
342 
343         String strEncoding = AppPropertiesService.getProperty( PROPERTY_ENCODING, PROPERTY_ENCODING_DEFAULT );
344 
345         if ( ( strEncoding == null ) || strEncoding.equals( "" ) )
346         {
347             strEncoding = PROPERTY_ENCODING_DEFAULT;
348         }
349 
350         model.put( Markers.ENCODING, strEncoding );
351 
352         model.put( MARK_IS_EXTEND_INSTALLED, isExtendActivated(  ) );
353 
354         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PAGE_FRAMESET, locale, model );
355 
356         template.substitute( BOOKMARK_BASE_URL, ( request != null ) ? AppPathService.getBaseUrl( request ) : "" ); // request could be null (method called by daemons or batch)
357 
358         return template.getHtml(  );
359     }
360 
361     ////////////////////////////////////////////////////////////////////////////
362     // Management of the pages path
363 
364     /**
365      * Returns the formated path of the site page whose identifier is specified
366      * in parameter
367      *
368      * @param nPageId The identifier of the page
369      * @param nMode The mode to use for the formatting
370      * @param request The HTTP request
371      * @return the formated path
372      */
373     public static String getPagePathContent( int nPageId, int nMode, HttpServletRequest request )
374     {
375         String strPathOnRoot = AppPropertiesService.getProperty( PROPERTY_PATH_ON_ROOT );
376 
377         // If the current page is the home page or the string strPathOnRoot equals false, not display the path
378         if ( ( nPageId == getRootPageId(  ) ) &&
379                 ( ( strPathOnRoot == null ) || strPathOnRoot.equalsIgnoreCase( "false" ) ) )
380         {
381             return "";
382         }
383 
384         // Selection of the XSL stylesheet
385         // Added in v1.3
386         // Use the same stylesheet for normal or admin mode
387         StyleSheet xslSource;
388 
389         switch ( nMode )
390         {
391             case MODE_NORMAL:
392             case MODE_ADMIN:
393                 xslSource = PortalComponentHome.getXsl( PORTAL_COMPONENT_PAGE_PATH_ID, MODE_NORMAL );
394 
395                 break;
396 
397             default:
398                 xslSource = PortalComponentHome.getXsl( PORTAL_COMPONENT_PAGE_PATH_ID, nMode );
399 
400                 break;
401         }
402 
403         String strXml = getXmlPagesList( getPagePath( nPageId ) );
404 
405         Properties outputProperties = ModeHome.getOuputXslProperties( nMode );
406 
407         // Added in v1.3
408         // Add a path param for choose url to use in admin or normal mode
409         Map<String, String> mapParamRequest = new HashMap<String, String>(  );
410         setXslPortalPath( mapParamRequest, nMode );
411 
412         XmlTransformerService xmlTransformerService = new XmlTransformerService(  );
413         String strPath = xmlTransformerService.transformBySourceWithXslCache( strXml, xslSource, mapParamRequest,
414                 outputProperties );
415 
416         return formatPath( strPath, nMode, request );
417     }
418 
419     /**
420      * Returns the formated path of a xpage (ex : result of a seek)
421      *
422      * @param strXPageName The xpage name
423      * @param nMode The mode to use for the formatting
424      * @param request The HTTP request
425      * @return the formated path
426      */
427     public static String getXPagePathContent( String strXPageName, int nMode, HttpServletRequest request )
428     {
429         // Added in v1.3
430         StyleSheet xslSource;
431 
432         // Selection of the XSL stylesheet
433         switch ( nMode )
434         {
435             case MODE_NORMAL:
436             case MODE_ADMIN:
437                 xslSource = PortalComponentHome.getXsl( PORTAL_COMPONENT_PAGE_PATH_ID, MODE_NORMAL );
438 
439                 break;
440 
441             default:
442                 xslSource = PortalComponentHome.getXsl( PORTAL_COMPONENT_PAGE_PATH_ID, nMode );
443 
444                 break;
445         }
446 
447         String strXml = StringUtils.EMPTY;
448         String strPageId = request.getParameter( Parameters.PAGE_ID );
449 
450         if ( StringUtils.isNotBlank( strPageId ) && StringUtils.isNumeric( strPageId ) )
451         {
452             int nPageId = Integer.parseInt( strPageId );
453             strXml = getXmlPagesList( getXPagePath( strXPageName, nPageId ) );
454         }
455         else
456         {
457             String strPortletId = request.getParameter( Parameters.PORTLET_ID );
458 
459             if ( StringUtils.isNotBlank( strPortletId ) && StringUtils.isNumeric( strPortletId ) )
460             {
461                 int nPortletId = Integer.parseInt( strPortletId );
462                 Portlet portlet = PortletHome.findByPrimaryKey( nPortletId );
463 
464                 if ( portlet != null )
465                 {
466                     int nPageId = portlet.getPageId(  );
467                     strXml = getXmlPagesList( getXPagePath( strXPageName, nPageId ) );
468                 }
469             }
470         }
471 
472         if ( StringUtils.isBlank( strXml ) )
473         {
474             strXml = getXmlPagesList( getXPagePath( strXPageName ) );
475         }
476 
477         Properties outputProperties = ModeHome.getOuputXslProperties( nMode );
478 
479         //Added in v1.3
480         // Add a path param for choose url to use in admin or normal mode
481         Map<String, String> mapXslParams = new HashMap<String, String>(  );
482         setXslPortalPath( mapXslParams, nMode );
483 
484         XmlTransformerService xmlTransformerService = new XmlTransformerService(  );
485         String strPath = xmlTransformerService.transformBySourceWithXslCache( strXml, xslSource, mapXslParams,
486                 outputProperties );
487 
488         return formatPath( strPath, nMode, request );
489     }
490 
491     /**
492      * Builds a collection of pages corresponding to the path of the page
493      * specified in parameter
494      *
495      * @param nPageId The identifier of the page
496      * @return A collection of pages from the home page to the specified page
497      */
498     public static Collection<Page> getPagePath( int nPageId )
499     {
500         ArrayList<Page> list = new ArrayList<Page>(  );
501         Page page = PageHome.getPage( nPageId );
502         int nParentPageId = page.getParentPageId(  );
503         list.add( page );
504 
505         while ( nParentPageId != 0 )
506         {
507             Page parentPage = PageHome.getPage( nParentPageId );
508 
509             // Insert the page in the begin of the list
510             list.add( 0, parentPage );
511             nParentPageId = parentPage.getParentPageId(  );
512         }
513 
514         return list;
515     }
516 
517     /**
518      * Builds a collection of pages corresponding to the path of a xpage
519      *
520      * @param strXPageName The xpage name
521      * @return A collection of pages made by the home page and the xpage
522      */
523     private static Collection<Page> getXPagePath( String strXPageName )
524     {
525         ArrayList<Page> list = new ArrayList<Page>(  );
526         Page homePage = PageHome.getPage( getRootPageId(  ) );
527         list.add( homePage );
528 
529         Page xPage = new Page(  );
530         xPage.setName( strXPageName );
531         list.add( xPage );
532 
533         return list;
534     }
535 
536     /**
537      * Builds a collection of pages corresponding to the path of a xpage
538      *
539      * @param strXPageName The xpage name
540      * @param nPageId The Page's ID
541      * @return A collection of pages made by the home page and the xpage
542      */
543     private static Collection<Page> getXPagePath( String strXPageName, int nPageId )
544     {
545         List<Page> list = new ArrayList<Page>(  );
546         Page page = PageHome.getPage( nPageId );
547 
548         if ( page != null )
549         {
550             int nParentPageId = page.getParentPageId(  );
551 
552             while ( ( nParentPageId > 0 ) && ( nParentPageId != getRootPageId(  ) ) )
553             {
554                 Page parentPage = PageHome.getPage( nParentPageId );
555 
556                 if ( parentPage != null )
557                 {
558                     // Insert the page at the beginning of the list
559                     list.add( 0, parentPage );
560                     nParentPageId = parentPage.getParentPageId(  );
561                 }
562             }
563 
564             if ( nPageId != getRootPageId(  ) )
565             {
566                 list.add( page );
567             }
568         }
569 
570         // Insert the home page at the beginning of the list
571         Page homePage = PageHome.getPage( getRootPageId(  ) );
572         list.add( 0, homePage );
573 
574         // Insert the XPage at the end of the list
575         Page xPage = new Page(  );
576         xPage.setName( strXPageName );
577         xPage.setId( nPageId );
578         list.add( xPage );
579 
580         return list;
581     }
582 
583     ////////////////////////////////////////////////////////////////////////////
584 
585     /**
586      * Formats the path specified in parameter and returns it
587      *
588      * @param strPath The path to format
589      * @param nMode The mode to use for the formatting
590      * @param request The HTTP request
591      * @return the html code to display the path
592      */
593     public static String formatPath( String strPath, int nMode, HttpServletRequest request )
594     {
595         HashMap<String, Object> model = new HashMap<String, Object>(  );
596         model.put( Markers.PAGE_PATH, strPath );
597 
598         List<PageInclude> listIncludes = PageIncludeService.getIncludes(  );
599         PageData data = new PageData(  );
600 
601         for ( PageInclude pic : listIncludes )
602         {
603             pic.fillTemplate( model, data, nMode, request );
604         }
605 
606         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PAGE_PATH,
607                 ( request == null ) ? null : request.getLocale(  ), model );
608 
609         return template.getHtml(  );
610     }
611 
612     /**
613      * Return the xml content of the pages specified by the xml code.
614      * This is called when using the Extended Xml path Label.
615      *
616      * @param strXmlExtend The xml code to append to the path
617      * @return the xml code for the content page
618      */
619     private static String getXmlPagesListExtended( String strXmlExtend )
620     {
621         StringBuffer strXml = new StringBuffer(  );
622         strXml.append( XmlUtil.getXmlHeader(  ) );
623         XmlUtil.beginElement( strXml, XmlContent.TAG_CHILD_PAGES_LIST );
624 
625         Page homePage = PageHome.getPage( getRootPageId(  ) );
626 
627         XmlUtil.beginElement( strXml, XmlContent.TAG_PAGE );
628         XmlUtil.addElement( strXml, XmlContent.TAG_PAGE_ID, homePage.getId(  ) );
629         XmlUtil.addElementHtml( strXml, XmlContent.TAG_PAGE_NAME, homePage.getName(  ) );
630         XmlUtil.endElement( strXml, XmlContent.TAG_PAGE );
631 
632         strXml.append( strXmlExtend );
633 
634         XmlUtil.endElement( strXml, XmlContent.TAG_CHILD_PAGES_LIST );
635 
636         return strXml.toString(  );
637     }
638 
639     /**
640      * Returns the formated extended path of an xpage.
641      * This method is used when giving the list of elements in the path as a Xml
642      * code.
643      * This is called when using the Extended Xml path Label.
644      *
645      * @param strXPageName The xpage name
646      * @param nMode The mode to use for the formatting
647      * @param strTitlesUrls list of links (url and titles)
648      * @param request The HTTP request
649      * @return the formatted path
650      */
651     public static String getXPagePathContent( String strXPageName, int nMode, String strTitlesUrls,
652         HttpServletRequest request )
653     {
654         // Selection of the XSL stylesheet
655         StyleSheet xslSource;
656 
657         // Selection of the XSL stylesheet
658         switch ( nMode )
659         {
660             case MODE_NORMAL:
661             case MODE_ADMIN:
662                 xslSource = PortalComponentHome.getXsl( PORTAL_COMPONENT_PAGE_PATH_ID, MODE_NORMAL );
663 
664                 break;
665 
666             default:
667                 xslSource = PortalComponentHome.getXsl( PORTAL_COMPONENT_PAGE_PATH_ID, nMode );
668 
669                 break;
670         }
671 
672         String strXml = getXmlPagesListExtended( strTitlesUrls );
673 
674         //Added in v1.3
675         // Add a path param for choose url to use in admin or normal mode
676         Map<String, String> mapXslParams = new HashMap<String, String>(  );
677         setXslPortalPath( mapXslParams, nMode );
678 
679         XmlTransformerService xmlTransformerService = new XmlTransformerService(  );
680         String strPath = xmlTransformerService.transformBySourceWithXslCache( strXml, xslSource, mapXslParams );
681 
682         return formatPath( strPath, nMode, request );
683     }
684 
685     /**
686      * Sets XSL portal path
687      * @param mapParameters Parameters as a map
688      * @param nMode The mode
689      */
690     public static void setXslPortalPath( Map<String, String> mapParameters, int nMode )
691     {
692         if ( nMode != MODE_ADMIN )
693         {
694             mapParameters.put( PARAMETER_SITE_PATH, AppPathService.getPortalUrl(  ) );
695         }
696         else
697         {
698             mapParameters.put( PARAMETER_SITE_PATH, AppPathService.getAdminPortalUrl(  ) );
699             mapParameters.put( MARKER_TARGET, TARGET_TOP );
700         }
701     }
702 
703     /**
704      * Returns the site name
705      * @return The site name
706      */
707     public static String getSiteName(  )
708     {
709         return DatastoreService.getDataValue( KEY_SITE_NAME, StringUtils.EMPTY );
710     }
711 
712     /**
713      * Check if the extend plugin is activated
714      * @return True if the plugin is activated, false otherwise
715      */
716     public static boolean isExtendActivated(  )
717     {
718         return PluginService.isPluginEnable( PLUGIN_EXTEND_NAME );
719     }
720 
721     /**
722      * Check if the cotnact plugin is activated
723      * @return True if the plugin is activated, false otherwise
724      */
725     public static boolean isContactActivated(  )
726     {
727         return PluginService.isPluginEnable( PLUGIN_CONTACT_NAME );
728     }
729 }