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

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

Introduction

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

Prototype

public ParameterParser() 

Source Link

Document

Default ParameterParser constructor.

Usage

From source file:com.softwarementors.extjs.djn.router.processor.standard.form.upload.DiskFileItem2.java

/**
 * Returns the content charset passed by the agent or <code>null</code> if
 * not defined./*from  www  .ja v  a  2s.c o m*/
 *
 * @return The content charset passed by the agent or <code>null</code> if
 *         not defined.
 */
@SuppressWarnings("unchecked")
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:act.data.ApacheMultipartParser.java

/**
 * Retrieves the field name from the <code>Content-disposition</code>
 * header./*from   www  .ja  v a 2  s . c o 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:lc.kra.servlet.FileManagerServlet.java

private String partFileName(Part part) {
    String header, file = null;/*from  w  ww .  j a  va 2s  .  c o m*/
    if ((header = part.getHeader("content-disposition")) != null) {
        String lowerHeader = header.toLowerCase(Locale.ENGLISH);
        if (lowerHeader.startsWith("form-data") || lowerHeader.startsWith("attachment")) {
            ParameterParser parser = new ParameterParser();
            parser.setLowerCaseNames(true);
            Map<String, String> parameters = parser.parse(header, ';');
            if (parameters.containsKey("filename"))
                file = (file = parameters.get("filename")) != null ? file.trim() : "";
        }
    }
    return file;
}

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
 *//*  w  w  w  .  jav  a 2 s. com*/
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.
 *///w w w .  j  a  va 2s  .  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.nordapp.web.util.link.LinkRelation.java

public LinkRelation(String field) throws Exception {

    // find the link target using a regexp
    Matcher m = P.matcher(field);
    if (!m.matches()) {
        throw new Exception("illegal Link header field value:" + field);
    }//from  ww  w  .  j av a  2  s .  com

    target = m.group(1);

    // pass the remainder to the generic parameter parser
    parameters = new ParameterParser().parse(m.group(2), ';');

}

From source file:org.nordapp.web.util.StateReader.java

/**
 * Parses a line that defines an applications RESTful state.
 * /*from w w  w  .  j a  v  a  2  s  .c  o  m*/
 * @param line The line to be parsed
 * @return The parsed line with the field-value pairs as elements of a map
 */
public Map<String, String> parseLine(String line) {

    Map<String, String> parameters = null;
    parameters = new ParameterParser().parse(line, ';');

    return parameters;
}

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

private String getFileName(String pContentDisposition) {
    String fileName = null;/*from  w ww  . j  a v a  2 s. c o  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;
}