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

File DefaultResourceReferenceEntityReferenceResolver.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
9
1
1
83
45
4
0.44
9
1
4

Classes

Class Line # Actions
DefaultResourceReferenceEntityReferenceResolver 46 9 0% 4 1
0.928571492.9%
 

Contributing tests

This file is covered by 9 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.internal.resolver;
21   
22    import java.lang.reflect.ParameterizedType;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Provider;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.manager.ComponentLookupException;
31    import org.xwiki.component.manager.ComponentManager;
32    import org.xwiki.component.util.DefaultParameterizedType;
33    import org.xwiki.model.EntityType;
34    import org.xwiki.model.reference.EntityReference;
35    import org.xwiki.model.reference.EntityReferenceResolver;
36    import org.xwiki.rendering.listener.reference.ResourceReference;
37   
38    /**
39    * Default entry point to convert a resource reference into an entity reference.
40    *
41    * @version $Id: 5baae237938182827f1a9ec507ee78fdb103c6a1 $
42    * @since 7.4.1
43    */
44    @Component
45    @Singleton
 
46    public class DefaultResourceReferenceEntityReferenceResolver implements EntityReferenceResolver<ResourceReference>
47    {
48    /**
49    * Type instance for EntityReferenceResolver<ResourceReference>.
50    */
51    public static final ParameterizedType TYPE_RESOURCEREFERENCE =
52    new DefaultParameterizedType(null, EntityReferenceResolver.class, ResourceReference.class);
53   
54    @Inject
55    @Named("context")
56    private Provider<ComponentManager> componentManagerProvider;
57   
 
58  21397 toggle @Override
59    public EntityReference resolve(ResourceReference resourceReference, EntityType type, Object... parameters)
60    {
61  21398 if (resourceReference == null) {
62  1 return null;
63    }
64   
65  21396 if (this.componentManagerProvider.get().hasComponent(TYPE_RESOURCEREFERENCE,
66    resourceReference.getType().getScheme())) {
67  21395 EntityReferenceResolver<ResourceReference> resolver;
68  21396 try {
69  21396 resolver = this.componentManagerProvider.get().getInstance(TYPE_RESOURCEREFERENCE,
70    resourceReference.getType().getScheme());
71    } catch (ComponentLookupException e) {
72  0 throw new RuntimeException(
73    String.format("Unknown error when trying to load resolver for reference [%s]", resourceReference),
74    e);
75    }
76   
77  21397 return resolver.resolve(resourceReference, type, parameters);
78    }
79   
80    // Unsupported resource reference type
81  1 return null;
82    }
83    }