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

File XWikiSyntaxResourceRenderer.java

 

Coverage histogram

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

Code metrics

16
27
2
1
113
61
11
0.41
13.5
2
5.5

Classes

Class Line # Actions
XWikiSyntaxResourceRenderer 39 27 0% 11 2
0.9555555695.6%
 

Contributing tests

This file is covered by 61 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.renderer.xwiki21.reference;
21   
22    import java.util.Map;
23   
24    import org.apache.commons.lang3.StringUtils;
25    import org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxEscapeWikiPrinter;
26    import org.xwiki.rendering.internal.renderer.xwiki20.XWikiSyntaxListenerChain;
27    import org.xwiki.rendering.listener.reference.AttachmentResourceReference;
28    import org.xwiki.rendering.listener.reference.DocumentResourceReference;
29    import org.xwiki.rendering.listener.reference.ResourceReference;
30    import org.xwiki.rendering.listener.reference.ResourceType;
31    import org.xwiki.rendering.renderer.reference.ResourceReferenceSerializer;
32   
33    /**
34    * Logic to render a XWiki Link into XWiki Syntax 2.1.
35    *
36    * @version $Id: cb58495aca7d8ff0f722a061f036e6583abe77d2 $
37    * @since 2.5M2
38    */
 
39    public class XWikiSyntaxResourceRenderer
40    extends org.xwiki.rendering.internal.renderer.xwiki20.reference.XWikiSyntaxResourceRenderer
41    {
42    /**
43    * Parameter name under which to serialize the query string in XWiki Syntax 2.1.
44    */
45    private static final String QUERY_STRING = "queryString";
46   
47    /**
48    * Parameter name under which to serialize the query string in XWiki Syntax 2.1.
49    */
50    private static final String ANCHOR = "anchor";
51   
52    /**
53    * @param listenerChain the rendering chain
54    * @param referenceSerializer the serializer implementation to use to serialize link references
55    * @since 2.5RC1
56    */
 
57  208 toggle public XWikiSyntaxResourceRenderer(XWikiSyntaxListenerChain listenerChain,
58    ResourceReferenceSerializer referenceSerializer)
59    {
60  208 super(listenerChain, referenceSerializer);
61    }
62   
 
63  41 toggle @Override
64    protected void printParameters(XWikiSyntaxEscapeWikiPrinter printer, ResourceReference reference,
65    Map<String, String> parameters)
66    {
67    // Print the Query String and Anchor as parameters if they're defined and if the link is a link to a document.
68  41 boolean shouldPrintSeparator = true;
69   
70    // The XWiki Syntax 2.1 supports two special reference parameters for document references:
71    // - queryString and anchor.
72    // The XWiki Syntax 2.1 supports one special reference parameters for attachment references:
73    // - queryString.
74  41 ResourceType resourceType = reference.getType();
75  41 if (ResourceType.DOCUMENT.equals(resourceType) || ResourceType.SPACE.equals(resourceType)) {
76    // Print first the query string
77  18 String queryString = reference.getParameter(DocumentResourceReference.QUERY_STRING);
78  18 if (!StringUtils.isEmpty(queryString)) {
79  4 printer.print(PARAMETER_SEPARATOR);
80  4 printer.print(this.PARAMETERS_PRINTER.print(QUERY_STRING, queryString, '~'));
81  4 shouldPrintSeparator = false;
82    }
83    // Then print the anchor
84  18 String anchor = reference.getParameter(DocumentResourceReference.ANCHOR);
85  18 if (!StringUtils.isEmpty(anchor)) {
86  4 if (shouldPrintSeparator) {
87  1 printer.print(PARAMETER_SEPARATOR);
88    } else {
89  3 printer.print(" ");
90    }
91  4 printer.print(this.PARAMETERS_PRINTER.print(ANCHOR, anchor, '~'));
92  4 shouldPrintSeparator = false;
93    }
94  23 } else if (ResourceType.ATTACHMENT.equals(resourceType)) {
95  4 String queryString = reference.getParameter(AttachmentResourceReference.QUERY_STRING);
96  4 if (!StringUtils.isEmpty(queryString)) {
97  2 printer.print(PARAMETER_SEPARATOR);
98  2 printer.print(this.PARAMETERS_PRINTER.print(QUERY_STRING, queryString, '~'));
99  2 shouldPrintSeparator = false;
100    }
101    }
102   
103    // Add all Link parameters but only if there isn't a Link Reference parameter of the same name...
104  41 if (!parameters.isEmpty()) {
105  2 if (shouldPrintSeparator) {
106  0 printer.print(PARAMETER_SEPARATOR);
107    } else {
108  2 printer.print(" ");
109    }
110  2 printer.print(this.PARAMETERS_PRINTER.print(parameters, '~'));
111    }
112    }
113    }