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:ostepu.file.fileCache.java

/**
 * liefert den lokalen Pfad einer Datei//from   w w w .  ja  va 2s .  co m
 *
 * @param context der Kontext des Servlet
 * @param URL     der Pfad/URL der Datei, fr den Namen
 * @return der Pfad (oder null, wenn sie nicht existert)
 */
public static String getCachedFilePath(ServletContext context, String URL) {
    // liefert einen lokalen Pfad oder null
    String fileHash = DigestUtils.sha512Hex(URL);
    String localFile = context.getRealPath("/cache/" + fileHash);

    try {
        if (Files.exists(Paths.get(localFile))) {
            return localFile;
        }
    } catch (Exception e) {
        // Datei konnte nicht gefunden werden
        return null;
    }
    // Datei konnte nicht gefunden werden
    return null;
}

From source file:com.ineunet.knife.upload.WebPaths.java

public static void init(ServletContext servletContext) {
    if (servletContext == null) {
        return;/*from  w w  w .  j  a va2  s. co m*/
    }
    if (inited)
        return;
    // init rootPath
    rootPath = servletContext.getRealPath("/");
}

From source file:edu.cornell.mannlib.vitro.webapp.auth.identifier.common.IsBlacklisted.java

/**
 * Runs through .sparql files in the BLACKLIST_SPARQL_DIR.
 * /*from w ww . j  av a 2  s.c  om*/
 * The first that returns one or more rows will be cause the user to be
 * blacklisted.
 * 
 * The first variable from the first solution set will be returned.
 */
private static String checkForBlacklisted(Individual ind, ServletContext context) {
    String realPath = context.getRealPath(BLACKLIST_SPARQL_DIR);
    File blacklistDir = new File(realPath);
    if (!blacklistDir.isDirectory() || !blacklistDir.canRead()) {
        log.debug("cannot read blacklist directory " + realPath);
        return NOT_BLACKLISTED;
    }

    log.debug("checking directlry " + realPath + " for blacklisting sparql query files");
    File[] files = blacklistDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".sparql");
        }
    });

    String reasonForBlacklist = NOT_BLACKLISTED;
    for (File file : files) {
        try {
            reasonForBlacklist = runSparqlFileForBlacklist(file, ind, context);
            if (reasonForBlacklist != NOT_BLACKLISTED)
                break;
        } catch (RuntimeException ex) {
            log.error("Could not run blacklist check query for file " + file.getAbsolutePath()
                    + File.separatorChar + file.getName(), ex);
        }
    }
    return reasonForBlacklist;
}

From source file:och.front.web.FrontAppProvider.java

private static FrontApp createApp(ServletContext servletContext) throws Exception {

    Props props = directProps;// w  ww .j av a2  s. com

    //from file and net
    if (props == null) {
        String webInfPath = servletContext.getRealPath("./WEB-INF");

        String configPath = System.getProperty("och.chat.propsDir");
        if (configPath == null) {
            configPath = webInfPath;
        }

        Props startProps = createProps(configPath + "/front.properties", webInfPath);
        if (System.getProperty("och.skipNetProps") != null) {
            props = startProps;
        } else {

            NetPropsClient netPropsClient = new NetPropsClient(startProps.getStrVal(netProps_front_host),
                    startProps.getIntVal(netProps_front_port), startProps.getStrVal(netProps_front_secureKey),
                    startProps.getBoolVal(netPropsClient_waitConnect),
                    startProps.getLongVal(netPropsClient_updateTime));

            addUpdateSecureKeyListener(startProps, netPropsClient, netProps_front_secureKey);

            Props netProps = netPropsClient.getProps();

            props = new MultiProps(startProps, netProps);
        }
    }

    return FrontApp.create(props, servletContext);
}

From source file:com.sifcoapp.report.util.ReportConfigUtil.java

public static String getJasperFilePath(ServletContext context, String compileDir, String jasperFile) {
    return context.getRealPath(compileDir + jasperFile);
}

From source file:com.intbit.util.ServletUtil.java

public static String getServerName(ServletContext context) {
    try {/* ww w. ja  va  2s  .  c o  m*/
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        String path = context.getRealPath("") + "/js/configurations.js";
        // read script file
        engine.eval(Files.newBufferedReader(Paths.get(path), StandardCharsets.UTF_8));

        Invocable inv = (Invocable) engine;
        // call function from script file
        return inv.invokeFunction("getHost", "").toString();
    } catch (Exception ex) {
        return "http://clients.brndbot.com/BrndBot/";
    }
}

From source file:nl.b3p.catalog.arcgis.ArcObjectsSynchronizerForker.java

private static String buildClasspath(ServletContext context) {
    StringBuilder cp = new StringBuilder();
    cp.append("classes");

    File lib = new File(context.getRealPath("/WEB-INF/lib"));
    File[] jarFiles = lib.listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".jar");
        }/*from www  .ja va2  s. c  o m*/
    });

    for (File f : jarFiles) {
        cp.append(File.pathSeparator);
        cp.append("lib");
        cp.append(File.separatorChar);
        cp.append(f.getName());
    }
    return cp.toString();
}

From source file:org.giavacms.base.common.util.ResourceUtils.java

public static String getRealPath() {
    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();//  w  w w .  j  av a 2  s .c  o m
    String folder = servletContext.getRealPath("") + File.separator;
    return folder;
}

From source file:org.apache.hawq.pxf.service.utilities.Log4jConfigure.java

/**
 * Initializes log4j logging for the webapp.
 *
 * Reads log4j properties file location from log4jConfigLocation parameter
 * in web.xml. When not using aboslute path, the path starts from the webapp
 * root directory. If the file can't be read, reverts to default
 * configuration file under WEB-INF/classes/pxf-log4j.properties.
 *
 * @param event Servlet context, used to determine webapp root directory.
 *//*from w  w w. ja va2s .c om*/
public static void configure(ServletContextEvent event) {

    final String defaultLog4jLocation = "WEB-INF/classes/pxf-log4j.properties";

    ServletContext context = event.getServletContext();
    String log4jConfigLocation = context.getInitParameter("log4jConfigLocation");

    if (!log4jConfigLocation.startsWith(File.separator)) {
        log4jConfigLocation = context.getRealPath("") + File.separator + log4jConfigLocation;
    }

    // revert to default properties file if file doesn't exist
    File log4jConfigFile = new File(log4jConfigLocation);
    if (!log4jConfigFile.canRead()) {
        log4jConfigLocation = context.getRealPath("") + File.separator + defaultLog4jLocation;
    }
    PropertyConfigurator.configure(log4jConfigLocation);
    LOG.info("log4jConfigLocation = " + log4jConfigLocation);
}

From source file:com.sifcoapp.report.util.ReportConfigUtil.java

/**
 * PRIVATE METHODS/* ww  w .  j a  v  a2  s  .  c o  m*/
 */
private static void setCompileTempDir(ServletContext context, String uri) {
    System.setProperty("jasper.reports.compile.temp", context.getRealPath(uri));
}