org.apache.commons.lang.StringEscapeUtils.unescapeJavaScript()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 JavaScript  
字(9.0k)|赞(0)|评价(0)|浏览(402)

本文整理了Java中org.apache.commons.lang.StringEscapeUtils.unescapeJavaScript()方法的一些代码示例,展示了StringEscapeUtils.unescapeJavaScript()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringEscapeUtils.unescapeJavaScript()方法的具体详情如下:
包路径:org.apache.commons.lang.StringEscapeUtils
类名称:StringEscapeUtils
方法名:unescapeJavaScript

StringEscapeUtils.unescapeJavaScript介绍

[英]Unescapes any JavaScript literals found in the String to a Writer.

For example, it will turn a sequence of '\' and 'n' into a newline character, unless the '\' is preceded by another '\'.

A null string input has no effect.
[中]将在String中找到的任何JavaScript文本取消转换为Writer
例如,它会将'\''n'的序列转换为换行符,除非'\'前面有另一个'\'
null字符串输入无效。

代码示例

代码示例来源:origin: internetarchive/heritrix3

protected boolean considerString(Extractor ext, CrawlURI curi,
      boolean handlingJSFile, String candidate) {
    try {
      candidate = StringEscapeUtils.unescapeJavaScript(candidate);
    } catch (NestableRuntimeException e) {
      LOGGER.log(Level.WARNING, "problem unescaping some javascript", e);
    }
    candidate = UriUtils.speculativeFixup(candidate, curi.getUURI());

    if (UriUtils.isVeryLikelyUri(candidate)) {
      try {
        int max = ext.getExtractorParameters().getMaxOutlinks();
        if (handlingJSFile) {
          addRelativeToVia(curi, max, candidate, JS_MISC, 
              SPECULATIVE);
          return true;
        } else {
          addRelativeToBase(curi, max, candidate, JS_MISC, 
              SPECULATIVE);
          return true;
        }
      } catch (URIException e) {
        ext.logUriError(e, curi.getUURI(), candidate);
      }
    }
    
    return false;
  }
}

代码示例来源:origin: ai.grakn/grakn-core

/**
 * @param string the string to unescape
 * @return the unescaped string, replacing any backslash escapes with the real characters
 */
public static String unescapeString(String string) {
  return StringEscapeUtils.unescapeJavaScript(string);
}

代码示例来源:origin: io.mindmaps/mindmaps-graql

/**
 * @param string the string to unescape
 * @return the unescaped string, replacing any backslash escapes with the real characters
 */
public static String unescapeString(String string) {
  return StringEscapeUtils.unescapeJavaScript(string);
}

代码示例来源:origin: org.owasp.jbrofuzz/jbrofuzz

private static String decodeEscJavaScript(final String decodeText) {
  return StringEscapeUtils.unescapeJavaScript(decodeText);
}

代码示例来源:origin: org.zaproxy/zap

public String decodeJavaScriptString(String JavaScriptText) {
  return StringEscapeUtils.unescapeJavaScript(JavaScriptText);
}

代码示例来源:origin: perfectsense/dari

public static String unescapeJavaScript(String string) {
  return string == null ? null : StringEscapeUtils.unescapeJavaScript(string);
}

代码示例来源:origin: com.onpositive.aml/com.mulesoft.jaxrs.raml.generator

static public String transformObjectToString(JSONArray object)	throws JSONException, IOException
{
  StringWriter sw = new StringWriter() ;
  object.write(sw) ;
  StringWriter sw1 = new StringWriter() ;
  StringEscapeUtils.unescapeJavaScript( sw1, sw.toString() );
  String result = sw1.toString() ;
  return result;
}

代码示例来源:origin: com.onpositive.aml/com.mulesoft.jaxrs.raml.generator

/**
 * <p>transformObjectToString.</p>
 *
 * @param object a {@link org.codehaus.jettison.json.JSONObject} object.
 * @return a {@link java.lang.String} object.
 * @throws org.codehaus.jettison.json.JSONException if any.
 * @throws java.io.IOException if any.
 */
