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.GetUserLikes.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 (PrintWriter writer = new PrintWriter(fileOutputPath + "/" + mediaId + "_media_likes", "UTF-8")) { LikesFeed userLikes = instagram.getUserLikes(mediaId); List<User> likeData = userLikes.getUserList(); if (likeData.size() > 0) { for (User likeData1 : likeData) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(likeData1); writer.println(json); }/*from w ww .jav a 2 s . c o m*/ } writer.close(); log.info("Total Likes collected: " + likeData.size()); Helpers.showRateLimitStatus(userLikes.getAPILimitStatus(), userLikes.getRemainingLimitStatus()); log.info("!!! DONE !!!"); } else { log.info("No likes found against provided mediaId."); } } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.SearchLocation.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); String latitudeStr = args[1].replace(".", ""); latitudeStr = latitudeStr.replace("-", ""); String longitudeStr = args[2].replace(".", ""); longitudeStr = longitudeStr.replace("-", ""); try {//www . j av a2s.c om latitude = Double.parseDouble(args[1]); } catch (Exception e) { System.err.println("latitude " + args[1] + " must be type of Double."); } try { longitude = Double.parseDouble(args[2]); } catch (Exception e) { System.err.println("longitude " + args[2] + " must be type of Double."); } fileOutputFormat = StringEscapeUtils.escapeJava(args[3]); fileOutputPath = StringEscapeUtils.escapeJava(args[4]); Instagram instagram = new Instagram(userApiKey); String fileName = "lat_lng_location_" + latitudeStr + "_" + longitudeStr; int mediaCount = 0; try { PrintWriter writer = null; if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { writer = new PrintWriter(fileOutputPath + "/" + fileName, "UTF-8"); } LocationSearchFeed locationFeed = instagram.searchLocation(latitude, longitude); List<Location> locationFeedsList = locationFeed.getLocationList(); if (locationFeedsList.size() > 0) { mediaCount += locationFeedsList.size(); for (Location locationData : locationFeedsList) { if ("console".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { log.info(""); log.info("id: " + locationData.getId()); log.info("name: " + locationData.getName()); log.info("latitude: " + locationData.getLatitude()); log.info("longitude: " + locationData.getLongitude()); } if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(locationData); if (writer != null) { writer.println(json); } } } // remove elements from list for next chunk locationFeedsList.clear(); if (writer != null) { writer.close(); } log.info("Total Locations collected: " + mediaCount); Helpers.showRateLimitStatus(locationFeed.getAPILimitStatus(), locationFeed.getRemainingLimitStatus()); } else { log.info("No location found against provided lat lng."); } log.info("!!! DONE !!!"); } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.SearchMediaByLatLng.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); String latitudeStr = args[1].replace(".", ""); latitudeStr = latitudeStr.replace("-", ""); String longitudeStr = args[2].replace(".", ""); longitudeStr = longitudeStr.replace("-", ""); try {/*from www .ja va 2 s . c o m*/ latitude = Double.parseDouble(args[1]); } catch (Exception e) { throw new IOException("Latitude " + args[1] + " must be type of Double."); } try { longitude = Double.parseDouble(args[2]); } catch (Exception e) { throw new IOException("Longitude " + args[2] + " must be type of Double."); } fileOutputFormat = StringEscapeUtils.escapeJava(args[3]); fileOutputPath = StringEscapeUtils.escapeJava(args[4]); Instagram instagram = new Instagram(userApiKey); String fileName = "lat_lng_media_" + latitudeStr + "_" + longitudeStr; try (PrintWriter writer = new PrintWriter(fileOutputPath + "/" + fileName, "UTF-8")) { MediaFeed searchMediaFeed = instagram.searchMedia(latitude, longitude); List<MediaFeedData> mediaFeedsList = searchMediaFeed.getData(); if (mediaFeedsList.size() > 0) { for (MediaFeedData mediaData : mediaFeedsList) { if ("json".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(mediaData); writer.println(json); } } writer.close(); log.info("Total Media collected: " + mediaFeedsList.size()); Helpers.showRateLimitStatus(searchMediaFeed.getAPILimitStatus(), searchMediaFeed.getRemainingLimitStatus()); } else { log.info("No Media found against provided lat lng."); } log.info("!!! DONE !!!"); } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.SearchTags.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 w ww .ja v a 2 s.c o m PrintWriter writer = null; if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { writer = new PrintWriter(fileOutputPath + "/" + tagName + "_tag_search_results", "UTF-8"); } TagSearchFeed tagsFeed = instagram.searchTags(tagName); List<TagInfoData> tagsList = tagsFeed.getTagList(); if (tagsList.size() > 0) { for (TagInfoData tagData : tagsList) { if ("console".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { log.info("name: " + tagData.getTagName()); log.info("media_count: " + tagData.getMediaCount()); log.info(""); } 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(); } log.info("Total Media collected: " + tagsList.size()); Helpers.showRateLimitStatus(tagsFeed.getAPILimitStatus(), tagsFeed.getRemainingLimitStatus()); log.info("!!! DONE !!!"); } else { log.info("No media tags found against provided tag."); } } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } }From source file:org.projectspinoza.isak.resources.SearchUser.java
public static void get(String[] args) throws IOException { userApiKey = StringEscapeUtils.escapeJava(args[0]); query = StringEscapeUtils.escapeJava(args[1]); fileOutputFormat = StringEscapeUtils.escapeJava(args[2]); fileOutputPath = StringEscapeUtils.escapeJava(args[3]); Instagram instagram = new Instagram(userApiKey); try {/*from w w w . ja va2 s . c om*/ PrintWriter writer = null; if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { writer = new PrintWriter(fileOutputPath + "/" + query + "_search_user", "UTF-8"); } UserFeed userFeed = instagram.searchUser(query); List<UserFeedData> userList = userFeed.getUserList(); for (UserFeedData userData : userList) { 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.getProfilePictureUrl()); log.info("bio: " + userData.getBio()); log.info("website: " + userData.getWebsite()); } if ("json".equals(fileOutputFormat.toLowerCase()) || "cj".equals(fileOutputFormat.toLowerCase())) { String json = new Gson().toJson(userData); if (writer != null) writer.println(json); } } if (writer != null) writer.close(); log.info(""); log.info("Total Users collected: " + userList.size()); Helpers.showRateLimitStatus(userFeed.getAPILimitStatus(), userFeed.getRemainingLimitStatus()); } catch (InstagramException ex) { throw new InstagramException(ex.getMessage()); } }From source file:org.roda.wui.server.browse.BrowserServiceImpl.java
@Override public <T extends IsIndexed> String createProcessJson(String jobName, SelectedItems<T> selected, String id, Map<String, String> value, String selectedClass) throws AuthorizationDeniedException, RequestNotValidException, NotFoundException, GenericException, JobAlreadyStartedException { SelectedItems<T> selectedItems = selected; User user = UserUtility.getUser(getThreadLocalRequest()); if (selectedItems instanceof SelectedItemsList) { SelectedItemsList<T> items = (SelectedItemsList<T>) selectedItems; if (items.getIds().isEmpty()) { selectedItems = getAllItemsByClass(selectedClass); }//from ww w . j a v a 2s . com } Job job = new Job(); job.setId(IdUtils.createUUID()); job.setName(jobName); job.setSourceObjects(selectedItems); job.setPlugin(id); job.setPluginParameters(value); job.setUsername(user.getName()); String command = RodaCoreFactory.getRodaConfiguration().getString("ui.createJob.curl"); if (command != null) { command = command.replace("{{jsonObject}}", StringEscapeUtils.escapeJava(JsonUtils.getJsonFromObject(job))); return command; } else { return ""; } }From source file:org.rythmengine.utils.S.java
/** * Return a {@link org.rythmengine.utils.RawData} type wrapper of * an object with Java escaping// ww w.j av a 2s . c o m * <p/> * <p>Object is {@link #toString(Object) converted to String} before escaping</p> * <p/> * <p>After the object get escaped, the output string is safe to put inside a pair of * Java quotation marks</p> * * @param o * @return Java escaped data */ public static RawData escapeJava(Object o) { if (null == o) return RawData.NULL; if (o instanceof RawData) return (RawData) o; return new RawData(StringEscapeUtils.escapeJava(o.toString())); }From source file:org.shareok.data.dspacemanager.DspaceApiHandlerImpl.java
/** * Suppose ONLY two metadata file names for importing: dublin_core.xml and metadata_dcterms.xml * /*w w w. j a v a 2 s . c o m*/ * @param paths : paths of the metadata files * @return : string array of metadata information */ @Override public Map<String, String> getMetadataFromXmlFiles(String[] paths) { Map<String, String> data = new HashMap<>(); Document doc = null; try { for (String path : paths) { String json = ""; String dcType = "dc"; doc = DocumentProcessorUtil.loadXMLFromString(path); if (null != doc) { doc.getDocumentElement().normalize(); Node dcNode = doc.getDocumentElement(); Node schema = dcNode.getAttributes().getNamedItem("schema"); if (null != schema) { dcType = schema.getNodeValue(); } NodeList nList = doc.getElementsByTagName("dcvalue"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String dcElement = ""; String qualifier = ""; String lang = "en_US"; String value = ""; if (eElement.hasAttribute("element")) { dcElement = eElement.getAttribute("element"); } if (eElement.hasAttribute("qualifier")) { qualifier = eElement.getAttribute("qualifier"); if ("none".equals(qualifier)) { qualifier = ""; } } if (eElement.hasAttribute("language")) { lang = eElement.getAttribute("language"); } value = StringEscapeUtils.escapeJava(eElement.getTextContent()); String key = dcType + "." + dcElement + (!"".equals(qualifier) ? "." + qualifier : ""); json += "{\"key\":\"" + key + "\",\"value\":\"" + value + "\",\"language\":\"" + lang + "\"},"; } } } if (!"".equals(json)) { json = "[" + json.substring(0, json.length() - 1) + "]"; data.put(path, json); } } } catch (Exception ex) { logger.error("Cannot read metadata information from xml files", ex); } return data; }From source file:org.siphon.d2js.D2jsUnitManager.java
protected String convertCode(String code, File src, String requestPath) throws Exception { // return "(function (d2js){" + new EmbedSqlTranslator().translate(code) + "; d2js.cloner = function(){}; // d2js.cloner.prototype=d2js; return d2js;})(d2js.clone());"; return "(function (d2js, src, path){" + "d2js.srcFile = src; " + "d2js.path = path;" + new EmbedSqlTranslator().translate(code) + "; " + "d2js.initD2js && d2js.initD2js(); return d2js;})" + "(" + "d2js.clone(), " + "\"" + StringEscapeUtils.escapeJava(src.getAbsolutePath()) + "\"," + "\"" + (requestPath) + "\"" + ");"; }From source file:org.siphon.d2js.EmbedSqlTranslator.java
private void appendSqlToCode(CodePart sql) { boolean isFollow = sql.isFollowSql; boolean dirty = false; for (String line : sql.lines) { if (line.trim().isEmpty()) { code.currentLine.append(line); code.lines.add(code.currentLine.toString()); code.currentLine.setLength(0); } else {// w w w . j a va 2 s . c o m if (!isFollow) { line = line.replaceFirst("^\\s+", ""); // trim left code.currentLine.append("\"" + StringEscapeUtils.escapeJava(line) + "\""); isFollow = true; } else { line = line.replaceFirst("^\\s+", " "); if (sql.isInCode && dirty == false) { code.currentLine.append(sql.name + " += \"").append(StringEscapeUtils.escapeJava(line)) .append("\""); } else { code.currentLine.append("+ \"").append(StringEscapeUtils.escapeJava(line)).append("\""); } } dirty = true; code.lines.add(code.currentLine.toString()); code.currentLine.setLength(0); } } String line = sql.currentLine.toString(); if (line.trim().isEmpty()) { if (!isFollow) { code.currentLine.append("''"); dirty = true; } else { code.currentLine.append(line); } // code.lines.add(code.currentLine.toString()); // code.currentLine.setLength(0); } else { if (!isFollow) { line = line.replaceFirst("^\\s+", ""); // trim left code.currentLine.append("\"" + StringEscapeUtils.escapeJava(line) + "\""); isFollow = true; dirty = true; } else { if (sql.isInCode && dirty == false) { code.currentLine.append(sql.name + " += \"").append(StringEscapeUtils.escapeJava(line)) .append("\""); } else { code.currentLine.append("+ \"").append(StringEscapeUtils.escapeJava(line)).append("\""); } dirty = true; } } if (dirty) { code.currentLine.append(";"); } sql.currentLine.setLength(0); sql.lines.clear(); }