com.yahoo.text.XML.xmlEscape()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(128)

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

XML.xmlEscape介绍

[英]Replaces the characters that need to be escaped with their corresponding character entities.
[中]将需要转义的字符替换为相应的字符实体。

代码示例

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Replaces the following:
 * <ul>
 * <li>all ascii codes less than 32 except 9 (tab), 10 (nl) and 13 (cr)
 * <li>ampersand (&amp;)
 * <li>less than (&lt;)
 * <li>larger than (&gt;)
 * <li>double quotes (&quot;) if isAttribute is <code>true</code>
 * </ul>
 * with character entities.
 *
 */
public static String xmlEscape(String string, boolean isAttribute, StringBuilder buffer) {
  return xmlEscape(string, isAttribute, true, buffer, -1);
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Replaces the following:
 * <ul>
 * <li>all ascii codes less than 32 except 9 (tab), 10 (nl) and 13 (cr) if
 * escapeLowAscii is <code>true</code>
 * <li>ampersand (&amp;)
 * <li>less than (&lt;)
 * <li>larger than (&gt;)
 * <li>double quotes (&quot;) if isAttribute is <code>true</code>
 * </ul>
 * with character entities.
 *
 */
public static String xmlEscape(String string, boolean isAttribute, boolean escapeLowAscii, StringBuilder buffer) {
  return xmlEscape(string, isAttribute, escapeLowAscii, buffer, -1);
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Replaces the characters that need to be escaped with their corresponding
 * character entities.
 *
 * @param s1
 *            String possibly containing characters that need to be escaped
 *            in XML
 *
 * @return Returns the input string with special characters that need to be
 *         escaped replaced by character entities.
 */
public static String xmlEscape(String s1) {
  return xmlEscape(s1, true, true, null, -1);
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Replaces the characters that need to be escaped with their corresponding
 * character entities.
 *
 * @param s1
 *            String possibly containing characters that need to be escaped
 *            in XML
 * @param isAttribute
 *            Is the input string to be used as an attribute?
 *
 * @return Returns the input string with special characters that need to be
 *         escaped replaced by character entities
 */
public static String xmlEscape(String s1, boolean isAttribute) {
  return xmlEscape(s1, isAttribute, true, null, -1);
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Replaces the characters that need to be escaped with their corresponding
 * character entities.
 *
 * @param s1
 *            String possibly containing characters that need to be escaped
 *            in XML
 * @param isAttribute
 *            Is the input string to be used as an attribute?
 *
 * @param escapeLowAscii
 *            Should ascii characters below 32 be escaped as well
 *
 * @return Returns the input string with special characters that need to be
 *         escaped replaced by character entities
 */
public static String xmlEscape(String s1, boolean isAttribute, boolean escapeLowAscii) {
  return xmlEscape(s1, isAttribute, escapeLowAscii, null, -1);
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Replaces the characters that need to be escaped with their corresponding
 * character entities.
 *
 * @param s1
 *            String possibly containing characters that need to be escaped
 *            in XML
 * @param isAttribute
 *            Is the input string to be used as an attribute?
 *
 *
 * @param stripCharacter
 *            any occurrence of this character is removed from the string
 *
 * @return Returns the input string with special characters that need to be
 *         escaped replaced by character entities
 */
public static String xmlEscape(String s1, boolean isAttribute, char stripCharacter) {
  return xmlEscape(s1, isAttribute, true, null, (int) stripCharacter);
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Replaces the characters that need to be escaped with their corresponding
 * character entities.
 *
 * @param s1
 *            String possibly containing characters that need to be escaped
 *            in XML
 * @param isAttribute
 *            Is the input string to be used as an attribute?
 *
 * @param escapeLowAscii
 *            Should ascii characters below 32 be escaped as well
 *
 * @param stripCharacter
 *            any occurrence of this character is removed from the string
 *
 * @return Returns the input string with special characters that need to be
 *         escaped replaced by character entities
 */
public static String xmlEscape(String s1, boolean isAttribute, boolean escapeLowAscii, char stripCharacter) {
  return xmlEscape(s1, isAttribute, escapeLowAscii, null, (int) stripCharacter);
}

代码示例来源:origin: com.yahoo.vespa/container-search

public static void renderString(StringBuilder renderTarget, String value) {
  renderTarget.append(XML.xmlEscape(value, false));
}

代码示例来源:origin: com.yahoo.vespa/document

/**
 * Add content to the last tag.
 *
 * @param content the content to add to the last tag
 */
public void addContent(String content) {
  if (cachedTag != null) {
    cachedContent.add(XML.xmlEscape(content, false));
  } else if (tags.isEmpty()) {
    throw new IllegalStateException("There is no open tag to add content to.");
  } else {
    for (int i = 0; i < tags.size(); ++i) {
      writer.write(indent);
    }
    writer.write(XML.xmlEscape(content, false));
    writer.write('\n');
  }
}

代码示例来源:origin: com.yahoo.vespa/container-search

private String asXML(Object value) {
  if (value == null)
    return "(null)";
  else if (value instanceof HitField)
    return ((HitField)value).quotedContent(false);
  else if (value instanceof StructuredData || value instanceof XMLString || value instanceof JSONString)
    return value.toString();
  else
    return XML.xmlEscape(value.toString(), false, '\u001f');
}

代码示例来源:origin: com.yahoo.vespa/container-search

private String asXML(Object value) {
  if (value == null)
    return "(null)";
  else if (value instanceof HitField)
    return ((HitField)value).quotedContent(false);
  else if (value instanceof StructuredData || value instanceof XMLString || value instanceof JSONString)
    return value.toString();
  else
    return XML.xmlEscape(value.toString(), false, '\u001f');
}

代码示例来源:origin: com.yahoo.vespa/container-search

private String asXML(Object value) {
  if (value == null)
    return "(null)";
  else if (value instanceof XmlProducer)
    return ((XmlProducer)value).toXML();
  else if (value instanceof HitField)
    return ((HitField)value).quotedContent(false);
  else if (value instanceof StructuredData || value instanceof XMLString || value instanceof JSONString)
    return value.toString();
  else
    return XML.xmlEscape(value.toString(), false, '\u001f');
}

代码示例来源:origin: com.yahoo.vespa/container-search

/**
 * Returns the content of the field, stripped of markup
 */
public String bareContent(boolean XMLQuote, boolean inAttribute) {
  StringBuilder bareContent = new StringBuilder();
  Iterator<FieldPart> iter = ensureTokenized().iterator();
  while(iter.hasNext()) {
    FieldPart f = iter.next();
    if (f instanceof MarkupFieldPart)
      continue;
    if (XMLQuote)
      bareContent.append(XML.xmlEscape(f.getContent(), inAttribute));
    else
      bareContent.append(f.getContent());
  }
  return bareContent.toString();
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * XML escapes and writes the content.toString(). If the content is null this does nothing but closing the start tag.
 *
 * @param content the content - output by XML.xmlEscape(content.toString())
 * @param multiline whether the content should be treated as multiline,
 *        such that the following end tag should appear on a new line
 */
public XMLWriter content(Object content,boolean multiline) {
  closeStartTag();
  return (content==null)
      ? this
      : escapedContent(XML.xmlEscape(content.toString(),false),multiline);
}

代码示例来源:origin: com.yahoo.vespa/container-search

/**
 * @param inAttribute whether to quote quotation marks
 * @return the content of this field as an XML string
 */
public String quotedContent(boolean inAttribute) {
  StringBuilder xml = new StringBuilder();
  Iterator<FieldPart> iter = ensureTokenized().iterator();
  while(iter.hasNext()) {
    FieldPart f = iter.next();
    if (f.isFinal())
      xml.append(f.getContent());
    else
      xml.append(XML.xmlEscape(f.getContent(), inAttribute));
  }
  return xml.toString();
}

代码示例来源:origin: com.yahoo.vespa/document

writer.write(attr.name);
writer.write("=\"");
writer.write(XML.xmlEscape(attr.value, true));
writer.write('"');

代码示例来源:origin: com.yahoo.vespa/container-search

/** Returns the content of this field, using the arguments as bolding tags, as an XML string */
public String quotedContent(String boldOpenTag,
              String boldCloseTag,
              String separatorTag,
              boolean inAttribute) {
  StringBuilder xml = new StringBuilder();
  Iterator<FieldPart> iter = ensureTokenized().iterator();
  while(iter.hasNext()) {
    FieldPart f = iter.next();
    if (f instanceof BoldOpenFieldPart
      && boldOpenTag != null
      && boldOpenTag.length() > 0)
      xml.append(boldOpenTag);
    else if (f instanceof BoldCloseFieldPart
         && boldCloseTag != null
         && boldCloseTag.length() > 0)
      xml.append(boldCloseTag);
    else if (f instanceof SeparatorFieldPart
         && separatorTag != null
         && separatorTag.length() > 0)
      xml.append(separatorTag);
    else if (f.isFinal())
      xml.append(f.getContent());
    else
      xml.append(XML.xmlEscape(f.getContent(), inAttribute));
  }
  return xml.toString();
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Writes an attribute by XML.xmlEscape(value.toString(),false)
 *
 * @param name the name of the attribute. An exception is thrown if this is null
 * @param value the value of the attribute. This method does nothing if the value is null or empty
 */
public XMLWriter attribute(Utf8String name, String value) {
  if ((value == null) || value.isEmpty()) return this;
  allowAttribute();
  return w(SPACE).w(name).w(ATTRIBUTE_START).wTranscode(XML.xmlEscape(value, true)).w(ATTRIBUTE_END);
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

/**
 * Writes an attribute by XML.xmlEscape(value.toString(),false)
 *
 * @param name the name of the attribute. An exception is thrown if this is null
 * @param value the value of the attribute. The empty string if the attribute is null or empty
 */
public XMLWriter forceAttribute(Utf8String name, Object value) {
  String stringValue = value!=null ? value.toString() : "";
  allowAttribute();
  return w(SPACE).w(name).w(ATTRIBUTE_START).wTranscode(XML.xmlEscape(stringValue,true)).w(ATTRIBUTE_END);
}

代码示例来源:origin: com.yahoo.vespa/container-search

void renderInspector(Inspector value, int nestingLevel) {
  if (value.type() == Type.ARRAY) {
    renderMapOrArray(value, nestingLevel);
  } else if (value.type() == Type.OBJECT) {
    renderStruct(value, nestingLevel);
  } else if (value.type() == Type.STRING) {
    renderTarget.append(XML.xmlEscape(value.asString(), false));
  } else if (value.type() == Type.LONG) {
    long l = value.asLong();
    renderTarget.append(String.valueOf(l));
  } else if (value.type() == Type.DOUBLE) {
    double d = value.asDouble();
    renderTarget.append(String.valueOf(d));
  } else if (value.type() == Type.BOOL) {
    boolean b = value.asBool();
    renderTarget.append(b ? "true" : "false");
  } else if (value.type() == Type.DATA) {
    byte[] data = value.asData();
    renderTarget.append("<data length=\"").append(data.length);
    renderTarget.append("\" encoding=\"hex\">");
    for (int i = 0; i < data.length; i++) {
      for (int sh = 4; sh >= 0; sh -= 4) {
        int val = (data[i] >> sh) & 0xF;
        char hexdigit = (val < 10) ? ((char)('0' + val)) : ((char)('A' + val - 10));
        renderTarget.append(hexdigit);
      }
    }
    renderTarget.append("</data>");
  }
}

相关文章

微信公众号

最新文章

更多