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 java.io.IOException; 37 import java.io.OutputStream; 38 39 import javax.servlet.ServletException; 40 import javax.servlet.http.HttpServlet; 41 import javax.servlet.http.HttpServletRequest; 42 import javax.servlet.http.HttpServletResponse; 43 44 import org.apache.commons.text.StringEscapeUtils; 45 46 import fr.paris.lutece.portal.service.util.AppPropertiesService; 47 48 /** 49 * Servlet using for BBCODE parsing 50 */ 51 @Deprecated 52 public class ParserBbcodeServlet extends HttpServlet 53 { 54 private static final long serialVersionUID = -6564244054015195801L; 55 56 // Properties 57 private static final String PROPERTY_ENCODING = "lutece.encoding"; 58 59 // Parameter 60 private static final String PARAMETER_DATA = "data"; 61 62 /** 63 * ParserBbcodeServlet 64 */ 65 public ParserBbcodeServlet( ) 66 { 67 super( ); 68 } 69 70 /** 71 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. 72 * 73 * @param request 74 * servlet request 75 * @param response 76 * servlet response 77 * @throws IOException 78 */ 79 protected void processRequest( HttpServletRequest request, HttpServletResponse response ) throws IOException 80 { 81 String strValue = request.getParameter( PARAMETER_DATA ); 82 String strEscaped = StringEscapeUtils.escapeHtml4( strValue ); 83 String strValueReturn = ( strValue != null ) ? EditorBbcodeService.getInstance( ).parse( strEscaped ) : ""; 84 85 OutputStream out = response.getOutputStream( ); 86 out.write( strValueReturn.getBytes( AppPropertiesService.getProperty( PROPERTY_ENCODING ) ) ); 87 out.flush( ); 88 out.close( ); 89 } 90 91 /** 92 * Handles the HTTP <code>GET</code> method. 93 * 94 * @param request 95 * servlet request 96 * @param response 97 * servlet response 98 * @throws ServletException 99 * the servlet Exception 100 * @throws IOException 101 * the io exception 102 */ 103 @Override 104 protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException 105 { 106 processRequest( request, response ); 107 } 108 109 /** 110 * Handles the HTTP <code>POST</code> method. 111 * 112 * @param request 113 * servlet request 114 * @param response 115 * servlet response 116 * @throws ServletException 117 * the servlet Exception 118 * @throws IOException 119 * the io exception 120 */ 121 @Override 122 protected void doPost( HttpServletRequest request, HttpServletResponse response ) throws IOException 123 { 124 processRequest( request, response ); 125 } 126 127 /** 128 * Returns a short description of the servlet. 129 * 130 * @return message 131 */ 132 @Override 133 public String getServletInfo( ) 134 { 135 return "Servlet parsing content"; 136 } 137 }