-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for custom labels and annotations
Signed-off-by: Decker, Stefan <Stefan.Decker@gdata.de>
- Loading branch information
1 parent
7e5bacb
commit 2eca828
Showing
8 changed files
with
375 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/de/gdata/mobilelab/alertmanagercallback/CustomPropertiesTextFieldParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package de.gdata.mobilelab.alertmanagercallback; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
/** | ||
* This parser can parse key-value-pairs from a text field string. | ||
* It uses {@link #KEY_VALUE_PAIR_SEPARATOR} for separating each key-value-pair. | ||
* The keys and related values will be parsed using {@link Properties#load(InputStream)}. | ||
*/ | ||
class CustomPropertiesTextFieldParser { | ||
|
||
/** The separator used in text field to split between key-value-pairs. */ | ||
static final String KEY_VALUE_PAIR_SEPARATOR = ";"; | ||
|
||
/** The separator used by {@link Properties#load(InputStream)} for key-value-pair separation. */ | ||
private static final String PROPERTIES_KEY_VALUE_PAIR_SEPARATOR = "\n"; | ||
|
||
/** | ||
* Parses the text field value with custom key-value-pairs into a map.<br> | ||
* It uses the {@link #KEY_VALUE_PAIR_SEPARATOR} for the line separation. This separation is required | ||
* for loading the key-value-pairs using {@link Properties#load(InputStream)}. | ||
* | ||
* @param textFieldValue the text field value | ||
* @return the map with key-value-pairs from text field | ||
* @throws IOException if parsing the key-value-pairs fails | ||
*/ | ||
Map<? extends String, ?> extractKeyValuePairsFromCustomField(String textFieldValue) throws IOException { | ||
Map<String, Object> extractedPairs = new HashMap<>(); | ||
|
||
if (textFieldValue != null && !"".equals(textFieldValue)) { | ||
final String preparedTextFieldValue = textFieldValue.replaceAll(KEY_VALUE_PAIR_SEPARATOR, PROPERTIES_KEY_VALUE_PAIR_SEPARATOR); | ||
Properties properties = new Properties(); | ||
InputStream stringInputStream = new ByteArrayInputStream(preparedTextFieldValue.getBytes(StandardCharsets.UTF_8)); | ||
properties.load(stringInputStream); | ||
properties.forEach((key, value) -> extractedPairs.put((String) key, value)); | ||
} | ||
|
||
return extractedPairs; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.