• 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/Factory.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 * Copyright 2011-2026 Hazendaz
4
 */
5
/*
6
 * Title:        Factory
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;
15

16
import com.opensymphony.module.sitemesh.factory.FactoryException;
17
import com.opensymphony.module.sitemesh.util.ClassLoaderUtil;
18
import com.opensymphony.module.sitemesh.util.Container;
19

20
import java.lang.reflect.Constructor;
21
import java.lang.reflect.InvocationTargetException;
22

23
import javax.naming.InitialContext;
24

25
/**
26
 * Factory responsible for creating appropriate instances of implementations. This is specific to a web context and is
27
 * obtained through {@link #getInstance(com.opensymphony.module.sitemesh.Config)}.
28
 * <p>
29
 * The actual Factory method used is determined by the enviroment entry <code>sitemesh.factory</code>. If this doesn't
30
 * exist, it defaults to {@link com.opensymphony.module.sitemesh.factory.DefaultFactory} .
31
 *
32
 * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
33
 */
34
public abstract class Factory implements PageParserSelector {
×
35

36
    /** Web context lookup key. */
37
    private static final String SITEMESH_FACTORY = "sitemesh.factory";
38

39
    /**
40
     * Entry-point for obtaining singleton instance of Factory. The default factory class that will be instantiated can
41
     * be overridden with the environment entry <code>sitemesh.factory</code>.
42
     *
43
     * @param config
44
     *            the config
45
     *
46
     * @return single instance of Factory
47
     */
48
    public static Factory getInstance(Config config) {
49
        Factory instance = (Factory) config.getServletContext().getAttribute(SITEMESH_FACTORY);
×
50
        if (instance == null) {
×
51
            String factoryClass = getEnvEntry("sitemesh.factory",
×
52
                    "com.opensymphony.module.sitemesh.factory.DefaultFactory");
53
            try {
54
                Class<?> cls = ClassLoaderUtil.loadClass(factoryClass, config.getClass());
×
55
                Constructor<?> con = cls.getConstructor(Config.class);
×
56
                instance = (Factory) con.newInstance(config);
×
57
                config.getServletContext().setAttribute(SITEMESH_FACTORY, instance);
×
58
            } catch (InvocationTargetException e) {
×
59
                throw new FactoryException("Cannot construct Factory : " + factoryClass, e.getTargetException());
×
60

61
            } catch (Exception e) {
×
62
                throw new FactoryException("Cannot construct Factory : " + factoryClass, e);
×
63
            }
×
64
        }
65
        instance.refresh();
×
66
        return instance;
×
67
    }
68

69
    /**
70
     * Refresh.
71
     */
72
    public abstract void refresh();
73

74
    /**
75
     * Return instance of DecoratorMapper.
76
     *
77
     * @return the decorator mapper
78
     */
79
    public abstract DecoratorMapper getDecoratorMapper();
80

81
    /**
82
     * Determine whether the given path should be excluded from decoration or not.
83
     *
84
     * @param path
85
     *            the path
86
     *
87
     * @return true, if is path excluded
88
     */
89
    public abstract boolean isPathExcluded(String path);
90

91
    /**
92
     * Find String environment entry, or return default if not found.
93
     *
94
     * @param envEntry
95
     *            the env entry
96
     * @param defaultValue
97
     *            the default value
98
     *
99
     * @return the env entry
100
     */
101
    private static String getEnvEntry(String envEntry, String defaultValue) {
102
        String result = null;
×
103
        try {
104
            if (Container.get() != Container.JRUN) {
×
105
                // TODO: JRun really isn't happy with this
106
                InitialContext ctx = new InitialContext();
×
107
                result = (String) ctx.lookup("java:comp/env/" + envEntry);
×
108
                ctx.close();
×
109
            }
110
        } catch (Exception | NoClassDefFoundError e) {
×
111
            // failed - don't moan, just return default.
112
        }
×
113
        // to deal with restricted class loaders (i.e. on AppEngine).
114
        return result == null || result.trim().length() == 0 ? defaultValue : result;
×
115
    }
116
}
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