1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.parser.reference

File AbstractUntypedReferenceParser.java

 

Coverage histogram

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

Code metrics

4
8
1
1
74
28
3
0.38
8
1
3

Classes

Class Line # Actions
AbstractUntypedReferenceParser 37 8 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 140 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.rendering.internal.parser.reference;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24   
25    import org.xwiki.rendering.listener.reference.ResourceReference;
26    import org.xwiki.rendering.listener.reference.ResourceType;
27    import org.xwiki.rendering.parser.ResourceReferenceTypeParser;
28   
29    /**
30    * Considers all passed references to be untyped and tries to guess the type by first looking for an URL. If an URL is
31    * not found, then a wiki resource (based on the implementation) will be resolved.
32    *
33    * @version $Id: 132639387294ff73f353a6b6d3812eb59d3e5069 $
34    * @since 7.4.1
35    * @since 8.0M1
36    */
 
37    public abstract class AbstractUntypedReferenceParser extends AbstractResourceReferenceParser
38    {
39    /**
40    * Parser to parse link references pointing to URLs.
41    */
42    @Inject
43    @Named("url")
44    private ResourceReferenceTypeParser urlResourceReferenceTypeParser;
45   
 
46  840 toggle @Override
47    public ResourceReference parse(String rawReference)
48    {
49  840 ResourceReference reference;
50   
51    // If we're not in wiki mode then references are considered URLs.
52  840 if (!isInWikiMode()) {
53  34 reference = new ResourceReference(rawReference, ResourceType.URL);
54    } else {
55    // Try to guess the link type. It can be either:
56    // - a URL (specified without the "url" type)
57    // - a reference to a wiki resource (document, space, attachment, etc, specified without the type prefix).
58  806 reference = this.urlResourceReferenceTypeParser.parse(rawReference);
59  806 if (reference == null) {
60  777 reference = getWikiResource(rawReference);
61    }
62    }
63  840 reference.setTyped(false);
64   
65  840 return reference;
66    }
67   
68    /**
69    * @param rawReference the untyped reference string
70    * @return the resource reference that points to a wiki resource
71    */
72    protected abstract ResourceReference getWikiResource(String rawReference);
73   
74    }