List of usage examples for org.apache.commons.fileupload ParameterParser setLowerCaseNames
public void setLowerCaseNames(boolean b)
From source file:at.gv.egiz.bku.binding.HttpUtil.java
/** * Extracts charset from a content type header. * /*w w w . j a va 2s .c o m*/ * @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. */// www. j a v a 2 s . c o m 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); 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 w w w .j a va 2 s .c o m }
From source file:com.gae.MemoryFileItem.java
@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:com.alibaba.citrus.service.upload.impl.cfu.ServletFileUpload.java
private String getFileName(String pContentDisposition) { String fileName = null;/*from www. j a v a 2 s . c om*/ 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 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: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 *///w w w . j a v a 2 s. c o 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 w w. j a v a2s .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.oneis.appserver.FileUploads.java
/** * Handle the incoming stream, processing files. *//* w ww . ja v a 2 s .c o m*/ public void performUploads(HttpServletRequest request) throws IOException, UserReportableFileUploadException { instructionsRequired = false; // Need a parser for parameters ParameterParser paramParser = new ParameterParser(); paramParser.setLowerCaseNames(true); // Thread ID is used for temporary filenames long threadId = Thread.currentThread().getId(); int fileId = 0; InputStream requestBody = request.getInputStream(); MultipartStream multipart = new MultipartStream(requestBody, boundary); multipart.setHeaderEncoding("UTF-8"); boolean nextPart = multipart.skipPreamble(); while (nextPart) { String headerPart = multipart.readHeaders(); // Parse headers, splitting out the bits we're interested in String name = null; String filename = null; Map<String, String> itemHeaders = HeaderParser.parse(headerPart, true /* keys to lower case */); String mimeType = itemHeaders.get("content-type"); String disposition = itemHeaders.get("content-disposition"); if (disposition != null) { Map disp = paramParser.parse(disposition, PARAMPARSER_SEPERATORS); name = (String) disp.get("name"); filename = (String) disp.get("filename"); } // Set a default MIME type if none is given (Safari may omit it) if (mimeType == null) { mimeType = "application/octet-stream"; } // Remove the path prefix from IE (before the length check) if (filename != null) { int slash1 = filename.lastIndexOf('/'); int slash2 = filename.lastIndexOf('\\'); int slash = (slash1 > slash2) ? slash1 : slash2; if (slash != -1) { filename = filename.substring(slash + 1); } } boolean isFile = (filename != null && filename.length() > 0); if (isFile) { // File - did the app server give instructions about it? Upload upload = files.get(name); if (upload == null) { // Looks like a file, but the app server didn't say it should be. Give up. throw new UserReportableFileUploadException( "A file was uploaded, but it was not expected by the application. Field name: '" + name + "'"); } String dir = upload.getSaveDirectory(); if (dir == null) { // Ooops. throw new IOException("app server didn't specify dir"); } // Generate a temporary filename File outFile = null; do { outFile = new File(String.format("%1$s/u%2$d.%3$d", dir, threadId, fileId++)); } while (!outFile.createNewFile()); OutputStream outStream = new FileOutputStream(outFile); // Decorate with a digest? MessageDigest digest = null; if (upload.getDigestName() != null) { try { digest = MessageDigest.getInstance(upload.getDigestName()); } catch (java.security.NoSuchAlgorithmException e) { digest = null; } if (digest != null) { outStream = new DigestOutputStream(outStream, digest); } } // Decorate with a decompressor? String filterName = upload.getFilterName(); if (filterName != null && filterName.equals("inflate")) { outStream = new InflaterOutputStream(outStream); } multipart.readBodyData(outStream); outStream.close(); String digestAsString = null; if (digest != null) { String.format("%1$s_digest", name); digestAsString = StringUtils.bytesToHex(digest.digest()); } upload.setUploadDetails(outFile.getPath(), digestAsString, mimeType, filename, outFile.length()); } else { // Normal field - just absorb a few k max of it, turn it into a field ByteArrayOutputStream value = new ByteArrayOutputStream(); // TODO: Limit request size as a whole, not on a per-parameter basis. multipart.readBodyData(new LimitedFilterOutputStream(value, MAX_TEXT_PARAMETER_LENGTH)); params.put(name, value.toString("UTF-8")); } nextPart = multipart.readBoundary(); } }
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./* w w w. j a va2 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"); }