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

File VfsResourceReferenceSerializer.java

 

Coverage histogram

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

Code metrics

0
8
2
1
86
46
3
0.38
4
2
1.5

Classes

Class Line # Actions
VfsResourceReferenceSerializer 48 8 0% 3 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.lang.reflect.Type;
23    import java.net.URI;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28    import javax.inject.Singleton;
29   
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.component.manager.ComponentLookupException;
32    import org.xwiki.component.manager.ComponentManager;
33    import org.xwiki.component.util.DefaultParameterizedType;
34    import org.xwiki.resource.ResourceReferenceSerializer;
35    import org.xwiki.resource.SerializeResourceReferenceException;
36    import org.xwiki.resource.UnsupportedResourceReferenceException;
37    import org.xwiki.url.ExtendedURL;
38    import org.xwiki.vfs.VfsResourceReference;
39   
40    /**
41    * Converts a {@link VfsResourceReference} into a relative {@link ExtendedURL} (with the Context Path added).
42    *
43    * @version $Id: c90ca7ff5b3054eae1d635a6f6cf7cc5842a81a1 $
44    * @since 7.4M2
45    */
46    @Component
47    @Singleton
 
48    public class VfsResourceReferenceSerializer extends AbstractVfsResourceReferenceSerializer
49    {
50    private static final Type TYPE = new DefaultParameterizedType(null,
51    ResourceReferenceSerializer.class, VfsResourceReference.class, ExtendedURL.class);
52   
53    @Inject
54    @Named("context")
55    private Provider<ComponentManager> componentManagerProvider;
56   
 
57  4 toggle @Override
58    public ExtendedURL serialize(VfsResourceReference resourceReference)
59    throws SerializeResourceReferenceException, UnsupportedResourceReferenceException
60    {
61  4 ExtendedURL extendedURL;
62   
63    // We need to ensure that the URI contains absolute references since the VFS handler that will handle
64    // the generated URL won't have any base reference to resolve any relative refeence.
65    //
66    // Look for a scheme-specific serializer to convert from a relative URI into an absolute URI and if not found
67    // then don't perform any transformation of the URI.
68  4 URI uri = resourceReference.getURI();
69  4 try {
70  4 ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> schemeSpecificSerializer =
71    this.componentManagerProvider.get().getInstance(TYPE, uri.getScheme());
72  3 extendedURL = schemeSpecificSerializer.serialize(resourceReference);
73    } catch (ComponentLookupException e) {
74  1 extendedURL = super.serialize(resourceReference);
75    }
76   
77  4 return extendedURL;
78    }
79   
 
80  1 toggle @Override
81    protected URI makeAbsolute(URI uri)
82    {
83    // Don't make any transformation by default
84  1 return uri;
85    }
86    }