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

File AttachmentDiff.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
12
8
1
123
50
11
0.92
1.5
8
1.38

Classes

Class Line # Actions
AttachmentDiff 33 12 0% 11 26
0.00%
 

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.api;
21   
22    import org.xwiki.diff.Delta;
23   
24    import com.xpn.xwiki.XWikiContext;
25    import com.xpn.xwiki.doc.XWikiAttachment;
26   
27    /**
28    * Safe version of {@link com.xpn.xwiki.doc.AttachmentDiff} that can be used by the scripts.
29    *
30    * @since 7.0RC1
31    * @version $Id: 2079cb05ad1fb5c79d5352b2aa1dda72fd7da176 $
32    */
 
33    public class AttachmentDiff
34    {
35    /**
36    * The unsafe attachment difference (exposes protected {@link XWikiAttachment}).
37    */
38    private com.xpn.xwiki.doc.AttachmentDiff diff;
39   
40    /**
41    * The XWiki context used to create save versions of {@link XWikiAttachment}.
42    */
43    private XWikiContext context;
44   
45    /**
46    * Wraps the given unsafe attachment difference.
47    *
48    * @param diff the unsafe attachment difference
49    * @param context the XWiki context needed to create the safe versions of {@link XWikiAttachment}
50    */
 
51  0 toggle public AttachmentDiff(com.xpn.xwiki.doc.AttachmentDiff diff, XWikiContext context)
52    {
53  0 this.diff = diff;
54  0 this.context = context;
55    }
56   
57    /**
58    * @return the name of the attachment whose versions are being compared
59    */
 
60  0 toggle public String getFileName()
61    {
62  0 return this.diff.getFileName();
63    }
64   
65    /**
66    * @return the type of difference (one of 'insert', 'delete', 'change')
67    */
 
68  0 toggle public String getType()
69    {
70  0 Delta.Type type = this.diff.getType();
71  0 return type != null ? type.toString().toLowerCase() : null;
72    }
73   
74    /**
75    * @return the original version of the attachment
76    */
 
77  0 toggle public Attachment getOrigAttachment()
78    {
79  0 XWikiAttachment origAttachment = this.diff.getOrigAttachment();
80  0 return origAttachment != null ? new Attachment(origAttachment.getDoc().newDocument(context), origAttachment,
81    context) : null;
82    }
83   
84    /**
85    * @return the new version of the attachment
86    */
 
87  0 toggle public Attachment getNewAttachment()
88    {
89  0 XWikiAttachment newAttachment = this.diff.getNewAttachment();
90  0 return newAttachment != null ? new Attachment(newAttachment.getDoc().newDocument(context), newAttachment,
91    context) : null;
92    }
93   
94    /**
95    * NOTE: We kept this method (despite being deprecated) in order to preserve backwards compatibility with existing
96    * scripts that were exposed to the unsafe {@link com.xpn.xwiki.doc.AttachmentDiff}.
97    *
98    * @return the original attachment version
99    */
 
100  0 toggle @Deprecated
101    public String getOrigVersion()
102    {
103  0 return this.diff.getOrigVersion();
104    }
105   
106    /**
107    * NOTE: We kept this method (despite being deprecated) in order to preserve backwards compatibility with existing
108    * scripts that were exposed to the unsafe {@link com.xpn.xwiki.doc.AttachmentDiff}.
109    *
110    * @return the new attachment version
111    */
 
112  0 toggle @Deprecated
113    public String getNewVersion()
114    {
115  0 return this.diff.getNewVersion();
116    }
117   
 
118  0 toggle @Override
119    public String toString()
120    {
121  0 return this.diff.toString();
122    }
123    }