1. Project Clover database Tue Dec 20 2016 21:24:09 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
111
57
11
0.58
6.33
3
3.67

Classes

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

Contributing tests

This file is covered by 118 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: dfefcd8c681ec6ba7ed58748a7d8bc2480fdd932 $
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  19452 toggle public XWiki21XWikiGeneratorListener(StreamParser parser, Listener listener,
65    ResourceReferenceParser linkReferenceParser, ResourceReferenceParser imageReferenceParser,
66    PrintRendererFactory plainRendererFactory, IdGenerator idGenerator, Syntax syntax)
67    {
68  19453 super(parser, listener, linkReferenceParser, imageReferenceParser, plainRendererFactory, idGenerator, syntax);
69    }
70   
 
71  627 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  627 ResourceType resourceType = reference.getType();
79  627 if (ResourceType.DOCUMENT.equals(resourceType) || ResourceType.SPACE.equals(resourceType)) {
80  193 String queryString = parameters.remove(QUERY_STRING);
81  193 if (queryString != null) {
82  65 reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString);
83    }
84  193 String anchor = parameters.remove(ANCHOR);
85  193 if (anchor != null) {
86  12 reference.setParameter(DocumentResourceReference.ANCHOR, anchor);
87    }
88  434 } else if (ResourceType.ATTACHMENT.equals(resourceType)) {
89  9 String queryString = parameters.remove(QUERY_STRING);
90  9 if (queryString != null) {
91  4 reference.setParameter(AttachmentResourceReference.QUERY_STRING, queryString);
92    }
93    }
94   
95  627 super.onReference(reference, label, freestanding, parameters);
96    }
97   
 
98  450 toggle @Override
99    protected void onImage(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
100    {
101    // Since 2.5M2, handle the special case when the image syntax used for an image has a query string specified.
102  450 if (ResourceType.ATTACHMENT.equals(reference.getType())) {
103  281 String queryString = parameters.remove(QUERY_STRING);
104  281 if (queryString != null) {
105  4 reference.setParameter(DocumentResourceReference.QUERY_STRING, queryString);
106    }
107    }
108   
109  450 super.onImage(reference, freestanding, parameters);
110    }
111    }