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

File DefaultVfsPathFactory.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

0
6
1
1
77
39
2
0.33
6
1
2

Classes

Class Line # Actions
DefaultVfsPathFactory 52 6 0% 2 7
0.00%
 

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    import java.nio.file.Path;
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.properties.converter.Converter;
31    import org.xwiki.resource.ResourceReferenceSerializer;
32    import org.xwiki.vfs.VfsException;
33    import org.xwiki.vfs.VfsPathFactory;
34    import org.xwiki.vfs.VfsPermissionChecker;
35    import org.xwiki.vfs.VfsResourceReference;
36   
37    import net.java.truevfs.access.TPath;
38   
39    /**
40    * Generate a {@link Path} instance but also does 2 things:
41    * <ul>
42    * <li>Transform the URI into a hierarchical URI (e.g. from {@code attach:Sandbox.WebHome@my.zip/some/path} to
43    * {@code attach://Sandbox.WebHome@my.zip/some/path}</li>
44    * <li>Verify that the current user has the permissions to access that URI</li>
45    * </ul>
46    *
47    * @version $Id: 92b8b0599cad7f1521a1737b7073f16917a29d2e $
48    * @since 8.4RC1
49    */
50    @Component
51    @Singleton
 
52    public class DefaultVfsPathFactory implements VfsPathFactory
53    {
54    @Inject
55    private VfsPermissionChecker permissionChecker;
56   
57    @Inject
58    private Converter<VfsResourceReference> vfsResourceReferenceConverter;
59   
60    @Inject
61    @Named("truevfs")
62    private ResourceReferenceSerializer<VfsResourceReference, URI> trueVfsResourceReferenceSerializer;
63   
 
64  0 toggle @Override
65    public Path create(URI uri) throws VfsException
66    {
67  0 try {
68  0 VfsResourceReference reference =
69    this.vfsResourceReferenceConverter.convert(VfsResourceReference.class, uri.toString());
70  0 this.permissionChecker.checkPermission(reference);
71  0 URI trueVFSURI = this.trueVfsResourceReferenceSerializer.serialize(reference);
72  0 return new TPath(trueVFSURI);
73    } catch (Exception e) {
74  0 throw new VfsException(String.format("Failed to create Path instance for [%s]", uri.toString()), e);
75    }
76    }
77    }