List of usage examples for org.apache.commons.fileupload ParameterParser parse
public Map parse(final char[] chars, char separator)
From source file:at.gv.egiz.bku.binding.HttpUtil.java
/** * Extracts charset from a content type header. * //from ww w . jav a 2 s . com * @param contentType * @param replaceNullWithDefault * if true the method return the default charset if not set * @return charset String or null if not present */ public static String getCharset(String contentType, boolean replaceNullWithDefault) { ParameterParser pf = new ParameterParser(); pf.setLowerCaseNames(true); Map<?, ?> map = pf.parse(contentType, SEPARATOR); String retVal = (String) map.get(CHAR_SET); if ((retVal == null) && (replaceNullWithDefault)) { if (map.containsKey(APPLICATION_URL_ENCODED)) { // default charset for url encoded data return "UTF-8"; } retVal = getDefaultCharset(); } return retVal; }
From source file:com.oneis.appserver.FileUploads.java
/** * Determine whether an HTTP request contains file uploads. If so, returns a * FileUploads object initialised for decoding the stream. * * @return FileUploads object to use to decode the streamed data. *///w w w.jav a 2 s . c om static public FileUploads createIfUploads(HttpServletRequest request) { String contentType = request.getHeader("Content-Type"); if (contentType == null) { return null; } // Set up a parser for the various values ParameterParser paramParser = new ParameterParser(); paramParser.setLowerCaseNames(true); // Decode content type Map contentTypeDecoded = paramParser.parse(contentType, PARAMPARSER_SEPERATORS); String boundaryStr = null; if (!contentTypeDecoded.containsKey("multipart/form-data") || (boundaryStr = (String) contentTypeDecoded.get("boundary")) == null) { // Wasn't a file upload return null; } byte[] boundary = null; try { boundary = boundaryStr.getBytes("ISO-8859-1"); } catch (java.io.UnsupportedEncodingException e) { throw new RuntimeException("Expected charset ISO-8859-1 not installed"); } if (boundaryStr == null || boundary.length < 2) { return null; } // Looks good... create an object to signal success return new FileUploads(boundary); }
From source file:at.gv.egiz.bku.binding.XWWWFormUrlInputDecoder.java
@Override public void setContentType(String contentType) { ParameterParser pp = new ParameterParser(); pp.setLowerCaseNames(true);/*from ww w .j a v a 2 s .c om*/ Map<String, String> params = pp.parse(contentType, new char[] { ':', ';' }); if (!params.containsKey(CONTENT_TYPE)) { throw new IllegalArgumentException("not a url encoded content type specification: " + contentType); } }
From source file:com.gae.MemoryFileItem.java
@SuppressWarnings("unchecked") public String getCharSet() { ParameterParser parser = new ParameterParser(); parser.setLowerCaseNames(true);// w ww. ja v a 2s . c om // Parameter parser can handle null input Map params = parser.parse(getContentType(), ';'); return (String) params.get("charset"); }
From source file:com.alibaba.citrus.service.upload.impl.cfu.ServletFileUpload.java
private String getFileName(String pContentDisposition) { String fileName = null;// w ww. ja 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 ? for (String key : getFileNameKey()) { fileName = trimToNull(params.get(key)); if (fileName != null) { break; } } } } return fileName; }
From source file:lc.kra.servlet.FileManagerServlet.java
private String partFileName(Part part) { String header, file = null;// w w w .j a v a 2 s .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:com.aspectran.web.support.multipart.inmemory.MemoryFileItem.java
/** * Returns the content charset passed by the agent or {@code null} if not defined. * * @return the content charset passed by the agent or {@code null} if not defined *//*from w w w . j av a2 s.co m*/ @SuppressWarnings("unchecked") 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"); }
From source file:cn.clxy.studio.common.web.multipart.GFileItem.java
/** * 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. *//*from w ww.jav a2 s . c o m*/ 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"); }
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 w w w . j a v a2 s. 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 boundary from the <code>Content-type</code> header. * * @param contentType The value of the content type header from which to extract the * boundary value.//from w w w. ja v a 2s . 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; }