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

File TagContext.java

 

Coverage histogram

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

Code metrics

18
30
13
1
137
90
24
0.8
2.31
13
1.85

Classes

Class Line # Actions
TagContext 33 30 0% 24 1
0.983606698.4%
 

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.impl;
21   
22    import org.xwiki.rendering.wikimodel.WikiPageUtil;
23    import org.xwiki.rendering.wikimodel.WikiParameters;
24    import org.xwiki.rendering.wikimodel.impl.WikiScannerContext;
25    import org.xwiki.rendering.wikimodel.xhtml.handler.TagHandler;
26   
27    /**
28    * Provides context for a given tag.
29    *
30    * @version $Id: 5394464be4fd8ef5121dc80056230964eb389fbd $
31    * @since 7.0RC1
32    */
 
33    public class TagContext
34    {
35    private final TagContext fParent;
36   
37    private final String fName;
38   
39    private final WikiParameters fParameters;
40   
41    private final TagStack fTagStack;
42   
43    private StringBuffer fContent;
44   
45    private TagHandler fHandler;
46   
 
47  5237 toggle public TagContext(TagContext parent, String name, WikiParameters params, TagStack tagStack)
48    {
49  5237 fName = (name != null) ? name.toLowerCase() : null;
50  5237 fParent = parent;
51  5237 fParameters = params;
52  5237 fTagStack = tagStack;
53    }
54   
 
55  2149 toggle public boolean appendContent(String content)
56    {
57  2149 if (fHandler == null || !fHandler.isAccumulateContent()) {
58  1941 return false;
59    }
60  208 if (fContent == null) {
61  208 fContent = new StringBuffer();
62    }
63  208 fContent.append(content);
64  208 return true;
65    }
66   
 
67  5151 toggle public void beginElement(TagHandler handler)
68    {
69  5151 if (fParent == null) {
70  437 getScannerContext().beginDocument();
71    }
72  5151 fHandler = handler;
73  5151 if (fHandler != null) {
74  3789 fHandler.beginElement(this);
75    }
76    }
77   
 
78  5143 toggle public void endElement()
79    {
80  5143 if (fHandler != null) {
81  3787 fHandler.endElement(this);
82    }
83  5143 if (fParent == null) {
84  435 getScannerContext().endDocument();
85    }
86    }
87   
 
88  171 toggle public String getContent()
89    {
90  171 return fContent != null ? WikiPageUtil.escapeXmlString(fContent.toString()) : "";
91    }
92   
 
93  5381 toggle public String getName()
94    {
95  5381 return fName;
96    }
97   
 
98  4354 toggle public WikiParameters getParams()
99    {
100  4354 return fParameters;
101    }
102   
 
103  5229 toggle public TagContext getParentContext() {
104  5229 return fParent;
105    }
106   
 
107  785 toggle public TagContext getParent()
108    {
109    // If my parent is not handled, I want it to be fully ignored, so I will go up the tree until I found
110    // a handled parent, however I should not reach the root.
111  785 if (fParent.fHandler == null && fParent.fParent.fName != null) {
112  90 return fParent.getParent();
113    } else {
114  695 return fParent;
115    }
116    }
117   
 
118  19879 toggle public TagStack getTagStack()
119    {
120  19879 return fTagStack;
121    }
122   
 
123  6297 toggle public WikiScannerContext getScannerContext()
124    {
125  6297 return fTagStack.getScannerContext();
126    }
127   
 
128  2220 toggle public boolean isContentContainer()
129    {
130  2220 return fHandler == null || fHandler.isContentContainer();
131    }
132   
 
133  1155 toggle public boolean isTag(String string)
134    {
135  1155 return string.equals(fName);
136    }
137    }