Java Code Examples for org.apache.commons.lang3.StringEscapeUtils.unescapeJava()

The following are Jave code examples for showing how to use unescapeJava() of the org.apache.commons.lang3.StringEscapeUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MinoanER   File: Utils.java   View Source Code Vote up 7 votes
public static String encodeURIinUTF8(String uri) {
    if (uri.startsWith("<http://dbpedia.org/resource/")) {            
        int splitPoint = uri.lastIndexOf("/")+1;
        String infix = uri.substring(splitPoint, uri.length()-1);
        if (infix.contains("%")) {
            return uri;
        }
        try {
            infix = infix.replace("\\\\", "\\");
            infix = StringEscapeUtils.unescapeJava(infix);
            infix = URLEncoder.encode(infix, "UTF-8");            
        } catch (UnsupportedEncodingException ex) {
            System.err.println("Encoding exception: "+ex);
        }
        uri = uri.substring(0, splitPoint) + infix + ">";            
    }
    return uri;
}
 
Example 2
Project: get-yahoo-quotes-java   File: GetYahooQuotes.java   View Source Code Vote up 6 votes
public String findCrumb(List<String> lines) {
    String crumb = "";
    String rtn = "";
    for (String l : lines) {
        if (l.indexOf("CrumbStore") > -1) {
            rtn = l;
            break;
        }
    }
    // ,"CrumbStore":{"crumb":"OKSUqghoLs8"        
    if (rtn != null && !rtn.isEmpty()) {
        String[] vals = rtn.split(":");                 // get third item
        crumb = vals[2].replace("\"", "");              // strip quotes
        crumb = StringEscapeUtils.unescapeJava(crumb);  // unescape escaped values (particularly, \u002f
        }
    return crumb;
}
 
Example 3
Project: atlas   File: TPatchTool.java   View Source Code Vote up 6 votes
protected File getLastPatchFile(String baseApkVersion,
                                String productName,
                                File outPatchDir) throws IOException {
    try {
        String httpUrl = ((TpatchInput)input).LAST_PATCH_URL +
                "baseVersion=" +
                baseApkVersion +
                "&productIdentifier=" +
                productName;
        String response = HttpClientUtils.getUrl(httpUrl);
        if (StringUtils.isBlank(response) ||
                response.equals("\"\"")) {
            return null;
        }
        File downLoadFolder = new File(outPatchDir, "LastPatch");
        downLoadFolder.mkdirs();
        File downLoadFile = new File(downLoadFolder, "lastpatch.tpatch");
        String downLoadUrl = StringEscapeUtils.unescapeJava(response);
        downloadTPath(downLoadUrl.substring(1, downLoadUrl.length() - 1), downLoadFile);

        return downLoadFile;
    } catch (Exception e) {
        return null;
    }
}
 
Example 4
Project: oneops   File: DLQMessageProcessor.java   View Source Code Vote up 6 votes
private String convertMessage(String message, Map<String, String> headers) {
    String newMessage = message;
    JsonElement msgRootElement = parser.parse(message);
    if (msgRootElement instanceof JsonObject) {
        JsonObject msgRoot = (JsonObject)msgRootElement;

        JsonElement element = msgRoot.get(PAYLOAD_ELEMENT_KEY);
        if (element != null) {
            if (!element.isJsonObject()) {
                //convert payLoad to a json object if it is not already
                msgRoot.remove(PAYLOAD_ELEMENT_KEY);
                String realPayload = element.getAsString();
                String escapedPayload = StringEscapeUtils.unescapeJava(realPayload);
                msgRoot.add(PAYLOAD_ELEMENT_KEY, parser.parse(escapedPayload));
            }
        }
        JsonElement hdrElement = GSON.toJsonTree(headers);
        msgRoot.add("msgHeaders", hdrElement);
        newMessage = GSON.toJson(msgRoot);
        if (logger.isDebugEnabled()) {
            logger.debug("message to be indexed " + newMessage);
        }
    }
    return newMessage;
}
 
Example 5
Project: OperatieBRP   File: Utils.java   View Source Code Vote up 6 votes
/**
 * Converteer een naam naar een java enumeratie naam.
 * @param javaNameBase naam
 * @return enumeratie naam
 */
