1. Project Clover database Sat Feb 2 2019 06:45:20 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 2
0.967213196.7%
 

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.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  2773 toggle public TagContext(TagContext parent, String name, WikiParameters params, TagStack tagStack)
48    {
49  2773 fName = (name != null) ? name.toLowerCase() : null;
50  2773 fParent = parent;
51  2773 fParameters = params;
52  2773 fTagStack = tagStack;
53    }
54   
 
55  1009 toggle public boolean appendContent(String content)
56    {
57  1009 if (fHandler == null || !fHandler.isAccumulateContent()) {
58  966 return false;
59    }
60  43 if (fContent == null) {
61  43 fContent = new StringBuffer();
62    }
63  43 fContent.append(content);
64  43 return true;
65    }
66   
 
67  2657 toggle public void beginElement(TagHandler handler)
68    {
69  2657 if (fParent == null) {
70  433 getScannerContext().beginDocument();
71    }
72  2657 fHandler = handler;
73  2657 if (fHandler != null) {
74  1641 fHandler.beginElement(this);
75    }
76    }
77   
 
78  2657 toggle public void endElement()
79    {
80  2657 if (fHandler != null) {
81  1641 fHandler.endElement(this);
82    }
83  2657 if (fParent == null) {
84  433 getScannerContext().endDocument();
85    }
86    }
87   
 
88  4 toggle public String getContent()
89    {
90  4 return fContent != null ? WikiPageUtil.escapeXmlString(fContent.toString()) : "";
91    }
92   
 
93  2848 toggle public String getName()
94    {
95  2848 return fName;
96    }
97   
 
98  3051 toggle public WikiParameters getParams()
99    {
100  3051 return fParameters;
101    }
102   
 
103  2773 toggle public TagContext getParentContext() {
104  2773 return fParent;
105    }
106   
 
107  493 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  493 if (fParent.fHandler == null && fParent.fParent.fName != null) {
112  66 return fParent.getParent();
113    } else {
114  427 return fParent;
115    }
116    }
117   
 
118  10236 toggle public TagStack getTagStack()
119    {
120  10236 return fTagStack;
121    }
122   
 
123  3535 toggle public WikiScannerContext getScannerContext()
124    {
125  3535 return fTagStack.getScannerContext();
126    }
127   
 
128  1118 toggle public boolean isContentContainer()
129    {
130  1118 return fHandler == null || fHandler.isContentContainer();
131    }
132   
 
133  746 toggle public boolean isTag(String string)
134    {
135  746 return string.equals(fName);
136    }
137    }