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

File VfsResourceReferenceConverter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

2
7
1
1
67
28
3
0.43
7
1
3

Classes

Class Line # Actions
VfsResourceReferenceConverter 47 7 0% 3 3
0.770%
 

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.script;
21   
22    import java.lang.reflect.Type;
23    import java.net.URI;
24   
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.properties.converter.AbstractConverter;
29    import org.xwiki.properties.converter.ConversionException;
30    import org.xwiki.vfs.VfsResourceReference;
31   
32    /**
33    * Converts {@link String} into {@link VfsResourceReference} objects.
34    * <p>
35    * Example:
36    * <ul>
37    * <li>Input: {@code attach:Sandbox.WebHome@my.zip/some/path}</li>
38    * <li>Output: uri = {@code attach:Sandbox.WebHome@my.zip}, path = {@code some/path}</li>
39    * </ul>
40    * Note that if the input contains "/" characters they need to be URL-encoded.
41    *
42    * @version $Id: 51d3eab85b4cc8e07b49274b32c7a5fc73ad2907 $
43    * @since 7.4M2
44    */
45    @Component
46    @Singleton
 
47    public class VfsResourceReferenceConverter extends AbstractConverter<VfsResourceReference>
48    {
 
49  4 toggle @Override
50    protected VfsResourceReference convertToType(Type targetType, Object value)
51    {
52  4 if (value == null) {
53  0 return null;
54    }
55   
56  4 VfsResourceReference reference;
57   
58  4 try {
59  4 reference = new VfsResourceReference(new URI(value.toString()));
60    } catch (Exception e) {
61  0 throw new ConversionException(
62    String.format("Failed to convert [%s] to a VFS Resource Reference", value), e);
63    }
64   
65  4 return reference;
66    }
67    }