List of usage examples for java.util HashMap putAll
public void putAll(Map<? extends K, ? extends V> m)
From source file:com.mysql.stresstool.StressTool.java
/** * Print the cursor //from ww w.jav a 2 s . c o m */ private void printProgress() { HashMap allTh = new HashMap(0); if (StressTool.getThreadInfoMap() != null && StressTool.getThreadInfoMap().size() > 0) allTh.putAll(StressTool.getThreadInfoMap()); if (StressTool.getThreadInfoSelectMap() != null && StressTool.getThreadInfoSelectMap().size() > 0) allTh.putAll(StressTool.getThreadInfoSelectMap()); if (StressTool.getThreadInfoDeleteMap() != null && StressTool.getThreadInfoDeleteMap().size() > 0) allTh.putAll(StressTool.getThreadInfoDeleteMap()); if (allTh != null && allTh.size() > 0) { double currentLastLoop = this.getCurrentLastLoop(); //GEt the real status of the execution if (allTh.size() > 0) { Object[] itAll = allTh.keySet().toArray(); for (int i = 0; i <= itAll.length - 1; i++) { double tmpMin = 0.0; if (itAll.length > 1 && i < itAll.length - 1) { int a = ((ThreadInfo) allTh.get(itAll[i])).getExecutedLoops(); int b = ((ThreadInfo) allTh.get(itAll[i + 1])).getExecutedLoops(); tmpMin = Math.min(a, b); } else { int a = ((ThreadInfo) allTh.get(itAll[i])).getExecutedLoops(); tmpMin = Math.min(a, a); } if (i > 0) currentLastLoop = Math.min(currentLastLoop, tmpMin); else currentLastLoop = tmpMin; // this.setCurrentLastLoop(currentLastLoop); //System.out.print("Running min = " + currentLastLoop + "\n"); // int a = ((ThreadInfo)allTh.get(i)).getExecutedLoops(); // int b = ((ThreadInfo)allTh.get(i+1)).getExecutedLoops(); // currentLastLoop = Math.min(a, b); } } else { Object[] itAll = allTh.keySet().toArray(); // currentLastLoop = ((ThreadInfo)allTh.get(itAll[0])).getExecutedLoops(); } int perccurrentLastLoop = 1; int curPrevLoop = this.getCurrentLastLoop() > 0 ? this.getCurrentLastLoop() : -1; perccurrentLastLoop = new Double(Math.ceil((((double) currentLastLoop / repeatNumber) * 100))) .intValue(); // System.out.println(perccurrentLastLoop + " " + this.getCurrentLastLoop() + " " + repeatNumber); if (perccurrentLastLoop > curPrevLoop) { // int toprint = new Double(perccurrentLastLoop - this.getCurrentLastLoop()).intValue(); int toprint = (perccurrentLastLoop - curPrevLoop); if (this.debug) System.out .println(toprint + " " + perccurrentLastLoop + " " + curPrevLoop + " " + repeatNumber); for (int ic = 0; ic < toprint; ic++) { System.out.print("*"); } this.setCurrentLastLoop(perccurrentLastLoop); // this.prevPercentLoop = perccurrentLastLoop; } } }
From source file:it.unibas.spicy.persistence.csv.DAOCsv.java
@SuppressWarnings("unchecked") public void loadInstanceSample(IDataSourceProxy dataSource, HashMap<String, ArrayList<Object>> strfullPath, String catalog) throws DAOException { INode root = null;/*from ww w .ja v a2s . c o m*/ try { HashMap<String, ArrayList<Object>> instanceInfoList = (HashMap<String, ArrayList<Object>>) dataSource .getAnnotation(SpicyEngineConstants.CSV_INSTANCES_INFO_LIST); root = new TupleNode(getNode(catalog).getLabel(), getOID()); root.setRoot(true); for (Map.Entry<String, ArrayList<Object>> entry : strfullPath.entrySet()) { String filePath = entry.getKey(); //the list entry.getValue() contains a)the table name //b)a boolean that contains the info if the instance file includes column names String tableName = (String) entry.getValue().get(0); boolean colNames = (Boolean) entry.getValue().get(1); SetNode setTable = new SetNode(getNode(tableName).getLabel(), getOID()); if (logger.isDebugEnabled()) logger.debug("extracting value for table " + tableName + " ...."); getInstanceByTable(tableName, setTable, filePath, colNames); root.addChild(setTable); if (instanceInfoList == null) { instanceInfoList = new HashMap<String, ArrayList<Object>>(); dataSource.addAnnotation(SpicyEngineConstants.CSV_INSTANCES_INFO_LIST, instanceInfoList); } instanceInfoList.putAll(strfullPath); } dataSource.addInstanceWithCheck(root); } catch (Throwable ex) { logger.error(ex); throw new DAOException(ex.getMessage()); } }
From source file:it.eng.spagobi.commons.presentation.tags.ListTag.java
/** * Builds Table list footer, reading all request information. * // w ww . j a v a2 s . c o m * @throws JspException If any Exception occurs. */ protected void makeFooterList() throws JspException { String pageNumberString = (String) _content.getAttribute("PAGED_LIST.PAGE_NUMBER"); int pageNumber = 1; try { pageNumber = Integer.parseInt(pageNumberString); } catch (NumberFormatException ex) { TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.WARNING, "ListTag::makeNavigationButton:: PAGE_NUMBER nullo"); } String pagesNumberString = (String) _content.getAttribute("PAGED_LIST.PAGES_NUMBER"); int pagesNumber = 1; try { pagesNumber = Integer.parseInt(pagesNumberString); } catch (NumberFormatException ex) { TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.WARNING, "ListTag::makeNavigationButton:: PAGES_NUMBER nullo"); } int prevPage = pageNumber - 1; if (prevPage < 1) prevPage = 1; int nextPage = pageNumber + 1; if (nextPage > pagesNumber) nextPage = pagesNumber; int startRangePages = 1; int endRangePages = END_RANGE_PAGES; int deltaPages = pagesNumber - endRangePages; String dotsStart = null; String dotsEnd = null; if (deltaPages > 0) { startRangePages = (pageNumber - 3 > 0) ? pageNumber - 3 : 1; endRangePages = ((pageNumber + 3 <= pagesNumber) && (pageNumber + 3 > END_RANGE_PAGES)) ? pageNumber + 3 : END_RANGE_PAGES; if (pageNumber + 3 <= pagesNumber) { if (pageNumber + 3 > END_RANGE_PAGES) endRangePages = pageNumber + 3; else endRangePages = END_RANGE_PAGES; } else { startRangePages = startRangePages - (pageNumber + 3 - pagesNumber); endRangePages = pagesNumber; } if (endRangePages < pagesNumber) dotsEnd = "... "; if (startRangePages > 1) dotsStart = "... "; } else { startRangePages = 1; endRangePages = pagesNumber; } _htmlStream.append(" <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH='100%' BORDER=0>\n"); _htmlStream.append(" <TR>\n"); // visualize page numbers String pageLabel = msgBuilder.getMessage("ListTag.pageLable", "messages", httpRequest); String pageOfLabel = msgBuilder.getMessage("ListTag.pageOfLable", "messages", httpRequest); _htmlStream.append( " <TD class='portlet-section-footer' style='vertical-align:top;horizontal-align:left;width:30%;'>\n"); _htmlStream.append(" <font class='aindice'> " + pageLabel + " " + pageNumber + " " + pageOfLabel + " " + pagesNumber + " </font>\n"); //_htmlStream.append(" \n"); _htmlStream.append(" </TD>\n"); //_htmlStream.append(" <TD class='portlet-section-footer' width='23%'>\n"); //_htmlStream.append(" \n"); //_htmlStream.append(" </TD>\n"); _htmlStream.append( " <TD class='portlet-section-footer' style='vertical-align:top;horizontal-align:center;width:40%;'>\n"); // visualize navigation's icons if (pageNumber != 1) { //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' align='left' width='1%'>\n"); _htmlStream.append(" <A href=\"" + _firstUrl + "\"><IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/2leftarrow.png", currTheme) + "' border=0></a>\n"); //_htmlStream.append(" </TD>\n"); //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' align='left' width='1%'>\n"); _htmlStream.append(" <A href=\"" + _prevUrl + "\"><IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/1leftarrow.png", currTheme) + "' border=0></a>\n"); //_htmlStream.append(" </TD>\n"); } else { //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' align='left' width='1%'>\n"); _htmlStream.append(" <IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/2leftarrow.png", currTheme) + "' border=0 />\n"); //_htmlStream.append(" </TD>\n"); //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' align='left' width='1%'>\n"); _htmlStream.append(" <IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/1leftarrow.png", currTheme) + "' border=0 />\n"); //_htmlStream.append(" </TD>\n"); } //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' width='20%'>\n"); if (dotsStart != null) { _htmlStream.append("<A style='vertical-align:top;'>" + dotsStart + "</a>\n"); _htmlStream.append(" \n"); } for (int i = startRangePages; i <= endRangePages; i++) { // create link for last page HashMap tmpParamsMap = new HashMap(); tmpParamsMap.putAll(_providerUrlMap); tmpParamsMap.put("MESSAGE", "LIST_PAGE"); tmpParamsMap.put("LIST_PAGE", String.valueOf(i)); String tmpUrl = createUrl(tmpParamsMap); String ORDER = (String) _serviceRequest.getAttribute("ORDER"); String FIELD_ORDER = (String) _serviceRequest.getAttribute("FIELD_ORDER"); if (FIELD_ORDER != null && ORDER != null) { tmpParamsMap.put("FIELD_ORDER", FIELD_ORDER); tmpParamsMap.put("ORDER", ORDER); } String valueFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.VALUE_FILTER); String typeValueFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.TYPE_VALUE_FILTER); String columnFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.COLUMN_FILTER); String typeFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.TYPE_FILTER); if (valueFilter != null && columnFilter != null && typeFilter != null) { tmpParamsMap.put(SpagoBIConstants.VALUE_FILTER, valueFilter); tmpParamsMap.put(SpagoBIConstants.TYPE_VALUE_FILTER, typeValueFilter); tmpParamsMap.put(SpagoBIConstants.COLUMN_FILTER, columnFilter); tmpParamsMap.put(SpagoBIConstants.TYPE_FILTER, typeFilter); tmpUrl = createUrl(tmpParamsMap); } tmpUrl = StringEscapeUtils.escapeHtml(tmpUrl); _htmlStream.append( " <A style='vertical-align:top;' href=\"" + tmpUrl + "\">" + String.valueOf(i) + "</a>\n"); _htmlStream.append(" \n"); } if (dotsEnd != null) { _htmlStream.append("<A style='vertical-align:top;'>" + dotsEnd + "</a>\n"); } //_htmlStream.append(" </TD>\n"); if (pageNumber != pagesNumber) { //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' width='1%'>\n"); _htmlStream.append(" <A href=\"" + _nextUrl + "\"><IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/1rightarrow.png", currTheme) + "' border=0 /></a>\n"); //_htmlStream.append(" </TD>\n"); //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' width='1%'>\n"); _htmlStream.append(" <A href=\"" + _lastUrl + "\"><IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/2rightarrow.png", currTheme) + "' border=0 /></a>\n"); //_htmlStream.append(" </TD>\n"); } else { //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' width='1%'>\n"); _htmlStream.append(" <IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/1rightarrow.png", currTheme) + "' border=0>\n"); //_htmlStream.append(" </TD>\n"); //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' width='1%'>\n"); _htmlStream.append(" <IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/2rightarrow.png", currTheme) + "' border=0>\n"); //_htmlStream.append(" </TD>\n"); } _htmlStream.append(" </TD>\n"); _htmlStream.append(" <TD class='portlet-section-footer' style='width:30%;'>\n"); _htmlStream.append(" \n"); _htmlStream.append(" </TD>\n"); _htmlStream.append(" </TR>\n"); _htmlStream.append("</TABLE>\n"); }
From source file:voldemort.VoldemortAdminTool.java
private static void executeFetchEntries(Integer nodeId, AdminClient adminClient, List<Integer> partitionIdList, String outputDir, List<String> storeNames, boolean useAscii, boolean fetchOrphaned) throws IOException { List<StoreDefinition> storeDefinitionList = adminClient.metadataMgmtOps.getRemoteStoreDefList(nodeId) .getValue();//from ww w .j a v a 2s . c o m HashMap<String, StoreDefinition> storeDefinitionMap = Maps.newHashMap(); for (StoreDefinition storeDefinition : storeDefinitionList) { storeDefinitionMap.put(storeDefinition.getName(), storeDefinition); } File directory = null; if (outputDir != null) { directory = new File(outputDir); if (!(directory.exists() || directory.mkdir())) { Utils.croak("Can't find or create directory " + outputDir); } } List<String> stores = storeNames; if (stores == null) { // when no stores specified, all user defined store will be fetched, // but not system stores. stores = Lists.newArrayList(); stores.addAll(storeDefinitionMap.keySet()); } else { // add system stores to the map so they can be fetched when // specified explicitly storeDefinitionMap.putAll(getSystemStoreDefs()); } // Pick up all the partitions if (partitionIdList == null) { partitionIdList = Lists.newArrayList(); for (Node node : adminClient.getAdminClientCluster().getNodes()) { partitionIdList.addAll(node.getPartitionIds()); } } StoreDefinition storeDefinition = null; for (String store : stores) { storeDefinition = storeDefinitionMap.get(store); if (null == storeDefinition) { System.out.println("No store found under the name \'" + store + "\'"); continue; } Iterator<Pair<ByteArray, Versioned<byte[]>>> entriesIteratorRef = null; if (fetchOrphaned) { System.out.println("Fetching orphaned entries of " + store); entriesIteratorRef = adminClient.bulkFetchOps.fetchOrphanedEntries(nodeId, store); } else { System.out.println( "Fetching entries in partitions " + Joiner.on(", ").join(partitionIdList) + " of " + store); entriesIteratorRef = adminClient.bulkFetchOps.fetchEntries(nodeId, store, partitionIdList, null, false); } final Iterator<Pair<ByteArray, Versioned<byte[]>>> entriesIterator = entriesIteratorRef; File outputFile = null; if (directory != null) { outputFile = new File(directory, store + ".entries"); } if (useAscii) { // k-v serializer SerializerDefinition keySerializerDef = storeDefinition.getKeySerializer(); SerializerDefinition valueSerializerDef = storeDefinition.getValueSerializer(); SerializerFactory serializerFactory = new DefaultSerializerFactory(); @SuppressWarnings("unchecked") final Serializer<Object> keySerializer = (Serializer<Object>) serializerFactory .getSerializer(keySerializerDef); @SuppressWarnings("unchecked") final Serializer<Object> valueSerializer = (Serializer<Object>) serializerFactory .getSerializer(valueSerializerDef); // compression strategy final CompressionStrategy keyCompressionStrategy; final CompressionStrategy valueCompressionStrategy; if (keySerializerDef != null && keySerializerDef.hasCompression()) { keyCompressionStrategy = new CompressionStrategyFactory() .get(keySerializerDef.getCompression()); } else { keyCompressionStrategy = null; } if (valueSerializerDef != null && valueSerializerDef.hasCompression()) { valueCompressionStrategy = new CompressionStrategyFactory() .get(valueSerializerDef.getCompression()); } else { valueCompressionStrategy = null; } writeAscii(outputFile, new Writable() { @Override public void writeTo(BufferedWriter out) throws IOException { while (entriesIterator.hasNext()) { final JsonGenerator generator = new JsonFactory(new ObjectMapper()) .createJsonGenerator(out); Pair<ByteArray, Versioned<byte[]>> kvPair = entriesIterator.next(); byte[] keyBytes = kvPair.getFirst().get(); byte[] valueBytes = kvPair.getSecond().getValue(); VectorClock version = (VectorClock) kvPair.getSecond().getVersion(); Object keyObject = keySerializer.toObject((null == keyCompressionStrategy) ? keyBytes : keyCompressionStrategy.inflate(keyBytes)); Object valueObject = valueSerializer .toObject((null == valueCompressionStrategy) ? valueBytes : valueCompressionStrategy.inflate(valueBytes)); if (keyObject instanceof GenericRecord) { out.write(keyObject.toString()); } else { generator.writeObject(keyObject); } out.write(' ' + version.toString() + ' '); if (valueObject instanceof GenericRecord) { out.write(valueObject.toString()); } else { generator.writeObject(valueObject); } out.write('\n'); } } }); } else { writeBinary(outputFile, new Printable() { @Override public void printTo(DataOutputStream out) throws IOException { while (entriesIterator.hasNext()) { Pair<ByteArray, Versioned<byte[]>> kvPair = entriesIterator.next(); byte[] keyBytes = kvPair.getFirst().get(); VectorClock clock = ((VectorClock) kvPair.getSecond().getVersion()); byte[] valueBytes = kvPair.getSecond().getValue(); out.writeChars(ByteUtils.toHexString(keyBytes)); out.writeChars(","); out.writeChars(clock.toString()); out.writeChars(","); out.writeChars(ByteUtils.toHexString(valueBytes)); out.writeChars("\n"); } } }); } if (outputFile != null) System.out.println("Fetched keys from " + store + " to " + outputFile); } }
From source file:com.goftagram.telegram.messenger.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;/*from ww w . j ava 2 s . c o m*/ } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); HashMap<Long, Integer> oldIdsAuto = new HashMap<>(); oldIdsAuto.putAll(autoNotificationsIds); autoNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } if (chat != null) { if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) { photoPath = chat.photo.photo_small; } } else { if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) { photoPath = user.photo.photo_small; } } } Integer notificationIdWear = oldIdsWear.get(dialog_id); if (notificationIdWear == null) { notificationIdWear = wearNotificationId++; } else { oldIdsWear.remove(dialog_id); } Integer notificationIdAuto = oldIdsAuto.get(dialog_id); if (notificationIdAuto == null) { notificationIdAuto = autoNotificationId++; } else { oldIdsAuto.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("com.goftagram.telegram.messenger.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("com.goftagram.telegram.messenger.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build(); } String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setColor(0xff2ca5e0).setGroupSummary(false).setContentIntent(contentIntent) .extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationIdWear, builder.build()); wearNotificationsIds.put(dialog_id, notificationIdWear); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:com.panahit.telegramma.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;/*from www .j a v a 2s. c o m*/ } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); HashMap<Long, Integer> oldIdsAuto = new HashMap<>(); oldIdsAuto.putAll(autoNotificationsIds); autoNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } if (chat != null) { if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) { photoPath = chat.photo.photo_small; } } else { if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) { photoPath = user.photo.photo_small; } } } Integer notificationIdWear = oldIdsWear.get(dialog_id); if (notificationIdWear == null) { notificationIdWear = wearNotificationId++; } else { oldIdsWear.remove(dialog_id); } Integer notificationIdAuto = oldIdsAuto.get(dialog_id); if (notificationIdAuto == null) { notificationIdAuto = autoNotificationId++; } else { oldIdsAuto.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("org.telegram.messenger.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("org.telegram.messenger.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build(); } String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setColor(0xff2ca5e0).setGroupSummary(false).setContentIntent(contentIntent) .extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationIdWear, builder.build()); wearNotificationsIds.put(dialog_id, notificationIdWear); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:it.eng.spagobi.commons.presentation.tags.ListTag.java
/** * Builds list navigation buttons inside the list tag. If the number * of elements is higher than 10, they are divided into pages; this * methods creates forward and backward arrows and page number information * for navigation./*from w ww . j ava 2 s. c o m*/ * * @throws JspException If any Exception occurs */ protected void makeNavigationButton() throws JspException { String pageNumberString = (String) _content.getAttribute("PAGED_LIST.PAGE_NUMBER"); int pageNumber = 1; try { pageNumber = Integer.parseInt(pageNumberString); } catch (NumberFormatException ex) { TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.WARNING, "ListTag::makeNavigationButton:: PAGE_NUMBER nullo"); } String pagesNumberString = (String) _content.getAttribute("PAGED_LIST.PAGES_NUMBER"); int pagesNumber = 1; try { pagesNumber = Integer.parseInt(pagesNumberString); } catch (NumberFormatException ex) { TracerSingleton.log(Constants.NOME_MODULO, TracerSingleton.WARNING, "ListTag::makeNavigationButton:: PAGES_NUMBER nullo"); } int prevPage = pageNumber - 1; if (prevPage < 1) prevPage = 1; int nextPage = pageNumber + 1; if (nextPage > pagesNumber) nextPage = pagesNumber; _htmlStream.append(" <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH='100%' BORDER=0>\n"); _htmlStream.append(" <TR>\n"); //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' align='left' width='14'>\n"); // create link for previous page HashMap prevParamsMap = new HashMap(); prevParamsMap.putAll(_providerUrlMap); prevParamsMap.put("MESSAGE", "LIST_PAGE"); prevParamsMap.put("LIST_PAGE", String.valueOf(prevPage)); _prevUrl = createUrl(prevParamsMap); //_prevUrl = response.encodeURL(_prevUrl); _prevUrl = StringEscapeUtils.escapeHtml(_prevUrl); // create url for refresh page HashMap refreshParamsMap = new HashMap(); refreshParamsMap.putAll(_providerUrlMap); refreshParamsMap.put("MESSAGE", "LIST_PAGE"); refreshParamsMap.put("LIST_PAGE", String.valueOf(pageNumber)); _refreshUrl = createUrl(refreshParamsMap); _refreshUrl = _refreshUrl.replaceAll("&", "&"); //_refreshUrl = response.encodeURL(_refreshUrl); _refreshUrl = StringEscapeUtils.escapeHtml(_refreshUrl); // create link for next page HashMap nextParamsMap = new HashMap(); nextParamsMap.putAll(_providerUrlMap); nextParamsMap.put("MESSAGE", "LIST_PAGE"); nextParamsMap.put("LIST_PAGE", String.valueOf(nextPage)); _nextUrl = createUrl(nextParamsMap); //_nextUrl = response.encodeURL(_nextUrl); _nextUrl = StringEscapeUtils.escapeHtml(_nextUrl); // create link for first page HashMap firstParamsMap = new HashMap(); firstParamsMap.putAll(_providerUrlMap); firstParamsMap.put("MESSAGE", "LIST_PAGE"); firstParamsMap.put("LIST_PAGE", "1"); _firstUrl = createUrl(firstParamsMap); //_firstUrl = response.encodeURL(_firstUrl); _firstUrl = StringEscapeUtils.escapeHtml(_firstUrl); // create link for last page HashMap lastParamsMap = new HashMap(); lastParamsMap.putAll(_providerUrlMap); lastParamsMap.put("MESSAGE", "LIST_PAGE"); lastParamsMap.put("LIST_PAGE", String.valueOf(pagesNumber)); _lastUrl = createUrl(lastParamsMap); //_lastUrl = response.encodeURL(_lastUrl); _lastUrl = StringEscapeUtils.escapeHtml(_lastUrl); String formId = "formFilter" + requestIdentity; String valueFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.VALUE_FILTER); String typeValueFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.TYPE_VALUE_FILTER); String columnFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.COLUMN_FILTER); String typeFilter = (String) _serviceRequest.getAttribute(SpagoBIConstants.TYPE_FILTER); if (valueFilter != null && columnFilter != null && typeFilter != null) { prevParamsMap.put(SpagoBIConstants.VALUE_FILTER, valueFilter); prevParamsMap.put(SpagoBIConstants.TYPE_VALUE_FILTER, typeValueFilter); prevParamsMap.put(SpagoBIConstants.COLUMN_FILTER, columnFilter); prevParamsMap.put(SpagoBIConstants.TYPE_FILTER, typeFilter); _prevUrl = createUrl(prevParamsMap); //_prevUrl = response.encodeURL(_prevUrl); _prevUrl = StringEscapeUtils.escapeHtml(_prevUrl); nextParamsMap.put(SpagoBIConstants.VALUE_FILTER, valueFilter); nextParamsMap.put(SpagoBIConstants.TYPE_VALUE_FILTER, typeValueFilter); nextParamsMap.put(SpagoBIConstants.COLUMN_FILTER, columnFilter); nextParamsMap.put(SpagoBIConstants.TYPE_FILTER, typeFilter); _nextUrl = createUrl(nextParamsMap); //_nextUrl = response.encodeURL(_nextUrl); _nextUrl = StringEscapeUtils.escapeHtml(_nextUrl); firstParamsMap.put(SpagoBIConstants.VALUE_FILTER, valueFilter); firstParamsMap.put(SpagoBIConstants.TYPE_VALUE_FILTER, typeValueFilter); firstParamsMap.put(SpagoBIConstants.COLUMN_FILTER, columnFilter); firstParamsMap.put(SpagoBIConstants.TYPE_FILTER, typeFilter); _firstUrl = createUrl(firstParamsMap); //_firstUrl = response.encodeURL(_firstUrl); _firstUrl = StringEscapeUtils.escapeHtml(_firstUrl); lastParamsMap.put(SpagoBIConstants.VALUE_FILTER, valueFilter); lastParamsMap.put(SpagoBIConstants.TYPE_VALUE_FILTER, typeValueFilter); lastParamsMap.put(SpagoBIConstants.COLUMN_FILTER, columnFilter); lastParamsMap.put(SpagoBIConstants.TYPE_FILTER, typeFilter); _lastUrl = createUrl(lastParamsMap); //_lastUrl = response.encodeURL(_lastUrl); _lastUrl = StringEscapeUtils.escapeHtml(_lastUrl); } else { valueFilter = ""; typeValueFilter = ""; columnFilter = ""; typeFilter = ""; } if (pageNumber != 1) { _htmlStream .append(" <TD class='portlet-section-footer' valign='center' align='left' width='1%'>\n"); _htmlStream.append(" <A href=\"" + _firstUrl + "\"><IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/2leftarrow.png", currTheme) + "' ALIGN=RIGHT border=0></a>\n"); _htmlStream.append(" </TD>\n"); _htmlStream .append(" <TD class='portlet-section-footer' valign='center' align='left' width='1%'>\n"); _htmlStream.append(" <A href=\"" + _prevUrl + "\"><IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/1leftarrow.png", currTheme) + "' ALIGN=RIGHT border=0></a>\n"); _htmlStream.append(" </TD>\n"); } else { _htmlStream .append(" <TD class='portlet-section-footer' valign='center' align='left' width='1%'>\n"); _htmlStream.append(" <IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/2leftarrow.png", currTheme) + "' ALIGN=RIGHT border=0 />\n"); _htmlStream.append(" </TD>\n"); _htmlStream .append(" <TD class='portlet-section-footer' valign='center' align='left' width='1%'>\n"); _htmlStream.append(" <IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/1leftarrow.png", currTheme) + "' ALIGN=RIGHT border=0 />\n"); _htmlStream.append(" </TD>\n"); } //_htmlStream.append(" </TD>\n"); // Form for list filtering; if not specified, the filter is enabled _htmlStream .append(" <TD class='portlet-section-footer' valign='center' align='middle' width='80%'>\n"); if (_filter == null || _filter.equalsIgnoreCase("enabled")) { /*HashMap allUrlMap = (HashMap) _providerUrlMap.clone(); allUrlMap.remove("valueFilter"); allUrlMap.remove("columnFilter"); allUrlMap.remove("typeFilter"); allUrlMap.remove("typeValueFilter");*/ String allUrl = createUrl(_providerUrlMap); String filterURL = createUrl(_providerUrlMap); filterURL = StringEscapeUtils.escapeHtml(filterURL); String label = msgBuilder.getMessage("SBIListLookPage.labelFilter", "messages", httpRequest); String labelTypeValueFilter = msgBuilder.getMessage("SBIListLookPage.labelTypeValueFilter", "messages", httpRequest); String labelNumber = msgBuilder.getMessage("SBIListLookPage.labelNumber", "messages", httpRequest); String labelString = msgBuilder.getMessage("SBIListLookPage.labelString", "messages", httpRequest); String labelDate = msgBuilder.getMessage("SBIListLookPage.labelDate", "messages", httpRequest); String labelStart = msgBuilder.getMessage("SBIListLookPage.startWith", "messages", httpRequest); String labelEnd = msgBuilder.getMessage("SBIListLookPage.endWith", "messages", httpRequest); String labelContain = msgBuilder.getMessage("SBIListLookPage.contains", "messages", httpRequest); String labelEqual = msgBuilder.getMessage("SBIListLookPage.isEquals", "messages", httpRequest); String labelIsLessThan = msgBuilder.getMessage("SBIListLookPage.isLessThan", "messages", httpRequest); String labelIsLessOrEqualThan = msgBuilder.getMessage("SBIListLookPage.isLessOrEqualThan", "messages", httpRequest); String labelIsGreaterThan = msgBuilder.getMessage("SBIListLookPage.isGreaterThan", "messages", httpRequest); String labelIsGreaterOrEqualThan = msgBuilder.getMessage("SBIListLookPage.isGreaterOrEqualThan", "messages", httpRequest); String labelFilter = msgBuilder.getMessage("SBIListLookPage.filter", "messages", httpRequest); String labelAll = msgBuilder.getMessage("SBIListLookPage.all", "messages", httpRequest); //_htmlStream.append(" <br/><br/>\n"); _htmlStream.append( " <form action='" + filterURL + "' id='" + formId + "' method='post'>\n"); _htmlStream.append(" " + label + "\n"); _htmlStream.append(" <select name='" + SpagoBIConstants.COLUMN_FILTER + "'>\n"); for (int i = 0; i < _columns.size(); i++) { String nameColumn = (String) ((SourceBean) _columns.elementAt(i)).getAttribute("NAME"); String labelColumnCode = (String) ((SourceBean) _columns.elementAt(i)).getAttribute("LABEL"); String labelColumn = new String(nameColumn); if (labelColumnCode != null) labelColumn = msgBuilder.getMessage(labelColumnCode, _bundle, httpRequest); String selected = ""; if (nameColumn.equalsIgnoreCase(columnFilter)) selected = " selected='selected' "; _htmlStream.append(" <option value='" + nameColumn + "' " + selected + " >" + labelColumn + "</option>\n"); } String selected = ""; _htmlStream.append(" </select>\n"); _htmlStream.append(" " + labelTypeValueFilter + "\n"); _htmlStream .append(" <select name='" + SpagoBIConstants.TYPE_VALUE_FILTER + "'>\n"); if (typeValueFilter.equalsIgnoreCase(SpagoBIConstants.STRING_TYPE_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.STRING_TYPE_FILTER + "' " + selected + " >" + labelString + "</option>\n"); if (typeValueFilter.equalsIgnoreCase(SpagoBIConstants.NUMBER_TYPE_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.NUMBER_TYPE_FILTER + "' " + selected + " >" + labelNumber + "</option>\n"); if (typeValueFilter.equalsIgnoreCase(SpagoBIConstants.DATE_TYPE_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.DATE_TYPE_FILTER + "' " + selected + " >" + labelDate + "</option>\n"); _htmlStream.append(" </select>\n"); _htmlStream.append(" <select name='" + SpagoBIConstants.TYPE_FILTER + "'>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.START_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.START_FILTER + "' " + selected + " >" + labelStart + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.END_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.END_FILTER + "' " + selected + " >" + labelEnd + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.CONTAIN_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.CONTAIN_FILTER + "' " + selected + " >" + labelContain + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.EQUAL_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.EQUAL_FILTER + "' " + selected + " >" + labelEqual + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.LESS_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.LESS_FILTER + "' " + selected + " >" + labelIsLessThan + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.LESS_OR_EQUAL_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.LESS_OR_EQUAL_FILTER + "' " + selected + " >" + labelIsLessOrEqualThan + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.GREATER_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.GREATER_FILTER + "' " + selected + " >" + labelIsGreaterThan + "</option>\n"); if (typeFilter.equalsIgnoreCase(SpagoBIConstants.GREATER_OR_EQUAL_FILTER)) selected = " selected='selected' "; else selected = ""; _htmlStream.append(" <option value='" + SpagoBIConstants.GREATER_OR_EQUAL_FILTER + "' " + selected + " >" + labelIsGreaterOrEqualThan + "</option>\n"); _htmlStream.append(" </select>\n"); _htmlStream.append(" <input type=\"text\" name=\"" + SpagoBIConstants.VALUE_FILTER + "\" size=\"10\" value=\"" + StringEscapeUtils.escapeHtml(valueFilter) + "\" /> \n"); _htmlStream.append(" <a href='javascript:document.getElementById(\"" + formId + "\").submit()'>" + StringEscapeUtils.escapeHtml(labelFilter) + "</a> \n"); _htmlStream.append(" <a href='" + allUrl + "'>" + StringEscapeUtils.escapeHtml(labelAll) + "</a> \n"); _htmlStream.append(" </form> \n"); // visualize any validation error present in the errorHandler boolean thereAreValidationErrors = false; StringBuffer errorsHtmlString = new StringBuffer(""); if (_errorHandler != null) { Collection errors = _errorHandler.getErrors(); if (errors != null && errors.size() > 0) { errorsHtmlString.append(" <div class='filter-list-errors'>\n"); Iterator iterator = errors.iterator(); EMFAbstractError error = null; String description = ""; while (iterator.hasNext()) { error = (EMFAbstractError) iterator.next(); if (error instanceof EMFValidationError) { description = error.getDescription(); errorsHtmlString.append(" " + description + "<br/>\n"); thereAreValidationErrors = true; } } errorsHtmlString.append(" </div>\n"); } } if (thereAreValidationErrors) _htmlStream.append(errorsHtmlString); } _htmlStream.append(" </TD>\n"); // create link for next page //_htmlStream.append(" <TD class='portlet-section-footer' valign='center' align='right' width='14'>\n"); if (pageNumber != pagesNumber) { _htmlStream.append(" <TD class='portlet-section-footer' valign='center' width='1%'>\n"); _htmlStream.append(" <A href=\"" + _nextUrl + "\"><IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/1rightarrow.png", currTheme) + "' ALIGN=RIGHT border=0 /></a>\n"); _htmlStream.append(" </TD>\n"); _htmlStream.append(" <TD class='portlet-section-footer' valign='center' width='1%'>\n"); _htmlStream.append(" <A href=\"" + _lastUrl + "\"><IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/2rightarrow.png", currTheme) + "' ALIGN=RIGHT border=0 /></a>\n"); _htmlStream.append(" </TD>\n"); } else { _htmlStream.append(" <TD class='portlet-section-footer' valign='center' width='1%'>\n"); _htmlStream.append(" <IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/1rightarrow.png", currTheme) + "' ALIGN=RIGHT border=0>\n"); _htmlStream.append(" </TD>\n"); _htmlStream.append(" <TD class='portlet-section-footer' valign='center' width='1%'>\n"); _htmlStream.append(" <IMG src='" + urlBuilder.getResourceLinkByTheme(httpRequest, "/img/commons/2rightarrow.png", currTheme) + "' ALIGN=RIGHT border=0>\n"); _htmlStream.append(" </TD>\n"); } // _htmlStream.append(" </TD>\n"); _htmlStream.append(" </TR>\n"); _htmlStream.append("</TABLE>\n"); }
From source file:org.openhab.binding.ebus.parser.EBusTelegramParser.java
/** * @param telegram/* ww w. ja va 2s. c om*/ * @return */ public Map<String, Object> parse(EBusTelegram telegram) { if (configurationProvider == null) { logger.error("Configuration not loaded, can't parse telegram!"); return null; } final Map<String, Object> valueRegistry = new HashMap<String, Object>(); final Map<String, Object> valueRegistry2 = new HashMap<String, Object>(); if (telegram == null) { return null; } final ByteBuffer byteBuffer = telegram.getBuffer(); final String bufferString = EBusUtils.toHexDumpString(byteBuffer).toString(); final List<Map<String, Object>> matchedTelegramRegistry = configurationProvider .getCommandsByFilter(bufferString); loggerAnalyses.debug(bufferString); if (matchedTelegramRegistry.isEmpty()) { loggerAnalyses.debug(" >>> Unknown ----------------------------------------"); if (loggerBrutforce.isTraceEnabled()) { loggerBrutforce.trace(bufferString); bruteforceEBusTelegram(telegram); } return null; } // loop thru all matching telegrams from registry for (Map<String, Object> registryEntry : matchedTelegramRegistry) { String classKey = registryEntry.containsKey("class") ? (String) registryEntry.get("class") : ""; int debugLevel = 0; if (registryEntry.containsKey("debug")) { debugLevel = ((Integer) registryEntry.get("debug")); } // get values block @SuppressWarnings("unchecked") Map<String, Map<String, Object>> values = (Map<String, Map<String, Object>>) registryEntry .get("values"); loggerAnalyses.debug(" >>> {}", registryEntry.containsKey("comment") ? registryEntry.get("comment") : "<No comment available>"); for (Entry<String, Map<String, Object>> entry : values.entrySet()) { String uniqueKey = (classKey != "" ? classKey + "." : "") + entry.getKey(); settings = entry.getValue(); String type = ((String) settings.get("type")).toLowerCase(); int pos = settings.containsKey("pos") ? ((Integer) settings.get("pos")).intValue() : -1; BigDecimal valueMin = NumberUtils.toBigDecimal(settings.get("min")); BigDecimal valueMax = NumberUtils.toBigDecimal(settings.get("max")); BigDecimal replaceValue = NumberUtils.toBigDecimal(settings.get("replaceValue")); BigDecimal factor = NumberUtils.toBigDecimal(settings.get("factor")); Object value = getValue(byteBuffer, type, pos, valueMin, valueMax, replaceValue, factor); // Add global variables thisValue and keyName to JavaScript context HashMap<String, Object> bindings = new HashMap<String, Object>(); bindings.put(entry.getKey(), value); bindings.put(uniqueKey, value); bindings.put("thisValue", value); if (settings.containsKey("cscript")) { try { value = evaluateScript(entry, bindings); } catch (ScriptException e) { logger.error("Error on evaluating JavaScript!", e); break; } } String label = (String) (settings.containsKey("label") ? settings.get("label") : ""); String format = String.format("%-35s%-10s%s", uniqueKey, value, label); if (debugLevel >= 2) { loggerAnalyses.debug(" >>> " + format); } else { loggerAnalyses.trace(" >>> " + format); } valueRegistry.put(uniqueKey, value); valueRegistry2.put(entry.getKey(), value); } // computes values available? if not exit here if (!registryEntry.containsKey("computed_values")) continue; @SuppressWarnings("unchecked") Map<String, Map<String, Object>> cvalues = (Map<String, Map<String, Object>>) registryEntry .get("computed_values"); for (Entry<String, Map<String, Object>> entry : cvalues.entrySet()) { String uniqueKey = (classKey != "" ? classKey + "." : "") + entry.getKey(); HashMap<String, Object> bindings = new HashMap<String, Object>(); bindings.putAll(valueRegistry); bindings.putAll(valueRegistry2); Object value; try { value = evaluateScript(entry, bindings); valueRegistry.put(entry.getKey(), value); if (debugLevel >= 2) { String label = (String) (settings.containsKey("label") ? settings.get("label") : ""); String format = String.format("%-35s%-10s%s", uniqueKey, value, label); loggerAnalyses.debug(" >>> " + format); } } catch (ScriptException e) { logger.error("Error on evaluating JavaScript!", e); } } } return valueRegistry; }
From source file:com.portfolioeffect.quant.client.portfolio.Portfolio.java
private String getMetricTypeList(String metric) throws Exception { String result = ""; try {// ww w .j a v a 2s . c o m Gson gson = new Gson(); Type mapTypeMetrics = new TypeToken<HashMap<String, String>>() { }.getType(); HashMap<String, String> metricArgs = gson.fromJson(metric, mapTypeMetrics); metricArgs.putAll(portfolioData.getSettings()); ArrayList<HashMap<String, String>> paramsArgs = new ArrayList<HashMap<String, String>>(); paramsArgs.add(metricArgs); result = gson.toJson(paramsArgs); } catch (Exception e) { throw new Exception(e.getMessage().split(":")[1]); } return result; }
From source file:com.portfolioeffect.quant.client.portfolio.Portfolio.java
private String getMetricTypeList(ArrayList<String> metrics) throws Exception { String result = ""; try {//from w ww. j ava2s .c o m Gson gson = new Gson(); ArrayList<HashMap<String, String>> paramsArgs = new ArrayList<HashMap<String, String>>(); for (String e : metrics) { Type mapTypeMetrics = new TypeToken<HashMap<String, String>>() { }.getType(); HashMap<String, String> metricArgs = gson.fromJson(e, mapTypeMetrics); metricArgs.putAll(portfolioData.getSettings()); paramsArgs.add(metricArgs); } result = gson.toJson(paramsArgs); } catch (Exception e) { throw new Exception(e.getMessage().split(":")[1]); } return result; }