static public String transformObjectToString(JSONObject object)	throws JSONException, IOException
{
  StringWriter sw = new StringWriter() ;
  object.write(sw) ;
  StringWriter sw1 = new StringWriter() ;
  StringEscapeUtils.unescapeJavaScript( sw1, sw.toString() );
  String result = sw1.toString() ;
  return result;
}

代码示例来源:origin: com.onpositive.aml/com.mulesoft.jaxrs.raml.generator

@Override
public String getStringValue() {
  if (this.object != null) {
    return JsonFormatter.format(StringEscapeUtils.unescapeJavaScript(this.object.toString()));
  } else {
    return null;
  }
}

代码示例来源:origin: com.onpositive.aml/com.mulesoft.jaxrs.raml.generator

@Override
public String getStringValue() {
  if (this.object != null) {
    return JsonFormatter.format(StringEscapeUtils.unescapeJavaScript(this.object.toString()));
  } else if (this.array != null) {
    return JsonFormatter.format(StringEscapeUtils.unescapeJavaScript(this.array.toString()));
  } else {
    return null;
  }
}

代码示例来源:origin: CogComp/cogcomp-nlp

@SuppressWarnings("unchecked")
  public MQLQueryWrapper(String namespace, String value) {
    this.value=value;
    JSONObject obj = new JSONObject();
    JSONArray key = new JSONArray();
    JSONArray type = new JSONArray();
    obj.put("mid", null);
    obj.put("type", type);
    JSONObject contents = new JSONObject();
    contents.put("namespace", namespace);
    contents.put("value", QueryMQL.encodeMQL(value));
    key.add(contents);
    obj.put("key", key);
    this.MQLquery = StringEscapeUtils
        .unescapeJavaScript(obj.toJSONString());
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/wikiutils

@SuppressWarnings("unchecked")
  public MQLQueryWrapper(String namespace, String value) {
    this.value=value;
    JSONObject obj = new JSONObject();
    JSONArray key = new JSONArray();
    JSONArray type = new JSONArray();
    obj.put("mid", null);
    obj.put("type", type);
    JSONObject contents = new JSONObject();
    contents.put("namespace", namespace);
    contents.put("value", QueryMQL.encodeMQL(value));
    key.add(contents);
    obj.put("key", key);
    this.MQLquery = StringEscapeUtils
        .unescapeJavaScript(obj.toJSONString());
  }
}

代码示例来源:origin: edu.illinois.cs.cogcomp/big-data-utils

@SuppressWarnings("unchecked")
  public MQLQueryWrapper(String namespace, String value) {
    this.value=value;
    JSONObject obj = new JSONObject();
    JSONArray key = new JSONArray();
    JSONArray type = new JSONArray();
    obj.put("mid", null);
    obj.put("type", type);
    JSONObject contents = new JSONObject();
    contents.put("namespace", namespace);
    contents.put("value", QueryMQL.encodeMQL(value));
    key.add(contents);
    obj.put("key", key);
    this.MQLquery = StringEscapeUtils
        .unescapeJavaScript(obj.toJSONString());
  }
}

代码示例来源:origin: baishui2004/common_gui_tools

/**
 * 还原转义字符.
 *
 * @param string 转义字符
 * @param type   字符类型
 */
public static String unescape(String string, String type) {
  String escape = "转义字符还原遇到错误";
  if (type.equals(LanguageUtils.CONST_HTML)) {
    escape = StringEscapeUtils.unescapeHtml(string);
  } else if (type.equals(LanguageUtils.CONST_XML)) {
    escape = StringEscapeUtils.unescapeXml(string);
  } else if (type.equals(LanguageUtils.CONST_SQL)) {
    escape = type + "转义字符不能进行还原";
  } else if (type.equals(LanguageUtils.CONST_JAVA)) {
    escape = StringEscapeUtils.unescapeJava(string);
  } else if (type.equals(LanguageUtils.CONST_JavaScript)) {
    escape = StringEscapeUtils.unescapeJavaScript(string);
  } else if (type.equals(LanguageUtils.CONST_CSV)) {
    escape = StringEscapeUtils.unescapeCsv(string);
  }
  return escape;
}

