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

File URIVfsResourceReferenceSerializer.java

 

Coverage histogram

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

Code metrics

0
6
1
1
73
39
2
0.33
6
1
2

Classes

Class Line # Actions
URIVfsResourceReferenceSerializer 48 6 0% 2 1
0.8571428785.7%
 

Contributing tests

No tests hitting this source file were found.

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   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Provider;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.manager.ComponentLookupException;
31    import org.xwiki.component.manager.ComponentManager;
32    import org.xwiki.component.util.DefaultParameterizedType;
33    import org.xwiki.resource.ResourceReferenceSerializer;
34    import org.xwiki.resource.SerializeResourceReferenceException;
35    import org.xwiki.resource.UnsupportedResourceReferenceException;
36    import org.xwiki.vfs.VfsResourceReference;
37   
38    /**
39    * Serializer which transforms a {@link VfsResourceReference} into a {@link URI} by looking for a URI scheme-specific
40    * Serializer and if none is found then returning the URI from the {@link VfsResourceReference} as is.
41    *
42    * @version $Id: d021db85d756b822da6f670df718600aa83f90b1 $
43    * @since 7.4M2
44    */
45    @Component
46    @Named("truevfs")
47    @Singleton
 
48    public class URIVfsResourceReferenceSerializer implements ResourceReferenceSerializer<VfsResourceReference, URI>
49    {
50    @Inject
51    @Named("context")
52    private Provider<ComponentManager> componentManagerProvider;
53   
 
54  5 toggle @Override
55    public URI serialize(VfsResourceReference reference)
56    throws SerializeResourceReferenceException, UnsupportedResourceReferenceException
57    {
58  5 URI resultURI;
59   
60  5 try {
61  5 ResourceReferenceSerializer<VfsResourceReference, URI> serializer =
62    this.componentManagerProvider.get().getInstance(new DefaultParameterizedType(null,
63    ResourceReferenceSerializer.class, VfsResourceReference.class, URI.class),
64    String.format("truevfs/%s", reference.getURI().getScheme()));
65  5 resultURI = serializer.serialize(reference);
66    } catch (ComponentLookupException e) {
67    // No serializer exist, we just don't perform any conversion!
68  0 resultURI = reference.toURI();
69    }
70   
71  5 return resultURI;
72    }
73    }