List of usage examples for com.google.gson JsonPrimitive getAsString
@Override
public String getAsString()
From source file:com.google.iosched.model.validator.GPlusURLConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { return null; }// w w w . ja v a 2 s . c o m String str = value.getAsString(); if (str.isEmpty()) { return value; } for (Pattern p : plusRecognizedPatterns) { Matcher m = p.matcher(str); if (m.find()) { return new JsonPrimitive(plusFormat.format(new String[] { m.group(1) })); } } // If URL starts with http/https: if (acceptableUrlPattern.matcher(str).matches()) { return value; } // Otherwise, just add https://: str = "https://" + str; return new JsonPrimitive(str); }
From source file:com.google.iosched.model.validator.IntegerConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { return new JsonPrimitive(0); }/*w w w . j ava 2 s . c om*/ if (value.isNumber()) { return value; } String str = value.getAsString(); try { return new JsonPrimitive(Integer.parseInt(str)); } catch (NumberFormatException ex) { throw new ConverterException(value, this); } }
From source file:com.google.iosched.model.validator.IntegerToStringConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { return null; }/*w w w . ja v a2 s. c o m*/ if (value.isNumber()) { return new JsonPrimitive(String.valueOf(value.getAsInt())); } try { Integer.parseInt(value.getAsString()); // if it parses correctly, it is validated: return value; } catch (NumberFormatException ex) { throw new ConverterException(value, this); } }
From source file:com.google.iosched.model.validator.PhotoURLConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { return null; }/* w ww . j av a2 s.c om*/ String entityId = value.getAsString(); return new JsonPrimitive(entityBaseUrl + entityId + ".jpg"); }
From source file:com.google.iosched.model.validator.RegexpConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { if (acceptsNull) { return null; } else {// w w w . j a v a 2 s. c o m throw new ConverterException(value, this); } } String str = value.getAsString(); if (str.isEmpty() || pattern.matcher(str).matches()) { return value; } else { throw new ConverterException(value, this); } }
From source file:com.google.iosched.model.validator.SessionURLConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive sessionId) { if (sessionId == null) { return null; }//from w w w .j av a 2s. co m return new JsonPrimitive(Config.SESSION_BASE_URL + sessionId.getAsString()); }
From source file:com.google.iosched.model.validator.StringObfuscateConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { return null; }/*www .ja va 2 s . c o m*/ return new JsonPrimitive(obfuscate(value.getAsString())); }
From source file:com.google.iosched.model.validator.TagNameConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { return null; }/*from w w w . ja v a 2s.c o m*/ return new JsonPrimitive(value.getAsString().toUpperCase().replace('/', '_').replaceAll("[ ']", "")); }
From source file:com.google.iosched.model.validator.YoutubeURLConverter.java
License:Open Source License
@Override public JsonPrimitive convert(JsonPrimitive value) { if (value == null) { if (acceptsNull) { return null; } else {/*from ww w . jav a 2s .c om*/ throw new ConverterException(value, this); } } String str = value.getAsString(); if (acceptsNull && str.isEmpty()) { return value; } for (Pattern p : patterns) { Matcher m = p.matcher(str); if (m.find()) { return new JsonPrimitive(outFormat.format(new String[] { m.group(1) })); } } throw new ConverterException(value, this); }
From source file:com.google.samples.apps.iosched.server.schedule.model.DataExtractor.java
License:Open Source License
private boolean isLivestreamed(JsonObject sessionObj) { // data generated after the end of the conference should never have livestream URLs long endOfConference = Config.CONFERENCE_DAYS[Config.CONFERENCE_DAYS.length - 1][1]; if (System.currentTimeMillis() > endOfConference) { return false; }/*from w ww . ja v a 2s . c o m*/ JsonPrimitive livestream = getMapValue(get(sessionObj, InputJsonKeys.VendorAPISource.Topics.info), InputJsonKeys.VendorAPISource.Topics.INFO_IS_LIVE_STREAM, null, null); return livestream != null && "true".equalsIgnoreCase(livestream.getAsString()); }