private String getSlingHome()

in src/main/java/org/apache/sling/launchpad/webapp/SlingServlet.java [419:476]


    private String getSlingHome(HttpServletRequest request) {

        String source = null;

        // access config and context to be able to log the sling.home source

        // 1. servlet config parameter
        String slingHome = getServletConfig().getInitParameter(
            SharedConstants.SLING_HOME);
        if (slingHome != null) {

            source = "servlet parameter sling.home";

        } else {

            // 2. servlet context parameter
            slingHome = getServletContext().getInitParameter(
                SharedConstants.SLING_HOME);
            if (slingHome != null) {

                source = "servlet context parameter sling.home";

            } else {

                // 3. servlet context path (Servlet API 2.5 and later)
                try {

                    String contextPath = getServletContext().getContextPath();
                    slingHome = toSlingHome(contextPath);
                    source = "servlet context path";

                } catch (NoSuchMethodError nsme) {

                    // 4.servlet context path (Servlet API 2.4 and earlier)
                    if (request != null) {

                        String contextPath = request.getContextPath();
                        slingHome = toSlingHome(contextPath);
                        source = "servlet context path (from request)";

                    } else {

                        log("ServletContext path not available here, delaying startup until first request");
                        return null;

                    }
                }

            }
        }

        // substitute any ${...} references and make absolute
        slingHome = Util.substVars(slingHome, SharedConstants.SLING_HOME, null, properties);
        slingHome = new File(slingHome).getAbsolutePath();

        log("Setting sling.home=" + slingHome + " (" + source + ")");
        return slingHome;
    }