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

File AbstractCurrentGetReferenceResolver.java

 

Coverage histogram

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

Code metrics

8
15
1
1
110
54
6
0.4
15
1
6

Classes

Class Line # Actions
AbstractCurrentGetReferenceResolver 44 15 0% 6 1
0.958333395.8%
 

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 com.xpn.xwiki.internal.model.reference;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24   
25    import org.xwiki.model.EntityType;
26    import org.xwiki.model.reference.DocumentReferenceResolver;
27    import org.xwiki.model.reference.EntityReference;
28    import org.xwiki.model.reference.EntityReferenceResolver;
29    import org.xwiki.model.reference.PageReferenceResolver;
30    import org.xwiki.wiki.descriptor.WikiDescriptor;
31    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
32   
33    /**
34    * Specialized version of {@link org.xwiki.model.reference.EntityReferenceResolver} which can be considered a helper
35    * component to resolve document/page reference objects from Entity Reference (when they miss some parent references or
36    * have NULL values).
37    * <p>
38    * The goal is to have the page that correspond the best to the passed reference (if a space then get the corresponding
39    * page, if a wiki then get the wiki home page, if an attachment then get the page where it's located, etc).
40    *
41    * @version $Id: 172d5efbe2aa5cab1b862fa958d47e408c9a85f5 $
42    * @since 10.6RC1
43    */
 
44    public abstract class AbstractCurrentGetReferenceResolver
45    {
46    @Inject
47    @Named("current")
48    private DocumentReferenceResolver<EntityReference> currentDocumentResolver;
49   
50    @Inject
51    @Named("current")
52    private PageReferenceResolver<EntityReference> currentPageResolver;
53   
54    @Inject
55    @Named("current")
56    private EntityReferenceResolver<EntityReference> currentResolver;
57   
58    @Inject
59    private PageReferenceResolver<EntityReference> defaultPageResolver;
60   
61    @Inject
62    private WikiDescriptorManager wikiDescriptorManager;
63   
 
64  78034 toggle protected EntityReference resolveInternal(EntityReference initialReference, Object... parameters)
65    {
66    // WIKI reference
67  78035 if (initialReference.getType() == EntityType.WIKI) {
68    // Use whatever document reference that is configured as wiki homepage.
69  12592 String wikiId = initialReference.getName();
70  12592 try {
71  12592 WikiDescriptor wikiDescriptor = this.wikiDescriptorManager.getById(wikiId);
72  12592 if (wikiDescriptor != null) {
73  12591 return wikiDescriptor.getMainPageReference();
74    }
75    } catch (Exception e) {
76    // It would not be safe to do any assumptions a this level since we risk affecting the wrong
77    // document.
78  0 throw new RuntimeException(
79    String.format("Failed to get wiki descriptor while resolving reference [%s]", initialReference), e);
80    }
81    }
82   
83  65449 EntityReference reference;
84   
85  65445 if (initialReference.getType().ordinal() >= EntityType.PAGE.ordinal()) {
86    // PAGE related reference
87   
88    // Resolve missing lower part as default (to get space home page and wiki home page)
89  23 reference = this.defaultPageResolver.resolve(initialReference, parameters);
90    } else {
91    // WIKI or DOCUMENT related references
92  65422 if (initialReference.getType().ordinal() <= EntityType.SPACE.ordinal()) {
93    // WIKI or SPACE reference
94   
95    // Get the complete initial reference
96  33768 EntityReference currentParentReference =
97    this.currentResolver.resolve(initialReference, initialReference.getType(), parameters);
98   
99    // Resolve missing lower part as default (to get space home page and wiki home page)
100  33768 reference = currentParentReference;
101    } else {
102    // Sub DOCUMENT related references
103   
104  31652 reference = this.currentDocumentResolver.resolve(initialReference, parameters);
105    }
106    }
107   
108  65445 return reference;
109    }
110    }