public static String convertToJavaEnumName(final String javaNameBase) {
    if (javaNameBase.startsWith(LITERAL)) {
        return StringEscapeUtils.unescapeJava(javaNameBase.replaceAll(String.format("^%s", LITERAL), ""));
    } else {
        String result = javaNameBase;

        // Unaccent
        result = Normalizer.normalize(result, Normalizer.Form.NFD);
        // Replace whitespace with underscore
        result = result.replaceAll("(\\s|-)", "_");
        // Uppercase
        result = result.toUpperCase();
        // Remove unsupported characters
        result = result.replaceAll("[^A-Z0-9_]", "");
        // Remove duplicate seperators
        result = result.replaceAll("_{2,}", "_");

        return result;
    }
}
 
Example 6
Project: iConA   File: ClassDAO.java   View Source Code Vote up 6 votes
public String getClassInitBodyUnescaped(){
	if(classInitBody==null)
		return null;
	
	Pattern pattern = Pattern.compile("\\t+");
    Matcher matcher = pattern.matcher(StringEscapeUtils.unescapeJava(this.classInitBody));
    StringBuilder sb=new StringBuilder(StringEscapeUtils.unescapeJava(this.classInitBody));
    
    while(matcher.find()){
    	sb.insert(matcher.start(), CodeStringBuilder.getTabString());
    }
    
    String tempString=sb.toString();
    
    pattern=Pattern.compile("\\n+");
    matcher=pattern.matcher(tempString);
    
    while(matcher.find()){
    	sb.insert(matcher.end(), CodeStringBuilder.getTabString());
    }
	return sb.toString();
}
 
Example 7
Project: BaseClient   File: NbtTagValue.java   View Source Code Vote up 5 votes
public NbtTagValue(String p_i61_1_, String p_i61_2_)
{
    String[] astring = Config.tokenize(p_i61_1_, ".");
    this.parents = (String[])Arrays.copyOfRange(astring, 0, astring.length - 1);
    this.name = astring[astring.length - 1];

    if (p_i61_2_.startsWith("pattern:"))
    {
        this.type = 1;
        p_i61_2_ = p_i61_2_.substring("pattern:".length());
    }
    else if (p_i61_2_.startsWith("ipattern:"))
    {
        this.type = 2;
        p_i61_2_ = p_i61_2_.substring("ipattern:".length()).toLowerCase();
    }
    else if (p_i61_2_.startsWith("regex:"))
    {
        this.type = 3;
        p_i61_2_ = p_i61_2_.substring("regex:".length());
    }
    else if (p_i61_2_.startsWith("iregex:"))
    {
        this.type = 4;
        p_i61_2_ = p_i61_2_.substring("iregex:".length()).toLowerCase();
    }
    else
    {
        this.type = 0;
    }

    p_i61_2_ = StringEscapeUtils.unescapeJava(p_i61_2_);
    this.value = p_i61_2_;
}
 
Example 8
Project: winter   File: WebTablesStringNormalizer.java   View Source Code Vote up 5 votes
/**
 *
 * @param columnName
 * @return the normalised string
 */
public static String normaliseHeader(String columnName) {
	columnName = StringEscapeUtils.unescapeJava(columnName);
	columnName = columnName.replace("\"", "");
	columnName = columnName.replace("|", " ");
	columnName = columnName.replace(",", "");
	columnName = columnName.replace("{", "");
	columnName = columnName.replace("}", "");
	columnName = columnName.replaceAll("\n", "");

	columnName = columnName.replace("&nbsp;", " ");
	columnName = columnName.replace("&nbsp", " ");
	columnName = columnName.replace("nbsp", " ");
	columnName = columnName.replaceAll("<.*>", "");

	columnName = columnName.toLowerCase();
	columnName = columnName.trim();

	columnName = columnName.replaceAll("\\.", "");
	columnName = columnName.replaceAll("\\$", "");
	// clean the values from additional strings
	if (columnName.contains("/")) {
		columnName = columnName.substring(0, columnName.indexOf("/"));
	}

	if (columnName.contains("\\")) {
		columnName = columnName.substring(0, columnName.indexOf("\\"));
	}
	if (possibleNullValues.contains(columnName)) {
		columnName = nullValue;
	}
	
	return columnName;
}
 
