net.sf.okapi.common.Util.escapeToXML()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(173)

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

Util.escapeToXML介绍

[英]Escapes a string for XML.
[中]转义XML的字符串。

代码示例

代码示例来源:origin: net.sf.okapi/okapi-core

private void printITSExtStringAttribute (String value,
  String attrName,
  StringBuilder output)
{
  if ( value != null ) {
    output.append((isHTML5 ? " data-" : ITSXLF_PREF)+attrName+"=\""+Util.escapeToXML(value, 3, false, encoder)+"\"");
  }
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-its

private static String escape (String text) {
  text = text.replace("\n", "\\n");
  text = text.replace("\t", "\\t");
  return Util.escapeToXML(text, 3, false, null);
}

代码示例来源:origin: net.sf.okapi/okapi-core

private String outputRefOrValue (String partialName,
  String value,
  boolean useHTML5Notation)
{
  if ( value.startsWith(GenericAnnotationType.REF_PREFIX) ) {
    value = value.substring(GenericAnnotationType.REF_PREFIX.length());
    partialName = partialName + (useHTML5Notation ? "-ref" : "Ref");
  }
  return partialName+"=\""+Util.escapeToXML(value, 3, false, encoder)+"\"";
}

代码示例来源:origin: net.sf.okapi/okapi-core

private void printITSStringAttribute (String value,
  String attrName,
  StringBuilder output)
{
  if ( value != null ) {
    String ref = "";
    if ( value.startsWith(REF_PREFIX) ) {
      ref = (isHTML5 ? "-ref" : "Ref");
      value = value.substring(REF_PREFIX.length());
    }
    output.append(" "+prefix+attrName+ref+"=\""+Util.escapeToXML(value, 3, false, encoder)+"\"");
  }
}

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * Writes an attribute and its associated value. You must use
 * {@link #writeStartElement(String)} just before.
 * @param name the name of the attribute.
 * @param value the value of the attribute.
 */
public void writeAttributeString (String name,
    String value)
{
  write(" " + name + "=\"" + Util.escapeToXML(value, 3, false, null) + "\"");
}

代码示例来源:origin: net.sf.okapi/okapi-core

public String toXML() {
  StringBuilder sb = new StringBuilder();
  sb.append("<tool");
  sb.append(" tool-id=\"")
   .append(Util.escapeToXML(id, 1, false, null)).append("\"");
  sb.append(" tool-name=\"")
   .append(Util.escapeToXML(name, 1, false, null)).append("\"");
  if (version != null) {
    sb.append(" tool-version=\"")
     .append(Util.escapeToXML(version, 1, false, null)).append("\"");
  }
  if (company != null) {
    sb.append(" tool-company=\"")
     .append(Util.escapeToXML(company, 1, false, null)).append("\"");
  }
  sb.append(">");
  sb.append(skel);
  sb.append("</tool>");
  return sb.toString();
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-ts

private void procCharacters(Characters chars) {
  String escaped = Util.escapeToXML(
      chars.getData().replace("\n", lineBreak), 0, true, null);
  skel.append(escaped);
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-icml

public String buildStartTag (Element elem) {
  StringBuilder sb = new StringBuilder("<"+elem.getNodeName());
  NamedNodeMap attrNames = elem.getAttributes();
  for ( int i=0; i<attrNames.getLength(); i++ ) {
    Attr attr = (Attr)attrNames.item(i);
    sb.append(" " + attr.getName() + "=\"");
    sb.append(Util.escapeToXML(attr.getValue(), 3, false, null));
    sb.append("\"");
  }
  // Make it an empty element if possible
  if ( elem.hasChildNodes() ) {
    sb.append(">");
  }
  else {
    sb.append("/>");
  }
  return sb.toString();
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-icml

public String buildStartTag (Element elem) {
  StringBuilder sb = new StringBuilder("<"+elem.getNodeName());
  NamedNodeMap attrNames = elem.getAttributes();
  for ( int i=0; i<attrNames.getLength(); i++ ) {
    Attr attr = (Attr)attrNames.item(i);
    sb.append(" " + attr.getName() + "=\"");
    sb.append(Util.escapeToXML(attr.getValue(), 3, false, null));
    sb.append("\"");
  }
  // Make it an empty element if possible
  if ( elem.hasChildNodes() ) {
    sb.append(">");
  }
  else {
    sb.append("/>");
  }
  return sb.toString();
}

代码示例来源:origin: net.sf.okapi/okapi-core

sb.append("<phase");
sb.append(" phase-name=\"")
 .append(Util.escapeToXML(phaseName, 1, false, null)).append("\"");
sb.append(" process-name=\"")
 .append(Util.escapeToXML(processName, 1, false, null)).append("\"");
if (companyName != null) {
  sb.append(" company-name=\"")
   .append(Util.escapeToXML(companyName, 1, false, null)).append("\"");
   .append(Util.escapeToXML(toolId, 1, false, null)).append("\"");
   .append(Util.escapeToXML(jobId, 1, false, null)).append("\"");
   .append(Util.escapeToXML(contactName, 1, false, null)).append("\"");
   .append(Util.escapeToXML(contactEmail, 1, false, null)).append("\"");
   .append(Util.escapeToXML(contactPhone, 1, false, null)).append("\"");

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-tmx

/**
 * Copy a parsed attribute to the provided buffer, escaping the value.  The
 * attribute will be preceded by a whitespace character.
 * 
 * @param sb target buffer
 * @param reader XMLStreamReader
 * @param attrIndex the index of the attribute to copy from the reader
 * @param lineBreak for escaping purposes
 * @param escapeGT whether or not to escape GT 
 */
static void copyAttributeToBuffer(StringBuilder sb,
    XMLStreamReader reader, int attrIndex, String lineBreak,
    boolean escapeGT) {
  String prefix = reader.getAttributePrefix(attrIndex);
  sb.append(" ");
  if (prefix != null && !"".equals(prefix)) {
    sb.append(prefix).append(":");
  }
  sb.append(reader.getAttributeLocalName(attrIndex));
  sb.append("=\"");
  sb.append(Util.escapeToXML(reader.getAttributeValue(attrIndex).replace("\n", lineBreak), 3, escapeGT, null));
  sb.append('\"');
}

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * Writes a string. The text is automatically escaped.
 * @param text the text to output.
 */
public void writeString (String text) {
  closeStartTag();
  appendRawXML(Util.escapeToXML(text, 0, false, null));
}

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * creates a ctype value for the given {@link Code} object and the given {@link TAG}.
 *
 * @param code the code object
 * @param tag the xliff TAG
 * @return a ctype value for the given {@link Code} object and the given {@link TAG}.
 */
private String createCtype(Code code, TAG tag) {
  String result = "";
  String codeType = code.getType();
  if (!isValidCtype(tag, codeType)) {
    result = EXTENDED_CODE_TYPE_PREFIX;
  }
  if (codeType == null || codeType.isEmpty()) {
    result += "empty";
  }
  else {
    // escape xml
    result += Util.escapeToXML(codeType, 1, false, null);
    // replace blanks in ctype values to underscores
    result = result.replaceAll(" ", "_");
  }
  return result;
}

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-its

tmp.append(Util.escapeToXML(attr.getNodeValue(), 3, false, null)
  + "\"");
tmp.append(Util.escapeToXML(attr.getNodeValue(), 3, false, null)
  + "\"");

代码示例来源:origin: net.sf.okapi/okapi-core

sb.append(Util.escapeToXML(displayText, 1, false, null));
sb.append("\"");
String merged = code.getMergedData();
merged = Util.escapeWhitespaceForXML(merged);
sb.append(Util.escapeToXML(merged, 1, false, null));
sb.append("\"");

代码示例来源:origin: net.sf.okapi.lib/okapi-lib-segmentation-ui

for ( Segment seg : textCont.getSegments() ) {
  writer.write("<p>"); //$NON-NLS-1$
  writer.write(Util.escapeToXML(sampleOutput.setContent(seg.text).toString(true), 0, false, null));
  writer.write("</p>"); //$NON-NLS-1$

代码示例来源:origin: net.sf.okapi/okapi-core

/**
 * Writes an element and its content.
 * @param name the name of the element to write.
 * @param content the content to enclose inside this element.
 */
public void writeElementString (String name,
    String content)
{
  closeStartTag();
  write("<" + name + ">");
  write(Util.escapeToXML(content, 0, false, null));
  write("</" + name + ">");
}

代码示例来源:origin: net.sf.okapi/okapi-core

if ( strVal != null ) sb.append(outputRefOrValue(" revTool", strVal, false));
strVal = ann.getString(GenericAnnotationType.PROV_PROVREF);
if ( strVal != null ) sb.append(" provRef=\"" + Util.escapeToXML(strVal, 3, false, encoder) + "\"");
sb.append("/>");

代码示例来源:origin: net.sf.okapi/okapi-core

String strVal = iann.getCodes();
if (strVal != null) {
  output.append(" okp:lqiCodes=\"" + Util.escapeToXML(strVal, 3, false, encoder) + "\"");
  output.append(" okp:lqiSegId=\"" + Util.escapeToXML(strVal, 3, false, encoder) + "\"");

代码示例来源:origin: net.sf.okapi.filters/okapi-filter-abstractmarkup

case DOCUMENT_PART:
  DocumentPart dp = e.getDocumentPart();
  dp.setSkeleton(new GenericSkeleton(Util.escapeToXML(dp.getSkeleton().toString(), 0, true, null)));
  break;
case TEXT_UNIT:
    for (GenericSkeletonPart p : s.getParts()) {
      if (p.getParent() == null) {
        p.setData(Util.escapeToXML(p.getData().toString(), 0, true, null));
    c.setData(Util.escapeToXML(c.getData(), 0, true, null));
    if (c.hasOuterData()) {
      c.setOuterData(Util.escapeToXML(c.getOuterData(), 0, true, null));
  TextFragment f = new TextFragment(Util.escapeToXML(tu.getSource().getFirstContent().getCodedText(), 0, true, null), codes);
  tu.setSourceContent(f);
  break;

相关文章