Java Code Examples for org.apache.tomcat.util.http.fileupload.ParameterParser#parse()

The following examples show how to use org.apache.tomcat.util.http.fileupload.ParameterParser#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLManagerServlet.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private String extractFilename(String cd) {
    String fileName = null;
    if (cd != null) {
        String cdl = cd.toLowerCase(Locale.ENGLISH);
        if (cdl.startsWith("form-data") || cdl.startsWith("attachment")) {
            ParameterParser parser = new ParameterParser();
            parser.setLowerCaseNames(true);
            // Parameter parser can handle null input
            Map<String,String> params =
                parser.parse(cd, ';');
            if (params.containsKey("filename")) {
                fileName = params.get("filename");
                if (fileName != null) {
                    fileName = fileName.trim();
                } 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;
}
 
Example 2
Source File: HTMLManagerServlet.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private String extractFilename(String cd) {
    String fileName = null;
    if (cd != null) {
        String cdl = cd.toLowerCase(Locale.ENGLISH);
        if (cdl.startsWith("form-data") || cdl.startsWith("attachment")) {
            ParameterParser parser = new ParameterParser();
            parser.setLowerCaseNames(true);
            // Parameter parser can handle null input
            Map<String,String> params =
                parser.parse(cd, ';');
            if (params.containsKey("filename")) {
                fileName = params.get("filename");
                if (fileName != null) {
                    fileName = fileName.trim();
                } 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;
}
 
Example 3
Source File: ApplicationPart.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public String getSubmittedFileName() {
    String fileName = null;
    String cd = getHeader("Content-Disposition");
    if (cd != null) {
        String cdl = cd.toLowerCase(Locale.ENGLISH);
        if (cdl.startsWith("form-data") || cdl.startsWith("attachment")) {
            ParameterParser paramParser = new ParameterParser();
            paramParser.setLowerCaseNames(true);
            // Parameter parser can handle null input
            Map<String,String> params = paramParser.parse(cd, ';');
            if (params.containsKey("filename")) {
                fileName = params.get("filename");
                // The parser will remove surrounding '"' but will not
                // unquote any \x sequences.
                if (fileName != null) {
                    // RFC 6266. This is either a token or a quoted-string
                    if (fileName.indexOf('\\') > -1) {
                        // This is a quoted-string
                        fileName = HttpParser.unquote(fileName.trim());
                    } else {
                        // This is a token
                        fileName = fileName.trim();
                    }
                } 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;
}
 
Example 4
Source File: DiskFileItem.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Returns the content charset passed by the agent or <code>null</code> if
 * not defined.
 *
 * @return The content charset passed by the agent or <code>null</code> if
 *         not defined.
 */
public String getCharSet() {
    ParameterParser parser = new ParameterParser();
    parser.setLowerCaseNames(true);
    // Parameter parser can handle null input
    Map<String, String> params = parser.parse(getContentType(), ';');
    return params.get("charset");
}
 
Example 5
Source File: ApplicationPart.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Adapted from FileUploadBase.getFileName(). Method name chosen to be
 * consistent with Servlet 3.1.
 */
public String getSubmittedFileName() {
    String fileName = null;
    String cd = getHeader("Content-Disposition");
    if (cd != null) {
        String cdl = cd.toLowerCase(Locale.ENGLISH);
        if (cdl.startsWith("form-data") || cdl.startsWith("attachment")) {
            ParameterParser paramParser = new ParameterParser();
            paramParser.setLowerCaseNames(true);
            // Parameter parser can handle null input
            Map<String,String> params =
                paramParser.parse(cd, ';');
            if (params.containsKey("filename")) {
                fileName = params.get("filename");
                if (fileName != null) {
                    fileName = fileName.trim();
                } 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;
}
 
Example 6
Source File: DiskFileItem.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the content charset passed by the agent or <code>null</code> if
 * not defined.
 *
 * @return The content charset passed by the agent or <code>null</code> if
 *         not defined.
 */
public String getCharSet() {
    ParameterParser parser = new ParameterParser();
    parser.setLowerCaseNames(true);
    // Parameter parser can handle null input
    Map<String,String> params = parser.parse(getContentType(), ';');
    return params.get("charset");
}
 
Example 7
Source File: ApplicationPart.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Adapted from FileUploadBase.getFileName(). Method name chosen to be
 * consistent with Servlet 3.1.
 */
public String getSubmittedFileName() {
    String fileName = null;
    String cd = getHeader("Content-Disposition");
    if (cd != null) {
        String cdl = cd.toLowerCase(Locale.ENGLISH);
        if (cdl.startsWith("form-data") || cdl.startsWith("attachment")) {
            ParameterParser paramParser = new ParameterParser();
            paramParser.setLowerCaseNames(true);
            // Parameter parser can handle null input
            Map<String,String> params = paramParser.parse(cd, ';');
            if (params.containsKey("filename")) {
                fileName = params.get("filename");
                // The parser will remove surrounding '"' but will not
                // unquote any \x sequences.
                if (fileName != null) {
                    // RFC 6266. This is either a token or a quoted-string
                    if (fileName.indexOf('\\') > -1) {
                        // This is a quoted-string
                        fileName = HttpParser.unquote(fileName.trim());
                    } else {
                        // This is a token
                        fileName = fileName.trim();
                    }
                } 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;
}
 
Example 8
Source File: DiskFileItem.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the content charset passed by the agent or <code>null</code> if
 * not defined.
 *
 * @return The content charset passed by the agent or <code>null</code> if
 *         not defined.
 */
public String getCharSet() {
    ParameterParser parser = new ParameterParser();
    parser.setLowerCaseNames(true);
    // Parameter parser can handle null input
    Map<String,String> params = parser.parse(getContentType(), ';');
    return params.get("charset");
}