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

File Syntax.java

 

Coverage histogram

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

Code metrics

8
19
10
1
208
101
14
0.74
1.9
10
1.4

Classes

Class Line # Actions
Syntax 34 19 0% 14 8
0.783783878.4%
 

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 org.xwiki.rendering.syntax;
21   
22    import org.apache.commons.lang3.builder.CompareToBuilder;
23    import org.apache.commons.lang3.builder.EqualsBuilder;
24    import org.apache.commons.lang3.builder.HashCodeBuilder;
25   
26    /**
27    * Represents a wiki syntax that the user can use to enter wiki content. A syntax is made of two parts: a type (eg
28    * XWiki, Confluence, MediaWiki, etc) and a version (1.0, 2.0, etc). For example the XWiki 1.0 syntax, the XWiki 2.0
29    * syntax, the Confluence 1.0 syntax, etc.
30    *
31    * @version $Id: b0a43917525212ae3c5f79e34fc74f047ec7db2c $
32    * @since 2.0RC1
33    */
 
34    public class Syntax implements Comparable<Syntax>
35    {
36    /**
37    * HTML5 syntax.
38    *
39    * @since 6.4M3
40    */
41    public static final Syntax HTML_5_0 = new Syntax(SyntaxType.HTML, "5.0");
42   
43    public static final Syntax XHTML_1_0 = new Syntax(SyntaxType.XHTML, "1.0");
44   
45    public static final Syntax HTML_4_01 = new Syntax(SyntaxType.HTML, "4.01");
46   
47    /**
48    * @deprecated since 5.0
49    */
50    @Deprecated
51    public static final Syntax XWIKI_1_0 = new Syntax(SyntaxType.XWIKI, "1.0");
52   
53    public static final Syntax XWIKI_2_0 = new Syntax(SyntaxType.XWIKI, "2.0");
54   
55    public static final Syntax XWIKI_2_1 = new Syntax(SyntaxType.XWIKI, "2.1");
56   
57    public static final Syntax PLAIN_1_0 = new Syntax(SyntaxType.PLAIN, "1.0");
58   
59    public static final Syntax EVENT_1_0 = new Syntax(SyntaxType.EVENT, "1.0");
60   
61    public static final Syntax TEX_1_0 = new Syntax(SyntaxType.TEX, "1.0");
62   
63    public static final Syntax CREOLE_1_0 = new Syntax(SyntaxType.CREOLE, "1.0");
64   
65    public static final Syntax JSPWIKI_1_0 = new Syntax(SyntaxType.JSPWIKI, "1.0");
66   
67    public static final Syntax MEDIAWIKI_1_0 = new Syntax(SyntaxType.MEDIAWIKI, "1.0");
68   
69    public static final Syntax TWIKI_1_0 = new Syntax(SyntaxType.TWIKI, "1.0");
70   
71    public static final Syntax DOCBOOK_4_4 = new Syntax(SyntaxType.DOCBOOK, "4.4");
72   
73    /**
74    * Confluence wiki syntax.
75    */
76    public static final Syntax CONFLUENCE_1_0 = new Syntax(SyntaxType.CONFLUENCE, "1.0");
77   
78    /**
79    * Confluence XHTML based syntax.
80    *
81    * @since 5.3M1
82    */
83    public static final Syntax CONFLUENCEXHTML_1_0 = new Syntax(SyntaxType.CONFLUENCEXHTML, "1.0");
84   
85    /**
86    * @since 3.3M1
87    */
88    public static final Syntax XDOMXML_CURRENT = new Syntax(SyntaxType.XDOMXML, "current");
89   
90    /**
91    * @since 3.3M1
92    */
93    public static final Syntax XDOMXML_1_0 = new Syntax(SyntaxType.XDOMXML, "1.0");
94   
95    /**
96    * @since 3.4M1
97    */
98    public static final Syntax MARKDOWN_1_0 = new Syntax(SyntaxType.MARKDOWN, "1.0");
99   
100    /**
101    * @since 5.2M1
102    */
103    public static final Syntax MARKDOWN_1_1 = new Syntax(SyntaxType.MARKDOWN, "1.1");
104   
105    /**
106    * @since 4.3M1
107    */
108    public static final Syntax APT_1_0 = new Syntax(SyntaxType.APT, "1.0");
109   
110    /**
111    * This is HTML with annotations (comments) in order to allow round tripping between for example the WYSIWYG editor
112    * and wiki syntax.
113    */
114    public static final Syntax ANNOTATED_XHTML_1_0 = new Syntax(SyntaxType.ANNOTATED_XHTML, "1.0");
115   
116    /**
117    * This is HTML5 with annotations (comments) in order to allow round tripping between for example the WYSIWYG editor
118    * and wiki syntax.
119    */
120    public static final Syntax ANNOTATED_HTML_5_0 = new Syntax(SyntaxType.ANNOTATED_HTML, "5.0");
121   
122    private SyntaxType type;
123   
124    private String version;
125   
126    /**
127    * Optional free form text that qualifies the version, eg "experimental".
128    */
129    private String qualifier;
130   
 
131  39373 toggle public Syntax(SyntaxType type, String version)
132    {
133  39367 this.type = type;
134  39368 this.version = version;
135    }
136   
 
137  0 toggle public Syntax(SyntaxType type, String version, String qualifier)
138    {
139  0 this(type, version);
140  0 this.qualifier = qualifier;
141    }
142   
 
143  524118 toggle public SyntaxType getType()
144    {
145  524120 return this.type;
146    }
147   
 
148  465792 toggle public String getVersion()
149    {
150  465793 return this.version;
151    }
152   
 
153  20689 toggle public String getQualifier()
154    {
155  20693 return this.qualifier;
156    }
157   
 
158  444547 toggle public String toIdString()
159    {
160  444551 return getType().getId() + "/" + getVersion().toLowerCase();
161    }
162   
 
163  5455 toggle @Override
164    public String toString()
165    {
166  5455 return getType().toString() + " " + getVersion() + (getQualifier() != null ? " (" + getQualifier() + ")" : "");
167    }
168   
 
169  9 toggle @Override
170    public int hashCode()
171    {
172  9 return new HashCodeBuilder(5, 7)
173    .append(getType())
174    .append(getVersion())
175    .append(getQualifier())
176    .toHashCode();
177    }
178   
 
179  7697 toggle @Override
180    public boolean equals(Object object)
181    {
182  7697 if (object == null) {
183  0 return false;
184    }
185  7697 if (object == this) {
186  83 return true;
187    }
188  7616 if (object.getClass() != getClass()) {
189  0 return false;
190    }
191  7616 Syntax rhs = (Syntax) object;
192  7617 return new EqualsBuilder()
193    .append(getType(), rhs.getType())
194    .append(getVersion(), rhs.getVersion())
195    .append(getQualifier(), rhs.getQualifier())
196    .isEquals();
197    }
198   
 
199  3 toggle @Override
200    public int compareTo(Syntax syntax)
201    {
202  3 return new CompareToBuilder()
203    .append(getType(), syntax.getType())
204    // TODO: Add a real version parser to compare the versions
205    .append(getVersion(), syntax.getVersion())
206    .toComparison();
207    }
208    }