org.apache.jackrabbit.util.Text.encodeIllegalXMLCharacters()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(93)

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

Text.encodeIllegalXMLCharacters介绍

[英]Replaces XML characters in the given string that might need escaping as XML text or attribute
[中]替换给定字符串中可能需要转义为XML文本或属性的XML字符

代码示例

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

/**
 * Escapes input text suitable for the output format.
 * <p>
 * By default does XML-escaping. Can be overridden for
 * other formats.
 * 
 * @param input raw text.
 * @return text suitably escaped.
 */
protected String escape(String input) {
  return Text.encodeIllegalXMLCharacters(input);
}

代码示例来源:origin: apache/jackrabbit

/**
 * Escapes input text suitable for the output format.
 * <p>
 * By default does XML-escaping. Can be overridden for
 * other formats.
 * 
 * @param input raw text.
 * @return text suitably escaped.
 */
protected String escape(String input) {
  return Text.encodeIllegalXMLCharacters(input);
}

代码示例来源:origin: apache/jackrabbit-oak

private static String noHighlight(StringBuilder text) {
  if (text.length() > maxFragmentSize) {
    int lastSpace = text.lastIndexOf(" ", maxFragmentSize);
    if (lastSpace != -1) {
      text.setLength(lastSpace);
    } else {
      text.setLength(maxFragmentSize);
    }
    text.append(" ...");
  }
  StringBuilder excerpt = new StringBuilder("<div><span>");
  excerpt.append(encodeIllegalXMLCharacters(text.toString()));
  excerpt.append("</span></div>");
  return excerpt.toString();
}

代码示例来源:origin: org.apache.jackrabbit/oak-core

private static String noHighlight(StringBuilder text) {
  if (text.length() > maxFragmentSize) {
    int lastSpace = text.lastIndexOf(" ", maxFragmentSize);
    if (lastSpace != -1) {
      text.setLength(lastSpace);
    } else {
      text.setLength(maxFragmentSize);
    }
    text.append(" ...");
  }
  StringBuilder excerpt = new StringBuilder("<div><span>");
  excerpt.append(encodeIllegalXMLCharacters(text.toString()));
  excerpt.append("</span></div>");
  return excerpt.toString();
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

private static String noHighlight(StringBuilder text) {
  if (text.length() > maxFragmentSize) {
    int lastSpace = text.lastIndexOf(" ", maxFragmentSize);
    if (lastSpace != -1) {
      text.setLength(lastSpace);
    } else {
      text.setLength(maxFragmentSize);
    }
    text.append(" ...");
  }
  StringBuilder excerpt = new StringBuilder("<div><span>");
  excerpt.append(encodeIllegalXMLCharacters(text.toString()));
  excerpt.append("</span></div>");
  return excerpt.toString();
}

代码示例来源:origin: apache/jackrabbit-oak

static String highlight(StringBuilder text, Set<String> searchToken) {
  Set<String> tokens = tokenize(searchToken);
  String escaped = encodeIllegalXMLCharacters(text.toString());
  BitSet highlight = new BitSet();
  for (String token : tokens) {
    highlight(escaped, highlight, token);
  }
  StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN);
  boolean strong = false;
  for (int i = 0; i < escaped.length(); i++) {
    if (highlight.get(i) && !strong) {
      strong = true;
      excerpt.append("<strong>");
    } else if (!highlight.get(i) && strong) {
      strong = false;
      excerpt.append("</strong>");
    }
    excerpt.append(escaped.charAt(i));
  }
  if (strong) {
    excerpt.append("</strong>");
  }
  excerpt.append(EXCERPT_END);
  return excerpt.toString();
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

static String highlight(StringBuilder text, Set<String> searchToken) {
  Set<String> tokens = tokenize(searchToken);
  String escaped = encodeIllegalXMLCharacters(text.toString());
  BitSet highlight = new BitSet();
  for (String token : tokens) {
    highlight(escaped, highlight, token);
  }
  StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN);
  boolean strong = false;
  for (int i = 0; i < escaped.length(); i++) {
    if (highlight.get(i) && !strong) {
      strong = true;
      excerpt.append("<strong>");
    } else if (!highlight.get(i) && strong) {
      strong = false;
      excerpt.append("</strong>");
    }
    excerpt.append(escaped.charAt(i));
  }
  if (strong) {
    excerpt.append("</strong>");
  }
  excerpt.append(EXCERPT_END);
  return excerpt.toString();
}

