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

File PathWikiReferenceExtractor.java

 

Coverage histogram

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

Code metrics

4
10
2
1
70
34
4
0.4
5
2
2

Classes

Class Line # Actions
PathWikiReferenceExtractor 40 10 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 8 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 org.xwiki.url.internal.standard;
21   
22    import javax.inject.Named;
23    import javax.inject.Singleton;
24   
25    import org.apache.commons.lang3.StringUtils;
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.model.reference.WikiReference;
28    import org.xwiki.url.ExtendedURL;
29    import org.xwiki.wiki.descriptor.WikiDescriptor;
30   
31    /**
32    * Handles path-based multiwiki configurations when extracting the wiki reference from the passed URL.
33    *
34    * @version $Id: 513750f7853cd0bf1add1b4e05ebe9bd121b4ef0 $
35    * @since 6.3M1
36    */
37    @Component
38    @Named("path")
39    @Singleton
 
40    public class PathWikiReferenceExtractor extends AbstractWikiReferenceExtractor
41    {
 
42  137 toggle @Override
43    public WikiReference extract(ExtendedURL url)
44    {
45    // The first segment is the name of the wiki.
46  137 String wikiId = resolvePathBasedWikiReference(url.getSegments().get(0));
47   
48  137 if (StringUtils.isEmpty(wikiId)) {
49  1 wikiId = getMainWikiId();
50    }
51   
52  136 return new WikiReference(wikiId.toLowerCase());
53    }
54   
 
55  134 toggle private String resolvePathBasedWikiReference(String alias)
56    {
57  136 String wikiId;
58   
59    // Look for a Wiki Descriptor
60  137 WikiDescriptor wikiDescriptor = getWikiDescriptorByAlias(alias);
61  134 if (wikiDescriptor != null) {
62    // Get the wiki id from the wiki descriptor
63  66 wikiId = wikiDescriptor.getId();
64    } else {
65  68 wikiId = normalizeWikiIdForNonExistentWikiDescriptor(alias);
66    }
67   
68  138 return wikiId;
69    }
70    }