• 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

31.34
/src/main/java/com/opensymphony/module/sitemesh/parser/AbstractPage.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 * Copyright 2011-2026 Hazendaz
4
 */
5
/*
6
 * Title:        AbstractPage
7
 * Description:
8
 *
9
 * This software is published under the terms of the OpenSymphony Software
10
 * License version 1.1, of which a copy has been included with this
11
 * distribution in the LICENSE.txt file.
12
 */
13

14
package com.opensymphony.module.sitemesh.parser;
15

16
import com.opensymphony.module.sitemesh.Page;
17
import com.opensymphony.module.sitemesh.SitemeshBuffer;
18

19
import jakarta.servlet.http.HttpServletRequest;
20
import jakarta.servlet.http.HttpServletRequestWrapper;
21

22
import java.io.IOException;
23
import java.io.StringWriter;
24
import java.io.Writer;
25
import java.util.HashMap;
26
import java.util.Map;
27
import java.util.Set;
28

29
/**
30
 * Abstract implementation of {@link com.opensymphony.module.sitemesh.Page} .
31
 * <p>
32
 * Contains base methods for storing and accessing page properties. *
33
 *
34
 * @author <a href="joe@truemesh.com">Joe Walnes</a>
35
 *
36
 * @see com.opensymphony.module.sitemesh.Page
37
 */
38
public abstract class AbstractPage implements Page {
39
    /**
40
     * Map of all properties. Key is String. Value is java.util.List of multiple String values.
41
     */
42
    private final Map<String, String> properties = new HashMap<String, String>();
1✔
43

44
    /** Date of page contents. */
45
    private final SitemeshBuffer sitemeshBuffer;
46

47
    /** RequestURI of original Page. */
48
    private HttpServletRequest request;
49

50
    /**
51
     * Instantiates a new abstract page.
52
     *
53
     * @param sitemeshBuffer
54
     *            the sitemesh buffer
55
     */
56
    protected AbstractPage(SitemeshBuffer sitemeshBuffer) {
1✔
57
        this.sitemeshBuffer = sitemeshBuffer;
1✔
58
    }
1✔
59

60
    @Override
61
    public void writePage(Writer out) throws IOException {
62
        sitemeshBuffer.writeTo(out, 0, sitemeshBuffer.getBufferLength());
1✔
63
    }
1✔
64

65
    @Override
66
    public String getPage() {
67
        try {
68
            StringWriter writer = new StringWriter();
1✔
69
            writePage(writer);
1✔
70
            return writer.toString();
1✔
71
        } catch (IOException e) {
×
72
            throw new IllegalStateException("Could not get page " + e.getMessage(), e);
×
73
        }
74
    }
75

76
    /**
77
     * Write data of html <code>&lt;body&gt;</code> tag.
78
     * <p>
79
     * Must be implemented. Data written should not actually contain the body tags, but all the data in between.
80
     */
81
    @Override
82
    public abstract void writeBody(Writer out) throws IOException;
83

84
    @Override
85
    public String getBody() {
86
        try {
87
            StringWriter writer = new StringWriter();
×
88
            writeBody(writer);
×
89
            return writer.toString();
×
90
        } catch (IOException e) {
×
91
            throw new IllegalStateException("Could not get body " + e.getMessage(), e);
×
92
        }
93
    }
94

95
    /** Return title of from "title" property. Never returns null. */
96
    @Override
97
    public String getTitle() {
98
        return noNull(getProperty("title"));
1✔
99
    }
100

101
    @Override
102
    public String getProperty(String name) {
103
        if (!isPropertySet(name)) {
1!
104
            return null;
×
105
        }
106
        return (String) properties.get(name);
1✔
107
    }
108

109
    @Override
110
    public int getIntProperty(String name) {
111
        try {
112
            return Integer.parseInt(noNull(getProperty(name)));
×
113
        } catch (NumberFormatException e) {
×
114
            return 0;
×
115
        }
116
    }
117

118
    @Override
119
    public long getLongProperty(String name) {
120
        try {
121
            return Long.parseLong(noNull(getProperty(name)));
×
122
        } catch (NumberFormatException e) {
×
123
            return 0;
×
124
        }
125
    }
126

127
    @Override
128
    public boolean getBooleanProperty(String name) {
129
        String property = getProperty(name);
×
130
        if (property == null || property.trim().length() == 0) {
×
131
            return false;
×
132
        }
133
        switch (property.charAt(0)) {
×
134
            case '1':
135
            case 't':
136
            case 'T':
137
            case 'y':
138
            case 'Y':
139
                return true;
×
140
            default:
141
                return false;
×
142
        }
143
    }
144

145
    @Override
146
    public boolean isPropertySet(String name) {
147
        return properties.containsKey(name);
1✔
148
    }
149

150
    @Override
151
    public String[] getPropertyKeys() {
152
        synchronized (properties) {
1✔
153
            Set<String> keys = properties.keySet();
1✔
154
            return (String[]) keys.toArray(new String[keys.size()]);
1✔
155
        }
156
    }
157

158
    @Override
159
    public Map<String, String> getProperties() {
160
        return properties;
×
161
    }
162

163
    /** @see com.opensymphony.module.sitemesh.Page#getRequest() */
164
    @Override
165
    public HttpServletRequest getRequest() {
166
        return request;
×
167
    }
168

169
    /**
170
     * Create snapshot of Request.
171
     *
172
     * @see com.opensymphony.module.sitemesh.Page#getRequest()
173
     */
174
    @Override
175
    public void setRequest(HttpServletRequest request) {
176
        this.request = new PageRequest(request);
×
177
    }
×
178

179
    /**
180
     * Add a property to the properties list.
181
     *
182
     * @param name
183
     *            Name of property
184
     * @param value
185
     *            Value of property
186
     */
187
    @Override
188
    public void addProperty(String name, String value) {
189
        properties.put(name, value);
1✔
190
    }
1✔
191

192
    /**
193
     * Return String as is, or "" if null. (Prevents NullPointerExceptions)
194
     *
195
     * @param in
196
     *            the in
197
     *
198
     * @return the string
199
     */
200
    protected static String noNull(String in) {
201
        return in == null ? "" : in;
1!
202
    }
203

204
}
205

206
class PageRequest extends HttpServletRequestWrapper {
207

208
    private String requestURI, method, pathInfo, pathTranslated, queryString, servletPath;
209

210
    public PageRequest(HttpServletRequest request) {
211
        super(request);
×
212
        requestURI = request.getRequestURI();
×
213
        method = request.getMethod();
×
214
        pathInfo = request.getPathInfo();
×
215
        pathTranslated = request.getPathTranslated();
×
216
        queryString = request.getQueryString();
×
217
        servletPath = request.getServletPath();
×
218
    }
×
219

220
    @Override
221
    public String getRequestURI() {
222
        return requestURI;
×
223
    }
224

225
    @Override
226
    public String getMethod() {
227
        return method;
×
228
    }
229

230
    @Override
231
    public String getPathInfo() {
232
        return pathInfo;
×
233
    }
234

235
    @Override
236
    public String getPathTranslated() {
237
        return pathTranslated;
×
238
    }
239

240
    @Override
241
    public String getQueryString() {
242
        return queryString;
×
243
    }
244

245
    @Override
246
    public String getServletPath() {
247
        return servletPath;
×
248
    }
249
}
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