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

File ResourceType.java

 

Coverage histogram

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

Code metrics

6
14
5
1
165
54
9
0.64
2.8
5
1.8

Classes

Class Line # Actions
ResourceType 40 14 0% 9 3
0.8888%
 

Contributing tests

This file is covered by 473 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.listener.reference;
21   
22    /**
23    * The Resource type. It can be one of:
24    * <ul>
25    * <li>document ("doc")</li>
26    * <li>space ("space")</li>
27    * <li>URL ("url")</li>
28    * <li>document in another wiki (interwiki) ("interwiki")</li>
29    * <li>relative URL ("path")</li>
30    * <li>mail ("mailto")</li>
31    * <li>attachment ("attach")</li>
32    * <li>UNC path ("unc")</li>
33    * <li>User ("user")</li>
34    * <li>Data URI image ("data")</li>
35    * </ul>
36    *
37    * @version $Id: ff8be31765452e3a67b33cd6dd7eb1eaddb4429e $
38    * @since 2.5RC1
39    */
 
40    public class ResourceType
41    {
42    /**
43    * Special type to be used when the type of the resource is not known.
44    */
45    public static final ResourceType UNKNOWN = new ResourceType("unknown");
46   
47    /**
48    * Represents a Document.
49    */
50    public static final ResourceType DOCUMENT = new ResourceType("doc");
51   
52    /**
53    * Represents a Space.
54    */
55    public static final ResourceType SPACE = new ResourceType("space");
56   
57    /**
58    * Represents an URL.
59    */
60    public static final ResourceType URL = new ResourceType("url");
61   
62    /**
63    * Represents a document in another wiki.
64    */
65    public static final ResourceType INTERWIKI = new ResourceType("interwiki");
66   
67    /**
68    * Represents a relative URL in the current wiki.
69    */
70    public static final ResourceType PATH = new ResourceType("path");
71   
72    /**
73    * Represents a mail.
74    */
75    public static final ResourceType MAILTO = new ResourceType("mailto");
76   
77    /**
78    * Represents an attachment.
79    */
80    public static final ResourceType ATTACHMENT = new ResourceType("attach");
81   
82    /**
83    * Represents an icon.
84    */
85    public static final ResourceType ICON = new ResourceType("icon");
86   
87    /**
88    * Represents a UNC (Universal Naming Convention) (eg "\\myserver\myshare\mydoc.txt").
89    *
90    * @since 2.7M1
91    */
92    public static final ResourceType UNC = new ResourceType("unc");
93   
94    /**
95    * Represents a user.
96    *
97    * @since 5.3M2
98    */
99    public static final ResourceType USER = new ResourceType("user");
100   
101    /**
102    * Represents a image specified as a <a href="http://tools.ietf.org/html/rfc2397">Data URI</a>.
103    *
104    * @since 5.4RC1
105    */
106    public static final ResourceType DATA = new ResourceType("data");
107   
108    /**
109    * @see #getScheme()
110    */
111    private final String scheme;
112   
113    /**
114    * @param scheme see {@link #getScheme()}
115    */
 
116  1055 toggle public ResourceType(String scheme)
117    {
118  1055 this.scheme = scheme;
119    }
120   
121    /**
122    * @return the type of the link (eg "doc" for links to documents, etc)
123    */
 
124  22137 toggle public String getScheme()
125    {
126  22137 return this.scheme;
127    }
128   
 
129  1008 toggle @Override
130    public int hashCode()
131    {
132    // Random number. See http://www.technofundo.com/tech/java/equalhash.html for the detail of this
133    // algorithm.
134  1008 int hash = 8;
135  1008 hash = 31 * hash + (null == getScheme() ? 0 : getScheme().hashCode());
136  1008 return hash;
137    }
138   
 
139  4994 toggle @Override
140    public boolean equals(Object object)
141    {
142  4994 boolean result;
143   
144    // See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm.
145  4994 if (this == object) {
146  2294 result = true;
147    } else {
148  2700 if ((object == null) || (object.getClass() != this.getClass())) {
149  0 result = false;
150    } else {
151    // object must be ResourceType at this point
152  2700 ResourceType type = (ResourceType) object;
153  2700 result =
154    (getScheme() == type.getScheme() || (getScheme() != null && getScheme().equals(type.getScheme())));
155    }
156    }
157  4994 return result;
158    }
159   
 
160  502 toggle @Override
161    public String toString()
162    {
163  502 return getScheme();
164    }
165    }