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

File TemporaryResourceReference.java

 

Coverage histogram

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

Code metrics

2
15
9
1
140
64
10
0.67
1.67
9
1.11

Classes

Class Line # Actions
TemporaryResourceReference 39 15 0% 10 6
0.769230876.9%
 

Contributing tests

This file is covered by 13 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.temporary;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.List;
25   
26    import org.apache.commons.lang3.builder.EqualsBuilder;
27    import org.apache.commons.lang3.builder.HashCodeBuilder;
28    import org.xwiki.model.reference.EntityReference;
29    import org.xwiki.resource.AbstractResourceReference;
30    import org.xwiki.resource.ResourceType;
31   
32    /**
33    * Points to a temporary Resource that's been generated by some XWiki process (For example the Formula Macro generates
34    * images of rendered formulas, the Chart Macro generates images of rendered chart data, etc).
35    *
36    * @version $Id: 834be151324cd2f60a773b6e593e333d4a2771c6 $
37    * @since 6.1M2
38    */
 
39    public class TemporaryResourceReference extends AbstractResourceReference
40    {
41    /**
42    * Represents a Temporary Resource Type.
43    */
44    public static final ResourceType TYPE = new ResourceType("tmp");
45   
46    private final EntityReference owningEntityReference;
47   
48    private final List<String> resourcePath;
49   
50    private final String moduleId;
51   
52    /**
53    * Create a new temporary resource reference.
54    *
55    * @param moduleId see {@link #getModuleId()}
56    * @param resourcePath see {@link #getResourcePath()}
57    * @param owningEntityReference see {@link #getOwningEntityReference()}
58    */
 
59  66 toggle public TemporaryResourceReference(String moduleId, List<String> resourcePath, EntityReference owningEntityReference)
60    {
61  66 setType(TYPE);
62  66 this.moduleId = moduleId;
63  66 this.resourcePath = Collections.unmodifiableList(new ArrayList<String>(resourcePath));
64  66 this.owningEntityReference = owningEntityReference;
65    }
66   
67    /**
68    * @param moduleId see {@link #getModuleId()}
69    * @param resourceName see {@link #getResourceName()}
70    * @param owningEntityReference see {@link #getOwningEntityReference()}
71    */
 
72  64 toggle public TemporaryResourceReference(String moduleId, String resourceName, EntityReference owningEntityReference)
73    {
74  64 this(moduleId, Collections.singletonList(resourceName), owningEntityReference);
75    }
76   
77    /**
78    * @param moduleId see {@link #getModuleId()}
79    * @param resourceName see {@link #getResourceName()}
80    */
 
81  0 toggle public TemporaryResourceReference(String moduleId, String resourceName)
82    {
83  0 this(moduleId, resourceName, null);
84    }
85   
86    /**
87    * @return the reference to the entity owning the current temporary resource. This can be used for example to verify
88    * that the user asking for the temporary resource has the permission to view the owning entity before
89    * letting him access the temporary resource.
90    */
 
91  234 toggle public EntityReference getOwningEntityReference()
92    {
93  234 return this.owningEntityReference;
94    }
95   
96    /**
97    * @return the name of the temporary resource (e.g. the temporary file name of a generated image)
98    */
 
99  2 toggle public String getResourceName()
100    {
101  2 return this.resourcePath.get(this.resourcePath.size() - 1);
102    }
103   
104    /**
105    * @return the path to the temporary resource (within the namespace defined by the module id)
106    */
 
107  232 toggle public List<String> getResourcePath()
108    {
109  232 return this.resourcePath;
110    }
111   
112    /**
113    * @return the module id, a free name (used as a namespace) allowing several components to generate temporary
114    * resources for the same entity
115    */
 
116  234 toggle public String getModuleId()
117    {
118  234 return this.moduleId;
119    }
120   
 
121  0 toggle @Override
122    public int hashCode()
123    {
124  0 return new HashCodeBuilder(super.hashCode(), 5).append(getModuleId()).append(getOwningEntityReference())
125    .append(getResourcePath()).toHashCode();
126    }
127   
 
128  116 toggle @Override
129    public boolean equals(Object object)
130    {
131  116 if (!super.equals(object)) {
132  0 return false;
133    }
134   
135  116 TemporaryResourceReference reference = (TemporaryResourceReference) object;
136  116 return new EqualsBuilder().append(getModuleId(), reference.getModuleId())
137    .append(getOwningEntityReference(), reference.getOwningEntityReference())
138    .append(getResourcePath(), reference.getResourcePath()).isEquals();
139    }
140    }