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

File AbstractDoxiaParser.java

 

Coverage histogram

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

Code metrics

0
13
3
1
105
57
4
0.31
4.33
3
1.33

Classes

Class Line # Actions
AbstractDoxiaParser 41 13 0% 4 1
0.937593.8%
 

Contributing tests

This file is covered by 31 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.doxia;
21   
22    import java.io.Reader;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26   
27    import org.xwiki.rendering.block.XDOM;
28    import org.xwiki.rendering.internal.parser.XDOMGeneratorListener;
29    import org.xwiki.rendering.listener.Listener;
30    import org.xwiki.rendering.parser.ParseException;
31    import org.xwiki.rendering.parser.Parser;
32    import org.xwiki.rendering.parser.ResourceReferenceParser;
33    import org.xwiki.rendering.parser.StreamParser;
34    import org.xwiki.rendering.renderer.PrintRendererFactory;
35    import org.xwiki.rendering.util.IdGenerator;
36   
37    /**
38    * @version $Id: b455daba781c9b04b12d6972a060f328c209ab62 $
39    * @since 1.5M2
40    */
 
41    public abstract class AbstractDoxiaParser implements Parser, StreamParser
42    {
43    /**
44    * Used by the XWikiGeneratorListener to generate unique header ids.
45    */
46    @Inject
47    @Named("plain/1.0")
48    protected PrintRendererFactory plainRendererFactory;
49   
50    @Inject
51    @Named("plain/1.0")
52    private StreamParser plainParser;
53   
54    @Inject
55    @Named("default/link")
56    private ResourceReferenceParser linkReferenceParser;
57   
58    @Inject
59    @Named("default/image")
60    private ResourceReferenceParser imageReferenceParser;
61   
62    public abstract org.apache.maven.doxia.parser.Parser createDoxiaParser();
63   
 
64  3 toggle @Override
65    public XDOM parse(Reader source) throws ParseException
66    {
67  3 IdGenerator idGenerator = new IdGenerator();
68  3 XDOMGeneratorListener listener = new XDOMGeneratorListener();
69  3 parse(source, listener, idGenerator);
70   
71  3 XDOM xdom = listener.getXDOM();
72  3 xdom.setIdGenerator(idGenerator);
73   
74  3 return xdom;
75    }
76   
 
77  28 toggle @Override
78    public void parse(Reader source, Listener listener) throws ParseException
79    {
80  28 IdGenerator idGenerator = new IdGenerator();
81   
82  28 parse(source, listener, idGenerator);
83    }
84   
85    /**
86    * @param source the content to parse
87    * @param listener receive event for each element
88    * @param idGenerator unique id tool generator
89    * @throws ParseException if the source cannot be read or an unexpected error happens during the parsing. Parsers
90    * should be written to not generate any error as much as possible.
91    */
 
92  31 toggle private void parse(Reader source, Listener listener, IdGenerator idGenerator) throws ParseException
93    {
94  31 XWikiGeneratorSink doxiaSink =
95    new XWikiGeneratorSink(listener, this.linkReferenceParser, this.plainRendererFactory, idGenerator,
96    this.plainParser, getSyntax());
97   
98  31 org.apache.maven.doxia.parser.Parser parser = createDoxiaParser();
99  31 try {
100  31 parser.parse(source, doxiaSink);
101    } catch (Exception e) {
102  0 throw new ParseException("Failed to parse input source", e);
103    }
104    }
105    }