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

File TagHandler.java

 

Coverage histogram

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

Code metrics

12
31
15
1
163
92
21
0.68
2.07
15
1.4

Classes

Class Line # Actions
TagHandler 30 31 0% 21 1
0.9827586498.3%
 

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 org.xwiki.rendering.wikimodel.WikiParameters;
23    import org.xwiki.rendering.wikimodel.xhtml.impl.TagContext;
24    import org.xwiki.rendering.wikimodel.xhtml.impl.TagStack;
25   
26    /**
27    * @version $Id: ecf89fff803bbb5ab4249e94b124ad3e2d3febc3 $
28    * @since 4.0M1
29    */
 
30    public class TagHandler
31    {
32   
33    private boolean fAccumulateContent;
34   
35    /**
36    * This flag is <code>true</code> if the current tag can have a text content
37    */
38    private final boolean fContentContainer;
39   
40    /**
41    * @param contentContainer when false, text content is dropped.
42    */
 
43  13349 toggle public TagHandler(boolean contentContainer)
44    {
45  13349 fContentContainer = contentContainer;
46    }
47   
 
48  0 toggle protected void begin(TagContext context)
49    {
50    }
51   
 
52  3789 toggle public void beginElement(TagContext context)
53    {
54  3789 if (isBlockHandler(context)) {
55    // If we're starting a block tag and we're in inline mode (ie inside
56    // a block element) then start a nested document
57    // and save the parent tag, see endElement().
58  1199 if (context.getTagStack().isInsideBlockElement()) {
59  29 beginDocument(context);
60   
61  29 context.getTagStack().setDocumentParent();
62    }
63   
64  1199 context.getTagStack().setInsideBlockElement();
65    }
66   
67  3789 begin(context);
68    }
69   
 
70  393 toggle protected void end(TagContext context)
71    {
72    }
73   
 
74  3787 toggle public final void endElement(TagContext context)
75    {
76    // Verify if we need to close a nested document that would have been
77    // opened.
78    // To verify this we check the current tag being closed and verify if
79    // it's the one saved when the nested document was opened.
80  3787 if (context == context.getTagStack().getDocumentParent()) {
81  29 endDocument(context);
82  29 context.getTagStack().setInsideBlockElement();
83    }
84   
85  3787 end(context);
86   
87  3787 if (isBlockHandler(context)) {
88  1197 context.getTagStack().unsetInsideBlockElement();
89    }
90    }
91   
 
92  1859 toggle public boolean isContentContainer()
93    {
94  1859 return fContentContainer;
95    }
96   
 
97  327 toggle public void setAccumulateContent(boolean accumulateContent)
98    {
99  327 fAccumulateContent = accumulateContent;
100    }
101   
 
102  1857 toggle public boolean isAccumulateContent()
103    {
104  1857 return fAccumulateContent;
105    }
106   
107    /**
108    * Check if we need to emit an onEmptyLines() event.
109    */
 
110  1446 toggle public static void sendEmptyLines(TagContext context)
111    {
112  1446 sendEmptyLines(context.getTagStack());
113    }
114   
 
115  1906 toggle public static void sendEmptyLines(TagStack stack)
116    {
117  1906 int lineCount = stack.getEmptyLinesCount();
118  1906 if (lineCount > 0) {
119  13 stack.getScannerContext().onEmptyLines(lineCount);
120  13 stack.resetEmptyLinesCount();
121    }
122    }
123   
 
124  27723 toggle public void initialize(TagStack stack)
125    {
126    // Nothing to do by default. Override in children classes if need be.
127    }
128   
129    /**
130    * @return true if the current handler handles block tags (paragraphs, lists, tables, headers, etc)
131    */
 
132  4796 toggle public boolean isBlockHandler(TagContext context)
133    {
134  4796 return false;
135    }
136   
 
137  29 toggle protected void beginDocument(TagContext context)
138    {
139  29 beginDocument(context, null);
140    }
141   
 
142  124 toggle protected void beginDocument(TagContext context, WikiParameters params)
143    {
144  124 sendEmptyLines(context);
145  124 if (params == null) {
146  29 context.getScannerContext().beginDocument();
147    } else {
148  95 context.getScannerContext().beginDocument(params);
149    }
150   
151    // Stack context parameters since we enter in a new document
152  124 context.getTagStack().pushStackParameters();
153   
154  124 context.getTagStack().unsetInsideBlockElement();
155    }
156   
 
157  124 toggle protected void endDocument(TagContext context)
158    {
159  124 context.getTagStack().popStackParameters();
160   
161  124 context.getScannerContext().endDocument();
162    }
163    }