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

File XWikiRCSNodeInfo.java

 

Coverage histogram

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

Code metrics

8
25
17
1
223
97
22
0.88
1.47
17
1.29

Classes

Class Line # Actions
XWikiRCSNodeInfo 38 25 0% 22 2
0.9696%
 

Contributing tests

This file is covered by 6 tests. .

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.rcs;
21   
22    import java.lang.ref.SoftReference;
23    import java.util.Date;
24   
25    import org.suigeneris.jrcs.rcs.Version;
26   
27    import com.xpn.xwiki.XWikiContext;
28    import com.xpn.xwiki.XWikiException;
29    import com.xpn.xwiki.user.api.XWikiRightService;
30    import com.xpn.xwiki.util.AbstractSimpleClass;
31   
32    /**
33    * Contains information about document version. Mutable.
34    *
35    * @version $Id: 82b6c2d0f639d438f7271610d0a0617dfaff4f63 $
36    * @since 1.2M1
37    */
 
38    public class XWikiRCSNodeInfo extends AbstractSimpleClass implements Comparable<XWikiRCSNodeInfo>
39    {
40    /**
41    * composite primary id of class.
42    */
43    private XWikiRCSNodeId id;
44   
45    /**
46    * date of this modification.
47    */
48    private Date date = new Date();
49   
50    /**
51    * author of modification.
52    */
53    private String author = XWikiRightService.GUEST_USER_FULLNAME;
54   
55    /**
56    * modification's comment.
57    */
58    private String comment = "";
59   
60    /**
61    * is this version diff or full version. read-only
62    */
63    private boolean isDiff = true;
64   
65    /**
66    * reference to its XWikiRCSNodeContent.
67    */
68    private SoftReference<XWikiRCSNodeContent> contentRef;
69   
70    /**
71    * default constructor used in Hibernate to load this class.
72    */
 
73  3773 toggle public XWikiRCSNodeInfo()
74    {
75    }
76   
77    /**
78    * @param id - primary key.
79    */
 
80  5752 toggle public XWikiRCSNodeInfo(XWikiRCSNodeId id)
81    {
82  5752 setId((XWikiRCSNodeId) id.clone());
83    }
84   
85    /**
86    * @return primary key.
87    */
 
88  56153 toggle public XWikiRCSNodeId getId()
89    {
90  56153 return this.id;
91    }
92   
93    /**
94    * @param id - primary key.
95    */
 
96  15378 toggle public void setId(XWikiRCSNodeId id)
97    {
98  15378 this.id = id;
99    }
100   
101    /**
102    * @return date of this modification.
103    */
 
104  15374 toggle public Date getDate()
105    {
106  15374 return this.date;
107    }
108   
109    /**
110    * @param updateDate - date of this modification.
111    */
 
112  9525 toggle public void setDate(Date updateDate)
113    {
114  9525 this.date = updateDate;
115    }
116   
117    /**
118    * @return get author of modification.
119    */
 
120  15385 toggle public String getAuthor()
121    {
122    // For Oracle and other databases, an empty string is equivalent to a NULL and thus
123    // we had to remove the NOT-NULL condition on this field. Hence we need to test if it's
124    // null here and return an empty string so that all code calling this will not be impacted.
125  15385 return this.author != null ? this.author : "";
126    }
127   
128    /**
129    * @param updateAuthor - author of modification.
130    */
 
131  9525 toggle public void setAuthor(String updateAuthor)
132    {
133  9525 this.author = updateAuthor;
134    }
135   
136    /**
137    * @return modification's comment.
138    */
 
139  15385 toggle public String getComment()
140    {
141    // For Oracle and other databases, an empty string is equivalent to a NULL and thus
142    // we had to remove the NOT-NULL condition on this field. Hence we need to test if it's
143    // null here and return an empty string so that all code calling this will not be impacted.
144  15385 return this.comment != null ? this.comment : "";
145    }
146   
147    /**
148    * @param comment - modification's comment.
149    */
 
150  9525 toggle public void setComment(String comment)
151    {
152  9525 this.comment = comment;
153    }
154   
155    /**
156    * @return is modification minor.
157    */
 
158  41 toggle public boolean isMinorEdit()
159    {
160  41 return this.id.getVersion().at(1) != 1;
161    }
162   
163    /**
164    * @return is patch or full version.
165    */
 
166  25963 toggle public boolean isDiff()
167    {
168  25963 return this.isDiff;
169    }
170   
171    /**
172    * @param diff - is patch (true) or full version (false). Should not be used directly.
173    * @see XWikiPatch#setDiff(boolean)
174    */
 
175  10879 toggle public void setDiff(boolean diff)
176    {
177  10879 this.isDiff = diff;
178    }
179   
180    /**
181    * @return {@link XWikiRCSNodeContent} for this node.
182    * @param context - load with this context. If null then do not load.
183    * @throws XWikiException if can't load
184    */
 
185  801 toggle public XWikiRCSNodeContent getContent(XWikiContext context) throws XWikiException
186    {
187  801 XWikiRCSNodeContent nodeContent = null;
188  801 if (this.contentRef != null) {
189  126 nodeContent = this.contentRef.get();
190    }
191  801 if (nodeContent != null || context == null) {
192  126 return nodeContent;
193    }
194  675 nodeContent = context.getWiki().getVersioningStore()
195    .loadRCSNodeContent(this.id, true, context);
196  675 this.contentRef = new SoftReference<XWikiRCSNodeContent>(nodeContent);
197  675 return nodeContent;
198    }
199   
200    /**
201    * @param content - {@link XWikiRCSNodeContent} for this node.
202    */
 
203  6284 toggle public void setContent(XWikiRCSNodeContent content)
204    {
205  6284 content.setId(getId());
206  6284 this.contentRef = new SoftReference<XWikiRCSNodeContent>(content);
207  6284 setDiff(content.getPatch().isDiff());
208    }
209   
210    /**
211    * @return version of this revision.
212    */
 
213  22 toggle public Version getVersion()
214    {
215  22 return getId().getVersion();
216    }
217   
 
218  5924 toggle @Override
219    public int compareTo(XWikiRCSNodeInfo o)
220    {
221  5924 return getId().getVersion().compareTo(o.getId().getVersion());
222    }
223    }