1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.wikimodel.xhtml.handler

File TeletypeTagHandler.java

 

Coverage histogram

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

Code metrics

4
14
5
1
91
53
9
0.64
2.8
5
1.8

Classes

Class Line # Actions
TeletypeTagHandler 33 14 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 322 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.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.TagContext;
28   
29    /**
30    * @version $Id: 5b2222cfca5f37544dc61f05fc18f47b88d412dd $
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  437 toggle public TeletypeTagHandler()
42    {
43  437 super(IWemConstants.MONO);
44    }
45   
 
46  17 toggle @Override
47    protected void begin(TagContext context)
48    {
49  17 WikiParameter param = context.getParams().getParameter("class");
50  17 if ((param != null)
51    && Arrays.asList(param.getValue().split(" ")).contains(
52    "wikimodel-verbatim"))
53    {
54  11 beginVerbatim(context);
55    } else {
56  6 super.begin(context);
57    }
58    }
59   
 
60  17 toggle @Override
61    protected void end(TagContext context)
62    {
63  17 WikiParameter param = context.getParams().getParameter("class");
64  17 if ((param != null)
65    && Arrays.asList(param.getValue().split(" ")).contains(
66    "wikimodel-verbatim"))
67    {
68  11 endVerbatim(context);
69    } else {
70  6 super.end(context);
71    }
72    }
73   
 
74  11 toggle private void beginVerbatim(TagContext context)
75    {
76    // filter content of the <tt> element
77  11 context.getTagStack().pushScannerContext(
78    new WikiScannerContext(new PreserverListener()));
79  11 context.getScannerContext().beginDocument();
80    }
81   
 
82  11 toggle private void endVerbatim(TagContext context)
83    {
84  11 context.getScannerContext().endDocument();
85  11 PreserverListener preserverListener = (PreserverListener) context
86    .getTagStack().popScannerContext().getfListener();
87   
88  11 context.getScannerContext().onVerbatim(preserverListener.toString(),
89    true);
90    }
91    }