1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.model.reference

File DocumentReferenceConverter.java

 

Coverage histogram

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

Code metrics

6
10
2
1
85
47
5
0.5
5
2
2.5

Classes

Class Line # Actions
DocumentReferenceConverter 44 10 0% 5 2
0.888888988.9%
 

Contributing tests

This file is covered by 4 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 com.xpn.xwiki.internal.model.reference;
21   
22    import java.lang.reflect.Type;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.DocumentReferenceResolver;
31    import org.xwiki.model.reference.EntityReference;
32    import org.xwiki.model.reference.EntityReferenceSerializer;
33    import org.xwiki.properties.converter.AbstractConverter;
34   
35    /**
36    * Converter that converts a value into a {@link DocumentReference} object. Relative references are resolved using
37    * "current" {@link DocumentReferenceResolver}.
38    *
39    * @version $Id: 68f10c07eace91f262386a651f0ca527b23c323a $
40    * @since 5.2RC1
41    */
42    @Component
43    @Singleton
 
44    public class DocumentReferenceConverter extends AbstractConverter<DocumentReference>
45    {
46    @Inject
47    @Named("current")
48    private DocumentReferenceResolver<String> stringResolver;
49   
50    @Inject
51    @Named("currentgetdocument")
52    private DocumentReferenceResolver<EntityReference> referenceResolver;
53   
54    @Inject
55    @Named("compact")
56    private EntityReferenceSerializer<String> serialier;
57   
 
58  99 toggle @Override
59    protected DocumentReference convertToType(Type type, Object value)
60    {
61  99 if (value == null) {
62  1 return null;
63    }
64   
65  98 DocumentReference reference;
66   
67  98 if (value instanceof EntityReference) {
68  3 reference = this.referenceResolver.resolve((EntityReference) value);
69    } else {
70  95 reference = this.stringResolver.resolve(value.toString());
71    }
72   
73  98 return reference;
74    }
75   
 
76  24855 toggle @Override
77    protected String convertToString(DocumentReference value)
78    {
79  24855 if (value == null) {
80  0 return null;
81    }
82   
83  24855 return this.serialier.serialize(value);
84    }
85    }