List of usage examples for java.util List iterator
Iterator<E> iterator();
From source file:com.aw.swing.mvp.ui.painter.PainterMessages.java
private static String buildCustomMessage(List messages) { StringBuffer sb = new StringBuffer(); for (Iterator iterator = messages.iterator(); iterator.hasNext();) { Object obj = iterator.next(); if (obj == null) continue; if (obj instanceof String) { sb.append(MsgDisplayer.getMessage((String) obj, null)); sb.append(" "); } else if (obj instanceof Message) { Message message = (Message) obj; sb.append(MsgDisplayer.getMessage(message.getMessage(), message.getArgs())); sb.append(" "); }//from w w w .j av a 2s .c om sb.append("\n"); } return sb.toString(); }
From source file:com.aurel.track.persist.TScreenTabPeer.java
public static List<IPanel> loadFullChildren(Integer objectID, Connection con) throws TorqueException { Criteria critChild = new Criteria(); critChild.add(BaseTScreenPanelPeer.PARENT, objectID); critChild.addAscendingOrderByColumn(BaseTScreenPanelPeer.SORTORDER); List<IPanel> result = new ArrayList<IPanel>(); List panels = BaseTScreenPanelPeer.doSelect(critChild, con); for (Iterator it = panels.iterator(); it.hasNext();) { TScreenPanelBean panelBean = ((TScreenPanel) it.next()).getBean(); panelBean.setFields(TScreenPanelPeer.loadFullChildren(panelBean.getObjectID(), con)); result.add(panelBean);// w w w . j a v a2s . c o m } return result; }
From source file:com.icl.integrator.util.patch.ServletAnnotationMappingUtils.java
/** * Check whether the given request matches the specified header conditions. * @param headers the header conditions, following * {@link org.springframework.web.bind.annotation.RequestMapping#headers() RequestMapping.headers()} * @param request the current HTTP request to check *//* ww w.j a v a 2 s. com*/ public static boolean checkHeaders(String[] headers, HttpServletRequest request) { if (!ObjectUtils.isEmpty(headers)) { for (String header : headers) { int separator = header.indexOf('='); if (separator == -1) { if (header.startsWith("!")) { if (request.getHeader(header.substring(1)) != null) { return false; } } else if (request.getHeader(header) == null) { return false; } } else { boolean negated = (separator > 0 && header.charAt(separator - 1) == '!'); String key = !negated ? header.substring(0, separator) : header.substring(0, separator - 1); String value = header.substring(separator + 1); if (isMediaTypeHeader(key)) { List<MediaType> requestMediaTypes = MediaType.parseMediaTypes(request.getHeader(key)); List<MediaType> valueMediaTypes = MediaType.parseMediaTypes(value); boolean found = false; for (Iterator<MediaType> valIter = valueMediaTypes.iterator(); valIter.hasNext() && !found;) { MediaType valueMediaType = valIter.next(); for (Iterator<MediaType> reqIter = requestMediaTypes.iterator(); reqIter.hasNext() && !found;) { MediaType requestMediaType = reqIter.next(); if (valueMediaType.includes(requestMediaType)) { found = true; } } } if (negated) { found = !found; } if (!found) { return false; } } else { boolean match = value.equals(request.getHeader(key)); if (negated) { match = !match; } if (!match) { return false; } } } } } return true; }
From source file:in.xebia.poc.FileUploadUtils.java
public static boolean parseFileUploadRequest(HttpServletRequest request, File outputFile, Map<String, String> params) throws Exception { log.debug("Request class? " + request.getClass().toString()); log.debug("Request is multipart? " + ServletFileUpload.isMultipartContent(request)); log.debug("Request method: " + request.getMethod()); log.debug("Request params: "); for (Object key : request.getParameterMap().keySet()) { log.debug((String) key);// w w w. j a va 2s . c om } log.debug("Request attribute names: "); boolean filedataInAttributes = false; Enumeration attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); log.debug(attrName); if ("filedata".equals(attrName)) { filedataInAttributes = true; } } if (filedataInAttributes) { log.debug("Found filedata in request attributes, getting it out..."); log.debug("filedata class? " + request.getAttribute("filedata").getClass().toString()); FileItem item = (FileItem) request.getAttribute("filedata"); item.write(outputFile); for (Object key : request.getParameterMap().keySet()) { params.put((String) key, request.getParameter((String) key)); } return true; } /*ServletFileUpload upload = new ServletFileUpload(); //upload.setSizeMax(Globals.MAX_UPLOAD_SIZE); FileItemIterator iter = upload.getItemIterator(request); while(iter.hasNext()){ FileItemStream item = iter.next(); InputStream stream = item.openStream(); //If this item is a file if(!item.isFormField()){ log.debug("Found non form field in upload request with field name = " + item.getFieldName()); String name = item.getName(); if(name == null){ throw new Exception("File upload did not have filename specified"); } // Some browsers, including IE, return the full path so trim off everything but the file name name = getFileNameFromPath(name); //Enforce required file extension, if present if(!name.toLowerCase().endsWith( ".zip" )){ throw new Exception("File uploaded did not have required extension .zip"); } bufferedCopyStream(stream, new FileOutputStream(outputFile)); } else { params.put(item.getFieldName(), Streams.asString(stream)); } } return true;*/ // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List /* FileItem */ items = upload.parseRequest(request); // Process the uploaded items Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { log.debug("Found non form field in upload request with field name = " + item.getFieldName()); String name = item.getName(); if (name == null) { throw new Exception("File upload did not have filename specified"); } // Some browsers, including IE, return the full path so trim off everything but the file name name = getFileNameFromPath(name); item.write(outputFile); } else { params.put(item.getFieldName(), item.getString()); } } return true; }
From source file:msec.org.FileUploadServlet.java
static protected String FileUpload(Map<String, String> fields, List<String> filesOnServer, HttpServletRequest request, HttpServletResponse response) { boolean isMultipart = ServletFileUpload.isMultipartContent(request); // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); int MaxMemorySize = 10000000; int MaxRequestSize = MaxMemorySize; String tmpDir = System.getProperty("TMP", "/tmp"); //System.out.printf("temporary directory:%s", tmpDir); // Set factory constraints factory.setSizeThreshold(MaxMemorySize); factory.setRepository(new File(tmpDir)); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding("utf8"); // Set overall request size constraint upload.setSizeMax(MaxRequestSize);/*w w w . ja va 2 s . c o m*/ // Parse the request try { @SuppressWarnings("unchecked") List<FileItem> items = upload.parseRequest(request); // Process the uploaded items Iterator<FileItem> iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); if (item.isFormField()) {//k -v String name = item.getFieldName(); String value = item.getString("utf-8"); fields.put(name, value); } else { String fieldName = item.getFieldName(); String fileName = item.getName(); if (fileName == null || fileName.length() < 1) { return "file name is empty."; } String localFileName = ServletConfig.fileServerRootDir + File.separator + "tmp" + File.separator + fileName; //System.out.printf("upload file:%s", localFileName); String contentType = item.getContentType(); boolean isInMemory = item.isInMemory(); long sizeInBytes = item.getSize(); File uploadedFile = new File(localFileName); item.write(uploadedFile); filesOnServer.add(localFileName); } } return "success"; } catch (FileUploadException e) { e.printStackTrace(); return e.toString(); } catch (Exception e) { e.printStackTrace(); return e.toString(); } }
From source file:com.ctrip.infosec.rule.resource.DataProxy.java
/** * ?DataProxyResponseresultMap//from ww w . jav a2s . c o m */ private static Map parseProfileResult(Map result) { if (result != null) { if (result.get("tagName") != null) { return parseResult(result); } else if (result.get("tagNames") != null) { Object tagValues = result.get("tagNames"); List oldResults = JSON.parseObject(JSON.toJSONString(tagValues), List.class); Map newResults = new HashMap(); Iterator iterator = oldResults.iterator(); while (iterator.hasNext()) { Map oneResult = (Map) iterator.next(); newResults.putAll(parseResult(oneResult)); } return newResults; } else { return result; } } return Collections.EMPTY_MAP; }
From source file:com.aurel.track.persist.TDashboardTabPeer.java
/** * delete all children and then delete the object * @param objectID/* ww w . j a va 2 s. c o m*/ * @param con * @throws TorqueException */ public static void deleteChildren(Integer objectID, Connection con) throws TorqueException { LOGGER.debug("Deleting children for tab:" + objectID + "..."); //remove all panels Criteria critChild = new Criteria(); critChild.add(BaseTDashboardPanelPeer.PARENT, objectID); List panels = BaseTDashboardPanelPeer.doSelect(critChild, con); for (Iterator iter = panels.iterator(); iter.hasNext();) { TDashboardPanel panel = (TDashboardPanel) iter.next(); //delete children of panel TDashboardPanelPeer.deleteChildren(panel.getObjectID(), con); //delete the panel BaseTDashboardPanelPeer.doDelete(SimpleKey.keyFor(panel.getObjectID()), con); } LOGGER.debug("Children deleted for tab:" + objectID + "!"); }
From source file:eu.eubrazilcc.lvl.core.util.UrlUtils.java
/** * Returns a list of name-value pairs as built from the URI's query portion. * @param uri - input URI// w ww . j av a2 s . c om * @return a list of name-value pairs as built from the URI's query portion. * @throws IllegalArgumentException If a malformed URI occurs. */ public static Map<String, String> getQueryParams(final URI uri) { checkArgument(uri != null, "Uninitialized URI"); try { final URI nUri = uri.normalize(); final URL url = nUri.isAbsolute() ? nUri.toURL() : new URL(new URL("http://example.org/"), nUri.toString()); final String query = new URL(URLDecoder.decode(url.toString(), defaultCharset().name())).getQuery(); final Map<String, String> map = newHashMap(); final List<NameValuePair> pairs = URLEncodedUtils.parse(query, defaultCharset()); final Iterator<NameValuePair> iterator = pairs.iterator(); while (iterator.hasNext()) { final NameValuePair pair = iterator.next(); map.put(pair.getName(), pair.getValue()); } return map; } catch (MalformedURLException | UnsupportedEncodingException e) { throw new IllegalArgumentException("Malformed URI", e); } }
From source file:com.aurel.track.persist.TScreenTabPeer.java
/** * delete all children and then delete the object * @param objectID/* w w w . j a v a 2 s .c o m*/ * @param con * @throws TorqueException */ public static void deleteChildren(Integer objectID, Connection con) throws TorqueException { LOGGER.debug("Deleting children for tab:" + objectID + "..."); //remove all panels Criteria critChild = new Criteria(); critChild.add(BaseTScreenPanelPeer.PARENT, objectID); List panels = BaseTScreenPanelPeer.doSelect(critChild, con); for (Iterator iter = panels.iterator(); iter.hasNext();) { TScreenPanel panel = (TScreenPanel) iter.next(); //delete children of panel TScreenPanelPeer.deleteChildren(panel.getObjectID(), con); //delete the panel BaseTScreenPanelPeer.doDelete(SimpleKey.keyFor(panel.getObjectID()), con); } LOGGER.debug("Children deleted for tab:" + objectID + "!"); }
From source file:com.aurel.track.persist.TDashboardTabPeer.java
public static List<IPanel> loadFullChildren(Integer objectID, Connection con) throws TorqueException { //delete also all children LOGGER.debug("Getting children for tab:" + objectID + "..."); Criteria critChild = new Criteria(); critChild.add(BaseTDashboardPanelPeer.PARENT, objectID); critChild.addAscendingOrderByColumn(BaseTDashboardPanelPeer.SORTORDER); List<IPanel> result = new ArrayList<IPanel>(); List panels = BaseTDashboardPanelPeer.doSelect(critChild, con); for (Iterator iter = panels.iterator(); iter.hasNext();) { TDashboardPanel panel = (TDashboardPanel) iter.next(); TDashboardPanelBean panelBean = panel.getBean(); List<IField> fields = TDashboardPanelPeer.loadFullChildren(panel.getObjectID(), con); panelBean.setFields(fields);// w ww . jav a2 s. co m result.add(panelBean); } return result; }