View Javadoc
1   /*
2    * Copyright (c) 2002-2023, 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   * This class represents business objects ArticlesList Portlet
45   */
46  public class DocumentListPortlet extends Portlet
47  {
48      public static final String RESOURCE_ID = "DOCUMENT_LIST_PORTLET";
49  
50      /////////////////////////////////////////////////////////////////////////////////
51      // Xml Tags
52      private static final String TAG_DOCUMENT_LIST_PORTLET = "document-list-portlet";
53  
54      /////////////////////////////////////////////////////////////////////////////////
55      // Constants
56      private String _strDocumentTypeCode;
57      private int _nPortletId;
58      private int [ ] _nArrayIdCategory;
59  
60      /**
61       * Sets the identifier of the portlet type to the value specified in the ArticlesListPortletHome class
62       */
63      public DocumentListPortlet( )
64      {
65          setPortletTypeId( DocumentListPortletHome.getInstance( ).getPortletTypeId( ) );
66      }
67  
68      /**
69       * Returns the Xml code of the Document List portlet without XML heading
70       *
71       * @param request
72       *            The HTTP Servlet request
73       * @return the Xml code of the Document List portlet content
74       */
75      public String getXml( HttpServletRequest request )
76      {
77          StringBuffer strXml = new StringBuffer( );
78          XmlUtil.beginElement( strXml, TAG_DOCUMENT_LIST_PORTLET );
79  
80          for ( Document document : PublishingService.getInstance( ).getPublishedDocumentsByPortletId( getId( ) ) )
81          {
82              if ( document.isValid( ) ) // to have only the valid documents
83              {
84                  strXml.append( document.getXml( request, getId( ) ) );
85              }
86          }
87  
88          XmlUtil.endElement( strXml, TAG_DOCUMENT_LIST_PORTLET );
89  
90          String str = addPortletTags( strXml );
91  
92          return str;
93      }
94  
95      /**
96       * Returns the Xml code of the Articles List portlet with XML heading
97       *
98       * @param request
99       *            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
137      *            The nPortletId
138      */
139     public void setPortletId( int nPortletId )
140     {
141         _nPortletId = nPortletId;
142     }
143 
144     /**
145      * Sets the parent page identifier of the portlet to the value specified in parameter
146      *
147      * @param strDocumentTypeCode
148      *            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
175      *            the _nIdCategory to set
176      */
177     public void setIdCategory( int [ ] arrayIdCategory )
178     {
179         _nArrayIdCategory = arrayIdCategory;
180     }
181 }