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.globalmanagement;
35  
36  import fr.paris.lutece.portal.business.globalmanagement.RichTextEditor;
37  import fr.paris.lutece.portal.business.globalmanagement.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  /**
49   * Service to manage front office and back office default rich text editor
50   */
51  public final class RichTextEditorService
52  {
53      public static final String MARK_DEFAULT_TEXT_EDITOR = "default_text_editor";
54      private static final String PARAMETER_DEFAULT_EDITOR_BACK_OFFICE = "core.backOffice.defaultEditor";
55      private static final String PARAMETER_DEFAULT_EDITOR_FRONT_OFFICE = "core.frontOffice.defaultEditor";
56      private static final String PROPERTY_DEFAULT_EDITOR_BACK_OFFICE = "lutece.backOffice.defaultEditor";
57      private static final String PROPERTY_DEFAULT_EDITOR_FRONT_OFFICE = "lutece.frontOffice.defaultEditor";
58  
59      /**
60       * Instantiates a new rich text editor service.
61       */
62      private RichTextEditorService(  )
63      {
64      }
65  
66      /**
67       * Get the default rich text editor for back office
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       * @return The default rich text editor for front office
80       */
81      public static String getFrontOfficeDefaultEditor(  )
82      {
83          String strDefaultEditorName = AppPropertiesService.getProperty( PROPERTY_DEFAULT_EDITOR_FRONT_OFFICE );
84  
85          return DatastoreService.getDataValue( PARAMETER_DEFAULT_EDITOR_FRONT_OFFICE, strDefaultEditorName );
86      }
87  
88      /**
89       * Update the default rich text editor for back office
90       * @param strEditorUrl Name of the new rich text editor for back office
91       */
92      public static void updateBackOfficeDefaultEditor( String strEditorUrl )
93      {
94          DatastoreService.setDataValue( PARAMETER_DEFAULT_EDITOR_BACK_OFFICE, strEditorUrl );
95      }
96  
97      /**
98       * Update the default rich text editor for front office
99       * @param strEditorUrl Name of the new rich text editor for front office
100      */
101     public static void updateFrontOfficeDefaultEditor( String strEditorUrl )
102     {
103         DatastoreService.setDataValue( PARAMETER_DEFAULT_EDITOR_FRONT_OFFICE, strEditorUrl );
104     }
105 
106     /**
107      * Get the list of rich text editors for back office
108      * @param locale The locale of to use
109      * @return The list of rich text editors for back office
110      */
111     public static ReferenceList getListEditorsForBackOffice( Locale locale )
112     {
113         Collection<RichTextEditor> listRichTextEditor = RichTextEditorHome.findListEditorsForBackOffice(  );
114         ReferenceList refList = new ReferenceList(  );
115 
116         for ( RichTextEditor editor : listRichTextEditor )
117         {
118             ReferenceItem refItem = new ReferenceItem(  );
119             refItem.setCode( editor.getEditorName(  ) );
120             refItem.setName( I18nService.getLocalizedString( editor.getDescription(  ), locale ) );
121             refList.add( refItem );
122         }
123 
124         return refList;
125     }
126 
127     /**
128      * Get the list of rich text editors for front office
129      * @param locale The locale of to use
130      * @return The list of rich text editors for front office
131      */
132     public static ReferenceList getListEditorsForFrontOffice( Locale locale )
133     {
134         Collection<RichTextEditor> listRichTextEditor = RichTextEditorHome.findListEditorsForFrontOffice(  );
135         ReferenceList refList = new ReferenceList(  );
136 
137         for ( RichTextEditor editor : listRichTextEditor )
138         {
139             ReferenceItem refItem = new ReferenceItem(  );
140             refItem.setCode( editor.getEditorName(  ) );
141             refItem.setName( I18nService.getLocalizedString( editor.getDescription(  ), locale ) );
142             refList.add( refItem );
143         }
144 
145         return refList;
146     }
147 }