1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.listener.reference

File ResourceType.java

 

Coverage histogram

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

Code metrics

6
14
5
1
175
57
9
0.64
2.8
5
1.8

Classes

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