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

File VoidAttachmentVersioningStore.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
14
15
2
168
96
17
1.21
0.93
7.5
1.13

Classes

Class Line # Actions
VoidAttachmentVersioningStore 47 5 0% 6 1
0.916666791.7%
VoidAttachmentVersioningStore.VoidAttachmentArchive 97 9 0% 11 6
0.7142857371.4%
 

Contributing tests

This file is covered by 2 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.store;
21   
22    import java.util.Date;
23   
24    import javax.inject.Named;
25    import javax.inject.Singleton;
26   
27    import org.suigeneris.jrcs.rcs.Archive;
28    import org.suigeneris.jrcs.rcs.Version;
29    import org.xwiki.component.annotation.Component;
30   
31    import com.xpn.xwiki.XWikiContext;
32    import com.xpn.xwiki.XWikiException;
33    import com.xpn.xwiki.doc.XWikiAttachment;
34    import com.xpn.xwiki.doc.XWikiAttachmentArchive;
35   
36    /**
37    * Void store for attachment versioning when it is disabled. ("xwiki.store.attachment.versioning=0" parameter is set in
38    * xwiki.cfg) It says what there is only one version of attachment - latest. It doesn't store anything. It is safe to
39    * use with any stores.
40    *
41    * @version $Id: e802cb4f89a13511c5d6e577a30daaa2498f5b2c $
42    * @since 1.4M2
43    */
44    @Component
45    @Named("void")
46    @Singleton
 
47    public class VoidAttachmentVersioningStore implements AttachmentVersioningStore
48    {
49    /**
50    * Constructor used by {@link com.xpn.xwiki.XWiki} during storage initialization.
51    *
52    * @param context The current context.
53    * @deprecated 1.6M1. Use ComponentManager.lookup(AttachmentVersioningStore.class) instead.
54    */
 
55  0 toggle @Deprecated
56    public VoidAttachmentVersioningStore(XWikiContext context)
57    {
58    }
59   
60    /**
61    * Empty constructor needed for component manager.
62    */
 
63  2 toggle public VoidAttachmentVersioningStore()
64    {
65    }
66   
 
67  1 toggle @Override
68    public void deleteArchive(XWikiAttachment attachment, XWikiContext context, boolean transaction)
69    throws XWikiException
70    {
71    // Don't do anything since it's a void implementation.
72    }
73   
 
74  1 toggle @Override
75    public void saveArchive(XWikiAttachmentArchive archive, XWikiContext context, boolean transaction)
76    throws XWikiException
77    {
78    // Don't do anything since it's a void implementation.
79    }
80   
 
81  4 toggle @Override
82    public XWikiAttachmentArchive loadArchive(XWikiAttachment attachment, XWikiContext context, boolean transaction)
83    throws XWikiException
84    {
85  4 XWikiAttachmentArchive archive = attachment.getAttachment_archive();
86  4 if (!(archive instanceof VoidAttachmentArchive)) {
87  2 archive = new VoidAttachmentArchive(attachment);
88    }
89  4 attachment.setAttachment_archive(archive);
90  4 return archive;
91    }
92   
93    /**
94    * Void realization of AttachmentArchive. It says what there is only one version of attachment - latest. Class is
95    * public because used in super.clone() via getClass().newInstance()
96    */
 
97    public static class VoidAttachmentArchive extends XWikiAttachmentArchive
98    {
99    /**
100    * Default constructor. Used in super.clone().
101    */
 
102  1 toggle public VoidAttachmentArchive()
103    {
104    }
105   
106    /**
107    * Helper constructor.
108    *
109    * @param attachment attachment of this archive
110    */
 
111  3 toggle public VoidAttachmentArchive(XWikiAttachment attachment)
112    {
113  3 setAttachment(attachment);
114    }
115   
 
116  0 toggle @Override
117    public void updateArchive(final byte[] data, final XWikiContext context) throws XWikiException
118    {
119  0 updateArchive(context);
120    }
121   
 
122  3 toggle @Override
123    public void updateArchive(XWikiContext context) throws XWikiException
124    {
125  3 getAttachment().incrementVersion();
126  3 getAttachment().setDate(new Date());
127    }
128   
 
129  0 toggle @Override
130    public void setArchive(byte[] data) throws XWikiException
131    {
132    // Don't do anything since it's a void implementation.
133    }
134   
 
135  0 toggle @Override
136    public byte[] getArchive(XWikiContext context) throws XWikiException
137    {
138  0 return new byte[0];
139    }
140   
 
141  1 toggle @Override
142    public void setRCSArchive(Archive archive)
143    {
144    // Don't do anything since it's a void implementation.
145    }
146   
 
147  2 toggle @Override
148    public Version[] getVersions()
149    {
150  2 return new Version[] { getAttachment().getRCSVersion() };
151    }
152   
 
153  2 toggle @Override
154    public XWikiAttachment getRevision(XWikiAttachment attachment, String rev, XWikiContext context)
155    throws XWikiException
156    {
157  2 return (attachment.getVersion().equals(rev)) ? attachment : null;
158    }
159   
 
160  1 toggle @Override
161    public Object clone()
162    {
163    // super.clone() is needed for checkstyle
164  1 super.clone();
165  1 return new VoidAttachmentArchive(getAttachment());
166    }
167    }
168    }