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 {
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);
}
}