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:com.squarespace.template.TreeEmitter.java
private static void emitArgs(Arguments args, StringBuilder buf) { List<String> rawArgs = args.getArgs(); if (!rawArgs.isEmpty()) { buf.append("delim='"); buf.append(StringEscapeUtils.escapeJava("" + args.getDelimiter())); buf.append("' parsed=").append(args.getArgs()); }/*www.j a v a2s .c o m*/ }From source file:com.datastax.loader.parser.AbstractParser.java
public String escape(String instr) { return StringEscapeUtils.escapeJava(instr); }From source file:net.famzangl.minecraft.minebot.PlayerUpdateHandler.java
@SubscribeEvent public void onPlayerTick(PlayerTickEvent evt) { if (toLoaded && to == null) { return;/*from w w w. j a v a2 s . c om*/ } final EntityPlayer player = evt.player; final String name = player.getDisplayName().getUnformattedText(); final Long blocked = blockTimes.get(name); if (blocked != null && blocked > System.currentTimeMillis()) { return; } blockTimes.put(name, System.currentTimeMillis() + 2000); final String json = String.format( "{\"players\":[{\"username\": \"%s\", \"x\": %d, \"y\" : %d, \"z\": %d, \"world\" : \"world\"}]}", StringEscapeUtils.escapeJava(name), (int) player.posX, (int) player.posY, (int) player.posZ); sendThread.execute(new SendToServerTask(json)); }From source file:de.fraunhofer.sciencedataamanager.beans.DataExportInstanceEdit.java
/** * Updates the Data Export Instance with the current values from the JSF * page./*from ww w. j a va 2s .c om*/ */ public void updateDataExportInstance() { try { DataExportInstance dataExportInstance = new DataExportInstance(); dataExportInstance.setID(dataExportInstanceID); dataExportInstance.setName(dataExportInstanceName); dataExportInstance.setExportFilePrefix(getDataExportFilePrefix()); dataExportInstance.setExportFilePostfix(getDataExportFilePostfix()); dataExportInstance.setResponseContentType(getResponseContentType()); dataExportInstance.setGroovyCode(StringEscapeUtils.escapeJava(dataExportInstanceGroovyCode)); DataExportInstanceDataManager dataExportInstanceDataProvider = new DataExportInstanceDataManager( applicationConfiguration); dataExportInstanceDataProvider.updateDataExportInstance(dataExportInstance); FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml"); } catch (Exception ex) { Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex); this.applicationConfiguration.getLoggingManager().logException(ex); } }From source file:net.antoinecomte.regex.RegExTesterApplication.java
private void showResult(String regexValue, String textValue) { Matcher matcher;/*from ww w .j av a 2s . c o m*/ try { result.setVisible(!"".equals(regexValue)); Label match = new Label("no match"); match.addStyleName("h3 color"); result.removeAllComponents(); result.addComponent(match); matcher = Pattern.compile(regexValue).matcher(textValue); if (matcher.matches()) { if (matcher.groupCount() > 0) for (int i = 1; i <= matcher.groupCount(); i++) { Label g = new Label("group " + i + " = " + matcher.group(i)); g.addStyleName("h3 color"); g.setSizeUndefined(); result.addComponent(g); } match.setValue("match"); } matcher.reset(); if (matcher.find()) { Label findresult = new Label("find=true, start = " + matcher.start() + " end = " + matcher.end()); findresult.addStyleName("h3 color"); result.addComponent(findresult); } Label javaString = new Label("java string : \"" + StringEscapeUtils.escapeJava(regexValue) + "\""); javaString.addStyleName("small color"); result.addComponent(javaString); } catch (Exception e) { result.removeAllComponents(); Label error = new Label(e.getMessage()); error.addStyleName("error"); result.addComponent(error); } }From source file:com.squarespace.template.TreeEmitter.java
private static void emitEscapedString(StringView view, StringBuilder buf) { String raw = view.toString(); int length = raw.length(); int maxLen = Math.min(40, length); buf.append("(len=").append(length).append(") "); buf.append('"').append(StringEscapeUtils.escapeJava(raw.substring(0, maxLen))); if (maxLen != raw.length()) { buf.append(" ..."); }/*from w ww . ja va 2s. co m*/ buf.append('"'); }From source file:net.sf.dynamicreports.report.builder.expression.Expressions.java
/** * Creates a new jasper string expression, useful only for showing a static text.<br/> * This method escapes the characters in a {@code String} using Java String rules. * * @param text text to be shown// w w w. java 2s .com * @return the expression */ public static JasperExpression<String> jasperSyntaxText(String text) { return new JasperExpression<String>("\"" + StringEscapeUtils.escapeJava(text) + "\"", String.class); }From source file:madgik.exareme.master.queryProcessor.analyzer.fanalyzer.FederatedAnalyzer.java
private Map<String, Set<String>> specifyColumns(String tableName) throws Exception { Map<String, Set<String>> info = new HashMap<String, Set<String>>(); DatabaseMetaData dbmd = con.getMetaData(); // dtabase metadata object // listing tables and columns String catalog = null;//from ww w .j a va 2 s .c om String schemaPattern = null; String columnNamePattern = null; String tname = tableName; if (tname.contains(".")) { schemaPattern = tname.split("\\.")[0]; tname = tname.split("\\.")[1]; } ResultSet resultColumns = dbmd.getColumns(catalog, schemaPattern, tname, columnNamePattern); Set<String> columns = new HashSet<String>(); while (resultColumns.next()) { String columnName = StringEscapeUtils.escapeJava(resultColumns.getString(4)); columns.add(columnName); } info.put(tableName, columns); resultColumns.close(); return info; }From source file:au.org.ands.vocabs.toolkit.provider.publish.SISSVocPublishProvider.java
/** Add the essential properties required by the spec file template. * @param taskInfo The TaskInfo object for this task. *//*from w w w. ja v a 2 s . c o m*/ private void addBasicSpecProperties(final TaskInfo taskInfo) { // Top-level of deployment path specProperties.put("DEPLOYPATH", PROPS.getProperty(PropertyConstants.SISSVOC_VARIABLE_DEPLOYPATH, "/repository/api/lda")); // The name of the ANDS Vocabulary service specProperties.put("SERVICE_TITLE", PROPS.getProperty(PropertyConstants.SISSVOC_VARIABLE_SERVICE_TITLE, "ANDS Vocabularies LDA service")); // The name of the ANDS Vocabulary service owner specProperties.put("SERVICE_AUTHOR", PROPS.getProperty(PropertyConstants.SISSVOC_VARIABLE_SERVICE_AUTHOR, "ANDS Services")); // Contact email address for the ANDS Vocabulary service owner specProperties.put("SERVICE_AUTHOR_EMAIL", PROPS.getProperty(PropertyConstants.SISSVOC_VARIABLE_SERVICE_AUTHOR_EMAIL, "services@ands.org.au")); // Homepage of the ANDS Vocabulary service // ANDS home page for now; in future, could be // vocabs.ands.org.au itself. specProperties.put("SERVICE_HOMEPAGE", PROPS.getProperty(PropertyConstants.SISSVOC_VARIABLE_SERVICE_HOMEPAGE, "http://www.ands.org.au/")); // Vocabulary title specProperties.put("SERVICE_LABEL", StringEscapeUtils.escapeJava(taskInfo.getVocabulary().getTitle())); String repositoryId = ToolkitFileUtils.getSesameRepositoryId(taskInfo); // SPARQL endpoint to use for doing queries specProperties .put("SPARQL_ENDPOINT", PROPS.getProperty(PropertyConstants.SISSVOC_VARIABLE_SPARQL_ENDPOINT_PREFIX, "http://localhost:8080/repository/" + "openrdf-sesame/repositories/") + repositoryId); specProperties.put("SVC_ID", repositoryId); // Additional path to all the endpoints for this repository. // The template assumes the variable begins with a slash. specProperties.put("SVC_PREFIX", "/" + ToolkitFileUtils.getSISSVocRepositoryPath(taskInfo)); // Path to the XSL stylesheet that generates the HTML pages. // Path is relative to the SISSVoc webapp. specProperties.put("HTML_STYLESHEET", PROPS.getProperty(PropertyConstants.SISSVOC_VARIABLE_HTML_STYLESHEET, "resources/default/transform/ands-ashtml-sissvoc.xsl")); // Empty string for now specProperties.put("NAMESPACES", ""); // Title of the vocab displayed at the top of HTML pages specProperties.put("ANDS_VOCABNAME", StringEscapeUtils.escapeJava(taskInfo.getVocabulary().getTitle())); // Add more properties here, if/when needed. // specProperties.put("", ""); // The above properties are all more-or-less required. // Below are properties that are optional, and // may be overridden by the subtask settings. specProperties.put("ANDS_VOCABMORE", ""); specProperties.put("ANDS_VOCABAPIDOCO", ""); }From source file:ca.hec.commons.utils.MergePropertiesUtils.java
/** * Merge newProps to mainProps./*from ww w . j ava 2 s . c om*/ * NOTE: The idea is that we want to write out the properties in exactly the same order, for future comparison purposes. * * @param newPropertiesFile * @param newProps * @return nb of properties from main props file. */ public static void merge(File newPropertiesFile, Properties updatedProps) throws Exception { /** * 1) Read line by line of the new PropertiesFile (Sakai 2.9.1) * For each line: extract property * check if we have a match one in the propToMerge * - if no, then rewrite the same line * - if yes: - if same value, rewrite the same line * - if different value, rewrite the prop with the new value * - For both cases, delete the key from newProperties. * * 2) At the end, write the remaining list of propToMerge at * the end of mainProp */ try { int nbPropsInMain = 0; int nbPropsChanged = 0; int nbPropsSimilar = 0; int nbPropsNotInNew = 0; // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(newPropertiesFile); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); LineWithContinuation lineIn; // Read File Line By Line while ((lineIn = LineWithContinuation.readLineWithContinuation(br)) != null) { KeyValue keyValue = extractKeyValue(lineIn.getFullLine()); // May be a comment line, or blank line, or not a line containing key & property pair (we expect "key = value" line). // Simply echo the line back. if (keyValue == null) { System.out.println(lineIn.getFullLine()); continue; } nbPropsInMain++; String key = keyValue.key; //System.out.println(key); String newValue = updatedProps.getProperty(key); String valueEscaped = unescapeJava(keyValue.value); if (newValue != null) { if (!newValue.equals(valueEscaped)) { String newLine = composeNewPropLine(key, StringEscapeUtils.escapeJava(newValue)); System.out.println(newLine); nbPropsChanged++; } else { System.out.println(lineIn.getLineWithReturn()); nbPropsSimilar++; } // remove the key from newProps because it is used updatedProps.remove(key); } else { System.out.println(lineIn.getLineWithReturn()); nbPropsNotInNew++; } } // Close the input stream in.close(); System.out.println("\n\n### " + nbPropsInMain + " properties in SAKAI 11 (" + nbPropsChanged + " changed, " + nbPropsSimilar + " props with same value in both versions, " + nbPropsNotInNew + " not in 2.9.1)"); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); throw e; } }