1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.doc

File DeletedAttachment.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

4
28
18
1
262
100
21
0.75
1.56
18
1.17

Classes

Class Line # Actions
DeletedAttachment 35 28 0% 21 22
0.5656%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.doc;
21   
22    import java.util.Date;
23   
24    import com.xpn.xwiki.XWikiContext;
25    import com.xpn.xwiki.XWikiException;
26    import com.xpn.xwiki.util.AbstractSimpleClass;
27   
28    /**
29    * Archive of deleted attachment, stored in {@link com.xpn.xwiki.store.AttachmentRecycleBinStore}. Immutable, because
30    * deleted attachments should not be modified.
31    *
32    * @version $Id: 615631705fae21d75c76ce9fcf86442f6aa538fd $
33    * @since 1.4M1
34    */
 
35    public class DeletedAttachment extends AbstractSimpleClass
36    {
37    /** Synthetic id, generated by Hibernate. This is used to address entries in the recycle bin. */
38    private long id;
39   
40    /** The ID of the document this attachment belonged to. */
41    private long docId;
42   
43    /** The name of the document this attachment belonged to. */
44    private String docName;
45   
46    /** The name of the attachment. */
47    private String filename;
48   
49    /** Date of delete action. */
50    private Date date;
51   
52    /** The user who deleted the attachment, in the <tt>XWiki.UserName</tt> format. */
53    private String deleter;
54   
55    /**
56    * XML export of the full attachment, with content and history.
57    *
58    * @see XWikiAttachment#toXML(boolean, boolean, XWikiContext)
59    */
60    private String xml;
61   
62    /** Default constructor. Used only by hibernate when restoring objects from the database. */
 
63  60 toggle protected DeletedAttachment()
64    {
65    }
66   
67    /**
68    * A constructor with all the information about the deleted attachment.
69    *
70    * @param attachment Deleted attachment.
71    * @param deleter User which deleted the attachment.
72    * @param deleteDate Date of delete action.
73    * @param context The current context. Used for determining the encoding.
74    * @throws XWikiException If the attachment cannot be exported to XML.
75    */
 
76  5 toggle public DeletedAttachment(XWikiAttachment attachment, String deleter, Date deleteDate, XWikiContext context)
77    throws XWikiException
78    {
79  5 this.docId = attachment.getDocId();
80  5 this.docName = attachment.getDoc().getFullName();
81  5 this.filename = attachment.getFilename();
82  5 this.deleter = deleter;
83  5 this.date = deleteDate;
84  5 setAttachment(attachment, context);
85    }
86   
87    /**
88    * Getter for {@link #id}.
89    *
90    * @return The synthetic id of this deleted attachment. Uniquely identifies an entry in the recycle bin.
91    */
 
92  65 toggle public long getId()
93    {
94  65 return this.id;
95    }
96   
97    /**
98    * Setter for {@link #id}.
99    *
100    * @param id The synthetic id to set. Used only by hibernate.
101    */
 
102  5 toggle protected void setId(long id)
103    {
104  5 this.id = id;
105    }
106   
107    /**
108    * Getter for {@link #docId}.
109    *
110    * @return The id of the document this attachment belonged to.
111    */
 
112  10 toggle public long getDocId()
113    {
114  10 return this.docId;
115    }
116   
117    /**
118    * Setter for {@link #docId}.
119    *
120    * @param docId The id of the document to set. Used only by hibernate.
121    */
 
122  0 toggle protected void setDocId(long docId)
123    {
124  0 this.docId = docId;
125    }
126   
127    /**
128    * Getter for {@link #docName}.
129    *
130    * @return The name of the document this attachment belonged to.
131    */
 
132  10 toggle public String getDocName()
133    {
134  10 return this.docName;
135    }
136   
137    /**
138    * Setter for {@link #docName}.
139    *
140    * @param docName The document name to set. Used only by hibernate.
141    */
 
142  0 toggle protected void setDocName(String docName)
143    {
144  0 this.docName = docName;
145    }
146   
147    /**
148    * Getter for {@link #filename}.
149    *
150    * @return The name of the attachment.
151    */
 
152  10 toggle public String getFilename()
153    {
154  10 return this.filename;
155    }
156   
157    /**
158    * Setter for {@link #filename}.
159    *
160    * @param filename The attachment filename to set. Used only by hibernate.
161    */
 
162  0 toggle protected void setFilename(String filename)
163    {
164  0 this.filename = filename;
165    }
166   
167    /**
168    * Getter for {@link #date}.
169    *
170    * @return The date of the delete action.
171    */
 
172  10 toggle public Date getDate()
173    {
174  10 return this.date;
175    }
176   
177    /**
178    * Setter for {@link #date}.
179    *
180    * @param date The date of the delete action to set. Used only by Hibernate.
181    */
 
182  0 toggle protected void setDate(Date date)
183    {
184  0 this.date = date;
185    }
186   
187    /**
188    * Getter for {@link #deleter}.
189    *
190    * @return the user who deleted the attachment, as its document name (e.g. {@code XWiki.Admin})
191    */
 
192  10 toggle public String getDeleter()
193    {
194  10 return this.deleter;
195    }
196   
197    /**
198    * Setter for {@link #deleter}.
199    *
200    * @param deleter The user which has removed the document to set. Used only by Hibernate.
201    */
 
202  0 toggle protected void setDeleter(String deleter)
203    {
204  0 this.deleter = deleter;
205    }
206   
207    /**
208    * Getter for {@link #xml}.
209    *
210    * @return XML serialization of {@link XWikiAttachment}
211    */
 
212  10 toggle public String getXml()
213    {
214  10 return this.xml;
215    }
216   
217    /**
218    * Setter for {@link #xml}.
219    *
220    * @param xml XML serialization of {@link XWikiAttachment}. Used only by Hibernate.
221    */
 
222  5 toggle protected void setXml(String xml)
223    {
224  5 this.xml = xml;
225    }
226   
227    /**
228    * Export {@link XWikiAttachment} to {@link DeletedAttachment}.
229    *
230    * @param attachment the deleted attachment
231    * @param context the current context, used in the XML export
232    * @throws XWikiException if an exception occurs during the XML export
233    */
 
234  5 toggle protected void setAttachment(XWikiAttachment attachment, XWikiContext context) throws XWikiException
235    {
236  5 setXml(attachment.toStringXML(true, true, context));
237    }
238   
239    /**
240    * Restore a {@link XWikiAttachment} from a {@link DeletedAttachment}. Note that this method does not actually
241    * restore the attachment to its owner document, it simply recomposes an {@link XWikiAttachment} object from the
242    * saved data.
243    *
244    * @return restored attachment
245    * @param attachment optional object where to put the attachment data, if not <code>null</code>
246    * @param context the current {@link XWikiContext context}
247    * @throws XWikiException If an exception occurs while the Attachment is restored from the XML. See
248    * {@link XWikiAttachment#fromXML(String)}.
249    */
 
250  0 toggle public XWikiAttachment restoreAttachment(XWikiAttachment attachment, XWikiContext context) throws XWikiException
251    {
252  0 XWikiAttachment result = attachment;
253  0 if (result == null) {
254  0 result = new XWikiAttachment();
255    }
256  0 result.fromXML(getXml());
257  0 if (result.getDoc() == null || !(this.getDocName().equals(result.getDoc().getFullName()))) {
258  0 result.setDoc(context.getWiki().getDocument(this.getDocName(), context));
259    }
260  0 return result;
261    }
262    }