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

File XWiki20LinkReferenceParser.java

 

Coverage histogram

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

Code metrics

2
5
1
1
101
28
2
0.4
5
1
2

Classes

Class Line # Actions
XWiki20LinkReferenceParser 68 5 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 69 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.xwiki20;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.rendering.internal.parser.reference.GenericLinkReferenceParser;
30   
31    /**
32    * Parses the content of XWiki 2.0 resource references. The supported generic format is as follows:
33    * <code>(link)(@interWikiAlias)?</code>, where:
34    * <ul>
35    * <li><code>link</code>: The full link reference using the following syntax:
36    * <code>(reference)(#anchor)?(?queryString)?</code>, where:
37    * <ul>
38    * <li><code>reference</code>: The link reference. This can be either a URI in the form <code>protocol:path</code>
39    * (example: "http://xwiki.org", "mailto:john@smith.com) or a wiki page name (example: "wiki:Space.WebHome"). Note that
40    * in the case of a wiki page name the character "\" is used as the escape character (for example if you wish to have
41    * "#" or "?" in your page name you'll need to write "\#" and "\?").</li>
42    * <li><code>anchor</code>: An optional anchor name pointing to an anchor defined in the referenced link. Note that in
43    * XWiki anchors are automatically created for titles. Example: "TableOfContentAnchor".</li>
44    * <li><code>queryString</code>: An optional query string for specifying parameters that will be used in the rendered
45    * URL. Example: "mydata1=5&mydata2=Hello".</li>
46    * </ul>
47    * The <code>link</code> element is mandatory.</li>
48    * <li><code>interWikiAlias</code>: An optional <a href="http://en.wikipedia.org/wiki/InterWiki">Inter Wiki</a> alias as
49    * defined in the InterWiki Map. Example: "wikipedia"</li>
50    * </ul>
51    * Examples of valid wiki links:
52    * <ul>
53    * <li>Hello World</li>
54    * <li>http://myserver.com/HelloWorld</li>
55    * <li>HelloWorld#Anchor</li>
56    * <li>Hello World@Wikipedia</li>
57    * <li>mywiki:HelloWorld</li>
58    * <li>Hello World?param1=1&param2=2</li>
59    * </ul>
60    * Note that allowed URIs are URLs of the form {@code http://}, {@code mailto:}, {@code image:} and {@code attach:}.
61    *
62    * @version $Id: ce5785d4732141bc23f5ad555dfd3fed26a187b9 $
63    * @since 2.5RC1
64    */
65    @Component
66    @Named("xwiki/2.0/link")
67    @Singleton
 
68    public class XWiki20LinkReferenceParser extends GenericLinkReferenceParser
69    {
70    /**
71    * Mailto URI scheme.
72    */
73    public static final String MAILTO_SCHEME = "mailto";
74   
75    /**
76    * Attachment URI scheme.
77    */
78    public static final String ATTACH_SCHEME = "attach";
79   
80    /**
81    * The list of recognized URL prefixes when in wiki mode.
82    */
83    public static final List<String> URI_PREFIXES = Arrays.asList(MAILTO_SCHEME, ATTACH_SCHEME);
84   
85    /**
86    * The list of recognized URL prefixes when in non wiki mode.
87    */
88    public static final List<String> URI_PREFIXES_NON_WIKI_MODE = Arrays.asList(MAILTO_SCHEME);
89   
 
90  141 toggle @Override
91    protected List<String> getAllowedURIPrefixes()
92    {
93  141 List<String> allowedURIs;
94  141 if (!isInWikiMode()) {
95  34 allowedURIs = URI_PREFIXES_NON_WIKI_MODE;
96    } else {
97  107 allowedURIs = URI_PREFIXES;
98    }
99  141 return allowedURIs;
100    }
101    }