List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:br.gov.lexml.oaicat.LexMLOAICatalog.java
private Map internalErrors(final List<RegistroItem> ri_list, final InternalResumptionToken irt) throws CannotDisseminateFormatException, NoItemsMatchException { purge(); // clean out old resumptionTokens Map listIdentifiersMap = new HashMap(); ArrayList errors = new ArrayList(); int numRows = ri_list.size(); Iterator<RegistroItem> ri_iter = ri_list.iterator(); if (numRows == 0) { throw new NoItemsMatchException(); }// w w w. j a v a 2 s.co m while (ri_iter.hasNext()) { errors.add(constructError(ri_iter.next())); // String[] header = getRecordFactory().createHeader(getNativeHeader(ri_iter.next())); // errors.add(header[0]); // identifiers.add(header[1]); } // Verifica se temos que informar um ResumptionToken if (numRows >= maxListSize) { String resumptionId = LexMLOAICatalog.getRSName(); String lastId = getLastId(ri_list); InternalResumptionToken novoIRT = new InternalResumptionToken(irt, lastId, numRows); resumptionTokens.put(resumptionId, novoIRT); listIdentifiersMap.put("resumptionMap", getResumptionMap(resumptionId, irt.total, irt.offset)); } listIdentifiersMap.put("errors", errors.iterator()); return listIdentifiersMap; }
From source file:com.skilrock.lms.web.scratchService.inventoryMgmt.common.DirectSaleReturnBORetailerAction.java
public String salesReturnAjax() { PrintWriter out;// w w w . j a va 2 s . co m SalesReturnHelper helper = new SalesReturnHelper(); try { String html = ""; out = getResponse().getWriter(); String orgName = getType(); logger.info("" + orgName); ArrayList gameList = null; if (orgId > 0) { gameList = helper.getGameList(orgId); } else { html = "<select class=\"option\" name=\"gameName\" id=\"gameName\" onchange=\"saleReturnNewAjax('im_common_saleReturn_fetchPacknBookList.action?gameName='+(this.value).split(\'-\')[1]+'&retOrgName=')\"><option class=\"option\" value=\"-1\">--Please Select--</option>"; html += "</select>"; response.setContentType("text/html"); out.print(html); return null; } // session.setAttribute("GAME_LIST",characters); // And yes, I know creating HTML in an Action is generally very bad // form, // but I wanted to keep this exampel simple. html = "<select class=\"option\" name=\"gameName\" id=\"gameName\" onchange=\"saleReturnNewAjax('im_common_saleReturn_fetchPacknBookList.action?gameName='+(this.value).split(\'-\')[1]+'&agentOrgName=')\"><option class=\"option\" value=\"-1\">--Please Select--</option>"; GameBean bean = null; for (Iterator it = gameList.iterator(); it.hasNext();) { bean = (GameBean) it.next(); html += "<option class=\"option\" value=\"" + (Integer) bean.getGameNbr() + "-" + bean.getGameName() + "\">" + (Integer) bean.getGameNbr() + "-" + bean.getGameName() + "</option>"; } html += "</select>"; response.setContentType("text/html"); out.print(html); return null; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.manh.pool.impl.GenericObjectPool.java
/** * Recover abandoned objects which have been checked out but * not used since longer than the removeAbandonedTimeout. * * @param ac The configuration to use to identify abandoned objects *///from w w w. java 2s . com private void removeAbandoned(AbandonedConfig ac) { // Generate a list of abandoned objects to remove final long now = System.currentTimeMillis(); final long timeout = now - (ac.getRemoveAbandonedTimeout() * 1000L); ArrayList<PooledObject<T>> remove = new ArrayList<PooledObject<T>>(); Iterator<PooledObject<T>> it = allObjects.values().iterator(); while (it.hasNext()) { PooledObject<T> pooledObject = it.next(); synchronized (pooledObject) { if (pooledObject.getStates() == PooledObjectState.ALLOCATED && pooledObject.getLastUsedTime() <= timeout) { pooledObject.markAbandoned(); remove.add(pooledObject); } } } // Now remove the abandoned objects Iterator<PooledObject<T>> itr = remove.iterator(); while (itr.hasNext()) { PooledObject<T> pooledObject = itr.next(); if (ac.getLogAbandoned()) { pooledObject.printStackTrace(ac.getLogWriter()); } try { invalidateObject(pooledObject.getObject()); } catch (Exception e) { e.printStackTrace(); } } }
From source file:JDBCPool.dbcp.demo.sourcecode.GenericObjectPool.java
/** * Recover abandoned objects which have been checked out but * not used since longer than the removeAbandonedTimeout. * * @param ac The configuration to use to identify abandoned objects *//* w w w . j a va 2 s . c o m*/ private void removeAbandoned(AbandonedConfig ac) { // Generate a list of abandoned objects to remove final long now = System.currentTimeMillis(); final long timeout = now - (ac.getRemoveAbandonedTimeout() * 1000L); ArrayList<PooledObject<T>> remove = new ArrayList<PooledObject<T>>(); Iterator<PooledObject<T>> it = allObjects.values().iterator(); while (it.hasNext()) { PooledObject<T> pooledObject = it.next(); synchronized (pooledObject) { if (pooledObject.getState() == PooledObjectState.ALLOCATED && pooledObject.getLastUsedTime() <= timeout) { pooledObject.markAbandoned(); remove.add(pooledObject); } } } // Now remove the abandoned objects Iterator<PooledObject<T>> itr = remove.iterator(); while (itr.hasNext()) { PooledObject<T> pooledObject = itr.next(); if (ac.getLogAbandoned()) { pooledObject.printStackTrace(ac.getLogWriter()); } try { invalidateObject(pooledObject.getObject()); } catch (Exception e) { e.printStackTrace(); } } }
From source file:gr.iit.demokritos.cru.cps.api.GetUserProfile.java
public JSONObject processRequest() throws IOException { String response_code = "e0"; ArrayList<UserProperty> up = new ArrayList<UserProperty>(); // String filename = "/WEB-INF/configuration.properties"; String location = (String) properties.get("location"); String database_name = (String) properties.get("database_name"); String username = (String) properties.get("username"); String password = (String) properties.get("password"); MySQLConnector mysql = new MySQLConnector(location, database_name, username, password); Connection connection = mysql.connectToCPSDatabase(); try {/*from w ww . j ava 2 s . c o m*/ CreativityUserModellingController cumc = new CreativityUserModellingController( Long.parseLong(application_key), Long.parseLong(user_id.trim())); boolean isvalid = cumc.validateClientApplication(mysql); if (isvalid == true) { isvalid = cumc.validateUser(mysql); if (isvalid == true) { cumc.retrieveUserProfile(mysql); up = cumc.getUserProperties(); response_code = "OK"; } else { response_code = "e102"; } } else { response_code = "e101"; } } catch (NumberFormatException ex) { response_code = "e101"; Logger.getLogger(CreateUser.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(GetUserProfile.class.getName()).log(Level.SEVERE, null, ex); } JSONArray list = new JSONArray(); Iterator it = up.iterator(); int window = 0; JSONObject obj = new JSONObject(); JSONObject obj_temp = new JSONObject(); while (it.hasNext()) { JSONObject obj_window = new JSONObject(); UserProperty temp_up = (UserProperty) it.next(); obj_window.put("window", temp_up.getWindow()); obj_window.put(temp_up.getProperty_name(), temp_up.getProperty_value()); obj_window.put("timestamp", temp_up.getTimestamp()); list.add(obj_window); //System.out.println(obj_temp.toJSONString()); //obj_window.clear(); } //obj_temp.put("properties",list); JSONObject main_obj = new JSONObject(); main_obj.put("application_key", application_key); main_obj.put("user_id", user_id); main_obj.put("profile", list); main_obj.put("response_code", response_code); return main_obj; }
From source file:com.concursive.connect.web.modules.messages.workflow.SendPrivateMessageNotification.java
/** * Description of the Method// w w w. ja v a 2 s .c o m * * @param context Description of the Parameter * @return Description of the Return Value */ public boolean execute(ComponentContext context) { boolean result = false; try { ArrayList<Integer> users = new ArrayList<Integer>(); // Add project leads Project thisProject = (Project) context.getAttribute(PROJECT); PrivateMessage thisPrivateMessage = (PrivateMessage) context.getThisObject(); User senderUser = UserUtils.loadUser(thisPrivateMessage.getEnteredBy()); String url = context.getParameter(URL); Key key = (Key) context.getAttribute("TEAM.KEY"); Configuration freeMarkerConfiguration = (Configuration) context .getAttribute(ComponentContext.FREEMARKER_CONFIGURATION); // Go through userIds set as attributes String includeList = (String) context.getAttribute(USERS_TO_IDS); if (includeList != null) { StringTokenizer st = new StringTokenizer(includeList, ","); while (st.hasMoreTokens()) { Integer id = Integer.parseInt(st.nextToken().trim()); if (!users.contains(id)) { users.add(id); } } } // Send the message(s) if (users.size() > 0) { SMTPMessage message = SMTPMessageFactory.createSMTPMessageInstance(context.getApplicationPrefs()); message.setFrom(context.getParameter(ComponentContext.APPLICATION_EMAIL_ADDRESS)); message.setType("text/html"); // Send to each user Iterator userList = users.iterator(); while (userList.hasNext()) { Integer id = (Integer) userList.next(); User teamMemberUser = UserUtils.loadUser(id.intValue()); String email = teamMemberUser.getEmail(); // Initialize the message template Template inviteSubject = null; Template inviteBody = null; // Set the data model Map subjectMappings = new HashMap(); subjectMappings.put("user", senderUser); Map bodyMappings = new HashMap(); bodyMappings.put("site", new HashMap()); ((Map) bodyMappings.get("site")).put("title", context.getApplicationPrefs().get(ApplicationPrefs.WEB_PAGE_TITLE)); bodyMappings.put("project", thisProject); bodyMappings.put("user", senderUser); bodyMappings.put("teamMember", teamMemberUser); bodyMappings.put("private", new HashMap()); ((Map) bodyMappings.get("private")).put("message", StringUtils.toHtmlValue(thisPrivateMessage.getBody())); bodyMappings.put("link", new HashMap()); ((Map) bodyMappings.get("link")).put("info", url); ((Map) bodyMappings.get("link")).put("projectMessages", url + "/show/" + thisProject.getUniqueId() + "/message/inbox/" + thisPrivateMessage.getId()); inviteSubject = freeMarkerConfiguration.getTemplate("project_private_message_subject-text.ftl"); inviteBody = freeMarkerConfiguration.getTemplate("project_private_message_body-html.ftl"); // Set the subject from the template StringWriter inviteSubjectTextWriter = new StringWriter(); inviteSubject.process(subjectMappings, inviteSubjectTextWriter); message.setSubject(inviteSubjectTextWriter.toString()); // Set the body from the template StringWriter inviteBodyTextWriter = new StringWriter(); inviteBody.process(bodyMappings, inviteBodyTextWriter); message.setBody(inviteBodyTextWriter.toString()); message.setTo(email); message.setType("text/html"); int emailResult = message.send(); if (emailResult == 0) { LOG.debug("email sent successfully to " + teamMemberUser.getNameFirstLast()); } else { LOG.debug("email not sent to " + teamMemberUser.getNameFirstLast()); } } } result = true; } catch (Exception e) { e.printStackTrace(System.out); } return result; }
From source file:com.skilrock.lms.web.scratchService.gameMgmt.common.GameUploadAction.java
public void TicketsUploadGameNameAjax() { System.out.println("Hello" + getGameType()); PrintWriter out;/* w w w . ja va 2s . co m*/ try { out = getResponse().getWriter(); String game_type = getGameType(); System.out.println("" + game_type); if (game_type == null) { game_type = ""; } GameuploadHelper gameuploadHelper = new GameuploadHelper(); ArrayList<GameBean> game = gameuploadHelper.fatchGameList(game_type); System.out.println("Game List is: " + game); StringBuilder html = new StringBuilder(""); html.append( "<select name=\"gameName\" class=\"option\" id=\"gameNameId\" onblur=\"check()\" onchange=\"disableSubmit(),setGameDigit()\"><option class=\"option\" value=\"Please Select\">Please Select</option>"); int i = 0; GameBean bean = null; for (Iterator<GameBean> it = game.iterator(); it.hasNext();) { bean = it.next(); String name = bean.getGameName(); i++; html.append("<option class=\"option\" value=\"" + name + "\">" + name + "</option>"); } html.append("</select>"); response.setContentType("text/html"); out.print(html.toString()); System.out.println("Hello" + html); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:jp.or.openid.eiwg.scim.operation.Operation.java
/** * ??//from w w w . j a v a 2s . c o m * * @param context * @param request */ public boolean Authentication(ServletContext context, HttpServletRequest request) throws IOException { boolean result = false; // Authorization? String authorization = request.getHeader("Authorization"); if (authorization == null || StringUtils.isEmpty(authorization)) { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_UNAUTHORIZED); //return false; return true; } String[] values = authorization.split(" "); // ? setError(0, null, null); if (values.length < 2) { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_UNAUTHORIZED); } else { // ???????? if ("Basic".equalsIgnoreCase(values[0])) { // HTTP Basic ? String userID; String password; String[] loginInfo = SCIMUtil.decodeBase64(values[1]).split(":"); if (loginInfo.length < 2) { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_INVALID_CREDENTIALS); } else { // ?? userID = loginInfo[0]; // password = loginInfo[1]; if (StringUtils.isEmpty(userID) || StringUtils.isEmpty(password)) { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_INVALID_CREDENTIALS); } else { // ???? // ??? ObjectMapper mapper = new ObjectMapper(); ArrayList<LinkedHashMap<String, Object>> adminInfoList = null; try { adminInfoList = mapper.readValue(new File(context.getRealPath("/WEB-INF/Admin.json")), new TypeReference<ArrayList<LinkedHashMap<String, Object>>>() { }); } catch (IOException e) { // setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, MessageConstants.ERROR_UNKNOWN); e.printStackTrace(); return result; } if (adminInfoList != null && !adminInfoList.isEmpty()) { Iterator<LinkedHashMap<String, Object>> adminInfoIt = adminInfoList.iterator(); while (adminInfoIt.hasNext()) { LinkedHashMap<String, Object> adminInfo = adminInfoIt.next(); Object adminID = SCIMUtil.getAttribute(adminInfo, "id"); Object adminPassword = SCIMUtil.getAttribute(adminInfo, "password"); // id???? if (adminID != null && adminID instanceof String) { if (userID.equals(adminID.toString())) { // password???? if (adminID != null && adminID instanceof String) { if (password.equals(adminPassword.toString())) { // ?? result = true; } } break; } } } if (result != true) { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_INVALID_CREDENTIALS); } } else { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_INVALID_CREDENTIALS); } } } } else if ("Bearer".equalsIgnoreCase(values[0])) { // OAuth2 Bearer String token = values[1]; if (StringUtils.isEmpty(token)) { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_INVALID_CREDENTIALS); } else { // ?? // ??? ObjectMapper mapper = new ObjectMapper(); ArrayList<LinkedHashMap<String, Object>> adminInfoList = null; try { adminInfoList = mapper.readValue(new File(context.getRealPath("/WEB-INF/Admin.json")), new TypeReference<ArrayList<LinkedHashMap<String, Object>>>() { }); } catch (IOException e) { // setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null, MessageConstants.ERROR_UNKNOWN); e.printStackTrace(); return result; } if (adminInfoList != null && !adminInfoList.isEmpty()) { Iterator<LinkedHashMap<String, Object>> adminInfoIt = adminInfoList.iterator(); while (adminInfoIt.hasNext()) { LinkedHashMap<String, Object> adminInfo = adminInfoIt.next(); Object adminToken = SCIMUtil.getAttribute(adminInfo, "bearer"); // token???? if (adminToken != null && adminToken instanceof String) { if (token.equals(adminToken.toString())) { // ?? result = true; break; } } } if (result != true) { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_INVALID_CREDENTIALS); } } else { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_INVALID_CREDENTIALS); } } } else { // setError(HttpServletResponse.SC_UNAUTHORIZED, null, MessageConstants.ERROR_INVALID_CREDENTIALS); } } return result; }
From source file:ar.com.fdvs.dj.core.layout.ClassicLayoutManager.java
/** * *//*from w w w.j a v a2 s.com*/ protected void applyHeaderAutotexts() { if (getReport().getAutoTexts() == null) return; /** * Apply the autotext in footer if any */ JRDesignBand headerband = (JRDesignBand) getDesign().getPageHeader(); if (headerband == null) { headerband = new JRDesignBand(); getDesign().setPageHeader(headerband); } ArrayList positions = new ArrayList(); positions.add(HorizontalBandAlignment.LEFT); positions.add(HorizontalBandAlignment.CENTER); positions.add(HorizontalBandAlignment.RIGHT); ArrayList autotexts = new ArrayList(getReport().getAutoTexts()); Collections.reverse(autotexts); int totalYoffset = findTotalOffset(positions, autotexts, AutoText.POSITION_HEADER); LayoutUtils.moveBandsElemnts(totalYoffset, headerband); for (Iterator iterator = positions.iterator(); iterator.hasNext();) { HorizontalBandAlignment currentAlignment = (HorizontalBandAlignment) iterator.next(); int yOffset = 0; for (Iterator iter = getReport().getAutoTexts().iterator(); iter.hasNext();) { AutoText text = (AutoText) iter.next(); if (text.getPosition() == AutoText.POSITION_HEADER && text.getAlignment().equals(currentAlignment)) { CommonExpressionsHelper.add(yOffset, (DynamicJasperDesign) getDesign(), this, headerband, text); yOffset += text.getHeight().intValue(); } } } /** END */ }