List of usage examples for com.google.gwt.json.client JSONString toString
@Override
public String toString()
From source file:com.ait.lienzo.client.core.shape.json.validators.URLValidator.java
License:Open Source License
@Override public void validate(JSONValue jval, ValidationContext ctx) throws ValidationException { if (null == jval) { ctx.addBadTypeError("URL"); return;//from w ww. jav a2 s .c o m } JSONString str = jval.isString(); if (null == str) { ctx.addBadTypeError("URL"); return; } String url = str.toString(); if (url.startsWith("data:")) { return; } if ((null == url) || ((url = url.trim()).isEmpty()) || (url.startsWith("#"))) { ctx.addBadTypeError("URL"); return; } url = UriUtils.fromString(url).asString(); if ((null == url) || ((url = url.trim()).isEmpty()) || (url.startsWith("#"))) { ctx.addBadTypeError("URL"); return; } }
From source file:com.google.api.explorer.client.history.JsonPrettifier.java
License:Apache License
private static List<Widget> formatString(ApiService service, String rawText, PrettifierLinkFactory linkFactory) { if (isLink(rawText)) { List<Widget> response = Lists.newArrayList(); response.add(new InlineLabel("\"")); boolean createdExplorerLink = false; try {//from w w w. j a v a 2 s . c o m ApiMethod method = getMethodForUrl(service, rawText); if (method != null) { String explorerLink = createExplorerLink(service, rawText, method); Widget linkObject = linkFactory.generateAnchor(rawText, explorerLink); linkObject.addStyleName(style.jsonStringExplorerLink()); response.add(linkObject); createdExplorerLink = true; } } catch (IndexOutOfBoundsException e) { // Intentionally blank - this will only happen when iterating the method // url template in parallel with the url components and you run out of // components } if (!createdExplorerLink) { Anchor linkObject = new Anchor(rawText, rawText, OPEN_IN_NEW_WINDOW); linkObject.addStyleName(style.jsonStringLink()); response.add(linkObject); } response.add(new InlineLabel("\"")); return response; } else { JSONString encoded = new JSONString(rawText); Widget stringText = new InlineLabel(encoded.toString()); stringText.addStyleName(style.jsonString()); return Lists.newArrayList(stringText); } }
From source file:lh.api.showcase.client.JsonParserUtils.java
License:Apache License
public static void getNameInfo(JSONObject jsNameObj, Map<LanguageCode, String> res) { JSONValue jsLang = jsNameObj.get("@LanguageCode"); JSONString jsLangStr = jsLang.isString(); JSONValue jsNameVal = jsNameObj.get("$"); JSONString jsNameStr = jsNameVal.isString(); res.put(LanguageCode.valueOf(jsLangStr.toString().replace("\"", "").toUpperCase()), jsNameStr.toString().replace("\"", "")); }
From source file:lh.api.showcase.client.JsonParserUtils.java
License:Apache License
public static Airport getAirportInfo(JSONObject jsAirportObj) { JSONValue jsAirportCodeVal = jsAirportObj.get("AirportCode"); JSONValue jsCityCodeVal = jsAirportObj.get("CityCode"); JSONValue jsCountryCodeVal = jsAirportObj.get("CountryCode"); JSONValue jsLocationTypeVal = jsAirportObj.get("LocationType"); if (jsAirportCodeVal == null || jsCityCodeVal == null || jsCountryCodeVal == null || jsLocationTypeVal == null) { return null; }//from w ww.j av a2 s . com JSONString jsAirportCodeStr = jsAirportCodeVal.isString(); JSONString jsCityCodeStr = jsCityCodeVal.isString(); JSONString jsCountryCodeStr = jsCountryCodeVal.isString(); JSONString jsLocationTypeStr = jsLocationTypeVal.isString(); JSONObject jsCoordinateObj = jsAirportObj.get("Position").isObject().get("Coordinate").isObject(); JSONNumber jsLatitudeNum = jsCoordinateObj.get("Latitude").isNumber(); JSONNumber jsLongitudeNum = jsCoordinateObj.get("Longitude").isNumber(); JSONObject jsNamesObj = jsAirportObj.get("Names").isObject(); return new Airport((jsAirportCodeStr == null) ? ("") : (jsAirportCodeStr.toString().replace("\"", "")), (jsCityCodeStr == null) ? ("") : (jsCityCodeStr.toString().replace("\"", "")), (jsCountryCodeStr == null) ? ("") : (jsCountryCodeStr.toString().replace("\"", "")), (jsLocationTypeStr == null) ? ("") : (jsLocationTypeStr.toString().replace("\"", "")), jsLatitudeNum.doubleValue(), jsLongitudeNum.doubleValue(), JsonParserUtils.getNamesMap(jsNamesObj)); }
From source file:lh.api.showcase.client.JsonParserUtils.java
License:Apache License
public static String getAircraftCode(JSONValue jsAircraftCodeVal) { if (jsAircraftCodeVal == null) { return null; }//from w w w . ja va 2 s . c om JSONString jsAircraftCodeStr = jsAircraftCodeVal.isString(); JSONNumber jsAircraftCodeNum = null; if (jsAircraftCodeStr == null) { jsAircraftCodeNum = jsAircraftCodeVal.isNumber(); } return (jsAircraftCodeStr != null) ? (jsAircraftCodeStr.toString().replace("\"", "")) : ((jsAircraftCodeNum != null) ? (String.valueOf(jsAircraftCodeNum.doubleValue())) : ("")); }
From source file:lh.api.showcase.client.operations.JsonParserFlightUtils.java
License:Apache License
public static Flight getFlightInfo(JSONObject jsFlightObj) { if (jsFlightObj == null) { return null; }//from w w w . j a va 2 s . c om // departure JSONObject jsDepartureObj = jsFlightObj.get("Departure").isObject(); Flight.FlightNode flightNodeDeparture = getFlightNodeInfo(jsDepartureObj); Flight.Departure departure = null; if (flightNodeDeparture != null) { departure = new Flight.Departure(flightNodeDeparture); } // arrival JSONObject jsArrivalObj = jsFlightObj.get("Arrival").isObject(); Flight.FlightNode flightNodeArrival = getFlightNodeInfo(jsArrivalObj); Flight.Arrival arrival = null; if (flightNodeDeparture != null) { arrival = new Flight.Arrival(flightNodeArrival); } // aircraft code String aircraftCode = JsonParserUtils .getAircraftCode(jsFlightObj.get("Equipment").isObject().get("AircraftCode")); //MarketingCarrier JSONObject jsMarketingCarrierObj = jsFlightObj.get("MarketingCarrier").isObject(); JSONString jsAirlineIdStr = jsMarketingCarrierObj.get("AirlineID").isString(); JSONString jsFlightNumberStr = jsMarketingCarrierObj.get("FlightNumber").isString(); JSONNumber jsFlightNumberNum = jsMarketingCarrierObj.get("FlightNumber").isNumber(); String flightNumber = (jsFlightNumberStr != null) ? (jsFlightNumberStr.toString().replace("\"", "")) : ((jsFlightNumberNum != null) ? (String.valueOf(jsFlightNumberNum.doubleValue())) : ("")); // details JSONValue jsDetailsVal = jsFlightObj.get("Details"); JSONObject jsDetailsObj = null; if (jsDetailsVal != null) { jsDetailsObj = jsDetailsVal.isObject(); } // flight status JSONString jsFlightStatusCodeStr = getStringIfExist(jsFlightObj, "FlightStatus", "Code"); JSONString jsFlightStatusDefinitionStr = getStringIfExist(jsFlightObj, "FlightStatus", "Definition"); return new Flight(departure, arrival, aircraftCode, (jsAirlineIdStr == null) ? ("") : (jsAirlineIdStr.toString().replace("\"", "")), flightNumber, getDetailsInfo(jsDetailsObj), new Flight.StatusCodeDefinition( (jsFlightStatusCodeStr == null) ? (FlightStatusCode.NA.toString()) : (jsFlightStatusCodeStr.toString().replace("\"", "")), (jsFlightStatusDefinitionStr == null) ? ("") : (jsFlightStatusDefinitionStr.toString().replace("\"", "")))); }
From source file:lh.api.showcase.client.operations.JsonParserFlightUtils.java
License:Apache License
private static Flight.Details getDetailsInfo(JSONObject jsDetailsObj) { if (jsDetailsObj == null) { return null; }//from www . ja va2s . c om JSONNumber jsStopsNumber = jsDetailsObj.get("Stops").isObject().get("StopQuantity").isNumber(); JSONNumber jsDaysOfOperationNumber = jsDetailsObj.get("DaysOfOperation").isNumber(); JSONObject jsDatePeriodObj = jsDetailsObj.get("DatePeriod").isObject(); JSONString jsEffectiveStr = jsDatePeriodObj.get("Effective").isString(); JSONString jsExpirationStr = jsDatePeriodObj.get("Expiration").isString(); Flight.Details.Builder detailsBuilder = new Flight.Details.Builder(); detailsBuilder.setStopQuantity(Long.valueOf((long) jsStopsNumber.doubleValue())) .setDaysOfOperation(String.valueOf(jsDaysOfOperationNumber.doubleValue())) .setEffectiveDateStr( (jsEffectiveStr == null) ? ("") : (jsEffectiveStr.toString().replace("\"", ""))) .setExpirationDateStr( (jsExpirationStr == null) ? ("") : (jsExpirationStr.toString().replace("\"", ""))); return detailsBuilder.build(); }
From source file:lh.api.showcase.client.operations.JsonParserFlightUtils.java
License:Apache License
private static Flight.FlightNode getFlightNodeInfo(JSONObject jsNodeObj) { if (jsNodeObj == null) { return null; }// w ww.j a va 2 s . c om JSONString jsAirportCodeStr = jsNodeObj.get("AirportCode").isString(); JSONString jsScheduledTimeLocalStr = jsNodeObj.get("ScheduledTimeLocal").isObject().get("DateTime") .isString(); JSONString jsScheduledTimeUtcStr = getStringIfExist(jsNodeObj, "ScheduledTimeUTC", "DateTime"); JSONString jsEstimatedOrActualTimeLocalStr = getStringIfExist(jsNodeObj, "EstimatedTimeLocal", "ActualTimeLocal", "DateTime"); JSONString jsEstimatedOrActualTimeUtcStr = getStringIfExist(jsNodeObj, "EstimatedTimeUTC", "ActualTimeUTC", "DateTime"); JSONString jsTimeStatusCodeStr = getStringIfExist(jsNodeObj, "TimeStatus", "Code"); JSONString jsTimeStatusDefinitionStr = getStringIfExist(jsNodeObj, "TimeStatus", "Definition"); JSONString jsTerminalGateStr = getStringIfExist(jsNodeObj, "Terminal", "Gate"); JSONString jsTerminalStr = getStringIfExist(jsNodeObj, "Terminal", "Name"); JSONNumber jsTerminalNum = getNumberIfExist(jsNodeObj, "Terminal", "Name"); String terminal = (jsTerminalStr != null) ? (jsTerminalStr.toString().replace("\"", "")) : ((jsTerminalNum != null) ? (String.valueOf(jsTerminalNum.doubleValue())) : ("")); Flight.FlightNode.Builder flightNodeBuilder = new Flight.FlightNode.Builder(); flightNodeBuilder .setAirportCode((jsAirportCodeStr == null) ? ("") : (jsAirportCodeStr.toString().replace("\"", ""))) .setScheduledTimeLocal((jsScheduledTimeLocalStr == null) ? ("") : (jsScheduledTimeLocalStr.toString().replace("\"", ""))) .setScheduledTimeUtc((jsScheduledTimeUtcStr == null) ? ("") : (jsScheduledTimeUtcStr.toString().replace("\"", ""))) .setEstimatedOrActualTimeLocal((jsEstimatedOrActualTimeLocalStr == null) ? ("") : (jsEstimatedOrActualTimeLocalStr.toString().replace("\"", ""))) .setEstimatedOrActualTimeUtc((jsEstimatedOrActualTimeUtcStr == null) ? ("") : (jsEstimatedOrActualTimeUtcStr.toString().replace("\"", ""))) .setTimeStatus(new Flight.StatusCodeDefinition( (jsTimeStatusCodeStr == null) ? (TimeStatusCode.NO.toString()) : (jsTimeStatusCodeStr.toString().replace("\"", "")), (jsTimeStatusDefinitionStr == null) ? ("") : (jsTimeStatusDefinitionStr.toString().replace("\"", "")))) .setTerminal(terminal).setTerminalGate( (jsTerminalGateStr == null) ? ("") : (jsTerminalGateStr.toString().replace("\"", ""))); return flightNodeBuilder.build(); }
From source file:lh.api.showcase.client.operations.schedules.SchedulesResponseJsonParser.java
License:Apache License
private Schedule getScheduleInfo(JSONObject jsScheduleObj) { if (jsScheduleObj == null) { return null; }// w ww . j a va 2s .com JSONValue jsTotalJourneyVal = jsScheduleObj.get("TotalJourney"); JSONObject jsTotalJourneyObj = jsTotalJourneyVal.isObject(); JSONString jsDurationStr = jsTotalJourneyObj.get("Duration").isString(); List<Flight> flightList = new ArrayList<Flight>(); JSONValue jsFlightVal = jsScheduleObj.get("Flight"); JSONObject jsFlightObj = jsFlightVal.isObject(); if (jsFlightObj == null) { JSONArray jarrayFlight = jsFlightVal.isArray(); if (jarrayFlight != null) { for (int i = 0; i < jarrayFlight.size(); ++i) { JSONObject jsFlightObject = jarrayFlight.get(i).isObject(); Flight flight = JsonParserFlightUtils.getFlightInfo(jsFlightObject); if (flight != null) { flightList.add(flight); } } } } else { Flight flight = JsonParserFlightUtils.getFlightInfo(jsFlightObj); if (flight != null) { flightList.add(flight); } } return new Schedule((jsDurationStr == null) ? ("") : (jsDurationStr.toString().replace("\"", "")), flightList); }
From source file:lh.api.showcase.client.referencedata.aircraft.AircraftResponseJsonParser.java
License:Apache License
private Aircraft getAircraftInfo(JSONObject jsAircraftSummaryObj) { JSONValue jsAircraftCodeVal = jsAircraftSummaryObj.get("AircraftCode"); JSONValue jsAircraftAirlineEquipCodeVal = jsAircraftSummaryObj.get("AirlineEquipCode"); if (jsAircraftCodeVal == null) { return null; }//www . j a v a 2 s . co m String aircraftCode = JsonParserUtils.getAircraftCode(jsAircraftCodeVal); JSONString jsAircraftAirlineEquipCodeStr = null; if (jsAircraftAirlineEquipCodeVal != null) { jsAircraftAirlineEquipCodeStr = jsAircraftAirlineEquipCodeVal.isString(); } JSONObject jsNamesObj = jsAircraftSummaryObj.get("Names").isObject(); return new Aircraft(aircraftCode, (jsAircraftAirlineEquipCodeStr == null) ? ("") : (jsAircraftAirlineEquipCodeStr.toString().replace("\"", "")), JsonParserUtils.getNamesMap(jsNamesObj)); }