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

File AbstractVfsResourceReferenceSerializer.java

 

Coverage histogram

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

Code metrics

0
6
1
1
79
31
1
0.17
6
1
1

Classes

Class Line # Actions
AbstractVfsResourceReferenceSerializer 43 6 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 2 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.vfs.internal;
21   
22    import java.net.URI;
23    import java.util.ArrayList;
24    import java.util.List;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28   
29    import org.xwiki.resource.ResourceReferenceSerializer;
30    import org.xwiki.resource.SerializeResourceReferenceException;
31    import org.xwiki.resource.UnsupportedResourceReferenceException;
32    import org.xwiki.url.ExtendedURL;
33    import org.xwiki.url.URLNormalizer;
34    import org.xwiki.vfs.VfsResourceReference;
35   
36    /**
37    * Helper to implemet scheme-specific serializers to Converts a {@link VfsResourceReference} into a relative
38    * {@link ExtendedURL} (with the Context Path added).
39    *
40    * @version $Id: da0382462a7a581e0e0a8dd9cd19e216ccabffe6 $
41    * @since 7.4M2
42    */
 
43    public abstract class AbstractVfsResourceReferenceSerializer
44    implements ResourceReferenceSerializer<VfsResourceReference, ExtendedURL>
45    {
46    @Inject
47    @Named("contextpath")
48    private URLNormalizer<ExtendedURL> extendedURLNormalizer;
49   
 
50  4 toggle @Override
51    public ExtendedURL serialize(VfsResourceReference resourceReference)
52    throws SerializeResourceReferenceException, UnsupportedResourceReferenceException
53    {
54  4 List<String> segments = new ArrayList<>();
55   
56    // Add the resource type segment.
57  4 segments.add("vfs");
58   
59    // Add the VFS URI part
60  4 segments.add(makeAbsolute(resourceReference.getURI()).toString());
61   
62    // Add the VFS path
63  4 segments.addAll(resourceReference.getPathSegments());
64   
65    // Add all optional parameters
66  4 ExtendedURL extendedURL = new ExtendedURL(segments, resourceReference.getParameters());
67   
68    // Normalize the URL to add the Context Path since we want a full relative URL to be returned.
69  4 return this.extendedURLNormalizer.normalize(extendedURL);
70    }
71   
72    /**
73    * Converts the passed URI into a URI containing an absolute reference to the VFS.
74    *
75    * @param uri the URI containing a relative reference to the VFS
76    * @return a URI with an absolute reference to the VFS
77    */
78    protected abstract URI makeAbsolute(URI uri);
79    }