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 java.util.Collection;
42  
43  import javax.servlet.http.HttpServletRequest;
44  
45  /**
46   *
47   * DocumentPortlet
48   *
49   */
50  public class DocumentPortlet extends Portlet
51  {
52      public static final String RESOURCE_ID = "DOCUMENT_PORTLET";
53  
54      /////////////////////////////////////////////////////////////////////////////////
55      // Xml Tags
56      private static final String TAG_DOCUMENT_PORTLET = "document-portlet";
57  
58      /////////////////////////////////////////////////////////////////////////////////
59      // Constants
60      private String _strDocumentTypeCode;
61      private int _nPortletId;
62      private int [ ] _nArrayIdCategory;
63  
64      /**
65       * Sets the identifier of the portlet type to the value specified in the DocumentPortletHome class
66       */
67      public DocumentPortlet( )
68      {
69          setPortletTypeId( DocumentPortletHome.getInstance( ).getPortletTypeId( ) );
70      }
71  
72      /**
73       * Returns the Xml code of the DocumentPortlet without XML heading
74       *
75       * @param request
76       *            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
102      *            The HTTP Servlet Request
103      * @return the Xml code of the DocumentPortlet
104      */
105     public String getXmlDocument( HttpServletRequest request )
106     {
107         return XmlUtil.getXmlHeader( ) + getXml( request );
108     }
109 
110     /**
111      * Updates the current instance of the DocumentPortlet object
112      */
113     public void update( )
114     {
115         DocumentPortletHome.getInstance( ).update( this );
116     }
117 
118     /**
119      * Removes the current instance of the DocumentPortlet object
120      */
121     public void remove( )
122     {
123         DocumentPortletHome.getInstance( ).remove( this );
124     }
125 
126     /**
127      * Returns the nPortletId
128      *
129      * @return The nPortletId
130      */
131     public int getPortletId( )
132     {
133         return _nPortletId;
134     }
135 
136     /**
137      * Sets the IdPortlet
138      *
139      * @param nPortletId
140      *            The nPortletId
141      */
142     public void setPortletId( int nPortletId )
143     {
144         _nPortletId = nPortletId;
145     }
146 
147     /**
148      * Sets the parent page identifier of the portlet to the value specified in parameter
149      *
150      * @param strDocumentTypeCode
151      *            the code
152      */
153     public void setDocumentTypeCode( String strDocumentTypeCode )
154     {
155         _strDocumentTypeCode = strDocumentTypeCode;
156     }
157 
158     /**
159      * Returns the identifier of the parent page of the portlet
160      *
161      * @return the parent page identifier
162      */
163     public String getDocumentTypeCode( )
164     {
165         return _strDocumentTypeCode;
166     }
167 
168     /**
169      * @return the _nIdCategory
170      */
171     public int [ ] getIdCategory( )
172     {
173         return _nArrayIdCategory;
174     }
175 
176     /**
177      * @param arrayIdCategory
178      *            the _nIdCategory to set
179      */
180     public void setIdCategory( int [ ] arrayIdCategory )
181     {
182         _nArrayIdCategory = arrayIdCategory;
183     }
184 }