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

File ReferenceHandler.java

 

Coverage histogram

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

Code metrics

12
21
3
1
97
57
15
0.71
7
3
5

Classes

Class Line # Actions
ReferenceHandler 30 21 0% 15 1
0.972222297.2%
 

Contributing tests

This file is covered by 147 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 utility class splits references to individual parts (hyper-link and
24    * label) and delegates to separate methods handling of images, normal
25    * references and downloads.
26    *
27    * @version $Id: 679b712d2f634e9fd86542883e0214add1fba68d $
28    * @since 4.0M1
29    */
 
30    public abstract class ReferenceHandler
31    {
32    public static final String PREFIX_DOWNLOAD = "^(?:d|F)ownload:.*";
33   
34    public static final int PREFIX_DOWNLOAD_LEN = "download:".length();
35   
36    public static final String PREFIX_IMAGE = "^(?:i|I)mage:.*";
37   
38    public static final int PREFIX_IMAGE_LEN = "image:".length();
39   
40    private boolean supportImage;
41   
42    private boolean supportDownload;
43   
 
44  1356 toggle protected ReferenceHandler(boolean supportImage, boolean supportDownload)
45    {
46  1356 this.supportImage = supportImage;
47  1356 this.supportDownload = supportDownload;
48    }
49   
 
50  129 toggle public void handle(WikiReference ref)
51    {
52  129 String link = ref.getLink();
53  129 String label = ref.getLabel();
54  129 WikiParameters params = ref.getParameters();
55   
56  129 if (params.getSize() == 0 && label == null) {
57  95 params = params.addParameter("class", "wikimodel-freestanding");
58    }
59   
60  129 if (this.supportImage && link.matches(PREFIX_IMAGE)) {
61  3 link = link.substring(PREFIX_IMAGE_LEN);
62  3 if (label == null || "".equals(label)) {
63  1 label = link;
64    }
65  3 handleImage(link, label, params);
66  126 } else if (this.supportDownload && link.matches(PREFIX_DOWNLOAD)) {
67  3 link = link.substring(PREFIX_DOWNLOAD_LEN);
68  3 if (label == null || "".equals(label)) {
69  3 label = link;
70    }
71  3 handleDownload(link, label, params);
72    } else {
73  123 if (label == null || "".equals(label)) {
74  91 label = link;
75    }
76  123 handleReference(link, label, params);
77    }
78    }
79   
 
80  3 toggle protected void handleDownload(
81    String ref,
82    String label,
83    WikiParameters params)
84    {
85  3 handleReference(ref, label, params);
86    }
87   
88    protected abstract void handleImage(
89    String ref,
90    String label,
91    WikiParameters params);
92   
93    protected abstract void handleReference(
94    String ref,
95    String label,
96    WikiParameters params);
97    }