1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.filter.type

File FilterStreamType.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

20
48
11
1
257
116
21
0.44
4.36
11
1.91

Classes

Class Line # Actions
FilterStreamType 33 48 0% 21 13
0.83544383.5%
 

Contributing tests

This file is covered by 85 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 org.xwiki.filter.type;
21   
22    import java.util.Objects;
23   
24    import org.apache.commons.lang3.builder.CompareToBuilder;
25    import org.apache.commons.lang3.builder.HashCodeBuilder;
26   
27    /**
28    * Combination of supported system and their data types.
29    *
30    * @version $Id: 8fc6cd67065b297b6b199e0cac18a7275296e0c5 $
31    * @since 6.2M1
32    */
 
33    public class FilterStreamType implements Comparable<FilterStreamType>
34    {
35    /**
36    * Data format identifier for XML.
37    */
38    public static final String DATA_XML = "xml";
39   
40    /**
41    * Data format identifier for XAR.
42    */
43    public static final String DATA_XAR = "xar";
44   
45    /**
46    * Generic WIKI XML Syntax.
47    */
48    public static final FilterStreamType FILTER_XML = new FilterStreamType(SystemType.FILTER, DATA_XML);
49   
50    /**
51    * The XAR format in version 1.1.
52    *
53    * @since 6.2M1
54    */
55    public static final FilterStreamType XWIKI_XAR_11 = new FilterStreamType(SystemType.XWIKI, DATA_XAR, "1.1");
56   
57    /**
58    * The XAR format in version 1.2.
59    *
60    * @since 7.2M1
61    */
62    public static final FilterStreamType XWIKI_XAR_12 = new FilterStreamType(SystemType.XWIKI, DATA_XAR, "1.2");
63   
64    /**
65    * The XAR format in version 1.3.
66    *
67    * @since 9.0RC1
68    */
69    public static final FilterStreamType XWIKI_XAR_13 = new FilterStreamType(SystemType.XWIKI, DATA_XAR, "1.3");
70   
71    /**
72    * The XAR format in the current version.
73    *
74    * @since 7.2M1
75    */
76    public static final FilterStreamType XWIKI_XAR_CURRENT = XWIKI_XAR_13;
77   
78    /**
79    * The database stream based on oldcore APIs.
80    */
81    public static final FilterStreamType XWIKI_INSTANCE = new FilterStreamType(SystemType.XWIKI, "instance");
82   
83    /**
84    * The Confluence XML format.
85    */
86    public static final FilterStreamType CONFLUENCE_XML = new FilterStreamType(SystemType.CONFLUENCE, DATA_XML);
87   
88    /**
89    * Wiki type.
90    */
91    private SystemType type;
92   
93    /**
94    * Export data format.
95    */
96    private String dataFormat;
97   
98    /**
99    * The version.
100    */
101    private String version;
102   
103    /**
104    * @param type the type of Wiki
105    * @param dataFormat the export data format
106    */
 
107  169 toggle public FilterStreamType(SystemType type, String dataFormat)
108    {
109  169 this(type, dataFormat, null);
110    }
111   
112    /**
113    * @param type the type of Wiki
114    * @param dataFormat the export data format
115    * @param version the version
116    */
 
117  357 toggle public FilterStreamType(SystemType type, String dataFormat, String version)
118    {
119  357 this.type = type;
120  357 this.dataFormat = dataFormat != null ? dataFormat.toLowerCase() : null;
121  357 this.version = version;
122    }
123   
124    /**
125    * @return the wiki
126    */
 
127  12764 toggle public SystemType getType()
128    {
129  12764 return this.type;
130    }
131   
132    /**
133    * @return the export data format
134    */
 
135  25405 toggle public String getDataFormat()
136    {
137  25405 return this.dataFormat;
138    }
139   
140    /**
141    * @return the version
142    */
 
143  24958 toggle public String getVersion()
144    {
145  24959 return this.version;
146    }
147   
148    /**
149    * @return a {@link String} representation of the {@link FilterStreamType}
150    */
 
151  12642 toggle public String serialize()
152    {
153  12642 StringBuilder builder = new StringBuilder();
154   
155  12641 builder.append(getType().serialize());
156   
157  12642 if (getDataFormat() != null) {
158  12642 builder.append('+');
159  12641 builder.append(getDataFormat());
160    }
161   
162  12642 if (getVersion() != null) {
163  12224 builder.append('/');
164  12225 builder.append(getVersion());
165    }
166   
167  12642 return builder.toString();
168    }
169   
170    /**
171    * Create a new {@link FilterStreamType} from a {@link String}.
172    *
173    * @param str the {@link String} to parse
174    * @return a {@link FilterStreamType}
175    */
 
176  46 toggle public static FilterStreamType unserialize(String str)
177    {
178  46 if (str == null) {
179  0 return null;
180    }
181   
182  46 String wikiType = str;
183  46 String data = null;
184  46 String version = null;
185   
186    // Version
187   
188  46 int versionIndex = str.lastIndexOf('/');
189   
190  46 if (versionIndex == 0) {
191  0 throw new IllegalArgumentException("'/' is invalid as first character: " + str);
192    }
193   
194  46 if (versionIndex != -1) {
195  16 version = wikiType.substring(versionIndex + 1);
196  16 wikiType = wikiType.substring(0, versionIndex);
197    }
198   
199    // Data
200   
201  46 int dataIndex = str.indexOf('+');
202   
203  46 if (dataIndex == 0) {
204  0 throw new IllegalArgumentException("'+' is invalid as first character: " + str);
205    }
206   
207  46 if (dataIndex != -1) {
208  44 data = wikiType.substring(dataIndex + 1);
209  44 wikiType = wikiType.substring(0, dataIndex);
210    }
211   
212  46 return new FilterStreamType(SystemType.unserialize(wikiType), data, version);
213    }
214   
 
215  24 toggle @Override
216    public String toString()
217    {
218  24 return serialize();
219    }
220   
 
221  0 toggle @Override
222    public int hashCode()
223    {
224  0 return new HashCodeBuilder().append(getType()).append(getDataFormat()).append(getVersion()).toHashCode();
225    }
226   
 
227  1 toggle @Override
228    public boolean equals(Object object)
229    {
230  1 boolean result;
231   
232  1 if (this == object) {
233  0 result = true;
234    } else {
235  1 if (object instanceof FilterStreamType) {
236  1 result = Objects.equals(getType(), ((FilterStreamType) object).getType())
237    && Objects.equals(getDataFormat(), ((FilterStreamType) object).getDataFormat());
238    } else {
239  0 result = false;
240    }
241    }
242   
243  1 return result;
244    }
245   
 
246  44 toggle @Override
247    public int compareTo(FilterStreamType o)
248    {
249  44 CompareToBuilder builder = new CompareToBuilder();
250   
251  44 builder.append(getType().toString(), o.getType().toString());
252  44 builder.append(getDataFormat(), o.getDataFormat());
253  44 builder.append(getVersion(), o.getVersion());
254   
255  44 return builder.toComparison();
256    }
257    }