• 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

0.0
/src/main/java/com/opensymphony/module/sitemesh/mapper/FileDecoratorMapper.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 * Copyright 2011-2026 Hazendaz
4
 */
5
/*
6
 * Title:        FileDecoratorMapper
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.mapper;
15

16
import com.opensymphony.module.sitemesh.Decorator;
17

18
import jakarta.servlet.http.HttpServletRequest;
19

20
import java.io.File;
21
import java.net.MalformedURLException;
22
import java.net.URL;
23
import java.nio.file.Path;
24

25
/**
26
 * The FileDecoratorMapper will treat the name of the decorator as a file-name to use (in the context of the web-app).
27
 *
28
 * @author <a href="joe@truemesh.com">Joe Walnes</a>
29
 * @author <a href="mike@atlassian.com">Mike Cannon-Brookes</a>
30
 *
31
 * @see com.opensymphony.module.sitemesh.DecoratorMapper
32
 * @see com.opensymphony.module.sitemesh.mapper.DefaultDecorator
33
 */
34
public class FileDecoratorMapper extends AbstractDecoratorMapper {
×
35

36
    /** The path not available. */
37
    private boolean pathNotAvailable = false;
×
38

39
    @Override
40
    public Decorator getNamedDecorator(HttpServletRequest req, String name) {
41
        if (pathNotAvailable || name == null) {
×
42
            return super.getNamedDecorator(req, name);
×
43
        }
44

45
        URL resourcePath;
46

47
        // try to locate the resource (might be an unexpanded WAR)
48
        try {
49
            resourcePath = config.getServletContext().getResource('/' + name);
×
50
        } catch (MalformedURLException e) {
×
51
            return super.getNamedDecorator(req, name);
×
52
        }
×
53

54
        String filePath = config.getServletContext().getRealPath(name);
×
55

56
        if (filePath == null && resourcePath == null) {
×
57
            pathNotAvailable = true;
×
58
            return super.getNamedDecorator(req, name);
×
59
        }
60
        if (filePath != null) { // do we really need this disk file check?!
×
61
            File file = Path.of(filePath).toFile();
×
62

63
            if (file.exists() && file.canRead() && file.isFile()) {
×
64
                // if filename exists with name of supplied decorator, return Decorator
65
                return new DefaultDecorator(name, name, null);
×
66
            } else {
67
                // otherwise delegate to parent mapper.
68
                return super.getNamedDecorator(req, name);
×
69
            }
70
        } else {
71
            // file path is null and resource path is not null - can't check file on disk
72
            return new DefaultDecorator(name, name, null);
×
73
        }
74
    }
75
}
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