List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeJava
public static final String escapeJava(final String input)
Escapes the characters in a String using Java String rules.
Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
So a tab becomes the characters '\\' and 't' .
The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote and forward-slash (/) are escaped.
Example:
input string: He didn't say, "Stop!"Usage
From source file:org.projectspinoza.isak.resources.GetMediaComments.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); mediaId = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); Instagram instagram = new Instagram(userApiKey); try (//from www .jav a2 s.c o m // put JSON in a file PrintWriter writer = new PrintWriter(fileOutputPath + "/" + mediaId + "_media_comments", "UTF-8")) { MediaCommentsFeed commentsFeed = instagram.getMediaComments(mediaId); List<CommentData> mediaFeedsList = commentsFeed.getCommentDataList(); if (mediaFeedsList.size() > 0) { for (CommentData mediaData : mediaFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(mediaData); writer.println(json); } } writer.close(); log.info("Total media comments collected: " + mediaFeedsList.size()); Helpers.showRateLimitStatus(commentsFeed.getAPILimitStatus(), commentsFeed.getRemainingLimitStatus()); log.info("!!! DONE !!!"); } else { log.info("No media comments found against provided userid."); } } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } catch (FileNotFoundException ex) { throw new FileNotFoundException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.GetMediaInfo.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); mediaId = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); Instagram instagram = new Instagram(userApiKey); try {//from w w w .jav a2 s . c o m MediaInfoFeed mediaInfo = instagram.getMediaInfo(mediaId); MediaFeedData mediaData = mediaInfo.getData(); if ("console".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { log.info(""); log.info("id: " + mediaData.getId()); log.info("CreatedTime: " + mediaData.getCreatedTime()); log.info("ImageFilter: " + mediaData.getImageFilter()); log.info("Link: " + mediaData.getLink()); log.info("Type: " + mediaData.getType()); log.info("Location: " + mediaData.getLocation()); log.info("Tags: " + mediaData.getTags()); } if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { try ( // put entities JSON in a file PrintWriter writer = new PrintWriter(fileOutputPath + "/" + mediaId + "_media_info", "UTF-8")) { String json = new Gson().toJson(mediaData); writer.println(json); writer.close(); } } Helpers.showRateLimitStatus(mediaInfo.getAPILimitStatus(), mediaInfo.getRemainingLimitStatus()); } catch (InstagramException | IllegalArgumentException ex) { throw new InstagramException(ex.getMessage()); } log.info("!!! DONE !!!"); }From source file:org.projectspinoza.isak.resources.GetPopularMedia.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); fileOutputFormat = StringEscapeUtils.escapeJava(args[1]); fileOutputPath = StringEscapeUtils.escapeJava(args[2]); Instagram instagram = new Instagram(userApiKey); try (PrintWriter writer = new PrintWriter(fileOutputPath + "/popularMedia", "UTF-8")) { MediaFeed popularMediaFeed = instagram.getPopularMedia(); List<MediaFeedData> mediaFeedsList = popularMediaFeed.getData(); for (MediaFeedData mediaData : mediaFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(mediaData); writer.println(json);/*from w w w . j a va 2 s . c o m*/ } } writer.close(); log.info("Total Media collected: " + mediaFeedsList.size()); Helpers.showRateLimitStatus(popularMediaFeed.getAPILimitStatus(), popularMediaFeed.getRemainingLimitStatus()); log.info("!!! DONE !!!"); } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.GetRecentMediaByLocation.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); locationId = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); Instagram instagram = new Instagram(userApiKey); int mediaCount = 0; try (//w w w . ja v a2 s . com // put JSON in a file PrintWriter writer = new PrintWriter( fileOutputPath + "/" + locationId + "_recent_media_by_location", "UTF-8")) { MediaFeed locationMediaFeed = instagram.getRecentMediaByLocation(locationId); List<MediaFeedData> mediaFeedsList = locationMediaFeed.getData(); if (mediaFeedsList.size() > 0) { log.info("Total media found in this call: " + mediaFeedsList.size()); Helpers.showRateLimitStatus(locationMediaFeed.getAPILimitStatus(), locationMediaFeed.getRemainingLimitStatus()); mediaCount += mediaFeedsList.size(); for (MediaFeedData mediaData : mediaFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(mediaData); writer.println(json); } } // remove elements from list for next chunk mediaFeedsList.clear(); MediaFeed recentLocationMediaNextPage = instagram .getRecentMediaNextPage(locationMediaFeed.getPagination()); while (recentLocationMediaNextPage.getPagination().getNextUrl() != null) { mediaFeedsList.addAll(recentLocationMediaNextPage.getData()); log.info("Total media found in this call: " + mediaFeedsList.size()); mediaCount += mediaFeedsList.size(); for (MediaFeedData mediaData : mediaFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(mediaData); writer.println(json); } } // remove elements from list for next chunk mediaFeedsList.clear(); recentLocationMediaNextPage = instagram .getRecentMediaNextPage(recentLocationMediaNextPage.getPagination()); log.info("Total media collected: " + mediaCount); if (recentLocationMediaNextPage.getRemainingLimitStatus() > 0) { Helpers.showRateLimitStatus(recentLocationMediaNextPage.getAPILimitStatus(), recentLocationMediaNextPage.getRemainingLimitStatus()); } } writer.close(); log.info("!!! DONE !!!"); } else { log.info("No recent media found against provided location id"); } } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } catch (FileNotFoundException ex) { throw new FileNotFoundException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.GetRecentMediaFeed.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); userId = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); Instagram instagram = new Instagram(userApiKey); int mediaCount = 0; try (// w w w .j a v a2 s .co m // put JSON in a file PrintWriter writer = new PrintWriter(fileOutputPath + "/" + userId + "_recent_media", "UTF-8")) { MediaFeed userMediaFeed = instagram.getRecentMediaFeed(userId); List<MediaFeedData> mediaFeedsList = userMediaFeed.getData(); if (mediaFeedsList.size() > 0) { log.info("Total media found in this call: " + mediaFeedsList.size()); Helpers.showRateLimitStatus(userMediaFeed.getAPILimitStatus(), userMediaFeed.getRemainingLimitStatus()); mediaCount += mediaFeedsList.size(); for (MediaFeedData mediaData : mediaFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(mediaData); writer.println(json); } } // remove elements from list for next chunk mediaFeedsList.clear(); MediaFeed recentUserMediaNextPage = instagram.getRecentMediaNextPage(userMediaFeed.getPagination()); while (recentUserMediaNextPage.getPagination().getNextUrl() != null) { mediaFeedsList.addAll(recentUserMediaNextPage.getData()); log.info("Total media found in this call: " + mediaFeedsList.size()); mediaCount += mediaFeedsList.size(); for (MediaFeedData mediaData : mediaFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(mediaData); writer.println(json); } } // remove elements from list for next chunk mediaFeedsList.clear(); recentUserMediaNextPage = instagram .getRecentMediaNextPage(recentUserMediaNextPage.getPagination()); log.info("Total media collected: " + mediaCount); if (recentUserMediaNextPage.getRemainingLimitStatus() > 0) { Helpers.showRateLimitStatus(recentUserMediaNextPage.getAPILimitStatus(), recentUserMediaNextPage.getRemainingLimitStatus()); } } log.info("!!! DONE !!!"); } else { log.info("No media found against provided userid."); } } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } catch (FileNotFoundException ex) { throw new FileNotFoundException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.GetRecentMediaTags.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); tagName = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); Instagram instagram = new Instagram(userApiKey); int mediaCount = 0; try (/* ww w.ja va 2 s . co m*/ // put JSON in a file PrintWriter writer = new PrintWriter(fileOutputPath + "/" + tagName + "_recent_taged_media", "UTF-8")) { TagMediaFeed tagMediaFeed = instagram.getRecentMediaTags(tagName); List<MediaFeedData> mediaFeedsList = tagMediaFeed.getData(); if (mediaFeedsList.size() > 0) { log.info("Total media tags found in this call: " + mediaFeedsList.size()); Helpers.showRateLimitStatus(tagMediaFeed.getAPILimitStatus(), tagMediaFeed.getRemainingLimitStatus()); mediaCount += mediaFeedsList.size(); for (MediaFeedData mediaData : mediaFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(mediaData); writer.println(json); } } // remove elements from list for next chunk mediaFeedsList.clear(); TagMediaFeed recentTagMediaNextPage = instagram .getTagMediaInfoNextPage(tagMediaFeed.getPagination()); while (recentTagMediaNextPage.getPagination().getNextUrl() != null) { mediaFeedsList.addAll(recentTagMediaNextPage.getData()); log.info("Total media tags found in this call: " + mediaFeedsList.size()); mediaCount += mediaFeedsList.size(); for (MediaFeedData mediaData : mediaFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(mediaData); writer.println(json); } } // remove elements from list for next chunk mediaFeedsList.clear(); recentTagMediaNextPage = instagram .getTagMediaInfoNextPage(recentTagMediaNextPage.getPagination()); log.info("Total media collected: " + mediaCount); if (recentTagMediaNextPage.getRemainingLimitStatus() > 0) { Helpers.showRateLimitStatus(recentTagMediaNextPage.getAPILimitStatus(), recentTagMediaNextPage.getRemainingLimitStatus()); } } writer.close(); log.info("!!! DONE !!!"); } else { log.info("No media tags found against provided tag."); } } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } catch (FileNotFoundException ex) { throw new FileNotFoundException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.GetTagInfo.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); tagName = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); Instagram instagram = new Instagram(userApiKey); try {//from ww w.jav a 2s . c o m PrintWriter writer = null; if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { writer = new PrintWriter(fileOutputPath + "/" + tagName + "_tag_info", "UTF-8"); } TagInfoFeed tagFeed = instagram.getTagInfo(tagName); TagInfoData tagData = tagFeed.getTagInfo(); if ("console".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { log.info("name: " + tagData.getTagName()); log.info("media_count: " + tagData.getMediaCount()); } if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(tagData); if (writer != null) writer.println(json); } if (writer != null) writer.close(); Helpers.showRateLimitStatus(tagFeed.getAPILimitStatus(), tagFeed.getRemainingLimitStatus()); log.info("!!! DONE !!!"); } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.GetUserFollowedByList.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); userId = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); // init Instagram Instagram instagram = new Instagram(userApiKey); int followersCount = 0; try (//from w w w. ja v a2 s . com // put output in a file PrintWriter writer = new PrintWriter(fileOutputPath + "/" + userId + "_followed_by", "UTF-8")) { UserFeed userFeed = instagram.getUserFollowedByList(userId); List<UserFeedData> userFeedsList = userFeed.getUserList(); if (userFeedsList.size() > 0) { log.info("Total Followed by found in this call: " + userFeedsList.size()); Helpers.showRateLimitStatus(userFeed.getAPILimitStatus(), userFeed.getRemainingLimitStatus()); followersCount += userFeedsList.size(); for (UserFeedData userData : userFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(userData); writer.println(json); } } // remove elements from list for next chunk userFeedsList.clear(); // pagination UserFeed recentUserFollowNextPage = instagram.getUserFollowListNextPage(userFeed.getPagination()); while (recentUserFollowNextPage.getPagination().getNextUrl() != null) { userFeedsList.addAll(recentUserFollowNextPage.getUserList()); log.info("Total Followed by found in this call: " + userFeedsList.size()); followersCount += userFeedsList.size(); for (UserFeedData userData : userFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(userData); writer.println(json); } } // remove elements from list for next chunk userFeedsList.clear(); recentUserFollowNextPage = instagram .getUserFollowListNextPage(recentUserFollowNextPage.getPagination()); log.info("Total Followed by collected: " + followersCount); if (recentUserFollowNextPage.getRemainingLimitStatus() > 0) { Helpers.showRateLimitStatus(recentUserFollowNextPage.getAPILimitStatus(), recentUserFollowNextPage.getRemainingLimitStatus()); } } log.info("!!! DONE !!!"); } else { log.info("No Followed by found against provided userid."); } } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } catch (FileNotFoundException ex) { throw new FileNotFoundException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.GetUserFollowList.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); userId = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); // init Instagram Instagram instagram = new Instagram(userApiKey); int followersCount = 0; try (//w w w .j a v a 2s . c o m // put output in a file PrintWriter writer = new PrintWriter(fileOutputPath + "/" + userId + "_followings", "UTF-8")) { UserFeed userFeed = instagram.getUserFollowList(userId); List<UserFeedData> userFeedsList = userFeed.getUserList(); if (userFeedsList.size() > 0) { log.info("Total Followers found in this call: " + userFeedsList.size()); Helpers.showRateLimitStatus(userFeed.getAPILimitStatus(), userFeed.getRemainingLimitStatus()); followersCount += userFeedsList.size(); for (UserFeedData userData : userFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(userData); writer.println(json); } } // remove elements from list for next chunk userFeedsList.clear(); // pagination UserFeed recentUserFollowNextPage = instagram.getUserFollowListNextPage(userFeed.getPagination()); while (recentUserFollowNextPage.getPagination().getNextUrl() != null) { userFeedsList.addAll(recentUserFollowNextPage.getUserList()); log.info("Total Followers found in this call: " + userFeedsList.size()); followersCount += userFeedsList.size(); for (UserFeedData userData : userFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(userData); writer.println(json); } } // remove elements from list for next chunk userFeedsList.clear(); recentUserFollowNextPage = instagram .getUserFollowListNextPage(recentUserFollowNextPage.getPagination()); log.info("Total Followers collected: " + followersCount); if (recentUserFollowNextPage.getRemainingLimitStatus() > 0) { Helpers.showRateLimitStatus(recentUserFollowNextPage.getAPILimitStatus(), recentUserFollowNextPage.getRemainingLimitStatus()); } } log.info("!!! DONE !!!"); } else { log.info("No Followers found against provided userid."); } } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } catch (FileNotFoundException ex) { throw new FileNotFoundException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.GetUserInfo.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); userId = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); Instagram instagram = new Instagram(userApiKey); try {/*www . j a va 2 s . c o m*/ UserInfo userInfo = instagram.getUserInfo(userId); UserInfoData userData = userInfo.getData(); if ("console".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { log.info(""); log.info("id: " + userData.getId()); log.info("username: " + userData.getUsername()); log.info("full_name: " + userData.getFullName()); log.info("profile_picture: " + userData.getProfilePicture()); log.info("bio: " + userData.getBio()); log.info("website: " + userData.getWebsite()); log.info("media_count: " + userData.getCounts().getMedia()); log.info("follows: " + userData.getCounts().getFollows()); log.info("followed_by: " + userData.getCounts().getFollowedBy()); } if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { try (PrintWriter writer = new PrintWriter(fileOutputPath + "/" + userId + "_info", "UTF-8")) { String json = new Gson().toJson(userData); writer.println(json); writer.close(); } } log.info("!!! DONE !!!"); Helpers.showRateLimitStatus(userInfo.getAPILimitStatus(), userInfo.getRemainingLimitStatus()); } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } catch (JsonSyntaxException ex) { throw new InstagramException("Invalid userId is provided."); } }