Example usage for org.apache.commons.fileupload ParameterParser setLowerCaseNames

List of usage examples for org.apache.commons.fileupload ParameterParser setLowerCaseNames

Introduction

In this page you can find the example usage for org.apache.commons.fileupload ParameterParser setLowerCaseNames.

Prototype

public void setLowerCaseNames(boolean b) 

Source Link

Document

Sets the flag if parameter names are to be converted to lower case when name/value pairs are parsed.

Usage

From source file:act.data.ApacheMultipartParser.java

/**
 * Retrieves the boundary from the <code>Content-type</code> header.
 *
 * @param contentType The value of the content type header from which to extract the
 *                    boundary value./*  w w  w  .  j  a v  a2  s .c o m*/
 * @return The boundary, as a byte array.
 */
private byte[] getBoundary(String contentType) {

    ParameterParser parser = new ParameterParser();
    parser.setLowerCaseNames(true);
    // Parameter parser can handle null input
    Map params = parser.parse(contentType, ';');
    String boundaryStr = (String) params.get("boundary");

    if (boundaryStr == null) {
        return null;
    }
    byte[] boundary;
    try {
        boundary = boundaryStr.getBytes("ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        boundary = boundaryStr.getBytes();
    }
    return boundary;
}

From source file:act.data.ApacheMultipartParser.java

/**
 * Retrieves the field name from the <code>Content-disposition</code>
 * header.// www .  j av  a 2s . co  m
 *
 * @param headers A <code>Map</code> containing the HTTP request headers.
 * @return The field name for the current <code>encapsulation</code>.
 */
private String getFieldName(Map /* String, String */ headers) {
    String fieldName = null;
    String cd = getHeader(headers, CONTENT_DISPOSITION);
    if (cd != null && cd.toLowerCase().startsWith(FORM_DATA)) {

        ParameterParser parser = new ParameterParser();
        parser.setLowerCaseNames(true);
        // Parameter parser can handle null input
        Map params = parser.parse(cd, ';');
        fieldName = (String) params.get("name");
        if (fieldName != null) {
            fieldName = fieldName.trim();
        }
    }
    return fieldName;
}

From source file:act.data.ApacheMultipartParser.java

/**
 * Retrieves the file name from the <code>Content-disposition</code>
 * header.//from   w  w  w.  ja  va  2 s  . c  om
 *
 * @param headers A <code>Map</code> containing the HTTP request headers.
 * @return The file name for the current <code>encapsulation</code>.
 */
private String getFileName(Map /* String, String */ headers) {
    String fileName = null;
    String cd = getHeader(headers, CONTENT_DISPOSITION);
    if (cd != null) {
        String cdl = cd.toLowerCase();
        if (cdl.startsWith(FORM_DATA) || cdl.startsWith(ATTACHMENT)) {
            ParameterParser parser = new ParameterParser();
            parser.setLowerCaseNames(true);
            // Parameter parser can handle null input
            Map params = parser.parse(cd, ';');
            if (params.containsKey("filename")) {
                fileName = (String) params.get("filename");
                if (fileName != null) {
                    fileName = fileName.trim();
                    // IE7 returning fullpath name (#300920)
                    if (fileName.indexOf('\\') != -1) {
                        fileName = fileName.substring(fileName.lastIndexOf('\\') + 1);
                    }

                } else {
                    // Even if there is no value, the parameter is present,
                    // so we return an empty file name rather than no file
                    // name.
                    fileName = "";
                }
            }
        }
    }
    return fileName;
}

From source file:org.apache.click.extras.gae.MemoryFileItem.java

/**
 * Returns the content charset passed by the agent or null if not defined.
 *
 * @return The content charset passed by the agent or null if not defined
 *//*from  w  w  w .  j ava  2 s .co  m*/
public String getCharSet() {
    ParameterParser parser = new ParameterParser();
    parser.setLowerCaseNames(true);
    // Parameter parser can handle null input
    Map<?, ?> params = parser.parse(getContentType(), ';');
    return (String) params.get("charset");
}

From source file:org.httpobjects.multipart.ApacheCommonsMultipartReader.java

/**
 * Retrieves the boundary from the <code>Content-type</code> header.
 *
 * @param contentTypeHeaderValue The value of the content type header from which to
 *                    extract the boundary value.
 *
 * @return The boundary, as a byte array.
 *///ww  w  .j a v a2s  .c o m
protected byte[] getBoundary(String contentTypeHeaderValue) {
    ParameterParser parser = new ParameterParser();
    parser.setLowerCaseNames(true);
    // Parameter parser can handle null input
    Map<String, String> params = parser.parse(contentTypeHeaderValue, ';');
    String boundaryStr = params.get("boundary");

    if (boundaryStr == null) {
        return null;
    }
    byte[] boundary;
    try {
        boundary = boundaryStr.getBytes("ISO-8859-1");
    } catch (UnsupportedEncodingException e) {
        boundary = boundaryStr.getBytes();
    }
    return boundary;
}

From source file:org.tinygroup.weblayer.webcontext.parser.impl.ServletFileUpload.java

private String getFileName(String pContentDisposition) {
    String fileName = null;/*  ww  w. j  a va 2 s  .co m*/

    if (pContentDisposition != null) {
        String cdl = pContentDisposition.toLowerCase();

        if (cdl.startsWith(FORM_DATA) || cdl.startsWith(ATTACHMENT)) {
            ParameterParser parser = new ParameterParser();
            parser.setLowerCaseNames(true);

            // Parameter parser can handle null input
            @SuppressWarnings("unchecked")
            Map<String, String> params = parser.parse(pContentDisposition, ';');

            // Flashfilename  fname ?
            boolean isFileFiled = false;
            for (String key : getFileNameKey()) {
                if (params.containsKey(key)) {
                    isFileFiled = true;
                }
                fileName = StringUtil.trimToNull(params.get(key));

                if (fileName != null) {
                    break;
                }
            }
            if (isFileFiled && fileName == null) {
                // Even if there is no value, the parameter is present,
                // so we return an empty file name rather than no file
                fileName = "";
            }
        }
    }

    return fileName;
}