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

File XDOMXMLContentHandlerStreamParser.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

8
22
6
1
119
82
13
0.59
3.67
6
2.17

Classes

Class Line # Actions
XDOMXMLContentHandlerStreamParser 42 22 0% 13 7
0.805555680.6%
 

Contributing tests

This file is covered by 2 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.xdomxml10.internal.parser;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24   
25    import org.dom4j.io.SAXContentHandler;
26    import org.xml.sax.Attributes;
27    import org.xml.sax.SAXException;
28    import org.xml.sax.helpers.DefaultHandler;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.annotation.InstantiationStrategy;
31    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
32    import org.xwiki.component.manager.ComponentLookupException;
33    import org.xwiki.component.manager.ComponentManager;
34    import org.xwiki.rendering.listener.Listener;
35    import org.xwiki.rendering.parser.xml.ContentHandlerStreamParser;
36    import org.xwiki.rendering.syntax.Syntax;
37    import org.xwiki.rendering.xdomxml10.internal.XDOMXMLConstants;
38   
39    @Component
40    @Named("xdom+xml/1.0")
41    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
42    public class XDOMXMLContentHandlerStreamParser extends DefaultHandler implements ContentHandlerStreamParser
43    {
44    private Listener listener;
45   
46    private BlockParser documentParser;
47   
48    @Inject
49    private ComponentManager componentManager;
50   
51    /**
52    * Avoid create a new SAXContentHandler for each block when the same can be used for all.
53    */
54    public SAXContentHandler currentDOMBuilder = new SAXContentHandler();
55   
 
56  0 toggle @Override
57    public Syntax getSyntax()
58    {
59  0 return Syntax.XDOMXML_1_0;
60    }
61   
 
62  2 toggle @Override
63    public void setListener(Listener listener)
64    {
65  2 this.listener = listener;
66    }
67   
 
68  18 toggle @Override
69    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
70    {
71  18 if (this.documentParser != null) {
72  16 this.documentParser.startElement(uri, localName, qName, attributes);
73  2 } else if (XDOMXMLConstants.ELEM_BLOCK.equals(qName)) {
74  2 try {
75  2 this.documentParser = getDocumentBlockParser();
76   
77  2 this.documentParser.setListener(this.listener);
78  2 this.documentParser.setVersion(Syntax.XDOMXML_1_0.getVersion());
79   
80  2 this.documentParser.startElement(uri, localName, qName, attributes);
81    } catch (ComponentLookupException e) {
82  0 throw new SAXException("Failed to find a document block parser", e);
83    }
84    }
85    }
86   
 
87  8 toggle @Override
88    public void characters(char[] ch, int start, int length) throws SAXException
89    {
90  8 if (this.documentParser != null) {
91  8 this.documentParser.characters(ch, start, length);
92    }
93    }
94   
 
95  18 toggle @Override
96    public void endElement(String uri, String localName, String qName) throws SAXException
97    {
98  18 if (this.documentParser != null) {
99  18 this.documentParser.endElement(uri, localName, qName);
100    }
101    }
102   
 
103  2 toggle protected BlockParser getDocumentBlockParser() throws ComponentLookupException
104    {
105  2 BlockParser blockParser;
106  2 try {
107  2 blockParser =
108    this.componentManager.getInstance(BlockParser.class, "document/" + Syntax.XDOMXML_1_0.getVersion());
109    } catch (ComponentLookupException e1) {
110  2 try {
111  2 blockParser = this.componentManager.getInstance(BlockParser.class, "document");
112    } catch (ComponentLookupException e2) {
113  0 blockParser = this.componentManager.getInstance(BlockParser.class);
114    }
115    }
116   
117  2 return blockParser;
118    }
119    }