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

File WikiReferenceParser.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

8
15
5
1
102
36
9
0.6
3
5
1.8

Classes

Class Line # Actions
WikiReferenceParser 32 15 0% 9 4
0.8571428785.7%
 

Contributing tests

This file is covered by 190 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.wikimodel;
21   
22    /**
23    * This class is used as a common parser of references. It is used to transform
24    * references found in wiki documents into corresponding structured objects -
25    * {@link WikiReference}. Methods of this class should be overloaded to parse
26    * correctly wiki-specific references.
27    *
28    * @version $Id: a5ef2bec0f1cb1eae766ffdc7459675f905050a0 $
29    * @since 4.0M1
30    * @see WikiReference
31    */
 
32    public class WikiReferenceParser implements IWikiReferenceParser
33    {
34    /**
35    * Extracts the label from the array of chunks and returns it.
36    *
37    * @param chunks the array of chunks
38    * @return a label extracted from the given array of chunks
39    */
 
40  17 toggle protected String getLabel(String[] chunks)
41    {
42  17 return chunks.length > 1 ? chunks[1].trim() : null;
43    }
44   
45    /**
46    * Extracts the link from the array of chunks and returns it.
47    *
48    * @param chunks the array of chunks
49    * @return a link extracted from the given array of chunks
50    */
 
51  17 toggle protected String getLink(String[] chunks)
52    {
53  17 return chunks[0].trim();
54    }
55   
56    /**
57    * Extracts parameters part of the original reference and returns it as a
58    * WikiParameters.
59    *
60    * @param chunks the array of chunks
61    * @return the parameters
62    */
 
63  20 toggle protected WikiParameters getParameters(String[] chunks)
64    {
65  20 return WikiParameters.newWikiParameters(chunks.length > 2 ? chunks[2]
66    .trim() : null);
67    }
68   
69    /**
70    * @see IWikiReferenceParser#parse(java.lang.String)
71    */
 
72  1467 toggle public WikiReference parse(String str)
73    {
74  1467 if (str == null) {
75  0 return null;
76    }
77   
78  1467 String[] chunks = splitToChunks(str);
79  1467 if (chunks.length == 0) {
80  0 return null;
81    }
82   
83  1467 String link = getLink(chunks);
84  1467 String label = getLabel(chunks);
85  1467 WikiParameters parameters = getParameters(chunks);
86   
87  1467 return new WikiReference(link, label, parameters);
88    }
89   
90    /**
91    * Returns the given string split to individual segments
92    *
93    * @param str the string to split
94    * @return the given string split to individual segments
95    */
 
96  20 toggle protected String[] splitToChunks(String str)
97    {
98  20 String delimiter = "[|>]";
99  20 String[] chunks = str.split(delimiter);
100  20 return chunks;
101    }
102    }