1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.filter.type

File FilterStreamType.java

 

Coverage histogram

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

Code metrics

20
48
11
1
284
120
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 99 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: e51ad8f68275b39d0e7824728995e128d992aae2 $
31    * @since 6.2M1
32    */
 
33    public class FilterStreamType implements Comparable<FilterStreamType>
34    {
35    /**
36    * Data format identifier for XML.
37    * <p>
38    * Main content is based on XML.
39    */
40    public static final String DATA_XML = "xml";
41   
42    /**
43    * Data format identifier for XAR.
44    * <p>
45    * Main content is based on XAR format.
46    */
47   
48    public static final String DATA_XAR = "xar";
49   
50    /**
51    * Data format identifier for TEXT.
52    * <p>
53    * Main content is textual content which does not belong to another well know and more specific textual content.
54    *
55    * @since 9.5RC1
56    */
57    public static final String DATA_TEXT = "text";
58   
59    /**
60    * Generic WIKI XML Syntax.
61    */
62    public static final FilterStreamType FILTER_XML = new FilterStreamType(SystemType.FILTER, DATA_XML);
63   
64    /**
65    * The XAR format in version 1.1.
66    *
67    * @since 6.2M1
68    */
69    public static final FilterStreamType XWIKI_XAR_11 = new FilterStreamType(SystemType.XWIKI, DATA_XAR, "1.1");
70   
71    /**
72    * The XAR format in version 1.2.
73    *
74    * @since 7.2M1
75    */
76    public static final FilterStreamType XWIKI_XAR_12 = new FilterStreamType(SystemType.XWIKI, DATA_XAR, "1.2");
77   
78    /**
79    * The XAR format in version 1.3.
80    *
81    * @since 9.0RC1
82    */
83    public static final FilterStreamType XWIKI_XAR_13 = new FilterStreamType(SystemType.XWIKI, DATA_XAR, "1.3");
84   
85    /**
86    * The XAR format in the current version.
87    *
88    * @since 7.2M1
89    */
90    public static final FilterStreamType XWIKI_XAR_CURRENT = XWIKI_XAR_13;
91   
92    /**
93    * The database stream based on oldcore APIs.
94    */
95    public static final FilterStreamType XWIKI_INSTANCE = new FilterStreamType(SystemType.XWIKI, "instance");
96   
97    /**
98    * The Confluence XML format.
99    */
100    public static final FilterStreamType CONFLUENCE_XML = new FilterStreamType(SystemType.CONFLUENCE, DATA_XML);
101   
102    /**
103    * The MediaWiki XML format.
104    */
105    public static final FilterStreamType MEDIAWIKI_XML = new FilterStreamType(SystemType.MEDIAWIKI, DATA_XML);
106   
107    /**
108    * The DokuWiki data format.
109    *
110    * @since 9.5RC1
111    */
112    public static final FilterStreamType DOKUWIKI_TEXT = new FilterStreamType(SystemType.DOKUWIKI, DATA_TEXT);
113   
114    /**
115    * Wiki type.
116    */
117    private SystemType type;
118   
119    /**
120    * Export data format.
121    */
122    private String dataFormat;
123   
124    /**
125    * The version.
126    */
127    private String version;
128   
129    /**
130    * @param type the type of Wiki
131    * @param dataFormat the export data format
132    */
 
133  330 toggle public FilterStreamType(SystemType type, String dataFormat)
134    {
135  330 this(type, dataFormat, null);
136    }
137   
138    /**
139    * @param type the type of Wiki
140    * @param dataFormat the export data format
141    * @param version the version
142    */
 
143  563 toggle public FilterStreamType(SystemType type, String dataFormat, String version)
144    {
145  563 this.type = type;
146  563 this.dataFormat = dataFormat != null ? dataFormat.toLowerCase() : null;
147  563 this.version = version;
148    }
149   
150    /**
151    * @return the wiki
152    */
 
153  35021 toggle public SystemType getType()
154    {
155  35020 return this.type;
156    }
157   
158    /**
159    * @return the export data format
160    */
 
161  69900 toggle public String getDataFormat()
162    {
163  69900 return this.dataFormat;
164    }
165   
166    /**
167    * @return the version
168    */
 
169  66290 toggle public String getVersion()
170    {
171  66290 return this.version;
172    }
173   
174    /**
175    * @return a {@link String} representation of the {@link FilterStreamType}
176    */
 
177  34881 toggle public String serialize()
178    {
179  34881 StringBuilder builder = new StringBuilder();
180   
181  34881 builder.append(getType().serialize());
182   
183  34880 if (getDataFormat() != null) {
184  34880 builder.append('+');
185  34881 builder.append(getDataFormat());
186    }
187   
188  34881 if (getVersion() != null) {
189  31308 builder.append('/');
190  31308 builder.append(getVersion());
191    }
192   
193  34881 return builder.toString();
194    }
195   
196    /**
197    * Create a new {@link FilterStreamType} from a {@link String}.
198    *
199    * @param str the {@link String} to parse
200    * @return a {@link FilterStreamType}
201    */
 
202  46 toggle public static FilterStreamType unserialize(String str)
203    {
204  46 if (str == null) {
205  0 return null;
206    }
207   
208  46 String wikiType = str;
209  46 String data = null;
210  46 String version = null;
211   
212    // Version
213   
214  46 int versionIndex = str.lastIndexOf('/');
215   
216  46 if (versionIndex == 0) {
217  0 throw new IllegalArgumentException("'/' is invalid as first character: " + str);
218    }
219   
220  46 if (versionIndex != -1) {
221  16 version = wikiType.substring(versionIndex + 1);
222  16 wikiType = wikiType.substring(0, versionIndex);
223    }
224   
225    // Data
226   
227  46 int dataIndex = str.indexOf('+');
228   
229  46 if (dataIndex == 0) {
230  0 throw new IllegalArgumentException("'+' is invalid as first character: " + str);
231    }
232   
233  46 if (dataIndex != -1) {
234  44 data = wikiType.substring(dataIndex + 1);
235  44 wikiType = wikiType.substring(0, dataIndex);
236    }
237   
238  46 return new FilterStreamType(SystemType.unserialize(wikiType), data, version);
239    }
240   
 
241  24 toggle @Override
242    public String toString()
243    {
244  24 return serialize();
245    }
246   
 
247  0 toggle @Override
248    public int hashCode()
249    {
250  0 return new HashCodeBuilder().append(getType()).append(getDataFormat()).append(getVersion()).toHashCode();
251    }
252   
 
253  5 toggle @Override
254    public boolean equals(Object object)
255    {
256  5 boolean result;
257   
258  5 if (this == object) {
259  0 result = true;
260    } else {
261  5 if (object instanceof FilterStreamType) {
262  5 result = Objects.equals(getType(), ((FilterStreamType) object).getType())
263    && Objects.equals(getDataFormat(), ((FilterStreamType) object).getDataFormat())
264    && Objects.equals(getVersion(), ((FilterStreamType) object).getVersion());
265    } else {
266  0 result = false;
267    }
268    }
269   
270  5 return result;
271    }
272   
 
273  45 toggle @Override
274    public int compareTo(FilterStreamType o)
275    {
276  45 CompareToBuilder builder = new CompareToBuilder();
277   
278  45 builder.append(getType().toString(), o.getType().toString());
279  45 builder.append(getDataFormat(), o.getDataFormat());
280  45 builder.append(getVersion(), o.getVersion());
281   
282  45 return builder.toComparison();
283    }
284    }