1 /* 2 * Copyright (c) 2002-2020, 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.plugins.document.business.portlet; 35 36 import fr.paris.lutece.plugins.document.business.Document; 37 import fr.paris.lutece.plugins.document.service.publishing.PublishingService; 38 import fr.paris.lutece.portal.business.portlet.Portlet; 39 import fr.paris.lutece.util.xml.XmlUtil; 40 41 import java.util.Collection; 42 43 import javax.servlet.http.HttpServletRequest; 44 45 46 /** 47 * 48 * DocumentPortlet 49 * 50 */ 51 public class DocumentPortlet extends Portlet 52 { 53 public static final String RESOURCE_ID = "DOCUMENT_PORTLET"; 54 55 ///////////////////////////////////////////////////////////////////////////////// 56 // Xml Tags 57 private static final String TAG_DOCUMENT_PORTLET = "document-portlet"; 58 59 ///////////////////////////////////////////////////////////////////////////////// 60 // Constants 61 private String _strDocumentTypeCode; 62 private int _nPortletId; 63 private int[] _nArrayIdCategory; 64 65 /** 66 * Sets the identifier of the portlet type to the value specified in the DocumentPortletHome class 67 */ 68 public DocumentPortlet( ) 69 { 70 setPortletTypeId( DocumentPortletHome.getInstance( ).getPortletTypeId( ) ); 71 } 72 73 /** 74 * Returns the Xml code of the DocumentPortlet without XML heading 75 * 76 * @param request The HTTP Servlet request 77 * @return the Xml code of the DocumentPortlvet content 78 */ 79 public String getXml( HttpServletRequest request ) 80 { 81 StringBuffer strXml = new StringBuffer( ); 82 XmlUtil.beginElement( strXml, TAG_DOCUMENT_PORTLET ); 83 84 Document document = PublishingService.getInstance( ).getFirstValidPublishedDocument( getId( ) ); 85 86 if ( document != null ) 87 { 88 strXml.append( document.getXml( request, getId( ) ) ); 89 } 90 91 XmlUtil.endElement( strXml, TAG_DOCUMENT_PORTLET ); 92 93 String str = addPortletTags( strXml ); 94 95 return str; 96 } 97 98 /** 99 * Returns the Xml code of the ADocumentPortlet with XML heading 100 * 101 * @param request The HTTP Servlet Request 102 * @return the Xml code of the DocumentPortlet 103 */ 104 public String getXmlDocument( HttpServletRequest request ) 105 { 106 return XmlUtil.getXmlHeader( ) + getXml( request ); 107 } 108 109 /** 110 * Updates the current instance of the DocumentPortlet object 111 */ 112 public void update( ) 113 { 114 DocumentPortletHome.getInstance( ).update( this ); 115 } 116 117 /** 118 * Removes the current instance of the DocumentPortlet object 119 */ 120 public void remove( ) 121 { 122 DocumentPortletHome.getInstance( ).remove( this ); 123 } 124 125 /** 126 * Returns the nPortletId 127 * 128 * @return The nPortletId 129 */ 130 public int getPortletId( ) 131 { 132 return _nPortletId; 133 } 134 135 /** 136 * Sets the IdPortlet 137 * 138 * @param nPortletId The nPortletId 139 */ 140 public void setPortletId( int nPortletId ) 141 { 142 _nPortletId = nPortletId; 143 } 144 145 /** 146 * Sets the parent page identifier of the portlet to the value specified in parameter 147 * 148 * @param strDocumentTypeCode the code 149 */ 150 public void setDocumentTypeCode( String strDocumentTypeCode ) 151 { 152 _strDocumentTypeCode = strDocumentTypeCode; 153 } 154 155 /** 156 * Returns the identifier of the parent page of the portlet 157 * 158 * @return the parent page identifier 159 */ 160 public String getDocumentTypeCode( ) 161 { 162 return _strDocumentTypeCode; 163 } 164 165 /** 166 * @return the _nIdCategory 167 */ 168 public int[] getIdCategory( ) 169 { 170 return _nArrayIdCategory; 171 } 172 173 /** 174 * @param arrayIdCategory the _nIdCategory to set 175 */ 176 public void setIdCategory( int[] arrayIdCategory ) 177 { 178 _nArrayIdCategory = arrayIdCategory; 179 } 180 }