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

File EntityResourceReference.java

 

Coverage histogram

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

Code metrics

6
26
12
1
182
95
15
0.58
2.17
12
1.25

Classes

Class Line # Actions
EntityResourceReference 38 26 0% 15 6
0.863636486.4%
 

Contributing tests

This file is covered by 77 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.resource.entity;
21   
22    import java.util.Locale;
23   
24    import org.apache.commons.lang3.builder.EqualsBuilder;
25    import org.apache.commons.lang3.builder.HashCodeBuilder;
26    import org.apache.commons.lang3.builder.ToStringBuilder;
27    import org.xwiki.model.reference.EntityReference;
28    import org.xwiki.resource.AbstractResourceReference;
29    import org.xwiki.resource.ResourceType;
30    import org.xwiki.text.XWikiToStringBuilder;
31   
32    /**
33    * Represents an XWiki Resource Reference pointing to an Entity (Document, Space, Wiki, Object, etc).
34    *
35    * @version $Id: 09786643d719cfc976b04e434e509489f96cf1d0 $
36    * @since 6.1M2
37    */
 
38    public class EntityResourceReference extends AbstractResourceReference
39    {
40    /**
41    * Represents an Entity Resource Type.
42    */
43    public static final ResourceType TYPE = new ResourceType("entity");
44   
45    /**
46    * The parameter name that represents a version of the entity.
47    */
48    private static final String REVISION_PARAMETER_NAME = "rev";
49   
50    /**
51    * @see #getEntityReference()
52    */
53    private EntityReference entityReference;
54   
55    /**
56    * @see #getLocale()
57    */
58    private Locale locale;
59   
60    /**
61    * @see #getAction()
62    */
63    private EntityResourceAction action;
64   
65    /**
66    * @param entityReference the entity reference being wrapped
67    * @param action the instance representing the technical Action id (e.g. View, Download, etc)
68    */
 
69  83726 toggle public EntityResourceReference(EntityReference entityReference, EntityResourceAction action)
70    {
71  83744 setType(TYPE);
72  83726 setEntityReference(entityReference);
73  83744 setAction(action);
74    }
75   
76    /**
77    * @return the action requested on this resource (e.g. View, Download, Edit, etc)
78    */
 
79  203562 toggle public EntityResourceAction getAction()
80    {
81  203655 return this.action;
82    }
83   
84    /**
85    * @param action see {@link #getAction()}
86    */
 
87  83734 toggle public void setAction(EntityResourceAction action)
88    {
89  83764 this.action = action;
90    }
91   
92    /**
93    * @return the wrapped entity reference
94    */
 
95  133224 toggle public EntityReference getEntityReference()
96    {
97  133266 return this.entityReference;
98    }
99   
100    /**
101    * @param entityReference see {@link #getEntityReference()}
102    */
 
103  83718 toggle public void setEntityReference(EntityReference entityReference)
104    {
105  83755 this.entityReference = entityReference;
106    }
107   
108    /**
109    * @param locale see {@link #getLocale()}
110    */
 
111  1 toggle public void setLocale(Locale locale)
112    {
113  1 this.locale = locale;
114    }
115   
116    /**
117    * @return the locale of the entity
118    */
 
119  36933 toggle public Locale getLocale()
120    {
121  36956 return this.locale;
122    }
123   
124    /**
125    * @param revision see {@link #getRevision()}
126    */
 
127  1 toggle public void setRevision(String revision)
128    {
129  1 addParameter(REVISION_PARAMETER_NAME, revision);
130    }
131   
132    /**
133    * @return the version of the resource (eg "2.1", etc)
134    */
 
135  1 toggle public String getRevision()
136    {
137  1 return getParameterValue(REVISION_PARAMETER_NAME);
138    }
139   
 
140  2 toggle @Override
141    public int hashCode()
142    {
143  2 return new HashCodeBuilder(9, 9)
144    .appendSuper(super.hashCode())
145    .append(getEntityReference())
146    .append(getLocale())
147    .append(getAction())
148    .toHashCode();
149    }
150   
 
151  120 toggle @Override
152    public boolean equals(Object object)
153    {
154  120 if (object == null) {
155  0 return false;
156    }
157  120 if (object == this) {
158  0 return true;
159    }
160  120 if (object.getClass() != getClass()) {
161  0 return false;
162    }
163  120 EntityResourceReference rhs = (EntityResourceReference) object;
164  120 return new EqualsBuilder()
165    .appendSuper(super.equals(object))
166    .append(getEntityReference(), rhs.getEntityReference())
167    .append(getLocale(), rhs.getLocale())
168    .append(getAction(), rhs.getAction())
169    .isEquals();
170    }
171   
 
172  36693 toggle @Override
173    public String toString()
174    {
175  36704 ToStringBuilder builder = new XWikiToStringBuilder(this);
176  36708 builder.appendSuper(super.toString());
177  36710 builder.append("reference", getEntityReference());
178  36718 builder.append("action", getAction());
179  36712 builder.append("locale", getLocale());
180  36703 return builder.toString();
181    }
182    }