List of usage examples for org.apache.commons.collections KeyValue getValue
Object getValue();
From source file:org.okj.commons.web.taglib.template.impl.CheckboxTemplate.java
/** * /*w w w . j a v a 2s .co m*/ * @param option * @return */ private boolean isChecked(KeyValue option) { //value Object value = attribute.getValue(); if (value == null) { return false; } List<Object> values = new ArrayList<Object>(); if (value.getClass().isArray()) { // values.addAll(Arrays.asList((Object[]) value)); } else if (value instanceof Collection) { // values.addAll((Collection<?>) value); } else if (value.getClass().isAssignableFrom(String.class)) { // values.add(value); } Object val = null; for (Object obj : values) { //listValueString if (StringUtils.isNotBlank(attribute.getListValue()) && !obj.getClass().isAssignableFrom(String.class)) { try { val = BeanUtils.getNestedProperty(obj, attribute.getListValue()); } catch (Exception ex) { LOGGER.error(ex); } } if (obj.getClass().isAssignableFrom(String.class)) { val = obj; } // if (StringUtils.equalsIgnoreCase(String.valueOf(val), String.valueOf(option.getValue()))) { return true; } } return false; }
From source file:org.okj.commons.web.taglib.template.impl.RadioTemplate.java
/** * @see com.lakala.bmcp.tags.template.impl.SelectOptionsTemplate#createOptions() *///from w w w . j a v a2 s . com @Override protected String createOptions() { List<KeyValue> options = getOptions(); StringBuffer sb = new StringBuffer(); if (options != null && options.size() > 0) { for (int i = 0, n = options.size(); i < n; i++) { sb.append("<input type=\"radio\" "); if (StringUtils.isNotBlank(attribute.getId())) { sb.append("id=\"").append(attribute.getId()).append("_" + i).append("\" "); } sb.append("name=\"").append(attribute.getName()).append("\" "); if (StringUtils.isNotBlank(attribute.getStyleClass())) { sb.append("class=\"").append(attribute.getStyleClass()).append("\" "); } if (StringUtils.isNotBlank(attribute.getStyle())) { sb.append("style=\"").append(attribute.getStyle()).append("\" "); } if (StringUtils.isNotBlank(attribute.getOnclick())) { sb.append("onclick=\"").append(attribute.getOnclick()).append("\" "); } KeyValue keyValue = options.get(i); sb.append(" value=\"").append(keyValue.getValue()); String str = ObjectUtils.nullSafeToString(attribute.getValue()); if (StringUtils.isNotBlank(str) && StringUtils.equalsIgnoreCase(str, String.valueOf(keyValue.getValue()))) { sb.append("\" checked=\"true\" />"); } else { sb.append("\"/>"); } sb.append("<label for=\"").append(attribute.getId()).append("_" + i).append("\">"); sb.append(keyValue.getKey()).append("</label>"); } } return sb.toString(); }
From source file:org.okj.commons.web.taglib.template.impl.SelectOptionsTemplate.java
/** * selectoptions//from w w w .j a va 2 s.c om * @return * @throws Exception */ protected String createOptions() { List<KeyValue> options = getOptions(); StringBuffer sb = new StringBuffer(); boolean alreadySelected = false;// option if (attribute.getHeaderValue() != null && attribute.getHeaderKey() != null) { sb.append("<option value=\"").append(attribute.getHeaderValue()).append("\">") .append(attribute.getHeaderKey()).append("</option>"); } if (options != null && options.size() > 0) { for (int i = 0, n = options.size(); i < n; i++) { KeyValue keyValue = options.get(i); sb.append("<option value=\"").append(keyValue.getValue()); String str = ObjectUtils.nullSafeToString(attribute.getValue()); if (StringUtils.isNotBlank(str) && StringUtils.equalsIgnoreCase(str, String.valueOf(keyValue.getValue())) && !alreadySelected) { sb.append("\" selected >"); alreadySelected = true; } else { sb.append("\">"); } sb.append(keyValue.getKey()).append("</option>"); } } return sb.toString(); }
From source file:org.openiot.gsn.beans.VSensorConfig.java
public String toString() { final StringBuilder builder = new StringBuilder("Input Stream ["); for (final InputStream inputStream : this.getInputStreams()) { builder.append("Input-Stream-Name").append(inputStream.getInputStreamName()); builder.append("Input-Stream-Query").append(inputStream.getQuery()); builder.append(" Stream-Sources ( "); if (inputStream.getSources() == null) builder.append("null"); else/*from w ww. j a v a 2s .c o m*/ for (final StreamSource ss : inputStream.getSources()) { builder.append("Stream-Source Alias : ").append(ss.getAlias()); for (final AddressBean addressing : ss.getAddressing()) { builder.append("Stream-Source-wrapper >").append(addressing.getWrapper()) .append("< with addressign predicates : "); for (final KeyValue keyValue : addressing.getPredicates()) builder.append("Key=").append(keyValue.getKey()).append("Value=") .append(keyValue.getValue()); } builder.append(" , "); } builder.append(")"); } builder.append("]"); return "VSensorConfig{" + "name='" + this.name + '\'' + ", priority=" + this.priority + ", mainClass='" + this.mainClass + '\'' + ", publish-to-lsm=" + this.getPublishToLSM() + ", description='" + this.description + '\'' + ", outputStreamRate=" + this.outputStreamRate + ", addressing=" + this.addressing + ", outputStructure=" + org.openiot.gsn.utils.Formatter.listArray(this.outputStructure) + ", storageHistorySize='" + this.storageHistorySize + '\'' + builder.toString() + ", mainClassInitialParams=" + this.mainClassInitialParams + ", lastModified=" + this.lastModified + ", fileName='" + this.fileName + '\'' + ", logger=" + this.logger + ", nameInitialized=" + this.nameInitialized + ", isStorageCountBased=" + this.isStorageCountBased + ", parsedStorageSize=" + this.parsedStorageSize + '}'; }
From source file:org.openiot.gsn.http.AddressingReqHandler.java
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setStatus(HttpServletResponse.SC_OK); String vsName = request.getParameter("name"); VSensorConfig sensorConfig = Mappings.getVSensorConfig(vsName); if (logger.isInfoEnabled()) logger.info(new StringBuilder().append("Structure request for *").append(vsName).append("* received.") .toString());//from ww w . j a v a 2 s . co m StringBuilder sb = new StringBuilder("<virtual-sensor name=\"").append(vsName).append("\" last-modified=\"") .append(new File(sensorConfig.getFileName()).lastModified()).append("\">\n"); for (KeyValue df : sensorConfig.getAddressing()) sb.append("<predicate key=\"").append(StringEscapeUtils.escapeXml(df.getKey().toString())).append("\">") .append(StringEscapeUtils.escapeXml(df.getValue().toString())).append("</predicate>\n"); sb.append("</virtual-sensor>"); response.setHeader("Cache-Control", "no-store"); response.setDateHeader("Expires", 0); response.setHeader("Pragma", "no-cache"); response.getWriter().write(sb.toString()); }
From source file:org.openiot.gsn.http.OneShotQueryWithAddressingHandler.java
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException { SimpleDateFormat sdf = new SimpleDateFormat(Main.getInstance().getContainerConfig().getTimeFormat()); String vsName = request.getParameter("name"); String vsCondition = request.getParameter("condition"); if (vsCondition == null || vsCondition.trim().length() == 0) vsCondition = " "; else/* ww w.ja v a2 s.c o m*/ vsCondition = " where " + vsCondition; String vsFields = request.getParameter("fields"); if (vsFields == null || vsFields.trim().length() == 0 || vsFields.trim().equals("*")) vsFields = "*"; else vsFields += " , pk, timed"; String windowSize = request.getParameter("window"); if (windowSize == null || windowSize.trim().length() == 0) windowSize = "1"; StringBuilder query = new StringBuilder("select " + vsFields + " from " + vsName + vsCondition + " order by timed DESC limit " + windowSize + " offset 0"); DataEnumerator result; try { result = Main.getStorage(vsName).executeQuery(query, true); } catch (SQLException e) { logger.error("ERROR IN EXECUTING, query: " + query); logger.error(e.getMessage(), e); logger.error("Query is from " + request.getRemoteAddr() + "- " + request.getRemoteHost()); return; } StringBuilder sb = new StringBuilder("<result>\n"); while (result.hasMoreElements()) { StreamElement se = result.nextElement(); sb.append("<stream-element>\n"); for (int i = 0; i < se.getFieldNames().length; i++) if (se.getFieldTypes()[i] == DataTypes.BINARY) sb.append("<field name=\"").append(se.getFieldNames()[i]).append("\">") .append(se.getData()[i].toString()).append("</field>\n"); else sb.append("<field name=\"").append(se.getFieldNames()[i]).append("\">") .append(StringEscapeUtils.escapeXml(se.getData()[i].toString())).append("</field>\n"); sb.append("<field name=\"timed\" >").append(sdf.format(new Date(se.getTimeStamp()))) .append("</field>\n"); VSensorConfig sensorConfig = Mappings.getVSensorConfig(vsName); if (logger.isInfoEnabled()) logger.info(new StringBuilder().append("Structure request for *").append(vsName) .append("* received.").toString()); //StringBuilder statement = new StringBuilder( "<virtual-sensor name=\"" ).append( vsName ).append( "\" last-modified=\"" ).append( new File( sensorConfig.getFileName( ) ).lastModified( ) ).append( "\">\n" ); for (KeyValue df : sensorConfig.getAddressing()) sb.append("<field name=\"").append(StringEscapeUtils.escapeXml(df.getKey().toString())) .append("\">").append(StringEscapeUtils.escapeXml(df.getValue().toString())) .append("</field>\n"); sb.append("</stream-element>\n"); } result.close(); sb.append("</result>"); response.setHeader("Cache-Control", "no-store"); response.setDateHeader("Expires", 0); response.setHeader("Pragma", "no-cache"); response.getWriter().write(sb.toString()); }
From source file:org.ovirt.engine.core.bll.Backend.java
/** * Handles compensation in case of uncompleted compensation-aware commands resulted from server failure. */// w w w .ja v a2 s .c o m private void compensate() { // get all command snapshot entries List<KeyValue> commandSnapshots = DbFacade.getInstance().getBusinessEntitySnapshotDAO().getAllCommands(); for (KeyValue commandSnapshot : commandSnapshots) { // create an instance of the related command by its class name and command id CommandBase<?> cmd = CommandsFactory.CreateCommand(commandSnapshot.getValue().toString(), (Guid) commandSnapshot.getKey()); if (cmd != null) { cmd.compensate(); log.infoFormat("Running compensation on startup for Command : {0} , Command Id : {1}", commandSnapshot.getValue(), commandSnapshot.getKey()); } else { log.errorFormat("Failed to run compensation on startup for Command {0} , Command Id : {1}", commandSnapshot.getValue(), commandSnapshot.getKey()); } } }
From source file:org.xmatthew.spy2servers.jmx.JmxServiceComponent.java
@SuppressWarnings("unchecked") public void startup() { status = ST_RUN;//from w w w.j av a2s. c o m statusName = ST_RUN_NAME; if (getContext() == null) { return; } //export spyComponentMBean List<Component> components = getContext().getComponents(); if (CollectionUtils.isBlankCollection(components)) { return; } mbeanExporter = new MBeanExporter(); Map mbeans = new HashMap(components.size()); String mbeanComponentName; IVisitor visitor = new JmxViewVisitor(); for (Component component : components) { component.accept(visitor); KeyValue result = visitor.getVisitingResult(); if (result != null) { mbeanComponentName = getUniMBeanName(mbeans, (String) result.getKey()); mbeans.put(mbeanComponentName, result.getValue()); } } if (mbeans.size() > 0) { // start jmx export server ManagementContext managementContext = null; if (port > 0) { managementContext = new ManagementContext(port); MBeanServer beanServer = managementContext.getMBeanServer(); mbeanExporter.setServer(beanServer); } mbeanExporter.setBeans(mbeans); try { if (managementContext != null) managementContext.start(); } catch (IOException e) { throw new RuntimeException(e); } mbeanExporter.afterPropertiesSet(); } }
From source file:oscar.oscarReport.ClinicalReports.ReportEvaluator.java
public void evaluate(Denominator deno, Numerator numer, List<KeyValue> additionalFields) { denominator = deno;//from w ww . j av a 2 s . co m numerator = numer; List demoList = deno.getDenominatorList(); denominatorCount = demoList.size(); setReportResultList(new ArrayList<Hashtable<String, Object>>()); for (int i = 0; i < demoList.size(); i++) { String demo = (String) demoList.get(i); boolean bool = numer.evaluate(demo); //Object obj = numer.getOutputValues(); // PROBLEM IS THAT THIS WILL ALWAYS HAVE A VALUE Hashtable<String, Object> h = new Hashtable<String, Object>(); h.put("_demographic_no", demo); h.put("_report_result", new Boolean(bool)); if (additionalFields != null) { for (KeyValue field : additionalFields) { String key = (String) field.getKey(); String val = (String) field.getValue(); EctMeasurementsDataBeanHandler ect = new EctMeasurementsDataBeanHandler(demo, val); Collection<EctMeasurementsDataBean> v = ect.getMeasurementsDataVector(); //Execute for the value and attach it to the key in the hashtable //Object obj = if (v.iterator().hasNext()) { h.put(key, v.iterator().next()); } } } getReportResultList().add(h); // if (obj != null){ // getReportResultList().add(obj); // } if (bool) { numeratorCount++; } } }
From source file:pt.ua.dicoogle.server.web.SearchHolderServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); if (session == null) { response.sendError(401, "ERROR: NO SESSION FOUND"); return;//from w ww .j a v a2s . co m } SearchHolder holder = (SearchHolder) session.getAttribute("dicoogle.web.queryHolder"); if (holder == null) { response.sendError(402, "ERROR: NO SEARCH SESSION FOUND"); return; } int id = Integer.parseInt(request.getParameter("id")); response.setHeader("pragma", "no-cache,no-store"); response.setHeader("cache-control", "no-cache,no-store,max-age=0,max-stale=0"); response.setHeader("connection", "keep-alive"); response.setContentType("text/event-stream"); response.setCharacterEncoding("UTF-8"); // set the apropriate encoding type PrintWriter wr = response.getWriter(); Iterable<KeyValue> it = holder.retrieveQueryOutput(id); wr.print("data: \n\n"); wr.flush(); int eventID = 0; for (KeyValue resp : it) { List<SearchResult> results = new ArrayList<>(); String provider = resp.getKey().toString(); @SuppressWarnings("unchecked") Iterable<SearchResult> result = (Iterable<SearchResult>) resp.getValue(); for (SearchResult r : result) results.add(r); try { DIMGeneric generic = new DIMGeneric(results); JSONObject obj = new JSONObject(); obj.put("provider", provider); JSONArray arr = DIM2JSONConverter.convertToJSON(generic); obj.put("rsp", arr); wr.print("id: " + (eventID++) + "\n"); wr.print("event: QueryResponse\n"); wr.print("data: " + obj.toString() + "\n\n"); wr.flush(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } wr.print("event: close\n"); wr.flush(); wr.close(); }