}
@Override
public ClientResponse retrieveResource(String resource, LDClientService client, Endpoint endpoint) throws DataRetrievalException {
Model model = new TreeModel();
String uri = resource;
URI objUri;
try {
objUri = new URI(uri);
} catch (URISyntaxException e) {
throw new RuntimeException("URI '" + uri + "'could not be parsed, it is not a valid URI");
}
String video_id = null;
if (uri.startsWith(YOUTUBE_V)) { // YouTube short watch video URL
String[] p_components = objUri.getPath().split("/");
video_id = p_components[p_components.length - 1];
} else if (resource.startsWith(YOUTUBE_WATCH)) { // YouTube watch video URL
List<NameValuePair> params = URLEncodedUtils.parse(objUri, "UTF-8");
for (NameValuePair pair : params) {
if ("v".equals(pair.getName())) {
video_id = pair.getValue();
break;
}
}
} else if (uri.startsWith(YOUTUBE_GDATA)) { // GData URI
video_id = StringUtils.removeStart(uri, YOUTUBE_GDATA);
}
if (StringUtils.isBlank(video_id)) {
String msg = "Not valid video id found in '" + uri + "'";
log.error(msg);
throw new DataRetrievalException(msg);
} else {
model.add(new URIImpl(uri), new URIImpl(FOAF_PRIMARY_TOPIC), new URIImpl(YoutubeVideoProvider.YOUTUBE_BASE_URI + video_id), (Resource)null);
// FIXME: add inverse triple, but maybe at the YoutubeVideoProvider
ClientResponse clientResponse = new ClientResponse(200, model);
clientResponse.setExpires(DateUtils.addYears(new Date(), 10));
return clientResponse;