• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / sitemesh2 / 59

22 Mar 2026 02:30AM UTC coverage: 40.347%. Remained the same
59

push

github

hazendaz
[mvn] Update maven wrapper

698 of 1891 branches covered (36.91%)

Branch coverage included in aggregate %.

1555 of 3693 relevant lines covered (42.11%)

0.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.41
/src/main/java/com/opensymphony/module/sitemesh/html/State.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 * Copyright 2011-2026 Hazendaz
4
 */
5
package com.opensymphony.module.sitemesh.html;
6

7
import com.opensymphony.module.sitemesh.html.util.StringSitemeshBuffer;
8

9
import java.util.ArrayList;
10
import java.util.Iterator;
11
import java.util.List;
12

13
/**
14
 * The Class State.
15
 */
16
public final class State {
1✔
17

18
    /** The rules. */
19
    private TagRule[] rules = new TagRule[16]; // List is too slow, according to profiler
1✔
20

21
    /** The rule count. */
22
    private int ruleCount = 0;
1✔
23

24
    /** The listeners. */
25
    private List<StateChangeListener> listeners;
26

27
    /** The text filters. */
28
    private List<TextFilter> textFilters; // lazily instantiated to reduce overhead for most cases where it's not
29
                                          // needed.
30

31
    /**
32
     * Adds the rule.
33
     *
34
     * @param rule
35
     *            the rule
36
     */
37
    public void addRule(TagRule rule) {
38
        if (ruleCount == rules.length) {
1!
39
            // grow array if necessary
40
            TagRule[] longerArray = new TagRule[rules.length * 2];
×
41
            System.arraycopy(rules, 0, longerArray, 0, ruleCount);
×
42
            rules = longerArray;
×
43
        }
44
        rules[ruleCount++] = rule;
1✔
45
    }
1✔
46

47
    /**
48
     * Adds the text filter.
49
     *
50
     * @param textFilter
51
     *            the text filter
52
     */
53
    public void addTextFilter(TextFilter textFilter) {
54
        if (textFilters == null) {
1✔
55
            textFilters = new ArrayList<TextFilter>(); // lazy instantiation
1✔
56
        }
57
        textFilters.add(textFilter);
1✔
58
    }
1✔
59

60
    /**
61
     * Should process tag.
62
     *
63
     * @param tagName
64
     *            the tag name
65
     *
66
     * @return true, if successful
67
     */
68
    public boolean shouldProcessTag(String tagName) {
69
        for (int i = ruleCount - 1; i >= 0; i--) { // reverse iteration to so most recently added rule matches
1✔
70
            if (rules[i].shouldProcess(tagName)) {
1✔
71
                return true;
1✔
72
            }
73
        }
74
        return false;
1✔
75
    }
76

77
    /**
78
     * Gets the rule.
79
     *
80
     * @param tagName
81
     *            the tag name
82
     *
83
     * @return the rule
84
     */
85
    public TagRule getRule(String tagName) {
86
        for (int i = ruleCount - 1; i >= 0; i--) { // reverse iteration to so most recently added rule matches
1!
87
            if (rules[i].shouldProcess(tagName)) {
1✔
88
                return rules[i];
1✔
89
            }
90
        }
91
        return null;
×
92
    }
93

94
    /**
95
     * Adds the listener.
96
     *
97
     * @param listener
98
     *            the listener
99
     */
100
    public void addListener(StateChangeListener listener) {
101
        if (listeners == null) {
1!
102
            listeners = new ArrayList<StateChangeListener>();
1✔
103
        }
104
        listeners.add(listener);
1✔
105
    }
1✔
106

107
    /**
108
     * End of state.
109
     */
110
    public void endOfState() {
111
        if (listeners == null) {
1✔
112
            return;
1✔
113
        }
114
        for (Iterator<StateChangeListener> iter = listeners.iterator(); iter.hasNext();) {
1✔
115
            StateChangeListener listener = (StateChangeListener) iter.next();
1✔
116
            listener.stateFinished();
1✔
117
        }
1✔
118
    }
1✔
119

120
    /**
121
     * Handle text.
122
     *
123
     * @param text
124
     *            the text
125
     * @param context
126
     *            the context
127
     */
128
    public void handleText(Text text, HTMLProcessorContext context) {
129
        if (textFilters != null && !textFilters.isEmpty()) {
1!
130
            String original = text.getContents();
1✔
131
            String asString = original;
1✔
132
            for (Iterator<TextFilter> iterator = textFilters.iterator(); iterator.hasNext();) {
1✔
133
                TextFilter textFilter = (TextFilter) iterator.next();
1✔
134
                asString = textFilter.filter(asString);
1✔
135
            }
1✔
136
            if (!original.equals(asString)) {
1✔
137
                context.currentBuffer().delete(text.getPosition(), text.getLength());
1✔
138
                context.currentBuffer().insert(text.getPosition(), StringSitemeshBuffer.createBufferFragment(asString));
1✔
139
            }
140
        }
141
    }
1✔
142

143
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc