Example usage for javax.servlet.http Part getHeader

List of usage examples for javax.servlet.http Part getHeader

Introduction

In this page you can find the example usage for javax.servlet.http Part getHeader.

Prototype

public String getHeader(String name);

Source Link

Document

Returns the value of the specified mime header as a String.

Usage

From source file:de.unirostock.sems.cbarchive.web.Tools.java

/**
 * Extract file name.//from w w  w  . ja  v a 2 s  .  com
 *
 * @param part the part
 * @return the string
 */
public static final String extractFileName(Part part) {
    if (part != null) {
        String header = part.getHeader("content-disposition");
        if (header != null) {
            LOGGER.debug("content-disposition not null: ", header);
            String[] items = header.split(";");
            for (String s : items) {
                LOGGER.debug("current disposition: ", s);
                if (s.trim().startsWith("filename"))
                    return s.substring(s.indexOf("=") + 2, s.length() - 1);
            }
        }
    } else
        LOGGER.debug("file part seems to be null -> cannot extract file name.");
    return "UploadedFile-" + DATE_FORMATTER.format(new Date());
}

From source file:com.vigglet.oei.technician.UploadProfilePhoto.java

protected String extractFileName(Part part) {
    String contentDisp = part.getHeader("content-disposition");
    String[] items = contentDisp.split(";");
    for (String s : items) {
        if (s.trim().startsWith("filename")) {
            return s.substring(s.indexOf("=") + 2, s.length() - 1);
        }//www.  j  a  va2  s . c  o m
    }
    return "";
}

From source file:algorithm.laddress.java

private String getFileName(final Part part) {
    final String partHeader = part.getHeader("content-disposition");
    LOGGER.log(Level.INFO, "Part Header = {0}", partHeader);
    for (String content : part.getHeader("content-disposition").split(";")) {
        if (content.trim().startsWith("filename")) {
            return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");
        }/*  w w w . j a v a2  s .c  om*/
    }
    return null;
}

From source file:VideoTestServlet.java

private String getFileName(final Part part) {
    final String partHeader = part.getHeader("content-disposition");
    for (String content : part.getHeader("content-disposition").split(";")) {
        if (content.trim().startsWith("filename")) {
            return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");
        }//  w  ww .  ja v  a  2 s  .co m
    }
    return null;
}

From source file:com.orangeandbronze.jblubble.sample.UploadServlet.java

private String getFileName(Part part) {
    for (String cd : part.getHeader("content-disposition").split(";")) {
        if (cd.trim().startsWith("filename")) {
            return cd.substring(cd.indexOf('=') + 1).trim().replace("\"", "");
        }/* ww w. jav a 2 s  . c  o m*/
    }
    return null;
}

From source file:com.shoylpik.controller.AddProduct.java

private String getFileName(Part part) {
    String contentDisp = part.getHeader("content-disposition");
    System.out.println("content-disposition header= " + contentDisp);
    String[] tokens = contentDisp.split(";");
    for (String token : tokens) {
        if (token.trim().startsWith("IPimage")) {
            return token.substring(token.indexOf("=") + 2, token.length() - 1);
        }//from w  w w.ja  v a2  s .  c o  m
    }
    return "";
}

From source file:marketDB.add_db.java

private String getFileName(final Part part) {
    final String partHeader = part.getHeader("content-disposition");

    for (String content : part.getHeader("content-disposition").split(";")) {
        if (content.trim().startsWith("filename")) {
            return content.substring(content.indexOf('=') + 1).trim().replace("\"", "");
        }//  w w  w .  j  a v  a  2s. c  o  m
    }
    return null;
}

From source file:com.rubinefocus.admin.servlet.UploadServlet.java

private String extractFileName(Part part) {
    String contentDisp = part.getHeader("content-disposition");
    String[] items = contentDisp.split(";");
    for (String s : items) {
        if (s.trim().startsWith("filename")) {
            return s.substring(s.indexOf("=") + 2, s.length() - 1);
        }//from w  ww  .j av a 2 s .c  o  m
    }
    return "";
}

From source file:org.apache.wicket.protocol.http.servlet.ServletPartFileItem.java

private String getFileName(Part part) {
    String contentDisposition = part.getHeader(AbstractResource.CONTENT_DISPOSITION_HEADER_NAME);
    for (String cd : Strings.split(contentDisposition, ';')) {
        if (cd.trim().startsWith("filename")) {
            return cd.substring(cd.indexOf('=') + 1).trim().replace("\"", "");
        }/*  w  w  w . jav  a 2 s  .  co m*/
    }
    return null;
}

From source file:controller.servlet.ImportAmenities.java

/**
* Obtenemos el nombre del fichero que se almacena en la parte que nos pasan por parametro
* 
* @param part Parte del formulario//w w w. ja v a 2  s .  c om
* @return string Nombre del fichero o nullo si no se encuentra el nombre
*/
private String obtenerNombreFichero(Part part) {
    String cabecera = part.getHeader("content-disposition");
    for (String cd : cabecera.split(";")) {
        if (cd.trim().startsWith("filename")) {
            return cd.substring(cd.indexOf('=') + 1).trim().replace("\"", "");
        }
    }
    return null;
}