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