Class | Line # | Actions | |||||
---|---|---|---|---|---|---|---|
ConfluenceWikiReferenceParser | 31 | 17 | 0% | 4 | 0 |
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.confluence; | |
21 | ||
22 | import org.xwiki.rendering.wikimodel.IWikiReferenceParser; | |
23 | import org.xwiki.rendering.wikimodel.WikiParameters; | |
24 | import org.xwiki.rendering.wikimodel.WikiReference; | |
25 | ||
26 | /** | |
27 | * @version $Id: 9026c6142d736be1e88b30b28e6c880321c617a3 $ | |
28 | * @since 4.0M1 | |
29 | * @see WikiReference | |
30 | */ | |
31 | public class ConfluenceWikiReferenceParser implements IWikiReferenceParser | |
32 | { | |
33 | 41 | public WikiReference parse(String str) |
34 | { | |
35 | 41 | str = str.trim(); |
36 | 41 | String[] array = str.split("[|]"); |
37 | 41 | String link; |
38 | 41 | String label; |
39 | 41 | String tip; |
40 | 41 | if (array.length == 1) { |
41 | 24 | link = str; |
42 | 24 | label = null; |
43 | 24 | tip = null; |
44 | } else { | |
45 | 17 | label = array[0].trim(); |
46 | 17 | link = array[1].trim(); |
47 | 17 | tip = (array.length > 2) ? array[2].trim() : null; |
48 | } | |
49 | 41 | WikiParameters params = WikiParameters.EMPTY; |
50 | 41 | if (tip != null) { |
51 | 8 | params = params.addParameter("title", tip); |
52 | } | |
53 | 41 | WikiReference ref = new WikiReference(link, label, params); |
54 | 41 | return ref; |
55 | } | |
56 | } |