View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of 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.editor;
35  
36  import fr.paris.lutece.portal.business.editor.RichTextEditor;
37  import fr.paris.lutece.portal.business.editor.RichTextEditorHome;
38  import fr.paris.lutece.portal.service.datastore.DatastoreService;
39  import fr.paris.lutece.portal.service.i18n.I18nService;
40  import fr.paris.lutece.portal.service.util.AppPropertiesService;
41  import fr.paris.lutece.util.ReferenceItem;
42  import fr.paris.lutece.util.ReferenceList;
43  
44  import java.util.Collection;
45  import java.util.Locale;
46  
47  /**
48   * Service to manage front office and back office default rich text editor
49   */
50  public final class RichTextEditorService
51  {
52      public static final String MARK_DEFAULT_TEXT_EDITOR = "default_text_editor";
53      private static final String PARAMETER_DEFAULT_EDITOR_BACK_OFFICE = "core.backOffice.defaultEditor";
54      private static final String PARAMETER_DEFAULT_EDITOR_FRONT_OFFICE = "core.frontOffice.defaultEditor";
55      private static final String PROPERTY_DEFAULT_EDITOR_BACK_OFFICE = "lutece.backOffice.defaultEditor";
56      private static final String PROPERTY_DEFAULT_EDITOR_FRONT_OFFICE = "lutece.frontOffice.defaultEditor";
57  
58      /**
59       * Instantiates a new rich text editor service.
60       */
61      private RichTextEditorService( )
62      {
63      }
64  
65      /**
66       * Get the default rich text editor for back office
67       * 
68       * @return The default rich text editor for back office
69       */
70      public static String getBackOfficeDefaultEditor( )
71      {
72          String strDefaultEditorName = AppPropertiesService.getProperty( PROPERTY_DEFAULT_EDITOR_BACK_OFFICE );
73  
74          return DatastoreService.getDataValue( PARAMETER_DEFAULT_EDITOR_BACK_OFFICE, strDefaultEditorName );
75      }
76  
77      /**
78       * Get the default rich text editor for front office
79       * 
80       * @return The default rich text editor for front office
81       */
82      public static String getFrontOfficeDefaultEditor( )
83      {
84          String strDefaultEditorName = AppPropertiesService.getProperty( PROPERTY_DEFAULT_EDITOR_FRONT_OFFICE );
85  
86          return DatastoreService.getDataValue( PARAMETER_DEFAULT_EDITOR_FRONT_OFFICE, strDefaultEditorName );
87      }
88  
89      /**
90       * Update the default rich text editor for back office
91       * 
92       * @param strEditorUrl
93       *            Name of the new rich text editor for back office
94       */
95      public static void updateBackOfficeDefaultEditor( String strEditorUrl )
96      {
97          DatastoreService.setDataValue( PARAMETER_DEFAULT_EDITOR_BACK_OFFICE, strEditorUrl );
98      }
99  
100     /**
101      * Update the default rich text editor for front office
102      * 
103      * @param strEditorUrl
104      *            Name of the new rich text editor for front office
105      */
106     public static void updateFrontOfficeDefaultEditor( String strEditorUrl )
107     {
108         DatastoreService.setDataValue( PARAMETER_DEFAULT_EDITOR_FRONT_OFFICE, strEditorUrl );
109     }
110 
111     /**
112      * Get the list of rich text editors for back office
113      * 
114      * @param locale
115      *            The locale of to use
116      * @return The list of rich text editors for back office
117      */
118     public static ReferenceList getListEditorsForBackOffice( Locale locale )
119     {
120         Collection<RichTextEditor> listRichTextEditor = RichTextEditorHome.findListEditorsForBackOffice( );
121         ReferenceListList.html#ReferenceList">ReferenceList refList = new ReferenceList( );
122 
123         for ( RichTextEditor editor : listRichTextEditor )
124         {
125             ReferenceItemItem.html#ReferenceItem">ReferenceItem refItem = new ReferenceItem( );
126             refItem.setCode( editor.getEditorName( ) );
127             refItem.setName( I18nService.getLocalizedString( editor.getDescription( ), locale ) );
128             refList.add( refItem );
129         }
130 
131         return refList;
132     }
133 
134     /**
135      * Get the list of rich text editors for front office
136      * 
137      * @param locale
138      *            The locale of to use
139      * @return The list of rich text editors for front office
140      */
141     public static ReferenceList getListEditorsForFrontOffice( Locale locale )
142     {
143         Collection<RichTextEditor> listRichTextEditor = RichTextEditorHome.findListEditorsForFrontOffice( );
144         ReferenceListList.html#ReferenceList">ReferenceList refList = new ReferenceList( );
145 
146         for ( RichTextEditor editor : listRichTextEditor )
147         {
148             ReferenceItemItem.html#ReferenceItem">ReferenceItem refItem = new ReferenceItem( );
149             refItem.setCode( editor.getEditorName( ) );
150             refItem.setName( I18nService.getLocalizedString( editor.getDescription( ), locale ) );
151             refList.add( refItem );
152         }
153 
154         return refList;
155     }
156 }