@GET @Produces(MediaType.TEXT_XML) public Urls getXMLCollect(@QueryParam("url") String newUrl) { Urls urls = new Urls(); String currentPage = Utils.wget(newUrl); urls.addAll(extractUrlSimple(currentPage)); urls.addAll(extractUrlAHref(currentPage, newUrl)); return urls; }
private static void writeHubRequestParams(JID user, URL feedUrl, String verb, Writer writer) throws IOException { String callbackUrl = "http://push-bot.appspot.com/push-subscriber/" + Urls.encode(Xmpp.toShortJid(user).getId()); writer.write("hub.callback=" + Urls.encode(callbackUrl)); writer.write("&hub.mode=" + verb); writer.write("&hub.topic=" + Urls.encode(feedUrl.toString())); writer.write("&hub.verify=sync"); // TODO(mihaip): Actually use a verification token. writer.write("&hub.verify_token="); }
@RequestMapping( value = {HELP_EDIT_FI, HELP_EDIT_SV}, method = GET) public String helpEdit( @PathVariable("helpPage") String localizedPageName, Model model, Locale locale) { Urls urls = Urls.get(locale); model.addAttribute(ALT_URI_ATTR, urls.alt().help("")); model.addAttribute("helpPage", localizedPageName); model.addAttribute("categoryLinksMap", infoTextService.getOmSubjectList(locale)); model.addAttribute("content", infoTextService.getDraft(localizedPageName)); model.addAttribute("urls", urls); return HELP_EDIT_VIEW; }
@Override public ArrayList<String> autocomplete(String input) { ArrayList<String> resultList = null; String url = Urls.getAutocompleteUrl(input); RequestFuture<JSONObject> future = RequestFuture.newFuture(); JsonObjectRequest request = new JsonObjectRequest(url, null, future, future); requestQueue.add(request); try { JSONObject response = future.get(10, TimeUnit.SECONDS); JSONArray predictions = response.getJSONArray("predictions"); // Extract the Place descriptions from the results resultList = new ArrayList<String>(predictions.length()); for (int i = 0; i < predictions.length(); i++) { JSONArray terms = predictions.getJSONObject(i).getJSONArray("terms"); resultList.add(terms.getJSONObject(0).getString("value")); } } catch (InterruptedException | ExecutionException | TimeoutException | JSONException e) { e.printStackTrace(); } return resultList; }
@Override public void getVideos() { StringRequest request = new StringRequest( Urls.getSearchVideosUrl(location), new Response.Listener<String>() { @Override public void onResponse(String response) { VideoSearchResponse videoSearchResponse = Utils.fromJson(VideoSearchResponse.class, response); if (videoSearchResponse != null && videoSearchResponse.getSize() > 0) { getVideoDetails(videoSearchResponse); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { EventBus.getDefault().post(new VideosErrorEvent(error)); } }); requestQueue.add(request); }
@Override public void getPlaces(final PlaceType placeType, String nextPageToken) { String url = Urls.getSearchPlacesUrl(placeType, nextPageToken, location); StringRequest request = new StringRequest( url, new Response.Listener<String>() { @Override public void onResponse(String response) { PlaceItemsResponse placeItemsResponse = Utils.fromJson(PlaceItemsResponse.class, response); if (placeItemsResponse != null && placeItemsResponse.getPlaces().size() > 0) { placeItemsResponse.setPlaceType(placeType); EventBus.getDefault().post(placeItemsResponse); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { EventBus.getDefault().post(new AttractionsErrorEvent(error)); } }); requestQueue.add(request); }
@RequestMapping( value = {NEWS_FI, NEWS_SV}, method = GET) public String news(Model model, Locale locale) { Urls urls = Urls.get(locale); String pageUri = HelpPage.NEWS.getUri(locale.toLanguageTag()); model.addAttribute(ALT_URI_ATTR, urls.alt().news()); model.addAttribute("content", infoTextService.getPublished(pageUri)); model.addAttribute("pageUri", pageUri); model.addAttribute("omUser", userService.getCurrentUser().isOm()); addPiwicIdIfNotAuthenticated(model); return NEWS_VIEW; }
@RequestMapping( value = {HELP_FI, HELP_SV}, method = GET) public String help( @PathVariable("helpPage") String localizedPageName, Model model, Locale locale) { Urls urls = Urls.get(locale); model.addAttribute(ALT_URI_ATTR, urls.alt().help("")); model.addAttribute("helpPage", localizedPageName); model.addAttribute("categoryLinksMap", infoTextService.getPublicSubjectList(locale)); model.addAttribute("content", infoTextService.getPublished(localizedPageName)); model.addAttribute("urls", urls); model.addAttribute("omUser", userService.getCurrentUser().isOm()); addPiwicIdIfNotAuthenticated(model); return HELP_VIEW; }
@Nullable private static HostAndPort getHostAndPort(@NotNull String rawUrl) { URI url = Urls.parseAsJavaUriWithoutParameters(rawUrl); if (url == null) { return null; } int port = url.getPort(); if (port == -1) { port = "https".equals(url.getScheme()) ? 443 : 80; } return HostAndPort.fromParts(StringUtil.notNullize(url.getHost(), "127.0.0.1"), port); }
@RequestMapping( value = {HELP_EDIT_FI, HELP_EDIT_SV}, method = POST, params = ACTION_EDITOR_PUBLISH_DRAFT) public String publishDraft( @PathVariable("helpPage") String localizedPageName, Locale locale, HttpServletRequest request) { infoTextService.publishDraft(localizedPageName); return redirectWithMessage( Urls.get(locale).helpEdit(localizedPageName), RequestMessage.EDITOR_PUBLISH_DRAFT, request); }
@RequestMapping( value = {HELP_EDIT_FI, HELP_EDIT_SV}, method = POST, params = ACTION_EDITOR_SAVE_DRAFT) public String helpEdit( @PathVariable("helpPage") String localizedPageName, @RequestParam(value = "content", required = true) String content, @RequestParam(value = "subject", required = true) String subject, Model model, Locale locale, HttpServletRequest request) { infoTextService.updateDraft(localizedPageName, content, subject); return redirectWithMessage( Urls.get(locale).helpEdit(localizedPageName), RequestMessage.EDITOR_SAVE_DRAFT, request); }
@Override public void getFlickrPhotos() { StringRequest request = new StringRequest( Urls.getSearchFlickrPhotosUrl(location), new Response.Listener<String>() { @Override public void onResponse(String response) { PhotosResponse photosResponse = Utils.fromJson(PhotosResponse.class, response); EventBus.getDefault().post(photosResponse.getPhotosResponse().getFlickrPhotos()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { EventBus.getDefault().post(new FlickrPhotosErrorEvent(error)); } }); requestQueue.add(request); }
@Override public void getPlaceDetails(String placeId) { StringRequest request = new StringRequest( Urls.getPlaceDetailsUrl(placeId), new Response.Listener<String>() { @Override public void onResponse(String response) { PlaceDetailsResponse placeItemsResponse = Utils.fromJson(PlaceDetailsResponse.class, response); EventBus.getDefault().post(placeItemsResponse); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { EventBus.getDefault().post(new PlaceDetailsErrorEvent(error)); } }); requestQueue.add(request); }
@Override public void getDescription() { StringRequest request = new StringRequest( Urls.getWikipediaDescriptionUrl(location), new Response.Listener<String>() { @Override public void onResponse(String response) { DescriptionResponse descriptionResponse = Utils.fromJson(DescriptionResponse.class, response); EventBus.getDefault().post(descriptionResponse); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { EventBus.getDefault().post(error); } }); requestQueue.add(request); }
private void getVideoDetails(final VideoSearchResponse videosResponse) { String url = Urls.getVideoDetailsUrl(videosResponse); StringRequest request = new StringRequest( url, new Response.Listener<String>() { @Override public void onResponse(String response) { VideoDetailsResponse detailsResponse = Utils.fromJson(VideoDetailsResponse.class, response); VideosResponse videos = VideoUtils.join(videosResponse, detailsResponse); EventBus.getDefault().post(videos); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { EventBus.getDefault().post(new VideosErrorEvent(error)); } }); requestQueue.add(request); }