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
14   91   9   2.8
4   53   0.64   5
5     1.8  
1    
 
  TeletypeTagHandler       Line # 33 14 0% 9 0 100% 1.0
 
  (219)
 
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.wikimodel.xhtml.handler;
21   
22    import java.util.Arrays;
23   
24    import org.xwiki.rendering.wikimodel.IWemConstants;
25    import org.xwiki.rendering.wikimodel.WikiParameter;
26    import org.xwiki.rendering.wikimodel.impl.WikiScannerContext;
27    import org.xwiki.rendering.wikimodel.xhtml.impl.XhtmlHandler;
28   
29    /**
30    * @version $Id: 85ff796ec73c3b27832fe2a6ed33245c2153b38e $
31    * @since 4.0M1
32    */
 
33    public class TeletypeTagHandler extends AbstractFormatTagHandler
34    {
35    // There are 2 possible output for <tt>:
36    // * If there a class="wikimodel-verbatim" specified then we emit a
37    // onVerbatimInline() event
38    // * If there no class or a class with another value then we emit a
39    // Monospace Format event.
40   
 
41  309 toggle public TeletypeTagHandler()
42    {
43  309 super(IWemConstants.MONO);
44    }
45   
 
46  16 toggle @Override
47    protected void begin(XhtmlHandler.TagStack.TagContext context)
48    {
49  16 WikiParameter param = context.getParams().getParameter("class");
50  16 if ((param != null)
51    && Arrays.asList(param.getValue().split(" ")).contains(
52    "wikimodel-verbatim"))
53    {
54  10 beginVerbatim(context);
55    } else {
56  6 super.begin(context);
57    }
58    }
59   
 
60  16 toggle @Override
61    protected void end(XhtmlHandler.TagStack.TagContext context)
62    {
63  16 WikiParameter param = context.getParams().getParameter("class");
64  16 if ((param != null)
65    && Arrays.asList(param.getValue().split(" ")).contains(
66    "wikimodel-verbatim"))
67    {
68  10 endVerbatim(context);
69    } else {
70  6 super.end(context);
71    }
72    }
73   
 
74  10 toggle private void beginVerbatim(XhtmlHandler.TagStack.TagContext context)
75    {
76    // filter content of the <tt> element
77  10 context.getTagStack().pushScannerContext(
78    new WikiScannerContext(new PreserverListener()));
79  10 context.getScannerContext().beginDocument();
80    }
81   
 
82  10 toggle private void endVerbatim(XhtmlHandler.TagStack.TagContext context)
83    {
84  10 context.getScannerContext().endDocument();
85  10 PreserverListener preserverListener = (PreserverListener) context
86    .getTagStack().popScannerContext().getfListener();
87   
88  10 context.getScannerContext().onVerbatim(preserverListener.toString(),
89    true);
90    }
91    }