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

File SyntaxType.java

 

Coverage histogram

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

Code metrics

6
21
9
1
207
86
13
0.62
2.33
9
1.44

Classes

Class Line # Actions
SyntaxType 31 21 0% 13 5
0.861111186.1%
 

Contributing tests

This file is covered by 1850 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.rendering.syntax;
21   
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import org.apache.commons.lang3.builder.CompareToBuilder;
26   
27    /**
28    * @version $Id: 9d36e0a247f320ae18806bc05a76bc7c24a0bdac $
29    * @since 2.0RC1
30    */
 
31    public class SyntaxType implements Comparable<SyntaxType>
32    {
33    /**
34    * Well-known Syntax types.
35    */
36    private static final Map<String, SyntaxType> KNOWN_SYNTAX_TYPES = new HashMap<String, SyntaxType>();
37   
38    public static final SyntaxType XWIKI = register("xwiki", "XWiki");
39   
40    /**
41    * Confluence wiki syntax.
42    */
43    public static final SyntaxType CONFLUENCE = register("confluence", "Confluence");
44   
45    /**
46    * Confluence XHTML based syntax.
47    *
48    * @since 5.3M1
49    */
50    public static final SyntaxType CONFLUENCEXHTML = register("confluence+xhtml", "Confluence");
51   
52    public static final SyntaxType MEDIAWIKI = register("mediawiki", "MediaWiki");
53   
54    public static final SyntaxType CREOLE = register("creole", "Creole");
55   
56    public static final SyntaxType JSPWIKI = register("jspwiki", "JSPWiki");
57   
58    public static final SyntaxType TWIKI = register("twiki", "TWiki");
59   
60    public static final SyntaxType XHTML = register("xhtml", "XHTML");
61   
62    public static final SyntaxType ANNOTATED_XHTML = register("annotatedxhtml", "Annotated XHTML");
63   
64    public static final SyntaxType ANNOTATED_HTML = register("annotatedhtml", "Annotated HTML");
65   
66    public static final SyntaxType HTML = register("html", "HTML");
67   
68    public static final SyntaxType PLAIN = register("plain", "Plain");
69   
70    public static final SyntaxType EVENT = register("event", "Event");
71   
72    public static final SyntaxType TEX = register("tex", "TeX");
73   
74    public static final SyntaxType DOCBOOK = register("docbook", "DocBook");
75   
76    /**
77    * @since 3.3M1
78    */
79    public static final SyntaxType XDOMXML = register("xdom+xml", "XML based XDOM");
80   
81    /**
82    * @since 3.4M1
83    */
84    public static final SyntaxType MARKDOWN = register("markdown", "Markdown");
85   
86    /**
87    * @since 4.3M1
88    */
89    public static final SyntaxType APT = register("apt", "APT");
90   
91    /**
92    * Register a Syntax Type.
93    *
94    * @param id see {@link SyntaxType#SyntaxType(String, String)}
95    * @param name see {@link SyntaxType#SyntaxType(String, String)}
96    * @return the created Syntax Type object
97    */
 
98  2214 toggle private static SyntaxType register(String id, String name)
99    {
100  2214 SyntaxType syntaxType = new SyntaxType(id, name);
101  2214 KNOWN_SYNTAX_TYPES.put(id, syntaxType);
102  2214 return syntaxType;
103    }
104   
105    /**
106    * @return the well-known Syntax types
107    */
 
108  36446 toggle public static Map<String, SyntaxType> getSyntaxTypes()
109    {
110  36443 return KNOWN_SYNTAX_TYPES;
111    }
112   
113    /**
114    * @see #getName()
115    */
116    private String name;
117   
118    /**
119    * @see #getId()
120    */
121    private String id;
122   
123    /**
124    * @param id the technical id of the Syntax type (ex "annotatedxhtml")
125    * @param name the human readable name of the Syntax type (ex "Annotated XHTML")
126    * @since 2.0M3
127    */
 
128  2290 toggle public SyntaxType(String id, String name)
129    {
130  2290 this.name = name;
131  2290 this.id = id;
132    }
133   
134    /**
135    * @return the technical id of the Syntax type (ex "annotatedxhtml")
136    * @since 2.0M3
137    */
 
138  517813 toggle public String getId()
139    {
140  517814 return this.id;
141    }
142   
143    /**
144    * @return the human readable name of the Syntax type (ex "Annotated XHTML")
145    * @since 2.0M3
146    */
 
147  547 toggle public String getName()
148    {
149  547 return this.name;
150    }
151   
152    /**
153    * {@inheritDoc}
154    * <p>
155    * Display a human readable name of the Syntax type.
156    * </p>
157    *
158    * @see java.lang.Object#toString()
159    */
 
160  5455 toggle @Override
161    public String toString()
162    {
163  5455 return this.name;
164    }
165   
 
166  9 toggle @Override
167    public int hashCode()
168    {
169    // Random number. See http://www.technofundo.com/tech/java/equalhash.html for the detail of this
170    // algorithm.
171    // Note that the name isn't part of the hashCode computation since it's not part of the Syntax type's identity
172  9 int hash = 7;
173  9 hash = 31 * hash + (null == getId() ? 0 : getId().hashCode());
174  9 return hash;
175    }
176   
 
177  5351 toggle @Override
178    public boolean equals(Object object)
179    {
180  5352 boolean result;
181   
182    // See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm.
183  5352 if (this == object) {
184  0 result = true;
185    } else {
186  5352 if ((object == null) || (object.getClass() != this.getClass())) {
187  0 result = false;
188    } else {
189    // Object must be Syntax at this point.
190  5352 SyntaxType syntaxType = (SyntaxType) object;
191    // Note that the name isn't part of the hashCode computation since it's not part of the Syntax type's
192    // identity.
193  5352 result = (getId() == syntaxType.getId() || (getId() != null && getId().equals(syntaxType.getId())));
194    }
195    }
196   
197  5351 return result;
198    }
199   
 
200  4 toggle @Override
201    public int compareTo(SyntaxType syntaxType)
202    {
203  4 return new CompareToBuilder()
204    .append(getName(), syntaxType.getName())
205    .toComparison();
206    }
207    }