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

File DefaultResourceReferenceResolver.java

 

Coverage histogram

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

Code metrics

2
9
1
1
95
49
3
0.33
9
1
3

Classes

Class Line # Actions
DefaultResourceReferenceResolver 50 9 0% 3 3
0.7575%
 

Contributing tests

This file is covered by 1 test. .

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.url.internal;
21   
22    import java.util.Map;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.manager.ComponentLookupException;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.component.util.DefaultParameterizedType;
32    import org.xwiki.resource.CreateResourceReferenceException;
33    import org.xwiki.resource.ResourceReference;
34    import org.xwiki.resource.ResourceReferenceResolver;
35    import org.xwiki.resource.ResourceType;
36    import org.xwiki.resource.UnsupportedResourceReferenceException;
37    import org.xwiki.url.ExtendedURL;
38    import org.xwiki.url.URLConfiguration;
39   
40    /**
41    * Delegates the work to the Resource Reference Resolver matching the URL Scheme defined in the XWiki Configuration
42    * (see {@link org.xwiki.url.URLConfiguration#getURLFormatId()}. If none is found, defaults to the Generic
43    * Resource Reference Resolver.
44    *
45    * @version $Id: b598e0c53c2a05eed6e2ccad579823602590078b $
46    * @since 6.1M2
47    */
48    @Component
49    @Singleton
 
50    public class DefaultResourceReferenceResolver implements ResourceReferenceResolver<ExtendedURL>
51    {
52    /**
53    * Used to get the hint of the {@link org.xwiki.resource.ResourceReferenceResolver} to use.
54    */
55    @Inject
56    private URLConfiguration configuration;
57   
58    @Inject
59    @Named("generic")
60    private ResourceReferenceResolver<ExtendedURL> genericResourceReferenceResolver;
61   
62    /**
63    * Used to lookup the correct {@link org.xwiki.resource.ResourceReferenceResolver} component.
64    */
65    @Inject
66    @Named("context")
67    private ComponentManager componentManager;
68   
 
69  22817 toggle @Override
70    public ResourceReference resolve(ExtendedURL extendedURL, ResourceType type, Map<String, Object> parameters)
71    throws CreateResourceReferenceException, UnsupportedResourceReferenceException
72    {
73  22818 ResourceReferenceResolver resolver;
74   
75    // Step 1: Look for a URL-scheme-specific Resolver (a general one that is independent of the passed
76    // Resource Type). This allows URL-scheme implementation to completely override handling of any
77    // Resource Type if they wish.
78  22816 DefaultParameterizedType parameterizedType = new DefaultParameterizedType(null,
79    ResourceReferenceResolver.class, ExtendedURL.class);
80  22820 String hint = this.configuration.getURLFormatId();
81  22823 if (this.componentManager.hasComponent(parameterizedType, hint)) {
82  22822 try {
83  22823 resolver = this.componentManager.getInstance(parameterizedType, hint);
84    } catch (ComponentLookupException e) {
85  0 throw new CreateResourceReferenceException(
86    String.format("Failed to create Resource Reference for [%s].", extendedURL.getWrappedURL()), e);
87    }
88    } else {
89    // Step 2: If not found, use the Generic Resolver, which tries to find a Resolver registered for the
90    // specific Resource Type.
91  0 resolver = this.genericResourceReferenceResolver;
92    }
93  22822 return resolver.resolve(extendedURL, type, parameters);
94    }
95    }