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

File WebjarsResourceReferenceSerializer.java

 

Coverage histogram

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

Code metrics

0
6
1
1
72
32
1
0.17
6
1
1

Classes

Class Line # Actions
WebjarsResourceReferenceSerializer 44 6 0% 1 0
1.0100%
 

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.ArrayList;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.resource.ResourceReferenceSerializer;
31    import org.xwiki.resource.SerializeResourceReferenceException;
32    import org.xwiki.resource.UnsupportedResourceReferenceException;
33    import org.xwiki.url.ExtendedURL;
34    import org.xwiki.url.URLNormalizer;
35   
36    /**
37    * Converts a {@link WebJarsResourceReference} into a relative {@link ExtendedURL} (with the Context Path added).
38    *
39    * @version $Id: 41fd2d443f148b2ffeaa4e655734863c608a6405 $
40    * @since 7.1M1
41    */
42    @Component
43    @Singleton
 
44    public class WebjarsResourceReferenceSerializer
45    implements ResourceReferenceSerializer<WebJarsResourceReference, ExtendedURL>
46    {
47    @Inject
48    @Named("contextpath")
49    private URLNormalizer<ExtendedURL> extendedURLNormalizer;
50   
 
51  25716 toggle @Override
52    public ExtendedURL serialize(WebJarsResourceReference resourceReference)
53    throws SerializeResourceReferenceException, UnsupportedResourceReferenceException
54    {
55  25716 List<String> segments = new ArrayList<>();
56   
57    // Add the resource type segment.
58  25716 segments.add("webjars");
59   
60    // Add the namespace
61  25716 segments.add(resourceReference.getNamespace());
62   
63    // Add the resource path segments
64  25715 segments.addAll(resourceReference.getResourceSegments());
65   
66    // Add all optional parameters
67  25716 ExtendedURL extendedURL = new ExtendedURL(segments, resourceReference.getParameters());
68   
69    // Normalize the URL to add the Context Path since we want a full relative URL to be returned.
70  25716 return this.extendedURLNormalizer.normalize(extendedURL);
71    }
72    }