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:com.orchestra.portale.utils.InsertUtils.java

public static String delimg(HttpServletRequest request, String id, String nameimg) {
    String esito = "";
    HttpSession session = request.getSession();
    ServletContext sc = session.getServletContext();
    File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "poi" + File.separator + "img"
            + File.separator + id);

    File img = new File(dir.getAbsolutePath() + File.separator + nameimg);
    if (img.delete())
        esito = "OK";
    else/*from   www. j a va2 s . c o m*/
        esito = "ERRORE";

    return esito;
}

From source file:org.nuxeo.ecm.web.embedded.NuxeoEmbeddedLoader.java

protected static FrameworkBootstrap loadRuntime(ServletContext context) {
    String warFile = context.getRealPath("");
    String root = context.getInitParameter("nxhome");
    if (root == null) {
        root = "";
    }/* w w w  . j  a va2  s .  c o m*/
    File appRoot = null;
    if (root.startsWith("/")) {
        appRoot = new File(root);
    } else {
        appRoot = new File(warFile + "/" + root);
    }
    root = appRoot.getAbsolutePath();

    FrameworkBootstrap fb;
    try {
        fb = new FrameworkBootstrap(NuxeoFilter.class.getClassLoader(), appRoot);
        fb.initialize();
        fb.start();
    } catch (Exception e) {
        throw new Error("Cannot load embedded server", e);
    }
    return fb;
}

From source file:org.apache.wookie.server.Diagnostics.java

/**
 * Run the diagnostic tests//from   w w w .j av  a  2s .c o m
 * @param context
 * @param configuration
 */
public static void run(ServletContext context, Configuration configuration) {
    final File UPLOADFOLDER = new File(context.getRealPath(configuration.getString("widget.useruploadfolder")));
    checkFolder("Upload", UPLOADFOLDER);
    final File WIDGETFOLDER = new File(context.getRealPath(configuration.getString("widget.widgetfolder")));
    checkFolder("Widget", WIDGETFOLDER);
    final File DEPLOYFOLDER = new File(WidgetPackageUtils
            .convertPathToPlatform(context.getRealPath(configuration.getString("widget.deployfolder"))));
    checkFolder("Deploy", DEPLOYFOLDER);
}

From source file:ostepu.file.fileCache.java

/**
 * entfernt alle gespeicherten Dateien/*from w w w .j  av a  2  s  .  c  o m*/
 *
 * @param context der Kontext des Servlet
 */
public static void cleanCache(ServletContext context) {
    File folder = new File(context.getRealPath("/cache"));
    if (folder.exists() && folder.isDirectory()) {
        try {
            FileUtils.deleteDirectory(folder);
        } catch (IOException ex) {
            Logger.getLogger(fileCache.class.getName()).log(Level.SEVERE, null, ex);
            // wenn es nicht gelscht werden kann, dann kann ich es auch
            // nicht ndern
            return;
        }
    }
}

From source file:org.sonar.server.platform.ServerSettings.java

static File getDeployDir(ServletContext servletContext) {
    String dirname = servletContext.getRealPath("/deploy/");
    if (dirname == null) {
        throw new IllegalArgumentException("Web app directory not found : /deploy/");
    }/*from  w w  w. ja v a2 s .  c  o  m*/
    File dir = new File(dirname);
    if (!dir.exists()) {
        throw new IllegalArgumentException("Web app directory does not exist: " + dir);
    }
    return dir;
}

From source file:com.ikon.util.WarUtils.java

/**
 * //w  ww.ja v  a  2s . co m
 */
public static synchronized void readAppVersion(ServletContext sc) {
    String appServerHome = sc.getRealPath("/");
    File manifestFile = new File(appServerHome, "META-INF/MANIFEST.MF");
    FileInputStream fis = null;

    try {
        fis = new FileInputStream(manifestFile);
        Manifest mf = new Manifest();
        mf.read(fis);
        Attributes atts = mf.getMainAttributes();
        String impVersion = atts.getValue("Implementation-Version");
        String impBuild = atts.getValue("Implementation-Build");
        log.info("Implementation-Version: " + impVersion);
        log.info("Implementation-Build: " + impBuild);

        if (impVersion != null) {
            String[] version = impVersion.split("\\.");

            if (version.length > 0 && version[0] != null) {
                appVersion.setMajor(version[0]);
            }

            if (version.length > 1 && version[1] != null) {
                appVersion.setMinor(version[1]);
            }

            if (version.length > 2 && version[2] != null && !version[2].equals("")) {
                appVersion.setMaintenance(version[2]);
            }
        }

        if (impBuild != null) {
            appVersion.setBuild(impBuild);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(fis);
    }
}

From source file:org.oscarehr.admin.traceability.GenerateTraceabilityUtil.java

public static Map<String, String> buildTraceMap(HttpServletRequest request) throws Exception {
    Map<String, String> traceMap = new HashMap<String, String>();
    HttpSession session = request.getSession();
    ServletContext servletContext = session.getServletContext();
    String realPath = servletContext.getRealPath("/");
    Iterator<File> iterator = FileUtils.iterateFiles(new File(realPath), null, true);
    while (iterator.hasNext()) {
        File f_ = iterator.next();
        FileInputStream fi_ = new FileInputStream(f_);
        String path = f_.getAbsolutePath();
        path = path.replace(realPath, "");
        traceMap.put(path, DigestUtils.sha256Hex(fi_));
        fi_.close();//from w  w  w. j a va  2  s.c o m
    }

    return traceMap;
}

From source file:org.mobicents.servlet.sip.restcomm.Bootstrapper.java

private static String getRestCommPath(final ServletConfig config) {
    final ServletContext context = config.getServletContext();
    final String path = context.getRealPath("/");
    if (path.endsWith("/")) {
        return path.substring(0, path.length() - 1);
    } else {/*  w w w  .  j  av  a 2 s. c o  m*/
        return path;
    }
}

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

/**
 * @return e.g. /Workspace/iNeunet/ioo/src/main/webapp
 *//*ww  w .  j av  a  2s.  c  o  m*/
public static String getRootPath() {
    if (rootPath == null) {
        WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
        if (webApplicationContext == null) {
            rootPath = System.getProperty(WebUtils.DEFAULT_WEB_APP_ROOT_KEY);
        } else {
            ServletContext servletContext = webApplicationContext.getServletContext();
            rootPath = servletContext.getRealPath("/");
        }
    }
    return rootPath;
}

From source file:edu.temple.cis3238.wiki.utils.FileUtils.java

/**
* Creates directories and subdirs for specified file.
* @param context servlet//  www  .  j  a va  2 s. c o m
* @param uploadDirectory [basepath]/uploads/[TopicID]/[FILENAME]
* @param topic topicVO
* @return Absolute path
* @see edu.temple.cis3238.wiki.ui.servlets.UploadServlet
*/
public static String makeDir(ServletContext context, String uploadDirectory, TopicVO topic) {
    try {
        String uploadPath = context.getRealPath("") + File.separator + uploadDirectory + File.separator
                + topic.getTopicID();

        // creates the directory if it does not exist
        File uploadDir = new File(uploadPath);
        if (!uploadDir.exists()) {
            uploadDir.mkdirs();
        }
        return uploadPath;
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }

}