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