代码示例来源:origin: com.onpositive.aml/com.mulesoft.jaxrs.raml.generator

StringWriter wr = new StringWriter(); 
obj.write(wr);
canonic = StringEscapeUtils.unescapeJavaScript(wr.toString());
StringWriter wr = new StringWriter(); 
obj.write(wr);
canonic = StringEscapeUtils.unescapeJavaScript(wr.toString());

代码示例来源:origin: terrier-org/terrier-core

/** Unescape a String according to the defined escape sequence requested */
public static String unescape(ESCAPE e, String s)
{
  try{
    switch(e) {
    case NONE: return s;
    case HTML: return StringEscapeUtils.unescapeHtml(s);
    case XML: return StringEscapeUtils.unescapeXml(s);
    case JAVA: return StringEscapeUtils.unescapeJava(s);
    case JAVASCRIPT: return StringEscapeUtils.unescapeJavaScript(s);
    case URL: return URLDecoder.decode(s, "UTF-8");
    }
  } catch (UnsupportedEncodingException uee) {
    //UTF-8 should never be unsupported			
  }
  //cannot reach here
  return null;
}

代码示例来源:origin: org.terrier/terrier-core

/** Unescape a String according to the defined escape sequence requested */
public static String unescape(ESCAPE e, String s)
{
  try{
    switch(e) {
    case NONE: return s;
    case HTML: return StringEscapeUtils.unescapeHtml(s);
    case XML: return StringEscapeUtils.unescapeXml(s);
    case JAVA: return StringEscapeUtils.unescapeJava(s);
    case JAVASCRIPT: return StringEscapeUtils.unescapeJavaScript(s);
    case URL: return URLDecoder.decode(s, "UTF-8");
    }
  } catch (UnsupportedEncodingException uee) {
    //UTF-8 should never be unsupported			
  }
  //cannot reach here
  return null;
}

代码示例来源:origin: com.onpositive.aml/com.mulesoft.jaxrs.raml.generator

private static String convertToJSON(Element rootElement) throws Exception {
  Configuration config = new Configuration();
  config.setTypeConverter(new SimpleConverter());
  MappedNamespaceConvention con = new MappedNamespaceConvention(config);
  StringWriter strWriter = new StringWriter();
  AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, strWriter);
  w.writeStartDocument();
  converToJSON(rootElement, w);
  w.writeEndDocument();
  w.close();
  strWriter.close();
  String jsonString = strWriter.toString();
  StringWriter wr = new StringWriter();
  StringEscapeUtils.unescapeJavaScript(wr, jsonString);
  String result = wr.toString();
  return result;
}

代码示例来源:origin: org.archive.heritrix/heritrix-modules

protected boolean considerString(Extractor ext, CrawlURI curi,
      boolean handlingJSFile, String candidate) {
    try {
      candidate = StringEscapeUtils.unescapeJavaScript(candidate);
    } catch (NestableRuntimeException e) {
      LOGGER.log(Level.WARNING, "problem unescaping some javascript", e);
    }
    candidate = UriUtils.speculativeFixup(candidate, curi.getUURI());

    if (UriUtils.isVeryLikelyUri(candidate)) {
      try {
        int max = ext.getExtractorParameters().getMaxOutlinks();
        if (handlingJSFile) {
          addRelativeToVia(curi, max, candidate, JS_MISC, 
              SPECULATIVE);
          return true;
        } else {
          addRelativeToBase(curi, max, candidate, JS_MISC, 
              SPECULATIVE);
          return true;
        }
      } catch (URIException e) {
        ext.logUriError(e, curi.getUURI(), candidate);
      }
    }
    
    return false;
  }
}

相关文章