1. Project Clover database Sat Feb 2 2019 06:45:20 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
32
15
1
165
93
21
0.66
2.13
15
1.4

Classes

Class Line # Actions
TagHandler 30 32 0% 21 1
0.983050898.3%
 

Contributing tests

This file is covered by 351 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: 1b4111d79ad58cbbe2efa5a1bc569bf92bc268fe $
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  12829 toggle public TagHandler(boolean contentContainer)
44    {
45  12829 fContentContainer = contentContainer;
46    }
47   
 
48  0 toggle protected void begin(TagContext context)
49    {
50    }
51   
 
52  1641 toggle public void beginElement(TagContext context)
53    {
54  1641 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  580 if (context.getTagStack().isInsideBlockElement()) {
59  21 beginDocument(context);
60   
61  21 context.getTagStack().setDocumentParent();
62    }
63   
64  580 context.getTagStack().setInsideBlockElement();
65    }
66   
67  1641 begin(context);
68    }
69   
 
70  102 toggle protected void end(TagContext context)
71    {
72    }
73   
 
74  1641 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  1641 if (context == context.getTagStack().getDocumentParent()) {
81  21 endDocument(context);
82  21 context.getTagStack().setInsideBlockElement();
83    }
84   
85  1641 end(context);
86   
87  1641 if (isBlockHandler(context)) {
88  580 context.getTagStack().unsetInsideBlockElement();
89    }
90    }
91   
 
92  998 toggle public boolean isContentContainer()
93    {
94  998 return fContentContainer;
95    }
96   
 
97  160 toggle public void setAccumulateContent(boolean accumulateContent)
98    {
99  160 fAccumulateContent = accumulateContent;
100    }
101   
 
102  989 toggle public boolean isAccumulateContent()
103    {
104  989 return fAccumulateContent;
105    }
106   
107    /**
108    * Check if we need to emit an onEmptyLines() event.
109    */
 
110  799 toggle public static void sendEmptyLines(TagContext context)
111    {
112  799 sendEmptyLines(context.getTagStack());
113    }
114   
 
115  1275 toggle public static void sendEmptyLines(TagStack stack)
116    {
117  1275 int lineCount = stack.getEmptyLinesCount();
118  1275 if (lineCount > 0) {
119  15 stack.getScannerContext().getfListener().onEmptyLines(lineCount);
120  15 stack.resetEmptyLinesCount();
121    }
122    }
123   
 
124  25080 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  1780 toggle public boolean isBlockHandler(TagContext context)
133    {
134  1780 return false;
135    }
136   
 
137  21 toggle protected void beginDocument(TagContext context)
138    {
139  21 beginDocument(context, null);
140    }
141   
 
142  95 toggle protected void beginDocument(TagContext context, WikiParameters params)
143    {
144  95 sendEmptyLines(context);
145  95 if (params == null) {
146  21 context.getScannerContext().beginDocument();
147    } else {
148  74 context.getScannerContext().beginDocument(params);
149    }
150   
151    // Stack context parameters since we enter in a new document
152  95 context.getTagStack().pushStackParameters();
153   
154  95 context.getTagStack().unsetInsideBlockElement();
155    }
156   
 
157  95 toggle protected void endDocument(TagContext context)
158    {
159  95 context.getTagStack().popStackParameters();
160   
161  95 sendEmptyLines(context);
162   
163  95 context.getScannerContext().endDocument();
164    }
165    }