1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.parser.xwiki21

File XWiki21XWikiGeneratorListener.java

 

Coverage histogram

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

Code metrics

14
19
3
1
112
58
12
0.63
6.33
3
4

Classes

Class Line # Actions
XWiki21XWikiGeneratorListener 42 19 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 122 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.xwiki21;
21   
22    import java.util.Map;
23   
24    import org.xwiki.rendering.internal.parser.wikimodel.DefaultXWikiGeneratorListener;
25    import org.xwiki.rendering.listener.Listener;
26    import org.xwiki.rendering.listener.reference.AttachmentResourceReference;
27    import org.xwiki.rendering.listener.reference.DocumentResourceReference;
28    import org.xwiki.rendering.listener.reference.ResourceReference;
29    import org.xwiki.rendering.listener.reference.ResourceType;
30    import org.xwiki.rendering.parser.ResourceReferenceParser;
31    import org.xwiki.rendering.parser.StreamParser;
32    import org.xwiki.rendering.renderer.PrintRendererFactory;
33    import org.xwiki.rendering.syntax.Syntax;
34    import org.xwiki.rendering.util.IdGenerator;
35   
36    /**
37    * WikiModel listener bridge for the XWiki Syntax 2.1.
38    *
39    * @version $Id: a5c978c80a6cab4a865c15c51ad87a7fc3930d8d $
40    * @since 2.5RC1
41    */
 
42    public class XWiki21XWikiGeneratorListener extends DefaultXWikiGeneratorListener
43    {
44    /**
45    * Parameter name for Query String.
46    */
47    private static final String QUERY_STRING = "queryString";
48   
49    /**
50    * Parameter name for Anchor.
51    */
52    private static final String ANCHOR = "anchor";
53   
54    /**
55    * @param parser the parser to use to parse link labels
56    * @param listener the XWiki listener to which to forward WikiModel events
57    * @param linkReferenceParser the parser to parse link references
58    * @param imageReferenceParser the parser to parse image references
59    * @param plainRendererFactory used to generate header ids
60    * @param idGenerator used to generate header ids
61    * @param syntax the syntax of the parsed source
62    * @since 3.0M3
63    */
 
64  272406 toggle public XWiki21XWikiGeneratorListener(StreamParser parser, Listener listener,
65    ResourceReferenceParser linkReferenceParser, ResourceReferenceParser imageReferenceParser,
66    PrintRendererFactory plainRendererFactory, IdGenerator idGenerator, Syntax syntax)
67    {
68  272402 super(parser, listener, linkReferenceParser, imageReferenceParser, plainRendererFactory, idGenerator, syntax);
69    }
70   
 
71  23644 toggle @Override
72    protected void onReference(ResourceReference reference, String label, boolean freestanding,
73    Map<String, String> parameters)
74    {
75    // Since 2.5M2, handle the special case when the link syntax used for a link to a document has the
76    // query string and/or the anchor specified as parameters. This is how the XWiki Syntax 2.1 specifies
77    // query string and anchor (ex: [[label>>doc:docReference||queryString="a=b" anchor="anchor"]]).
78  23647 ResourceType resourceType = reference.getType();
79  23650 if (ResourceType.DOCUMENT.equals(resourceType) || ResourceType.SPACE.equals(resourceType)
80    || ResourceType.PAGE.equals(resourceType)) {
81  6648 String queryString = parameters.remove(QUERY_STRING);
82  6650 if (queryString != null) {
83  665 reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString);
84    }
85  6648 String anchor = parameters.remove(ANCHOR);
86  6649 if (anchor != null) {
87  245 reference.setParameter(DocumentResourceReference.ANCHOR, anchor);
88    }
89  17000 } else if (ResourceType.ATTACHMENT.equals(resourceType)) {
90  258 String queryString = parameters.remove(QUERY_STRING);
91  258 if (queryString != null) {
92  4 reference.setParameter(AttachmentResourceReference.QUERY_STRING, queryString);
93    }
94    }
95   
96  23647 super.onReference(reference, label, freestanding, parameters);
97    }
98   
 
99  2411 toggle @Override
100    protected void onImage(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
101    {
102    // Since 2.5M2, handle the special case when the image syntax used for an image has a query string specified.
103  2411 if (ResourceType.ATTACHMENT.equals(reference.getType())) {
104  2110 String queryString = parameters.remove(QUERY_STRING);
105  2110 if (queryString != null) {
106  5 reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString);
107    }
108    }
109   
110  2411 super.onImage(reference, freestanding, parameters);
111    }
112    }