View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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.directory.business;
35  
36  import fr.paris.lutece.portal.service.plugin.Plugin;
37  import fr.paris.lutece.util.xml.XmlUtil;
38  import java.sql.Timestamp;
39  
40  import java.util.HashMap;
41  import java.util.Locale;
42  
43  /**
44   *
45   * class File
46   *
47   */
48  public class File
49  {
50      public static final String TAG_FILE = "file";
51      private static final String ATTRIBUTE_FILE_ID = "id";
52      private static final String ATTRIBUTE_TYPE_ENTRY = "type-entry";
53      private static final String TAG_TITLE = "title";
54      private static final String TAG_SIZE = "size";
55      private static final String TAG_MIME_TYPE = "mime-type";
56      private static final String TAG_HEIGHT = "height";
57      private static final String TAG_WIDTH = "width";
58      private int _nIdFile;
59      private PhysicalFile _physicalFile;
60      private String _strTitle;
61      private int _nSize;
62      private String _strExtension;
63      private String _strMimeType;
64      private Timestamp _dateExpiration;
65  
66      /**
67       *
68       * @return the id of the file
69       */
70      public int getIdFile( )
71      {
72          return _nIdFile;
73      }
74  
75      /**
76       * set the id of the file
77       * 
78       * @param idFile
79       *            id of the file
80       */
81      public void setIdFile( int idFile )
82      {
83          _nIdFile = idFile;
84      }
85  
86      /**
87       *
88       * @return the title of the file
89       */
90      public String getTitle( )
91      {
92          return _strTitle;
93      }
94  
95      /**
96       * set the title of the file
97       * 
98       * @param title
99       *            the title of the file
100      */
101     public void setTitle( String title )
102     {
103         _strTitle = title;
104     }
105 
106     /**
107      *
108      * @return the size of the file
109      */
110     public int getSize( )
111     {
112         return _nSize;
113     }
114 
115     /**
116      * set the size of the file
117      * 
118      * @param size
119      *            the size of the file
120      */
121     public void setSize( int size )
122     {
123         _nSize = size;
124     }
125 
126     /**
127      *
128      * @return the extension of the file
129      */
130     public String getExtension( )
131     {
132         return _strExtension;
133     }
134 
135     /**
136      * set the extension of the file
137      * 
138      * @param extension
139      *            the title of the file
140      */
141     public void setExtension( String extension )
142     {
143         _strExtension = extension;
144     }
145 
146     /**
147      *
148      * @return the extension of the file
149      */
150     public String getMimeType( )
151     {
152         return _strMimeType;
153     }
154 
155     /**
156      * set the mime type of the file
157      * 
158      * @param mimeType
159      *            the mime type of the file
160      */
161     public void setMimeType( String mimeType )
162     {
163         _strMimeType = mimeType;
164     }
165 
166     /**
167      *
168      * @return the PhysicalFile associate to the file
169      */
170     public PhysicalFile getPhysicalFile( )
171     {
172         return _physicalFile;
173     }
174 
175     /**
176      * set the PhysicalFile associate to the file
177      * 
178      * @param file
179      *            PhysicalFile
180      */
181     public void setPhysicalFile( PhysicalFile file )
182     {
183         _physicalFile = file;
184     }
185 
186     /**
187      * return the xml of file
188      * 
189      * @param plugin
190      *            the plugin
191      * @param locale
192      *            the locale
193      * @param nTypeEntry
194      *            The entry type
195      * @param nWidth
196      *            The width
197      * @param nHeight
198      *            The height
199      * @return The produced xml
200      */
201     public StringBuffer getXml( Plugin plugin, Locale locale, int nTypeEntry, int nWidth, int nHeight )
202     {
203         StringBuffer strXml = new StringBuffer( );
204         HashMap<String, Object> model = new HashMap<String, Object>( );
205         model.put( ATTRIBUTE_FILE_ID, String.valueOf( getIdFile( ) ) );
206         model.put( ATTRIBUTE_TYPE_ENTRY, String.valueOf( nTypeEntry ) );
207         XmlUtil.beginElement( strXml, TAG_FILE, model );
208         XmlUtil.addElementHtml( strXml, TAG_TITLE, getTitle( ) );
209         XmlUtil.addElement( strXml, TAG_SIZE, getSize( ) );
210         XmlUtil.addElement( strXml, TAG_MIME_TYPE, getMimeType( ) );
211         XmlUtil.addElement( strXml, TAG_WIDTH, nWidth );
212         XmlUtil.addElement( strXml, TAG_HEIGHT, nHeight );
213         XmlUtil.endElement( strXml, TAG_FILE );
214 
215         return strXml;
216     }
217 
218     /**
219      * Get the expiration date of the file
220      * 
221      * @return the expiration date of the file
222      */
223     public Timestamp getDateExpiration( )
224     {
225         return _dateExpiration;
226     }
227 
228     /**
229      * Set the expiration date of the file
230      * 
231      * @param _dateExpiration
232      *            the expiration date of the file
233      */
234     public void setDateExpiration( Timestamp _dateExpiration )
235     {
236         this._dateExpiration = _dateExpiration;
237     }
238 
239     /**
240      * Return true if the file as expired, false otherwise
241      * 
242      * @return true if the file has expired
243      */
244     public boolean isFileExpired( )
245     {
246         return _dateExpiration.after( new Timestamp( System.currentTimeMillis( ) ) );
247     }
248 
249 }