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

File DefaultContentParser.java

 
testMissingParserException: Failed to find a parser for syntax [XWiki 2.1]
 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
8
3
1
92
51
5
0.62
2.67
3
1.67

Classes

Class Line # Actions
DefaultContentParser 50 8 0% 5 2
0.8461538684.6%
 

Contributing tests

This file is covered by 34 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;
21   
22    import java.io.StringReader;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Provider;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.manager.ComponentLookupException;
31    import org.xwiki.component.manager.ComponentManager;
32    import org.xwiki.model.reference.EntityReference;
33    import org.xwiki.model.reference.EntityReferenceSerializer;
34    import org.xwiki.rendering.block.XDOM;
35    import org.xwiki.rendering.listener.MetaData;
36    import org.xwiki.rendering.parser.ContentParser;
37    import org.xwiki.rendering.parser.MissingParserException;
38    import org.xwiki.rendering.parser.ParseException;
39    import org.xwiki.rendering.parser.Parser;
40    import org.xwiki.rendering.syntax.Syntax;
41   
42    /**
43    * Default implementation of {@link ContentParser}.
44    *
45    * @version $Id: a58b43b563ba4794638679cb537b44b7c0beab4a $
46    * @since 6.0M2
47    */
48    @Component
49    @Singleton
 
50    public class DefaultContentParser implements ContentParser
51    {
52    @Inject
53    @Named("context")
54    private Provider<ComponentManager> componentManagerProvider;
55   
56    @Inject
57    private EntityReferenceSerializer<String> serializer;
58   
 
59  13919 toggle @Override
60    public XDOM parse(String content, Syntax syntax) throws ParseException, MissingParserException
61    {
62  13920 Test failure here return getParser(syntax).parse(new StringReader(content));
63    }
64   
 
65  13922 toggle @Override
66    public XDOM parse(String content, Syntax syntax, EntityReference source) throws ParseException,
67    MissingParserException
68    {
69  13922 Test failure here XDOM xdom = parse(content, syntax);
70  13917 if (source != null) {
71  13912 xdom.getMetaData().addMetaData(MetaData.SOURCE, serializer.serialize(source));
72    }
73  13917 return xdom;
74    }
75   
76    /**
77    * Return a parser for the given syntax.
78    *
79    * @param syntax the syntax.
80    * @return a parser.
81    * @throws MissingParserException when no parser where found for the given syntax.
82    * @since 6.0M2
83    */
 
84  13920 toggle private Parser getParser(Syntax syntax) throws MissingParserException
85    {
86  13920 try {
87  13921 Test failure here return this.componentManagerProvider.get().getInstance(Parser.class, syntax.toIdString());
88    } catch (ComponentLookupException e) {
89  0 Test failure here throw new MissingParserException(syntax, e);
90    }
91    }
92    }