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
39   203   24   2.29
12   113   0.62   17
17     1.41  
1    
 
  TagHandler       Line # 32 39 0% 24 5 92.6% 0.9264706
 
  (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.Stack;
23   
24    import org.xwiki.rendering.wikimodel.WikiParameters;
25    import org.xwiki.rendering.wikimodel.xhtml.impl.XhtmlHandler;
26    import org.xwiki.rendering.wikimodel.xhtml.impl.XhtmlHandler.TagStack;
27   
28    /**
29    * @version $Id: 5dd55262ab6a3106c96b43d10e9e14aaf5068833 $
30    * @since 4.0M1
31    */
 
32    public class TagHandler
33    {
34    private boolean fAccumulateContent;
35   
36    /**
37    * This flag is <code>true</code> if the current tag can have a text content
38    */
39    private final boolean fContentContainer;
40   
41    /**
42    * This flag shows if the current tag can be used as a container for embedded documents.
43    */
44    private final boolean fDocumentContainer;
45   
46    /**
47    * This flag shows if the current tag should be created as a direct child of a document.
48    */
49    private final boolean fRequiresDocument;
50   
51    /**
52    * @param documentContainer
53    * @param requiresDocument
54    * @param contentContainer
55    */
 
56  8730 toggle public TagHandler(boolean documentContainer, boolean requiresDocument, boolean contentContainer)
57    {
58  8730 fDocumentContainer = documentContainer;
59  8730 fRequiresDocument = requiresDocument;
60  8730 fContentContainer = contentContainer;
61    }
62   
 
63  0 toggle protected void begin(XhtmlHandler.TagStack.TagContext context)
64    {
65    }
66   
 
67  1213 toggle public void beginElement(XhtmlHandler.TagStack.TagContext context)
68    {
69   
70  1213 Stack<Boolean> insideBlockElementsStack =
71    (Stack<Boolean>) context.getTagStack().getStackParameter("insideBlockElement");
72   
73  1213 if (isBlockHandler(context)) {
74    // If we're starting a block tag and we're in inline mode (ie inside
75    // a block element) then start a nested document
76    // and save the parent tag, see endElement().
77  424 if (!insideBlockElementsStack.isEmpty() && insideBlockElementsStack.peek()) {
78  18 beginDocument(context);
79   
80  18 context.getTagStack().setStackParameter("documentParent", context.getParent());
81   
82    // Get the new inside block element state
83  18 insideBlockElementsStack =
84    (Stack<Boolean>) context.getTagStack().getStackParameter("insideBlockElement");
85    }
86   
87  424 insideBlockElementsStack.push(true);
88    }
89   
90  1213 begin(context);
91    }
92   
 
93  92 toggle protected void end(XhtmlHandler.TagStack.TagContext context)
94    {
95    }
96   
 
97  1213 toggle public final void endElement(XhtmlHandler.TagStack.TagContext context)
98    {
99    // Verify if we need to close a nested document that would have been
100    // opened.
101    // To verify this we check the current tag being closed and verify if
102    // it's the one saved when the nested document was opened.
103  1213 XhtmlHandler.TagStack.TagContext docParent =
104    (XhtmlHandler.TagStack.TagContext) context.getTagStack().getStackParameter("documentParent");
105  1213 if (context == docParent) {
106  18 endDocument(context);
107    }
108   
109  1213 end(context);
110   
111  1213 Stack<Boolean> insideBlockElementsStack =
112    (Stack<Boolean>) context.getTagStack().getStackParameter("insideBlockElement");
113   
114  1213 if (isBlockHandler(context)) {
115  424 insideBlockElementsStack.pop();
116    }
117    }
118   
 
119  703 toggle public boolean isContentContainer()
120    {
121  703 return fContentContainer;
122    }
123   
 
124  0 toggle public boolean isDocumentContainer()
125    {
126  0 return fDocumentContainer;
127    }
128   
 
129  0 toggle public boolean requiresDocument()
130    {
131  0 return fRequiresDocument;
132    }
133   
 
134  127 toggle public void setAccumulateContent(boolean accumulateContent)
135    {
136  127 fAccumulateContent = accumulateContent;
137    }
138   
 
139  701 toggle public boolean isAccumulateContent()
140    {
141  701 return fAccumulateContent;
142    }
143   
144    /**
145    * Check if we need to emit an onEmptyLines() event.
146    */
 
147  795 toggle public static void sendEmptyLines(XhtmlHandler.TagStack.TagContext context)
148    {
149  795 sendEmptyLines(context.getTagStack());
150    }
151   
 
152  815 toggle public static void sendEmptyLines(TagStack stack)
153    {
154  815 int lineCount = (Integer) stack.getStackParameter("emptyLinesCount");
155  815 if (lineCount > 0) {
156  11 stack.getScannerContext().onEmptyLines(lineCount);
157  11 stack.setStackParameter("emptyLinesCount", 0);
158    }
159    }
160   
 
161  13028 toggle public void initialize(XhtmlHandler.TagStack stack)
162    {
163    // Nothing to do by default. Override in children classes if need be.
164    }
165   
166    /**
167    * @return true if the current handler handles block tags (paragraphs, lists, tables, headers, etc)
168    */
 
169  1426 toggle public boolean isBlockHandler(XhtmlHandler.TagStack.TagContext context)
170    {
171  1426 return false;
172    }
173   
 
174  18 toggle protected void beginDocument(XhtmlHandler.TagStack.TagContext context)
175    {
176  18 beginDocument(context, null);
177    }
178   
 
179  47 toggle protected void beginDocument(XhtmlHandler.TagStack.TagContext context, WikiParameters params)
180    {
181  47 sendEmptyLines(context);
182  47 if (params == null) {
183  18 context.getScannerContext().beginDocument();
184    } else {
185  29 context.getScannerContext().beginDocument(params);
186    }
187   
188  47 Object ignoreElements = context.getTagStack().getStackParameter("ignoreElements");
189   
190    // Stack context parameters since we enter in a new document
191  47 context.getTagStack().pushStackParameters();
192   
193    // ignoreElements apply on embedded document
194  47 context.getTagStack().setStackParameter("ignoreElements", ignoreElements);
195    }
196   
 
197  47 toggle protected void endDocument(XhtmlHandler.TagStack.TagContext context)
198    {
199  47 context.getTagStack().popStackParameters();
200   
201  47 context.getScannerContext().endDocument();
202    }
203    }