1 /* 2 * Copyright (c) 2002-2018, 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.plugins.html.business.portlet; 35 36 import fr.paris.lutece.portal.business.portlet.Portlet; 37 import fr.paris.lutece.util.xml.XmlUtil; 38 39 import javax.servlet.http.HttpServletRequest; 40 41 /** 42 * This class represents business objects HtmlPortlet 43 */ 44 public class HtmlPortlet extends Portlet implements IHtmlPortlet 45 { 46 // /////////////////////////////////////////////////////////////////////////////// 47 // Constants 48 private static final String TAG_HTML_PORTLET = "html-portlet"; 49 private static final String TAG_HTML_PORTLET_CONTENT = "html-portlet-content"; 50 private String _strHtml; 51 52 /** 53 * Sets the identifier of the portlet type to value specified 54 */ 55 public HtmlPortlet( ) 56 { 57 setPortletTypeId( HtmlPortletHome.getInstance( ).getPortletTypeId( ) ); 58 } 59 60 /** 61 * Sets the Html portlet content 62 * 63 * @param strHtml 64 * the Html code to sets content 65 */ 66 @Override 67 public void setHtml( String strHtml ) 68 { 69 _strHtml = strHtml; 70 } 71 72 /** 73 * Returns the content of the Html portlet 74 * 75 * @return the Html code content 76 */ 77 @Override 78 public String getHtml( ) 79 { 80 return _strHtml; 81 } 82 83 /** 84 * Returns the Xml code of the HTML portlet without XML heading 85 * 86 * @param request 87 * The Request 88 * @return the Xml code of the HTML portlet content 89 */ 90 @Override 91 public String getXml( HttpServletRequest request ) 92 { 93 StringBuffer strXml = new StringBuffer( ); 94 XmlUtil.beginElement( strXml, TAG_HTML_PORTLET ); 95 XmlUtil.addElementHtml( strXml, TAG_HTML_PORTLET_CONTENT, getHtml( ) ); 96 XmlUtil.endElement( strXml, TAG_HTML_PORTLET ); 97 98 return addPortletTags( strXml ); 99 } 100 101 /** 102 * Returns the Xml code of the HTML portlet with XML heading 103 * 104 * @param request 105 * The request 106 * @return the Xml code of the HTML portlet 107 */ 108 @Override 109 public String getXmlDocument( HttpServletRequest request ) 110 { 111 return XmlUtil.getXmlHeader( ) + getXml( request ); 112 } 113 114 /** 115 * Updates the current instance of the HtmlPortlet object 116 */ 117 @Override 118 public void update( ) 119 { 120 HtmlPortletHome.getInstance( ).update( this ); 121 } 122 123 /** 124 * Removes the current instance of the HtmlPortlet object 125 */ 126 @Override 127 public void remove( ) 128 { 129 HtmlPortletHome.getInstance( ).remove( this ); 130 } 131 }