RichTextEditorService.java

  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. import fr.paris.lutece.portal.business.editor.RichTextEditor;
  36. import fr.paris.lutece.portal.business.editor.RichTextEditorHome;
  37. import fr.paris.lutece.portal.service.datastore.DatastoreService;
  38. import fr.paris.lutece.portal.service.i18n.I18nService;
  39. import fr.paris.lutece.portal.service.util.AppPropertiesService;
  40. import fr.paris.lutece.util.ReferenceItem;
  41. import fr.paris.lutece.util.ReferenceList;

  42. import java.util.Collection;
  43. import java.util.Locale;

  44. /**
  45.  * Service to manage front office and back office default rich text editor
  46.  */
  47. public final class RichTextEditorService
  48. {
  49.     public static final String MARK_DEFAULT_TEXT_EDITOR = "default_text_editor";
  50.     private static final String PARAMETER_DEFAULT_EDITOR_BACK_OFFICE = "core.backOffice.defaultEditor";
  51.     private static final String PARAMETER_DEFAULT_EDITOR_FRONT_OFFICE = "core.frontOffice.defaultEditor";
  52.     private static final String PROPERTY_DEFAULT_EDITOR_BACK_OFFICE = "lutece.backOffice.defaultEditor";
  53.     private static final String PROPERTY_DEFAULT_EDITOR_FRONT_OFFICE = "lutece.frontOffice.defaultEditor";

  54.     /**
  55.      * Instantiates a new rich text editor service.
  56.      */
  57.     private RichTextEditorService( )
  58.     {
  59.     }

  60.     /**
  61.      * Get the default rich text editor for back office
  62.      *
  63.      * @return The default rich text editor for back office
  64.      */
  65.     public static String getBackOfficeDefaultEditor( )
  66.     {
  67.         String strDefaultEditorName = AppPropertiesService.getProperty( PROPERTY_DEFAULT_EDITOR_BACK_OFFICE );

  68.         return DatastoreService.getDataValue( PARAMETER_DEFAULT_EDITOR_BACK_OFFICE, strDefaultEditorName );
  69.     }

  70.     /**
  71.      * Get the default rich text editor for front office
  72.      *
  73.      * @return The default rich text editor for front office
  74.      */
  75.     public static String getFrontOfficeDefaultEditor( )
  76.     {
  77.         String strDefaultEditorName = AppPropertiesService.getProperty( PROPERTY_DEFAULT_EDITOR_FRONT_OFFICE );

  78.         return DatastoreService.getDataValue( PARAMETER_DEFAULT_EDITOR_FRONT_OFFICE, strDefaultEditorName );
  79.     }

  80.     /**
  81.      * Update the default rich text editor for back office
  82.      *
  83.      * @param strEditorUrl
  84.      *            Name of the new rich text editor for back office
  85.      */
  86.     public static void updateBackOfficeDefaultEditor( String strEditorUrl )
  87.     {
  88.         DatastoreService.setDataValue( PARAMETER_DEFAULT_EDITOR_BACK_OFFICE, strEditorUrl );
  89.     }

  90.     /**
  91.      * Update the default rich text editor for front office
  92.      *
  93.      * @param strEditorUrl
  94.      *            Name of the new rich text editor for front office
  95.      */
  96.     public static void updateFrontOfficeDefaultEditor( String strEditorUrl )
  97.     {
  98.         DatastoreService.setDataValue( PARAMETER_DEFAULT_EDITOR_FRONT_OFFICE, strEditorUrl );
  99.     }

  100.     /**
  101.      * Get the list of rich text editors for back office
  102.      *
  103.      * @param locale
  104.      *            The locale of to use
  105.      * @return The list of rich text editors for back office
  106.      */
  107.     public static ReferenceList getListEditorsForBackOffice( Locale locale )
  108.     {
  109.         Collection<RichTextEditor> listRichTextEditor = RichTextEditorHome.findListEditorsForBackOffice( );
  110.         ReferenceList refList = new ReferenceList( );

  111.         for ( RichTextEditor editor : listRichTextEditor )
  112.         {
  113.             ReferenceItem refItem = new ReferenceItem( );
  114.             refItem.setCode( editor.getEditorName( ) );
  115.             refItem.setName( I18nService.getLocalizedString( editor.getDescription( ), locale ) );
  116.             refList.add( refItem );
  117.         }

  118.         return refList;
  119.     }

  120.     /**
  121.      * Get the list of rich text editors for front office
  122.      *
  123.      * @param locale
  124.      *            The locale of to use
  125.      * @return The list of rich text editors for front office
  126.      */
  127.     public static ReferenceList getListEditorsForFrontOffice( Locale locale )
  128.     {
  129.         Collection<RichTextEditor> listRichTextEditor = RichTextEditorHome.findListEditorsForFrontOffice( );
  130.         ReferenceList refList = new ReferenceList( );

  131.         for ( RichTextEditor editor : listRichTextEditor )
  132.         {
  133.             ReferenceItem refItem = new ReferenceItem( );
  134.             refItem.setCode( editor.getEditorName( ) );
  135.             refItem.setName( I18nService.getLocalizedString( editor.getDescription( ), locale ) );
  136.             refList.add( refItem );
  137.         }

  138.         return refList;
  139.     }
  140. }