List of usage examples for com.google.gson JsonObject get
public JsonElement get(String memberName)
From source file:arces.unibo.SEPA.commons.SPARQL.Bindings.java
License:Open Source License
public String getBindingValue(String variable) { if (solution.get(variable) == null) return null; JsonObject json = solution.get(variable).getAsJsonObject(); return json.get("value").getAsString(); }
From source file:arces.unibo.SEPA.commons.SPARQL.Bindings.java
License:Open Source License
public String getDatatype(String variable) { if (solution.get(variable) == null) return null; JsonObject json = solution.get(variable).getAsJsonObject(); if (json.get("datatype") == null) return null; return json.get("datatype").getAsString(); }
From source file:arces.unibo.SEPA.commons.SPARQL.Bindings.java
License:Open Source License
public String getLanguage(String variable) { if (solution.get(variable) == null) return null; JsonObject json = solution.get(variable).getAsJsonObject(); if (json.get("xml:lang") == null) return null; return json.get("xml:lang").getAsString(); }
From source file:arces.unibo.SEPA.commons.SPARQL.Bindings.java
License:Open Source License
public boolean isLiteral(String variable) { if (solution.get(variable) == null) return false; JsonObject json = solution.get(variable).getAsJsonObject(); return json.get("type").getAsString().equals("literal"); }
From source file:arces.unibo.SEPA.commons.SPARQL.Bindings.java
License:Open Source License
public boolean isURI(String variable) { if (solution.get(variable) == null) return false; JsonObject json = solution.get(variable).getAsJsonObject(); return json.get("type").getAsString().equals("uri"); }
From source file:arces.unibo.SEPA.commons.SPARQL.Bindings.java
License:Open Source License
public boolean isBNode(String variable) { if (solution.get(variable) == null) return false; JsonObject json = solution.get(variable).getAsJsonObject(); return json.get("type").getAsString().equals("bnode"); }
From source file:arces.unibo.SEPA.server.protocol.WSGate.java
License:Open Source License
protected Request parseRequest(Integer token, String request) { JsonObject req; try {//from ww w .j a v a 2 s . com req = new JsonParser().parse(request).getAsJsonObject(); } catch (JsonParseException | IllegalStateException e) { return null; } if (req.get("subscribe") != null) { if (req.get("alias") != null) return new SubscribeRequest(token, req.get("subscribe").getAsString(), req.get("alias").getAsString()); return new SubscribeRequest(token, req.get("subscribe").getAsString()); } if (req.get("unsubscribe") != null) return new UnsubscribeRequest(token, req.get("unsubscribe").getAsString()); return null; }
From source file:arces.unibo.SEPA.server.protocol.WSSGate.java
License:Open Source License
private Response validateToken(String request) { JsonObject req; try {/* w ww .j a v a 2 s . co m*/ req = new JsonParser().parse(request).getAsJsonObject(); } catch (JsonParseException | IllegalStateException e) { return new ErrorResponse(500, e.getMessage()); } if (req.get("authorization") == null) return new ErrorResponse(400, "authorization key is missing"); ; //Token validation return am.validateToken(req.get("authorization").getAsString()); }
From source file:asteroidtracker.AsteroidTrackerSpeechlet.java
License:Open Source License
/** * Parse JSON-formatted list of events/births/deaths from Wikipedia, extract list of events and * split the events into a String array of individual events. Run Regex matchers to make the * list pretty by adding a comma after the year to add a pause, and by removing a unicode char. * /*from w w w .j a v a2 s . c o m*/ * @param text * the JSON formatted list of events/births/deaths for a certain date * @return String array of events for that date, 1 event per element of the array */ private ArrayList<String> parseJson(String text, String date) { ArrayList<String> events = new ArrayList<String>(); if (text.isEmpty()) { return events; } JsonParser parser = new JsonParser(); JsonObject object = parser.parse(text).getAsJsonObject(); JsonArray asteroidArray = object.get("near_earth_objects").getAsJsonObject().get(date).getAsJsonArray(); for (int i = 0; i < object.get("element_count").getAsInt(); i++) { JsonObject thisAsteroid = asteroidArray.get(i).getAsJsonObject(); String asteroidName = thisAsteroid.get("name").getAsString(); float absoluteMagnitude = thisAsteroid.get("absolute_magnitude_h").getAsFloat(); JsonObject estimatedDiameterKilometers = thisAsteroid.get("estimated_diameter").getAsJsonObject() .get("kilometers").getAsJsonObject(); float minimumDiameter = estimatedDiameterKilometers.get("estimated_diameter_min").getAsFloat(); float maximumDiameter = estimatedDiameterKilometers.get("estimated_diameter_max").getAsFloat(); boolean isDangerousObject = thisAsteroid.get("is_potentially_hazardous_asteroid") .getAsString() == "false"; JsonObject closeApproachData = thisAsteroid.get("close_approach_data").getAsJsonArray().get(0) .getAsJsonObject(); float speed = closeApproachData.get("relative_velocity").getAsJsonObject().get("kilometers_per_hour") .getAsFloat(); Number missDistance = closeApproachData.get("miss_distance").getAsJsonObject().get("kilometers") .getAsNumber(); String orbitingBody = closeApproachData.get("orbiting_body").getAsString(); DecimalFormat df = new DecimalFormat("#.##"); String asteroidIdText = "Asteroid " + i + ", name is " + asteroidName + ","; String magnitudeText = "The absolute magnitude is " + absoluteMagnitude; String sizeText = ", the estimated diameter is from " + df.format(minimumDiameter) + " to " + df.format(maximumDiameter) + " kilometers,"; String dangerousnessText; if (isDangerousObject) { dangerousnessText = "This object is dangerous!"; } else { dangerousnessText = "This object is not dangerous,"; } String speedText = "It is traveling at " + df.format(speed) + " kilometers per hour"; String distanceText = " at a distance of " + missDistance + " kilometers"; String orbitingBodyText = " and is orbiting " + orbitingBody; String eventText = asteroidIdText + magnitudeText + sizeText + dangerousnessText + speedText + distanceText + orbitingBodyText; events.add(eventText); } return events; }
From source file:at.ac.dbisinformatik.snowprofile.web.svgcreator.SVGCreator.java
License:Open Source License
/** * creates a SVG-Graph for given jsonDocument which includes ExtJS-SVG-Objects. The created SVG-Document will be converted in the given export type. * // w w w . j a v a 2 s . co m * @param jsonDocument * @param exportType * @param profileID * @return * @throws TransformerException * @throws URISyntaxException * @throws TranscoderException * @throws IOException */ public static ByteArrayOutputStream svgDocument(JsonArray jsonDocument, String exportType, String profileID) throws TransformerException, URISyntaxException, TranscoderException, IOException { ByteArrayOutputStream ret = null; DOMImplementation impl = SVGDOMImplementation.getDOMImplementation(); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; Document doc = impl.createDocument(svgNS, "svg", null); // Get the root element (the 'svg' element). Element svgRoot = doc.getDocumentElement(); // Set the width and height attributes on the root 'svg' element. svgRoot.setAttributeNS(null, "width", "1500"); svgRoot.setAttributeNS(null, "height", "1500"); JsonArray items = jsonDocument; for (int i = 0; i < items.size(); ++i) { String type = items.get(i).getAsJsonObject().get("type").getAsString(); Element element = null; org.w3c.dom.Text test = null; String path = ""; String width = ""; String height = ""; String x = ""; String y = ""; String fill = ""; String text = ""; String font = ""; String fontFamily = ""; String fontSize = ""; String degrees = ""; String stroke = ""; String opacity = ""; String src = ""; switch (type) { case "rect": width = items.get(i).getAsJsonObject().get("width").getAsString(); height = items.get(i).getAsJsonObject().get("height").getAsString(); x = items.get(i).getAsJsonObject().get("x").getAsString(); y = items.get(i).getAsJsonObject().get("y").getAsString(); fill = items.get(i).getAsJsonObject().get("fill").getAsString(); stroke = items.get(i).getAsJsonObject().get("stroke").getAsString(); opacity = items.get(i).getAsJsonObject().get("opacity").getAsString(); // Create the rectangle. element = doc.createElementNS(svgNS, "rect"); element.setAttributeNS(null, "width", width); element.setAttributeNS(null, "height", height); element.setAttributeNS(null, "x", x); element.setAttributeNS(null, "y", y); element.setAttributeNS(null, "fill", fill); element.setAttributeNS(null, "stroke", stroke); element.setAttributeNS(null, "opacity", opacity); break; case "path": path = items.get(i).getAsJsonObject().get("path").getAsString(); fill = items.get(i).getAsJsonObject().get("fill").getAsString(); stroke = items.get(i).getAsJsonObject().get("stroke").getAsString(); // Create the path. element = doc.createElementNS(svgNS, "path"); element.setAttributeNS(null, "d", path); element.setAttributeNS(null, "fill", fill); element.setAttributeNS(null, "stroke", stroke); break; case "image": x = items.get(i).getAsJsonObject().get("x").getAsString(); y = items.get(i).getAsJsonObject().get("y").getAsString(); width = items.get(i).getAsJsonObject().get("width").getAsString(); height = items.get(i).getAsJsonObject().get("height").getAsString(); src = System.class.getResource("/at/ac/dbisinformatik/snowprofile/web/resources/" + items.get(i).getAsJsonObject().get("src").getAsString()).toString(); // Create the path. element = doc.createElementNS(svgNS, "image"); element.setAttributeNS(null, "x", x); element.setAttributeNS(null, "y", y); element.setAttributeNS(null, "width", width); element.setAttributeNS(null, "height", height); element.setAttributeNS(null, "xlink:href", src); break; case "text": text = items.get(i).getAsJsonObject().get("text").getAsString(); fill = items.get(i).getAsJsonObject().get("fill").getAsString(); font = items.get(i).getAsJsonObject().get("font").getAsString(); x = items.get(i).getAsJsonObject().get("x").getAsString(); y = items.get(i).getAsJsonObject().get("y").getAsString(); // Transformation if (items.get(i).getAsJsonObject().get("rotate") != null) { JsonObject temp = items.get(i).getAsJsonObject().get("rotate").getAsJsonObject(); degrees = temp.get("degrees").getAsString(); } fontSize = font.split(" ")[0]; fontFamily = font.split(" ")[1]; // Create the text. test = doc.createTextNode(text); element = doc.createElementNS(svgNS, "text"); element.setAttributeNS(null, "text", text); element.setAttributeNS(null, "fill", fill); element.setAttributeNS(null, "font-family", fontFamily); element.setAttributeNS(null, "font-size", fontSize); element.setAttributeNS(null, "x", x); element.setAttributeNS(null, "y", y); if (!degrees.equals("")) { // element.setAttributeNS(null, "transform", // "rotate(270 "+500+","+80+")"); } element.appendChild(test); break; default: break; } // Attach the rectangle to the root 'svg' element. svgRoot.appendChild(element); } TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(doc); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); StreamResult result = new StreamResult(outputStream); transformer.transform(source, result); InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); switch (exportType) { case "png": ret = createPNG(inputStream); break; case "jpg": ret = createJPG(inputStream); break; case "pdf": ret = createPDF(inputStream); break; default: break; } return ret; }