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

File WebJarsResourceReferenceResolver.java

 

Coverage histogram

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

Code metrics

2
9
1
1
70
34
2
0.22
9
1
2

Classes

Class Line # Actions
WebJarsResourceReferenceResolver 46 9 0% 2 2
0.833333383.3%
 

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.webjars.internal;
21   
22    import java.util.List;
23    import java.util.Map;
24   
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.resource.CreateResourceReferenceException;
30    import org.xwiki.resource.ResourceType;
31    import org.xwiki.resource.UnsupportedResourceReferenceException;
32    import org.xwiki.url.ExtendedURL;
33    import org.xwiki.url.internal.AbstractResourceReferenceResolver;
34   
35    /**
36    * Transform WebJars URL into a typed Resource Reference. The URL format handled is
37    * {@code http://server/context/webjars/path/to/resource[?version=<version>][&evaluate=true|false]}.
38    * For example: {@code http://localhost:8080/xwiki/webjars/angularjs/1.1.5/angular.js}.
39    *
40    * @version $Id: 688137a048679dc95927a4b8d7f921883b61cfec $
41    * @since 7.1M1
42    */
43    @Component
44    @Named("webjars")
45    @Singleton
 
46    public class WebJarsResourceReferenceResolver extends AbstractResourceReferenceResolver
47    {
 
48  1716 toggle @Override
49    public WebJarsResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType,
50    Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException
51    {
52  1716 WebJarsResourceReference reference;
53  1716 List<String> segments = extendedURL.getSegments();
54   
55  1716 if (segments.size() > 1) {
56    // The first segment is the namespace
57  1715 String namespace = segments.get(0);
58   
59    // The other segments point to the resource path
60  1715 List<String> resourceSegments = segments.subList(1, segments.size());
61   
62  1710 reference = new WebJarsResourceReference(namespace, resourceSegments);
63  1714 copyParameters(extendedURL, reference);
64    } else {
65  0 throw new CreateResourceReferenceException(String.format("Invalid WebJars URL format [%s]",
66    extendedURL.toString()));
67    }
68  1711 return reference;
69    }
70    }