Example usage for javax.servlet ServletContext getRealPath

List of usage examples for javax.servlet ServletContext getRealPath

Introduction

In this page you can find the example usage for javax.servlet ServletContext getRealPath.

Prototype

public String getRealPath(String path);

Source Link

Document

Gets the real path corresponding to the given virtual path.

Usage

From source file:net.ontopia.topicmaps.webed.impl.utils.TagUtils.java

protected static VelocityEngine getVelocityEngine(ServletContext scontext) {
    VelocityEngine vengine = (VelocityEngine) scontext.getAttribute(Constants.SCTXT_VELOCITY_ENGINE);

    if (vengine == null) {

        // create a new velocity engine
        vengine = new VelocityEngine();

        // --- try to get properties from an own file
        String relPath = scontext.getInitParameter(Constants.SCTXT_VELOPROPS_PATH);
        if (relPath != null) {
            String velocityPropPath = scontext.getRealPath(relPath);
            log.info("Initialising velocity from property file: " + velocityPropPath);
            // load in properties
            Properties props = new Properties();
            try {
                props.load(new java.io.FileInputStream(velocityPropPath));
            } catch (java.io.IOException ioe) {
                throw new OntopiaRuntimeException(ioe);
            }//from  w w  w  .java  2  s .  c  o  m
            // pre-cat the real directory
            String path = props.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH, null);
            if (path != null) {
                path = scontext.getRealPath(path);
                props.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
            } else {
                // no directory set, use default loader (classpath) for default templates
                props.setProperty("resource.loader", "class");
                props.setProperty("class.resource.loader.class",
                        "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
                props.setProperty("class.resource.loader.cache", "true");
            }
            try {
                vengine.init(props);
            } catch (Exception e) {
                throw new OntopiaRuntimeException(e);
            }
        } else {
            log.info("Initializing velocity with default properties.");
            // use class resource loaders
            Properties props = new Properties();
            props.setProperty("resource.loader", "class");
            props.setProperty("class.resource.loader.class",
                    "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
            props.setProperty("class.resource.loader.cache", "true");
            // use log4j logging system
            props.setProperty("runtime.log.system", "org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
            props.setProperty("runtime.log.logsystem.log4j.category", "net.ontopia.velocity");
            props.setProperty("runtime.log", "velocity.log");
            try {
                vengine.init(props);
            } catch (Exception e) {
                throw new OntopiaRuntimeException(e);
            }
        }

        // add velocity engine to servlet context
        scontext.setAttribute(Constants.SCTXT_VELOCITY_ENGINE, vengine);
    }
    return vengine;
}

From source file:com.orchestra.portale.controller.CheckController.java

@RequestMapping("/check")
public ModelAndView check(HttpServletRequest request) {
    HttpSession session = request.getSession();
    ServletContext sc = session.getServletContext();
    File f = new File(sc.getRealPath("/"));
    ModelAndView model = new ModelAndView("check");
    model.addObject("mess",
            f.getParentFile().getParentFile().getParentFile().getPath() + File.separator + "BackupImg");
    return model;
}

From source file:org.openmrs.module.mapperoverridedemo.overrideadminlogo.CopyLegacyUiContentToWebInf.java

@Override
public void setServletContext(ServletContext servletContext) {

    String basePath = servletContext.getRealPath("");

    try {//from   ww  w.  j  a  v a2s .  c o  m

        //copy images
        File destDir = new File(basePath + "/images".replace("/", File.separator));
        File srcDir = new File(basePath + MODULE_ROOT_DIR + "/resources/images".replace("/", File.separator));
        FileUtils.copyDirectory(srcDir, destDir);

    } catch (IOException ex) {
        log.error("Failed to copy legacy ui files", ex);
    }
}

From source file:org.openmrs.module.web.WebModuleUtil.java

public static String getRealPath(ServletContext servletContext) {
    return servletContext.getRealPath("");
}

From source file:ContextLogger.java

public void contextInitialized(ServletContextEvent sce) {

    ServletContext context = sce.getServletContext();

    String realPath = context.getRealPath("/");
    String fileSep = System.getProperty("file.separator");

    if (realPath != null && (!realPath.endsWith(fileSep)))
        realPath = realPath + fileSep;//from  w ww.ja v  a  2 s.c  o  m
    //Initialize logger here:
    PropertyConfigurator.configure(realPath + "WEB-INF/classes/" + context.getInitParameter("logger-config"));
    log = Logger.getLogger(ContextLogger.class);

    String name = context.getServletContextName();
    //log request about servlet context being initialized
    log.info("ServletContext ready: " + (name == null ? "" : name));

}

From source file:com.tacitknowledge.util.migration.jdbc.spring.SpringAutoPatchService.java

/**
 * @see ServletContextAware#setServletContext(ServletContext)
 *///from   ww w  .ja  v  a 2  s.  c  o m
public void setServletContext(ServletContext context) {
    ClassDiscoveryUtil.addResourceListSource(new WebAppResourceListSource(context.getRealPath("/WEB-INF")));
}

From source file:main.server.ClassFinder.java

public ClassFinder(ServletContext sc, String pkg) {
    File classesDir = new File(sc.getRealPath("WEB-INF/classes"));
    classesPath = classesDir.getAbsolutePath();
    pkgDir = new File(classesDir, pkg.replace('.', '/'));
}

From source file:ca.simplegames.micro.MicroFilter.java

@Override
public Object init(Object config) throws Exception {
    FilterConfig filterConfig = (FilterConfig) config;
    ServletContext servletContext = filterConfig.getServletContext();

    micro = new Micro(servletContext.getRealPath("/"), servletContext,
            StringUtils.defaultString(((FilterConfig) config).getInitParameter("userClassPaths")));

    return this;
}

From source file:org.tangram.view.AbstractInternalResourceTemplateResolver.java

@Inject
public void setServletContext(ServletContext servletContext) {
    filePathPrefix = servletContext.getRealPath("");
}

From source file:com.wavemaker.spinup.web.VersionProvider.java

public String getVersion(ServletContext servletContext) throws IOException {
    String uploadDirName = servletContext.getRealPath(SpinupConstants.STUDIOD_UPLOAD_DIR);
    if (studioVersion != null) {
        return this.studioVersion;
    }/* w  ww  . j  a  v  a2 s  .c o m*/
    ZipArchive studioZip = new ZipArchive(new LocalFolder(uploadDirName).getFile(SpinupConstants.STUDIO_FILE));
    InputStream configjs = studioZip.getFile("app/config.js").getContent().asInputStream();
    Scanner s = new Scanner(configjs);
    while (s.hasNext()) {
        String ln = s.nextLine();
        if (ln.contains("studioVersion:")) {
            this.studioVersion = ln.substring(ln.indexOf(":") + 1).replace(",", "").replace("'", "").trim();
            break;
        }
    }
    if (log.isInfoEnabled()) {
        log.info("*** Studio version is: " + this.studioVersion + "***");
    }
    configjs.close();
    return this.studioVersion;

}