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

File XClassRelativeStringEntityReferenceResolver.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
9
2
1
78
37
6
0.67
4.5
2
3

Classes

Class Line # Actions
XClassRelativeStringEntityReferenceResolver 46 9 0% 6 1
0.941176594.1%
 

Contributing tests

This file is covered by 16 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 javax.inject.Named;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.model.EntityType;
27    import org.xwiki.model.internal.reference.AbstractStringEntityReferenceResolver;
28    import org.xwiki.model.reference.EntityReference;
29   
30    /**
31    * Resolve a String representing an Entity Reference into an {@link org.xwiki.model.reference.EntityReference} object.
32    * The behavior is the one defined in {@link org.xwiki.model.internal.reference.RelativeStringEntityReferenceResolver}
33    * except that it uses a space with the "XWiki" value if no space is specified and that an optional parameter can be
34    * passed to specify what page name to use if no page is specified in the passed string representation.
35    *
36    * @version $Id: cbef9b3ea42762d743bee6a5af0a910e76f149ac $
37    * @since 2.2.3
38    * @deprecated this is only a backward compatibility resolver since the old behavior for class reference was to use the
39    * "XWiki" space when no space was specified. Since we now pass absolute references there's no need to
40    * resolve anything...
41    */
42    @Deprecated
43    @Component
44    @Named("xclass")
45    @Singleton
 
46    public class XClassRelativeStringEntityReferenceResolver extends AbstractStringEntityReferenceResolver
47    {
 
48  171514 toggle @Override
49    protected EntityReference getDefaultReference(EntityType type, Object... parameters)
50    {
51  171511 if (type == EntityType.DOCUMENT) {
52    // This means that the user has not passed an optional page reference and we don't have a fallback, we
53    // raise an error.
54  1 throw new IllegalArgumentException("A Reference to a page must be passed as a parameter when the string "
55    + "to resolve doesn't specify a page");
56    }
57   
58  171506 return null;
59    }
60   
 
61  171552 toggle @Override
62    public EntityReference resolve(String entityReferenceRepresentation, EntityType type, Object... parameters)
63    {
64    // We allow to pass a page reference in parameter. If the passed representation doesn't contain a page then the
65    // page from the parameter will be used.
66  171559 EntityReference explicitReference = new EntityReference("XWiki", EntityType.SPACE);
67  171554 if (parameters.length > 0 && (parameters[0] instanceof EntityReference)) {
68  94297 EntityReference extractedPageReference =
69    ((EntityReference) parameters[0]).extractReference(EntityType.DOCUMENT);
70  94294 if (extractedPageReference != null) {
71  94295 explicitReference =
72    new EntityReference(extractedPageReference.getName(), EntityType.DOCUMENT, explicitReference);
73    }
74    }
75   
76  171550 return super.resolve(entityReferenceRepresentation, type, explicitReference);
77    }
78    }