List of usage examples for java.util HashMap entrySet
Set entrySet
To view the source code for java.util HashMap entrySet.
Click Source Link
From source file:de.betterform.agent.web.servlet.XFormsErrorServlet.java
private String getHTML(HttpServletRequest request) { StringBuffer html = new StringBuffer(); String msg = (String) request.getSession().getAttribute("betterform.exception.message"); String xpath = "unknown"; String cause = " "; if (msg != null) { int start = msg.indexOf("::"); if (start > 3) { xpath = msg.substring(start + 2); msg = msg.substring(0, start); }// w w w . ja va 2 s.com } Exception ex = (Exception) request.getSession().getAttribute("betterform.exception"); if (ex != null && ex.getCause() != null && ex.getCause().getMessage() != null) { cause = ex.getCause().getMessage(); } request.getSession().removeAttribute("betterform.exception"); request.getSession().removeAttribute("betterform.exception.message"); html.append("<div class=\"message2\" id=\"msg\">"); html.append(msg); html.append("</div>"); html.append("<div class=\"message3\"><strong>URL:</strong><br/>"); html.append(request.getSession().getAttribute("betterform.referer")); html.append("</div>"); html.append("<div class=\"message3\"><strong>Element causing Exception:</strong><br/>"); html.append(xpath); html.append("</div>"); if (ex.getCause() != null) { html.append("<div class=\"message3\"><strong>Caused by:</strong><br/>"); html.append(cause); html.append("</div>"); } if (ex instanceof XFormsErrorIndication) { Object o = ((XFormsErrorIndication) ex).getContextInfo(); if (o instanceof HashMap) { HashMap<String, Object> map = (HashMap) ((XFormsErrorIndication) ex).getContextInfo(); if (map.size() != 0) { html.append("<table>"); html.append("<caption>Context Information:</caption>"); for (Map.Entry<String, Object> entry : map.entrySet()) { html.append("<tr><td>"); html.append(entry.getKey()); html.append("</td>"); html.append("<td>"); html.append(entry.getValue().toString()); html.append("</td></tr>"); } html.append("</table>"); } } //todo: check -> there are contextInfos containing a simple string but seems to be integrated within above error message already - skip for now /* else{ html.append("<div>"); html.append(o.toString()); html.append("</div>"); } */ } html.append("<form><input type=\"button\" value=\"Back\" onClick=\"history.back()\"/></form>"); try { String mail = Config.getInstance().getProperty("admin.mail"); StringBuffer mailbody = new StringBuffer(); html.append("<div class=\"message3\">"); html.append("<a href=\"mailto:"); html.append(mail); mailbody.append("?subject=XForms Problem at "); mailbody.append(request.getSession().getAttribute("betterform.referer")); mailbody.append("&Body=Message:\n"); mailbody.append(msg); mailbody.append("%0D%0A%0D%0AElement causing Exception:"); mailbody.append(xpath); mailbody.append("%0D%0A%0D%0ACaused by:\n"); mailbody.append(URLEncoder.encode(cause, "UTF-8")); html.append(mailbody.toString()); html.append("\">"); html.append("Report this problem...</a>"); html.append("</div>"); } catch (Exception e) { LOGGER.debug(e); } LOGGER.error(html.toString()); return html.toString(); }
From source file:hd3gtv.mydmam.useraction.fileoperation.UAFileOperationDelete.java
@Override public void process(JobProgression progression, UserProfile userprofile, UAConfigurator user_configuration, HashMap<String, SourcePathIndexerElement> source_elements) throws Exception { Log2Dump dump = new Log2Dump(); dump.add("user", userprofile.key); progression.updateStep(1, source_elements.size()); ArrayList<File> items_to_delete = new ArrayList<File>(); for (Map.Entry<String, SourcePathIndexerElement> entry : source_elements.entrySet()) { progression.incrStep();//from w ww. j av a 2 s . com File current_element = Explorer.getLocalBridgedElement(entry.getValue()); CopyMove.checkExistsCanRead(current_element); CopyMove.checkIsWritable(current_element.getParentFile()); if (current_element.isFile() | FileUtils.isSymlink(current_element)) { if (current_element.delete() == false) { Log2.log.debug("Can't delete correctly file", dump); throw new IOException("Can't delete correctly file: " + current_element.getPath()); } if (stop) { return; } } else { items_to_delete.clear(); items_to_delete.add(current_element); boolean can_delete_all = true; recursivePath(current_element, items_to_delete); progression.updateProgress(1, items_to_delete.size()); for (int pos_idel = items_to_delete.size() - 1; pos_idel > -1; pos_idel--) { progression.updateProgress(items_to_delete.size() - pos_idel, items_to_delete.size()); if (items_to_delete.get(pos_idel).delete() == false) { dump.add("item", items_to_delete.get(pos_idel)); can_delete_all = false; } if (stop) { return; } } if (can_delete_all == false) { Log2.log.debug("Can't delete correctly multiple files", dump); throw new IOException("Can't delete multiple files from: " + current_element.getPath()); } } if (stop) { return; } ElasticsearchBulkOperation bulk = Elasticsearch.prepareBulk(); /** * Delete mtds */ Container container = ContainerOperations.getByPathIndexId(entry.getKey()); if (container != null) { ContainerOperations.requestDelete(container, bulk); RenderedFile.purge(entry.getKey()); } explorer.deleteStoragePath(bulk, Arrays.asList(entry.getValue())); bulk.terminateBulk(); if (stop) { return; } } }
From source file:fr.xebia.extras.selma.codegen.CustomMapperWrapper.java
private void addMissingMappings(HashMap<CustomMapperKey, CustomMapperEntry> customInOutTypes, TypeElement element, boolean ignoreAbstract) { for (Map.Entry<CustomMapperKey, CustomMapperEntry> entry : customInOutTypes.entrySet()) { if (entry.getValue().updateGraphMethod == null) { pushCustomMapper(element, entry.getValue().immutableMethod, Boolean.TRUE, ignoreAbstract); } else if (entry.getValue().immutableMethod == null) { pushCustomMapper(element, entry.getValue().updateGraphMethod, Boolean.FALSE, ignoreAbstract); }//from w w w. j a v a 2 s . co m } }
From source file:com.yahoo.ycsb.db.CouchbaseClient.java
/** * Encode the object for couchbase storage. * * @param source the source value.//w w w . j av a 2 s . c om * @return the storable object. */ private Object encode(final HashMap<String, ByteIterator> source) { HashMap<String, String> stringMap = StringByteIterator.getStringMap(source); if (!useJson) { return stringMap; } ObjectNode node = JSON_MAPPER.createObjectNode(); for (Map.Entry<String, String> pair : stringMap.entrySet()) { node.put(pair.getKey(), pair.getValue()); } JsonFactory jsonFactory = new JsonFactory(); Writer writer = new StringWriter(); try { JsonGenerator jsonGenerator = jsonFactory.createGenerator(writer); JSON_MAPPER.writeTree(jsonGenerator, node); } catch (Exception e) { throw new RuntimeException("Could not encode JSON value"); } return writer.toString(); }
From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java
/** * DELETE./*from www. ja v a 2 s. c om*/ * @param url URL * @param headers ?? * @return DcResponse * @throws DcException DAO */ public final DcResponse del(final String url, final HashMap<String, String> headers) throws DcException { HttpDelete req = new HttpDelete(url); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion()); debugHttpRequest(req, ""); return this.request(req); }
From source file:com.fujitsu.dc.test.jersey.DcRestAdapter.java
/** * ????GET.//from w w w . ja v a 2 s .c o m * @param url URL * @param headers ?? * @return DcResponse * @throws DcException DAO */ public final DcResponse get(final String url, final HashMap<String, String> headers) throws DcException { HttpUriRequest req = new HttpGet(url); for (Map.Entry<String, String> entry : headers.entrySet()) { req.setHeader(entry.getKey(), entry.getValue()); } req.addHeader("X-Dc-Version", DcCoreTestConfig.getCoreVersion()); debugHttpRequest(req, ""); DcResponse res = this.request(req); return res; }
From source file:com.intuit.tank.okhttpclient.TankOkHttpClient.java
/** * Set all the header keys defined by user * * @param connection//from w w w.j a va2 s .c o m */ @SuppressWarnings("rawtypes") private void setHeaders(BaseRequest request, Builder builder, HashMap<String, String> headerInformation) { try { Set set = headerInformation.entrySet(); Iterator iter = set.iterator(); while (iter.hasNext()) { Map.Entry mapEntry = (Map.Entry) iter.next(); builder.addHeader((String) mapEntry.getKey(), (String) mapEntry.getValue()); } } catch (Exception ex) { LOG.warn(request.getLogUtil().getLogMessage("Unable to set header: " + ex.getMessage(), LogEventType.System)); } }
From source file:com.stgmastek.core.logic.ExecutionOrder.java
/** * Static method to setup the execution order. * This method essentially looks up in to the setup table BATCH_COLUMN_MAP to * get the details.Using the details it would setup the execution order for the batch * Once the execution order is set, it sets the order into the {@link BatchInfo#setOrderedMap(TreeMap)} * for all other objects to derive knowledge from. * Note: The batch could be run for - //from w ww . j a v a2s . c o m * <OL> * <LI> For a date i.e. all entities and all values for those entities. * <LI> For an entity i.e. batch for only policy records and all its values * i.e. P1, P2 ... Pn * <LI> For a single object identified as GENERAL type of job with a * sequence number i.e. JOB_SCHEDULE.job_seq * <LI> For only Meta events like ALL PRE and ALL POST * <LI> For any combination of above, a few given - * <UL> * <LI> Policy P1 and ALL PRE * <LI> ALL Agency records and Policy P1 * <LI> Policy P1 and Agency A1 * </UL> * </OL> * * Every step has inline comments associated with it. * * @param batchContext * The context for the batch * @return true * If the setup is done successfully * @throws BatchException * Any database I/O exception */ public synchronized static Boolean setExecutionOrder(BatchContext batchContext) throws BatchException { //Get request parameters HashMap<String, Object> params = batchContext.getRequestParams().getProcessRequestParams(); //Check whether it is a date batch run or specific batch run if (params.size() < 1) { batchContext.getBatchInfo().setDateRun(true); } Connection con = batchContext.getBATCHConnection(); IBatchDao bDao = DaoFactory.getBatchDao(); try { //Query the setup table to get the setup values LookupTable lookupTable = bDao.getLookupTable(con); Map<String, String> orderByLookupTable = bDao.getOrderByLookupTable(con); TreeMap<Integer, EntityParams> orderedMap = new TreeMap<Integer, EntityParams>(); //If it is date batch run, then for all entities, populate "ALL" if (batchContext.getBatchInfo().isDateRun()) { Iterator<String> lTableIter = lookupTable.keySet().iterator(); while (lTableIter.hasNext()) { String entity = lTableIter.next(); params.put(entity + "_1", "ALL"); } } //Iterate over each parameters set for (Entry<String, Object> entry : params.entrySet()) { String paramName = entry.getKey(); Object paramValue = entry.getValue(); if (logger.isDebugEnabled()) { logger.debug("In ExecutionOrder >>>> paramName ==>" + paramName); } String entity = null; //Strip the last occurrence of _ and get the entity name entity = paramName.substring(0, paramName.lastIndexOf("_")); if (logger.isDebugEnabled()) { logger.debug("In ExecutionOrder >>>> Entity ==>" + entity); } //Validate whether the entity is setup appropriately in //the BATCH_COLUMN_MAP table if (!lookupTable.containsKey(entity)) { //If the entity is not set, raise an exception and exit throw new BatchException("The entity " + entity + " is not set up in the COLUMN_MAP table."); } else { //Get the lookup record //Once found, get the details and set it against the entity List<ColumnLookup> lookupColumns = lookupTable.get(entity); Integer order = lookupColumns.get(0).getPrecedenceOrder(); if (!orderedMap.containsKey(order)) { EntityParams entityParams = new EntityParams(entity); orderedMap.put(order, entityParams); } EntityParams entityParams = orderedMap.get(order); entityParams.setLookupColumns(lookupColumns); entityParams.setOrderByMap(orderByLookupTable);//Added on 01-OCT-2013 - Mandar //Check 'ALL' or for specific entity values. //Note: Batch could be run for a date i.e. all entities (and all values) // or for any combination of entity and values if (!paramValue.equals("ALL")) { List<GroupInfo> list = entityParams.getValues(); //check if all exists. If exists do not write the new value if (list.size() == 0 || !list.get(0).getEntityValue().equals("ALL")) entityParams.getValues().add(new GroupInfo((String) paramValue)); } else { entityParams.setAll(new GroupInfo((String) paramValue)); } } } batchContext.getBatchInfo().setOrderedMap(orderedMap); } finally { bDao.releaseResources(null, null, con); } return true; }
From source file:com.elsevier.spark_xml_utils.xslt.XSLTProcessor.java
/** * Transform the content./*from w ww .ja v a 2 s. c o m*/ * @param content the xml to be transformed * @param stylesheetParams HashMap of stylesheet params * @return transformed content * @throw XSLTException */ private String transform(StreamSource content, HashMap<String, String> stylesheetParams) throws XSLTException { try { //Reset the serializer serializer.close(); baos.reset(); // Set stylesheet parameters (if any were specified) for (Entry<String, String> entry : stylesheetParams.entrySet()) { XdmValue xdmValue = builder .build(new StreamSource(IOUtils.toInputStream(entry.getValue(), CharEncoding.UTF_8))); trans.setParameter(new QName("", entry.getKey()), xdmValue); } // Set the content to use for the transformation trans.setSource(content); // Transform the content trans.transform(); // Return the transformed content return new String(baos.toByteArray(), CharEncoding.UTF_8); } catch (IOException e) { log.error("Problems transforming the content. " + e.getMessage(), e); throw new XSLTException(e.getMessage()); } catch (SaxonApiException e) { log.error("Problems transforming the content. " + e.getMessage(), e); throw new XSLTException(e.getMessage()); } }
From source file:edu.utexas.cs.tactex.shiftingpredictors.ShiftingPredictorNoShifts.java
@Override public HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> updateEstimatedEnergyWithShifting( HashMap<CustomerInfo, ArrayRealVector> customer2estimatedEnergy, HashMap<TariffSpecification, HashMap<CustomerInfo, Double>> predictedCustomerSubscriptions, int currentTimeslot) { HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> result = new HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>>(); // add same customer=>energy mapping for all possible tariff-specs // to make a customer=>[spec]=>energy structure for (Entry<TariffSpecification, HashMap<CustomerInfo, Double>> entry : predictedCustomerSubscriptions .entrySet()) {/*from w w w . j a v a2s .c o m*/ TariffSpecification spec = entry.getKey(); for (CustomerInfo cust : entry.getValue().keySet()) { ArrayRealVector energy = customer2estimatedEnergy.get(cust); // get, or create if doesn't exist HashMap<TariffSpecification, ShiftedEnergyData> spec2energy = result.get(cust); if (null == spec2energy) { spec2energy = new HashMap<TariffSpecification, ShiftedEnergyData>(); result.put(cust, spec2energy); } spec2energy.put(spec, new ShiftedEnergyData(energy, 0.0)); // no inconvenience } } return result; }