Example 9
Project: iConA   File: ClassDAO.java   View Source Code Vote up 5 votes
public String getClassEndBodyUnescaped(){
	if(classEndBody==null)
		return null;
	
	Pattern pattern = Pattern.compile("\\t+");
    Matcher matcher = pattern.matcher(StringEscapeUtils.unescapeJava(this.classEndBody));
    StringBuilder sb=new StringBuilder(StringEscapeUtils.unescapeJava(this.classEndBody));
    
    while(matcher.find()){
    	sb.insert(matcher.start(), CodeStringBuilder.getTabString());
    }
	return sb.toString();
}
 
Example 10
Project: iConA   File: FunctionDAO.java   View Source Code Vote up 5 votes
/**
 * Pretifies the function initialization body of the function, by adding appropriate number of tabs
 * @return Pretified code
 */
public String getFunctionInitBodyUnescaped(){
	if(functionInitBody==null)
		return null;
	
	Pattern pattern = Pattern.compile("\\t+");
    Matcher matcher = pattern.matcher(StringEscapeUtils.unescapeJava(this.functionInitBody));
    StringBuilder sb=new StringBuilder(StringEscapeUtils.unescapeJava(this.functionInitBody));
    
    while(matcher.find()){
    	sb.insert(matcher.start(), CodeStringBuilder.getTabString());
    }
	return StringEscapeUtils.unescapeJava(sb.toString());
}
 
Example 11
Project: Backmemed   File: NbtTagValue.java   View Source Code Vote up 5 votes
public NbtTagValue(String p_i66_1_, String p_i66_2_)
{
    String[] astring = Config.tokenize(p_i66_1_, ".");
    this.parents = (String[])Arrays.copyOfRange(astring, 0, astring.length - 1);
    this.name = astring[astring.length - 1];

    if (p_i66_2_.startsWith("pattern:"))
    {
        this.type = 1;
        p_i66_2_ = p_i66_2_.substring("pattern:".length());
    }
    else if (p_i66_2_.startsWith("ipattern:"))
    {
        this.type = 2;
        p_i66_2_ = p_i66_2_.substring("ipattern:".length()).toLowerCase();
    }
    else if (p_i66_2_.startsWith("regex:"))
    {
        this.type = 3;
        p_i66_2_ = p_i66_2_.substring("regex:".length());
    }
    else if (p_i66_2_.startsWith("iregex:"))
    {
        this.type = 4;
        p_i66_2_ = p_i66_2_.substring("iregex:".length()).toLowerCase();
    }
    else
    {
        this.type = 0;
    }

    p_i66_2_ = StringEscapeUtils.unescapeJava(p_i66_2_);

    if (this.type == 0 && PATTERN_HEX_COLOR.matcher(p_i66_2_).matches())
    {
        this.valueFormat = 1;
    }

    this.value = p_i66_2_;
}
 
Example 12
Project: AndroidApktool   File: YamlStringEscapeUtils.java   View Source Code Vote up 2 votes
/**
 * <p>Unescapes any Java literals found in the <code>String</code>.
 * For example, it will turn a sequence of <code>'\'</code> and
 * <code>'n'</code> into a newline character, unless the <code>'\'</code>
 * is preceded by another <code>'\'</code>.</p>
 *
 * @param str  the <code>String</code> to unescape, may be null
 * @return a new unescaped <code>String</code>, <code>null</code> if null string input
 */
public static String unescapeString(String str) {
    return StringEscapeUtils.unescapeJava(str);
}
 
Example 13
Project: QDrill   File: DrillStringUtils.java   View Source Code Vote up 2 votes
/**
 * Unescapes any Java literals found in the {@code String}.
 * For example, it will turn a sequence of {@code '\'} and
 * {@code 'n'} into a newline character, unless the {@code '\'}
 * is preceded by another {@code '\'}.
 *
 * @param input  the {@code String} to unescape, may be null
 * @return a new unescaped {@code String}, {@code null} if null string input
 */
public static final String unescapeJava(String input) {
  return StringEscapeUtils.unescapeJava(input);
}
 
Example 14
Project: dremio-oss   File: DremioStringUtils.java   View Source Code Vote up 2 votes
/**
 * Unescapes any Java literals found in the {@code String}.
 * For example, it will turn a sequence of {@code '\'} and
 * {@code 'n'} into a newline character, unless the {@code '\'}
 * is preceded by another {@code '\'}.
 *
 * @param input  the {@code String} to unescape, may be null
 * @return a new unescaped {@code String}, {@code null} if null string input
 */
public static final String unescapeJava(String input) {
  return StringEscapeUtils.unescapeJava(input);
}