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

File DocumentInfo.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

44
61
16
1
205
150
41
0.67
3.81
16
2.56

Classes

Class Line # Actions
DocumentInfo 29 61 0% 41 81
0.330578533.1%
 

Contributing tests

This file is covered by 9 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.plugin.packaging;
21   
22    import org.slf4j.Logger;
23    import org.slf4j.LoggerFactory;
24   
25    import com.xpn.xwiki.XWikiContext;
26    import com.xpn.xwiki.XWikiException;
27    import com.xpn.xwiki.doc.XWikiDocument;
28   
 
29    public class DocumentInfo
30    {
31    private static final Logger LOGGER = LoggerFactory.getLogger(DocumentInfo.class);
32   
33    private XWikiDocument doc;
34   
35    private int installable = INSTALL_IMPOSSIBLE;
36   
37    private int action = ACTION_NOT_DEFINED;
38   
39    private int fileType;
40   
41    public final static int TYPE_SAMPLE = 0;
42   
43    public final static int TYPE_NORMAL = 1;
44   
45    public final static int ACTION_NOT_DEFINED = -1;
46   
47    public final static int ACTION_OVERWRITE = 0;
48   
49    public final static int ACTION_SKIP = 1;
50   
51    public final static int ACTION_MERGE = 2;
52   
53    public final static int INSTALL_IMPOSSIBLE = 0;
54   
55    public final static int INSTALL_ALREADY_EXIST = 1;
56   
57    public final static int INSTALL_OK = 2;
58   
59    public final static int INSTALL_ERROR = 4;
60   
 
61  2007 toggle public DocumentInfo(XWikiDocument doc)
62    {
63  2007 this.doc = doc;
64    }
65   
 
66  21745 toggle public XWikiDocument getDoc()
67    {
68  21745 return this.doc;
69    }
70   
 
71  0 toggle public boolean isNew()
72    {
73  0 return this.doc.isNew();
74    }
75   
 
76  0 toggle public void changeSpace(String Space)
77    {
78  0 if (this.doc.getSpace().compareTo("XWiki") != 0) {
79  0 return;
80    }
81  0 this.doc.setSpace(Space);
82  0 this.installable = INSTALL_IMPOSSIBLE;
83    }
84   
 
85  0 toggle public int getFileType()
86    {
87  0 return this.fileType;
88    }
89   
 
90  0 toggle public void setFileType(int fileType)
91    {
92  0 this.fileType = fileType;
93    }
94   
 
95  64606 toggle public String getFullName()
96    {
97  64606 return (this.doc.getFullName());
98    }
99   
 
100  8210 toggle public String getLanguage()
101    {
102  8210 return (this.doc.getLanguage());
103    }
104   
 
105  0 toggle public int isInstallable()
106    {
107  0 return this.installable;
108    }
109   
 
110  4126 toggle public int testInstall(boolean isAdmin, XWikiContext context)
111    {
112  4126 if (LOGGER.isDebugEnabled()) {
113  0 LOGGER.debug("Package test install document " + ((this.doc == null) ? "" : getFullName()) + " "
114  0 + ((this.doc == null) ? "" : getLanguage()));
115    }
116   
117  4126 this.installable = INSTALL_IMPOSSIBLE;
118   
119  4126 try {
120  4126 if (this.doc == null) {
121  0 return this.installable;
122    }
123  4126 try {
124  4126 if ((!isAdmin) && (!context.getWiki().checkAccess("edit", this.doc, context))) {
125  0 return this.installable;
126    }
127  4126 XWikiDocument doc1 = context.getWiki().getDocument(this.doc.getFullName(), context);
128  4126 boolean isNew = doc1.isNew();
129  4126 if (!isNew) {
130  164 if ((this.doc.getLanguage() != null) && (!this.doc.getLanguage().equals(""))) {
131  158 isNew = !doc1.getTranslationList(context).contains(this.doc.getLanguage());
132    }
133    }
134   
135  4126 if (!isNew) {
136  8 this.installable = INSTALL_ALREADY_EXIST;
137  8 return this.installable;
138    }
139    } catch (XWikiException e) {
140  0 this.installable = INSTALL_IMPOSSIBLE;
141  0 return this.installable;
142    }
143  4118 this.installable = INSTALL_OK;
144  4118 return this.installable;
145    } finally {
146  4126 if (LOGGER.isDebugEnabled()) {
147  0 LOGGER.debug("Package test install document " + ((this.doc == null) ? "" : getFullName()) + " "
148  0 + ((this.doc == null) ? "" : getLanguage()) + " result " + this.installable);
149    }
150    }
151    }
152   
 
153  0 toggle public static String installStatusToString(int status)
154    {
155  0 if (status == INSTALL_IMPOSSIBLE) {
156  0 return "Impossible";
157  0 } else if (status == INSTALL_ERROR) {
158  0 return "Error";
159  0 } else if (status == INSTALL_OK) {
160  0 return "Ok";
161  0 } else if (status == INSTALL_ALREADY_EXIST) {
162  0 return "Already exist";
163    }
164  0 return "Unknown Status";
165    }
166   
 
167  0 toggle public static String actionToString(int status)
168    {
169  0 if (status == ACTION_MERGE) {
170  0 return "merge";
171  0 } else if (status == ACTION_OVERWRITE) {
172  0 return "overwrite";
173  0 } else if (status == ACTION_SKIP) {
174  0 return "skip";
175    }
176  0 return "Not defined";
177    }
178   
 
179  0 toggle public static int actionToInt(String status)
180    {
181  0 if (status.compareTo("merge") == 0) {
182  0 return ACTION_MERGE;
183  0 } else if (status.compareTo("overwrite") == 0) {
184  0 return ACTION_OVERWRITE;
185  0 } else if (status.compareTo("skip") == 0) {
186  0 return ACTION_SKIP;
187    }
188  0 return ACTION_NOT_DEFINED;
189    }
190   
 
191  2006 toggle public int getAction()
192    {
193  2006 return this.action;
194    }
195   
 
196  3989 toggle public void setAction(int action)
197    {
198  3989 this.action = action;
199    }
200   
 
201  0 toggle public void setDoc(XWikiDocument doc)
202    {
203  0 this.doc = doc;
204    }
205    }