use of org.json.simple.parser.ParseException in project spatial-portal by AtlasOfLivingAustralia.
the class ContextualLayerListComposer method addToMap.
private void addToMap(Map htCat1, Map htCat2, String cat1, String cat2, DefaultTreeNode treeNode) {
String nCat1 = cat1;
if (cat1.trim().isEmpty() || "?".equals(cat1.trim()) || StringConstants.NULL.equals(cat1.trim())) {
nCat1 = "Other";
}
if (cat2.trim().isEmpty() || "?".equals(cat2.trim()) || StringConstants.NULL.equals(cat2.trim())) {
List alCat1 = (List) htCat1.get(cat1);
if (alCat1 == null) {
alCat1 = new ArrayList();
}
alCat1.add(treeNode);
htCat1.put(nCat1, alCat1);
} else {
// first check if cat1 already exists
// if yes, grab the cat2 list and add add to its AL
// else, create a new one and add it to cat1.list
String cat2Full = nCat1 + ">" + cat2;
List alCat2 = (List) htCat2.get(cat2Full);
if (alCat2 == null) {
alCat2 = new ArrayList();
}
alCat2.add(treeNode);
if (!htCat2.containsKey(cat2Full)) {
htCat2.put(cat2Full, alCat2);
}
List alCat1 = (List) htCat1.get(cat1);
if (alCat1 == null) {
alCat1 = new ArrayList();
}
String subtype = ((JSONObject) ((JSONObject) treeNode.getData()).get("layer")).get(StringConstants.TYPE).toString();
JSONParser jp = new JSONParser();
JSONObject joCat2 = null;
try {
joCat2 = (JSONObject) jp.parse("{\"name\":\"" + cat2Full + "\",\"layer\":{\"type\":\"node\"},\"subtype\":" + ((StringConstants.ENVIRONMENTAL.equalsIgnoreCase(subtype)) ? LayerUtilitiesImpl.GRID : LayerUtilitiesImpl.CONTEXTUAL) + "}");
} catch (ParseException e) {
LOGGER.error("parse error");
}
DefaultTreeNode stnCat2 = new DefaultTreeNode(joCat2, alCat2);
boolean found = false;
for (int i = 0; i < alCat1.size(); i++) {
if (stnCat2.toString().equals(alCat1.get(i).toString())) {
found = true;
((DefaultTreeNode) alCat1.get(i)).add(treeNode);
break;
}
}
if (!found) {
alCat1.add(stnCat2);
}
if (!htCat1.containsKey(nCat1)) {
htCat1.put(nCat1, alCat1);
}
}
}
use of org.json.simple.parser.ParseException in project Glowstone by GlowstoneMC.
the class GlowServer method broadcast.
@Override
public void broadcast(BaseComponent... components) {
try {
Message packet = new ChatMessage((JSONObject) parser.parse(ComponentSerializer.toString(components)));
broadcastPacket(packet);
} catch (ParseException e) {
//should never happen
e.printStackTrace();
}
}
use of org.json.simple.parser.ParseException in project Glowstone by GlowstoneMC.
the class PlayerStatisticIoService method readStats.
/**
* Reads the stats of a player from its statistics file and writes the values to the StatisticMap.
*
* @param player the player to read the statistics from
*/
public void readStats(GlowPlayer player) {
File statsFile = getPlayerFile(player.getUniqueId());
player.getStatisticMap().getValues().clear();
if (statsFile.exists()) {
try {
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(new FileReader(statsFile));
for (Object obj : json.entrySet()) {
Map.Entry<String, Object> entry = (Map.Entry<String, Object>) obj;
Long longValue = null;
if (entry.getValue() instanceof Long) {
longValue = (Long) entry.getValue();
} else if (entry.getValue() instanceof JSONObject) {
JSONObject object = (JSONObject) entry.getValue();
if (object.containsKey("value")) {
longValue = (Long) object.get("value");
}
} else {
GlowServer.logger.warning("Unknown statistic type for '" + entry.getKey() + "': " + entry.getValue() + " (" + entry.getValue().getClass().getSimpleName() + ")");
}
if (longValue != null) {
player.getStatisticMap().getValues().put(entry.getKey(), longValue.intValue());
}
}
} catch (ParseException | IOException e) {
e.printStackTrace();
}
}
}
use of org.json.simple.parser.ParseException in project flink by apache.
the class SimpleTweetInputFormat method readRecord.
@Override
public Tweet readRecord(Tweet reuse, byte[] bytes, int offset, int numBytes) throws IOException {
InputStreamReader jsonReader = new InputStreamReader(new ByteArrayInputStream(bytes));
jsonReader.skip(offset);
try {
handler.reuse = reuse;
parser.parse(jsonReader, handler, false);
} catch (ParseException e) {
LOG.debug(" Tweet Parsing Exception : " + e.getMessage());
}
return reuse;
}
use of org.json.simple.parser.ParseException in project Gargoyle by callakrsos.
the class SVNCreateFunction method apply.
/**
* @inheritDoc
*/
@Override
public Boolean apply(Properties t) {
JSONArray parse = null;
try {
String string = ResourceLoader.getInstance().get(SVN_REPOSITORIES);
if (string == null || string.length() == 0) {
parse = new JSONArray();
} else {
parse = (JSONArray) new JSONParser().parse(string);
}
} catch (ParseException e) {
LOGGER.error(ValueUtil.toString(e));
return false;
}
JSONObject jsonObject = new JSONObject();
Iterator<Entry<Object, Object>> it = t.entrySet().iterator();
while (it.hasNext()) {
Entry<Object, Object> e = it.next();
Object key = e.getKey();
Object value = e.getValue();
if (SVN_USER_PASS.equals(key)) {
try {
value = EncrypUtil.encryp(value.toString());
} catch (Exception e1) {
LOGGER.error(ValueUtil.toString(e1));
return false;
}
}
jsonObject.put(key, value);
}
parse.add(jsonObject);
ResourceLoader.getInstance().put(SVN_REPOSITORIES, parse.toJSONString());
return true;
}
Aggregations