代码示例来源:origin: org.apache.jackrabbit/oak-core

static String highlight(StringBuilder text, Set<String> searchToken) {
  Set<String> tokens = tokenize(searchToken);
  String escaped = encodeIllegalXMLCharacters(text.toString());
  BitSet highlight = new BitSet();
  for (String token : tokens) {
    highlight(escaped, highlight, token);
  }
  StringBuilder excerpt = new StringBuilder(EXCERPT_BEGIN);
  boolean strong = false;
  for (int i = 0; i < escaped.length(); i++) {
    if (highlight.get(i) && !strong) {
      strong = true;
      excerpt.append("<strong>");
    } else if (!highlight.get(i) && strong) {
      strong = false;
      excerpt.append("</strong>");
    }
    excerpt.append(escaped.charAt(i));
  }
  if (strong) {
    excerpt.append("</strong>");
  }
  excerpt.append(EXCERPT_END);
  return excerpt.toString();
}

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

String encodedNodeType = Text.encodeIllegalXMLCharacters(state.getNodeTypeName().toString());
writer.write("<?xml version=\"1.0\" encoding=\"" + DEFAULT_ENCODING.name() + "\"?>\n");
writer.write("<" + NODE_ELEMENT + " "
for (Name mixin : state.getMixinTypeNames()) {
  writer.write("\t\t<" + MIXINTYPE_ELEMENT + " "
      + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(mixin.toString()) + "\"/>\n");
for (Name propName : state.getPropertyNames()) {
  writer.write("\t\t<" + PROPERTY_ELEMENT + " "
      + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(propName.toString()) + "\">\n");
for (ChildNodeEntry entry : state.getChildNodeEntries()) {
  writer.write("\t\t<" + NODE_ELEMENT + " "
      + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(entry.getName().toString()) + "\" "
      + UUID_ATTRIBUTE + "=\"" + entry.getId() + "\">\n");
  writer.write("\t\t</" + NODE_ELEMENT + ">\n");

代码示例来源:origin: apache/jackrabbit

String encodedNodeType = Text.encodeIllegalXMLCharacters(state.getNodeTypeName().toString());
writer.write("<?xml version=\"1.0\" encoding=\"" + DEFAULT_ENCODING.name() + "\"?>\n");
writer.write("<" + NODE_ELEMENT + " "
for (Name mixin : state.getMixinTypeNames()) {
  writer.write("\t\t<" + MIXINTYPE_ELEMENT + " "
      + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(mixin.toString()) + "\"/>\n");
for (Name propName : state.getPropertyNames()) {
  writer.write("\t\t<" + PROPERTY_ELEMENT + " "
      + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(propName.toString()) + "\">\n");
for (ChildNodeEntry entry : state.getChildNodeEntries()) {
  writer.write("\t\t<" + NODE_ELEMENT + " "
      + NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(entry.getName().toString()) + "\" "
      + UUID_ATTRIBUTE + "=\"" + entry.getId() + "\">\n");
  writer.write("\t\t</" + NODE_ELEMENT + ">\n");

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

+ NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(state.getName().toString()) + "\" "
+ PARENTUUID_ATTRIBUTE + "=\"" + state.getParentId() + "\" "
+ MULTIVALUED_ATTRIBUTE + "=\"" + Boolean.toString(state.isMultiValued()) + "\" "
    writer.write(Text.encodeIllegalXMLCharacters(val.toString()));

代码示例来源:origin: apache/jackrabbit

+ NAME_ATTRIBUTE + "=\"" + Text.encodeIllegalXMLCharacters(state.getName().toString()) + "\" "
+ PARENTUUID_ATTRIBUTE + "=\"" + state.getParentId() + "\" "
+ MULTIVALUED_ATTRIBUTE + "=\"" + Boolean.toString(state.isMultiValued()) + "\" "
    writer.write(Text.encodeIllegalXMLCharacters(val.toString()));

相关文章