Search in sources :

Example 1 with ParseException

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);
        }
    }
}
Also used : JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 2 with ParseException

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();
    }
}
Also used : Message(com.flowpowered.network.Message) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) ParseException(org.json.simple.parser.ParseException)

Example 3 with ParseException

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();
        }
    }
}
Also used : IOException(java.io.IOException) JSONObject(org.json.simple.JSONObject) JSONParser(org.json.simple.parser.JSONParser) FileReader(java.io.FileReader) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) File(java.io.File) StatisticMap(net.glowstone.util.StatisticMap) Map(java.util.Map)

Example 4 with ParseException

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ParseException(org.json.simple.parser.ParseException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 5 with ParseException

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;
}
Also used : Entry(java.util.Map.Entry) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException) ParseException(org.json.simple.parser.ParseException)

Aggregations

ParseException (org.json.simple.parser.ParseException)258 JSONObject (org.json.simple.JSONObject)191 JSONParser (org.json.simple.parser.JSONParser)185 JSONArray (org.json.simple.JSONArray)84 IOException (java.io.IOException)71 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)50 HashMap (java.util.HashMap)41 ArrayList (java.util.ArrayList)34 Map (java.util.Map)23 HashSet (java.util.HashSet)18 API (org.wso2.carbon.apimgt.api.model.API)18 BufferedReader (java.io.BufferedReader)13 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)13 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)13 List (java.util.List)12 File (java.io.File)11 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)11 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)11 InputStreamReader (java.io.InputStreamReader)10 URL (java.net.URL)10