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

File VfsResourceReferenceResolver.java

 

Coverage histogram

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

Code metrics

0
10
1
1
85
44
2
0.2
10
1
2

Classes

Class Line # Actions
VfsResourceReferenceResolver 56 10 0% 2 1
0.9090909490.9%
 

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.vfs.internal;
21   
22    import java.net.URI;
23    import java.net.URISyntaxException;
24    import java.util.ArrayList;
25    import java.util.List;
26    import java.util.Map;
27   
28    import javax.inject.Inject;
29    import javax.inject.Named;
30    import javax.inject.Singleton;
31   
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.model.reference.AttachmentReferenceResolver;
34    import org.xwiki.resource.CreateResourceReferenceException;
35    import org.xwiki.resource.ResourceType;
36    import org.xwiki.resource.UnsupportedResourceReferenceException;
37    import org.xwiki.url.ExtendedURL;
38    import org.xwiki.url.internal.AbstractResourceReferenceResolver;
39    import org.xwiki.vfs.VfsResourceReference;
40   
41    /**
42    * Transform VFS URLs into a typed Resource Reference. The URL format handled is {@code http://server/<servlet
43    * context>/vfs/<vfs reference as URI>/path/inside/zip}. For example:
44    * <ul>
45    * <li>{@code http://localhost:8080/xwiki/vfs/encoded(attach:space.page@attachment)/some/path/file.txt}.</li>
46    * <li>{@code http://localhost:8080/xwiki/vfs/encoded(http://server/path/to/zip)/some/path/file.txt}.</li>
47    * <li>{@code http://localhost:8080/xwiki/vfs/encoded(file://server/path/to/zip)/some/path/file.txt}.</li>
48    * </ul>
49    *
50    * @version $Id: f9f856657db2222bbc40aeab0c8df4fdd4c22bcd $
51    * @since 7.4M2
52    */
53    @Component
54    @Named("vfs")
55    @Singleton
 
56    public class VfsResourceReferenceResolver extends AbstractResourceReferenceResolver
57    {
58    @Inject
59    @Named("current")
60    private AttachmentReferenceResolver<String> referenceResolver;
61   
 
62  2 toggle @Override
63    public VfsResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType,
64    Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException
65    {
66  2 List<String> segments = extendedURL.getSegments();
67   
68    // First segment is the url-encoded VFS reference, defined as URI
69  2 URI vfsUri;
70  2 try {
71  2 vfsUri = new URI(segments.get(0));
72    } catch (URISyntaxException e) {
73  0 throw new CreateResourceReferenceException(
74    String.format("Invalid VFS URI [%s] for URL [%s]", segments.get(0), extendedURL));
75    }
76   
77    // Other segments are the path to the archive resource
78  2 List<String> vfsPathSegments = new ArrayList<>(segments);
79  2 vfsPathSegments.remove(0);
80   
81  2 VfsResourceReference vfsReference = new VfsResourceReference(vfsUri, vfsPathSegments);
82  2 copyParameters(extendedURL, vfsReference);
83  2 return vfsReference;
84    }
85    }