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

File XWikiDeletedDocument.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
24
17
1
228
96
19
0.79
1.41
17
1.12

Classes

Class Line # Actions
XWikiDeletedDocument 39 24 0% 19 2
0.9555555695.6%
 

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    import java.util.Locale;
24   
25    import org.xwiki.localization.LocaleUtils;
26   
27    import com.xpn.xwiki.XWikiContext;
28    import com.xpn.xwiki.XWikiException;
29    import com.xpn.xwiki.util.AbstractSimpleClass;
30    import com.xpn.xwiki.util.Util;
31   
32    /**
33    * Archive of deleted document, stored in {@link com.xpn.xwiki.store.XWikiRecycleBinStoreInterface} Immutable, because
34    * we don't need modify deleted document.
35    *
36    * @version $Id: 6016788673f128d9b311d20c8bb08c731afe9b1f $
37    * @since 1.2M1
38    */
 
39    public class XWikiDeletedDocument extends AbstractSimpleClass
40    {
41    /**
42    * Synthetic id.
43    */
44    private long id;
45   
46    /**
47    * @see XWikiDocument#getFullName()
48    */
49    private String fullName;
50   
51    /**
52    * @see XWikiDocument#getLocale()
53    */
54    private Locale locale;
55   
56    /**
57    * date of delete action.
58    */
59    private Date date;
60   
61    /**
62    * @see XWikiDeletedDocument#getDeleter()
63    */
64    private String deleter;
65   
66    /**
67    * @see XWikiDocument#toXML(XWikiContext)
68    */
69    private String xml;
70   
71    /**
72    * Default constructor. Used only in hibernate.
73    */
 
74  88 toggle protected XWikiDeletedDocument()
75    {
76    }
77   
78    /**
79    * @param doc - deleted document
80    * @param deleter - user which delete document
81    * @param deleteDate - date of delete action
82    * @param context - used for environment
83    * @throws XWikiException if any error
84    */
 
85  153 toggle public XWikiDeletedDocument(XWikiDocument doc, String deleter, Date deleteDate, XWikiContext context)
86    throws XWikiException
87    {
88  153 this.fullName = doc.getFullName();
89  153 this.locale = doc.getLocale();
90  153 this.deleter = deleter;
91  153 this.date = deleteDate;
92   
93  153 setDocument(doc, context);
94    }
95   
96    /**
97    * @return the synthetic id of this deleted document. unique only for document.
98    */
 
99  263 toggle public long getId()
100    {
101  263 return this.id;
102    }
103   
104    /**
105    * @param id - the synthetic id to set. used only in hibernate.
106    */
 
107  178 toggle protected void setId(long id)
108    {
109  178 this.id = id;
110    }
111   
112    /**
113    * @return {@link XWikiDocument#getFullName()}
114    */
 
115  360 toggle public String getFullName()
116    {
117  360 return this.fullName;
118    }
119   
120    /**
121    * @param docFullName - {@link XWikiDocument#getFullName()} to set
122    */
 
123  25 toggle protected void setFullName(String docFullName)
124    {
125  25 this.fullName = docFullName;
126    }
127   
128    /**
129    * @return {@link XWikiDocument#getLanguage()}
130    * @deprecated since 8.0M1, use {@link #getLocale()} instead
131    */
 
132  308 toggle @Deprecated
133    public String getLanguage()
134    {
135  308 return getLocale().toString();
136    }
137   
138    /**
139    * @return {@link XWikiDocument#getLocale()}
140    * @since 8.0M1
141    */
 
142  308 toggle public Locale getLocale()
143    {
144  308 return this.locale != null ? this.locale : Locale.ROOT;
145    }
146   
147    /**
148    * @param locale - {@link XWikiDocument#getLanguage()} to set
149    * @deprecated since 8.0M1
150    */
 
151  25 toggle @Deprecated
152    protected void setLanguage(String locale)
153    {
154  25 this.locale = LocaleUtils.toLocale(Util.normalizeLanguage(locale), Locale.ROOT);
155    }
156   
157    /**
158    * @return the date of delete action
159    */
 
160  341 toggle public Date getDate()
161    {
162  341 return this.date;
163    }
164   
165    /**
166    * @param date - the date of delete action to set
167    */
 
168  25 toggle protected void setDate(Date date)
169    {
170  25 this.date = date;
171    }
172   
173    /**
174    * @return the user which has removed the document
175    */
 
176  323 toggle public String getDeleter()
177    {
178  323 return this.deleter;
179    }
180   
181    /**
182    * @param deleter - the user which has removed the document to set
183    */
 
184  25 toggle protected void setDeleter(String deleter)
185    {
186  25 this.deleter = deleter;
187    }
188   
189    /** @return xml serialization of {@link XWikiDocument} */
 
190  309 toggle public String getXml()
191    {
192  309 return this.xml;
193    }
194   
195    /** @param xml - xml serialization of {@link XWikiDocument} */
 
196  178 toggle protected void setXml(String xml)
197    {
198  178 this.xml = xml;
199    }
200   
201    /**
202    * export {@link XWikiDocument} to {@link XWikiDeletedDocument}.
203    *
204    * @param doc - deleted document
205    * @param context - used in {@link XWikiDocument#toXML(XWikiContext)}
206    * @throws XWikiException in error in {@link XWikiDocument#toXML(XWikiContext)}
207    */
 
208  153 toggle protected void setDocument(XWikiDocument doc, XWikiContext context) throws XWikiException
209    {
210  153 setXml(doc.toFullXML(context));
211    }
212   
213    /**
214    * @return restored document
215    * @param doc - restore to this document, if not null
216    * @param context - may be useful in future
217    * @throws XWikiException if error in {@link XWikiDocument#fromXML(String)}
218    */
 
219  3 toggle public XWikiDocument restoreDocument(XWikiDocument doc, XWikiContext context) throws XWikiException
220    {
221  3 XWikiDocument result = doc;
222  3 if (result == null) {
223  3 result = new XWikiDocument();
224    }
225  3 result.fromXML(getXml(), true);
226  3 return result;
227    }
228    }