gpt4 book ai didi

net.sf.okapi.common.XMLWriter类的使用及代码示例

转载 作者:知者 更新时间:2024-03-27 05:31:05 26 4
gpt4 key购买 nike

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

XMLWriter介绍

[英]Helper class to write XML documents.

IMPORTANT: flush() or close() must always be called to assure all content is flushed to the underlying streams.

If a StringWriter is used the flush() or close() must be be called before calling the toString() method
[中]帮助类来编写XML文档。
重要提示:必须始终调用flush()或close(),以确保将所有内容刷新到底层流。
如果使用StringWriter,则必须在调用toString()方法之前调用flush()或close()

代码示例

代码示例来源:origin: net.sf.okapi.connectors/okapi-connector-microsoft

public String toXML() {
  StringWriter sw = new StringWriter();
  XMLWriter xmlWriter = new XMLWriter(sw);
  xmlWriter.writeStartDocument();
  xmlWriter.writeStartElement("GetTranslationsArrayRequest");
  xmlWriter.writeElementString("AppId", "");
  xmlWriter.writeElementString("From", srcLang);
  xmlWriter.writeStartElement("Options");
  xmlWriter.writeAttributeString("xmlns:o", "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2");
  xmlWriter.writeElementString("o:Category", category);
  xmlWriter.writeElementString("o:ContentType", contentType);
  xmlWriter.writeElementString("o:ReservedFlags", "");
  xmlWriter.writeElementString("o:State", "");
  xmlWriter.writeElementString("o:Uri", "");
  xmlWriter.writeElementString("o:User", "");
  xmlWriter.writeEndElement(); // Options
  xmlWriter.writeStartElement("Texts");
  xmlWriter.writeAttributeString("xmlns:s", "http://schemas.microsoft.com/2003/10/Serialization/Arrays");
  for (String text : texts) {
    xmlWriter.writeStartElement("s:string");
    xmlWriter.writeString(text);
    xmlWriter.writeEndElement();
  xmlWriter.writeEndElement(); // !Texts
  xmlWriter.writeElementString("To", trgLang);
  xmlWriter.writeElementString("MaxTranslations", String.valueOf(maxHits));
  xmlWriter.writeEndElement(); // !GetTranslationsArrayRequest
  xmlWriter.writeEndDocument();
  xmlWriter.close();
  return sw.toString();

代码示例来源:origin: net.sf.okapi.steps/okapi-step-gttbatchtranslation

private void startExtractedBlock () {
  try {
    File tmpFile = File.createTempFile("~okapi-45_gttbt_", ".html");
    blocks.add(tmpFile);
    
    // Create the HTML file
    htmlWriter = new XMLWriter(tmpFile.getPath());
    // Start building the source file
    htmlWriter.writeStartElement("html");
    htmlWriter.writeStartElement("meta");
    htmlWriter.writeAttributeString("http-equiv", "Content-Type");
    htmlWriter.writeAttributeString("content", "text/html; charset=UTF-8");
    htmlWriter.writeEndElementLineBreak();
    count = 100; // Roughly
  }
  catch ( IOException e ) {
    throw new OkapiIOException("Error creating extraction file.", e);
  }
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-translationcomparison

private void printBracket (int index,
  String range)
{
  writer.writeRawXML("<tr "+
    ((index % 2)==0 ? "" : "bgcolor=#FFFFCC")
    + "><td>"+range+"</td>"); //$NON-NLS-1$
  writer.writeRawXML(String.format("<td align='right'>%d</td>", edBrackets[index])); //$NON-NLS-1$
  // ED-Scores
  writer.writeRawXML(((itemCount == 0) ? "<td align='right'>NA</td>" : String.format("<td align='right'>%.0f</td>", (float)edBrackets[index]/itemCount*100))); //$NON-NLS-1$
  writer.writeRawXML(String.format("<td align='right'>%d</td>", edWCBrackets[index])); //$NON-NLS-1$
  writer.writeRawXML(((wcTotal == 0) ? "<td align='right'>NA</td>" : String.format("<td align='right'>%.0f</td>", (float)edWCBrackets[index]/wcTotal*100))); //$NON-NLS-1$
  writer.writeRawXML(String.format("<td align='right'>%d</td>", fmBrackets[index])); //$NON-NLS-1$
  // FM-Scores
  writer.writeRawXML(((itemCount == 0) ? "<td align='right'>NA</td>" : String.format("<td align='right'>%.0f</td>", (float)fmBrackets[index]/itemCount*100))); //$NON-NLS-1$
  writer.writeRawXML(String.format("<td align='right'>%d</td>", fmWCBrackets[index])); //$NON-NLS-1$
  writer.writeRawXML(((wcTotal == 0) ? "<td align='right'>NA</td>" : String.format("<td align='right'>%.0f</td>", (float)fmWCBrackets[index]/wcTotal*100))); //$NON-NLS-1$
  writer.writeRawXML("</tr>\n"); //$NON-NLS-1$
}

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

/**
 * Writes the end of the TMX document.
 */
public void writeEndDocument () {
  writer.writeEndElementLineBreak(); // body
  writer.writeEndElementLineBreak(); // tmx
  writer.writeEndDocument();
}

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

@Override
protected void endWriting(OutputStream outStream) {
  writer.writeEndElementLineBreak(); // body
  writer.writeEndDocument();
  writer.close();
}

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

@Override
protected void startWriting(OutputStream outStream) {		
  //this.outStream = outStream;
  prWriter = new PrintWriter(outStream);
  writer = new XMLWriter(prWriter);
  writer.writeStartDocument();
  writer.writeStartElement("body");
  writer.writeLineBreak();
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit

XR = new XMLWriter(projectSaveFile);
XR.writeStartDocument();
XR.writeStartElement("omegat");
XR.writeStartElement("project");
XR.writeAttributeString("version", "1.0");
XR.writeStartElement("source_dir");
XR.writeRawXML("__DEFAULT__");
XR.writeEndElementLineBreak(); // source_dir
XR.writeStartElement("target_dir");
XR.writeRawXML("__DEFAULT__");
XR.writeEndElementLineBreak(); // target_dir
XR.writeStartElement("tm_dir");
XR.writeRawXML("__DEFAULT__");
XR.writeEndElementLineBreak(); // tm_dir
XR.writeStartElement("glossary_dir");
XR.writeRawXML("__DEFAULT__");
XR.writeEndElementLineBreak(); // glossary_dir
XR.writeStartElement("dictionary_dir");
XR.writeRawXML("__DEFAULT__");
XR.writeEndElementLineBreak(); // dictionary_dir
XR.writeStartElement("source_lang");
XR.writeRawXML(manifest.getSourceLocale().toString());
XR.writeEndElementLineBreak(); // source_lang

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

writer.writeStartElement("tu");
if ( !Util.isEmpty(tuid) ) {
  writer.writeAttributeString("tuid", tuid);
writer.writeLineBreak();
  writer.writeStartElement("prop");
  writer.writeAttributeString("type", name);
  writer.writeString(attributes.get(name));
  writer.writeEndElementLineBreak(); // prop
writer.writeStartElement("tuv");
writer.writeAttributeString("xml:lang", srcLoc.toBCP47());
writer.writeStartElement("seg");
writer.writeRawXML(tmxCont.setContent(source).toString());
writer.writeEndElement(); // seg
writer.writeEndElementLineBreak(); // tuv
  writer.writeStartElement("tuv");
    writer.writeAttributeString("xml:lang",
      ((altTrgLoc != null) ? altTrgLoc.toBCP47() : trgLoc.toBCP47()));
    writer.writeAttributeString(CREATIONID, attributes.get(CREATIONID));
  writer.writeStartElement("seg");
  writer.writeRawXML(tmxCont.setContent(target).toString());
  writer.writeEndElement(); // seg
  writer.writeEndElementLineBreak(); // tuv

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

private void saveRules(XMLWriter writer, boolean saveExtensions, boolean saveNonValidInfo) {
  try {
    writer.writeStartDocument();
    if (docComment != null) {
      writer.writeComment(docComment, true);
    writer.writeStartElement("srx");
    writer.writeAttributeString("xmlns", NSURI_SRX20);
    if (saveExtensions) {
      writer.writeAttributeString("xmlns:" + NSPREFIX_OKPSRX, NSURI_OKPSRX);
    writer.writeAttributeString("version", "2.0");
    version = "2.0";
    writer.writeLineBreak();
      writer.writeComment(headerComment, true);
    writer.writeStartElement("header");
    writer.writeAttributeString("segmentsubflows", (segmentSubFlows ? "yes" : "no"));
    writer.writeAttributeString("cascade", (cascade ? "yes" : "no"));
    writer.writeLineBreak();
    writer.writeStartElement("formathandle");
    writer.writeAttributeString("type", "start");
    writer.writeAttributeString("include", (includeStartCodes ? "yes" : "no"));
    writer.writeEndElementLineBreak(); // formathandle
    writer.writeStartElement("formathandle");
    writer.writeAttributeString("type", "end");
    writer.writeAttributeString("include", (includeEndCodes ? "yes" : "no"));

代码示例来源:origin: net.sf.okapi.connectors/okapi-connector-microsoft

public String toXML() {
    StringWriter sw = new StringWriter();
    XMLWriter xml = new XMLWriter(sw);
    xml.writeStartDocument();
    xml.writeStartElement("TranslateOptions");
    xml.writeAttributeString("xmlns", "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2");
    xml.writeStartElement("Category");
    xml.writeString(this.category);
    xml.writeEndElement();
    xml.writeStartElement("ContentType");
    xml.writeString(this.contentType);
    xml.writeEndElement();
    xml.writeStartElement("ReservedFlags");
    xml.writeEndElement();
    xml.writeStartElement("State");
    xml.writeEndElement();
    xml.writeStartElement("Uri");
    xml.writeEndElement();
    xml.writeStartElement("User");
    xml.writeString("defaultUser");
    xml.writeEndElement();
    xml.writeEndElement(); // !TranslateOptions
    xml.close();
    return sw.toString();
  }
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-translationcomparison

if ( writer != null ) writer.close();
if ( prnWriter != null ) prnWriter.close();
  writer = new XMLWriter(getOutputFilename()); //$NON-NLS-1$
  writer.writeStartDocument();
  writer.writeStartElement("html"); //$NON-NLS-1$
  writer.writeStartElement("head"); //$NON-NLS-1$
  writer.writeRawXML("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"); //$NON-NLS-1$
  writer.writeRawXML("<style>td { font-family: monospace } td { vertical-align: top; white-space: pre } td.p { border-top-style: solid; border-top-width: 1px;}</style>"); //$NON-NLS-1$
  writer.writeEndElement(); // head
  writer.writeStartElement("body"); //$NON-NLS-1$
  writer.writeStartElement("h1"); //$NON-NLS-1$
  writer.writeString("Translation Comparison");
  writer.writeEndElement();
  writer.writeStartElement("p"); //$NON-NLS-1$
  writer.writeString(String.format("Base document (%s): %s",
    params.getDocument1Label(), baseDocumentPath));
  writer.writeRawXML("<br>");
  writer.writeString(String.format("Comparison 1 (%s): %s",
    params.getDocument2Label(), compDocumentPath));
  if ( rawDoc3 != null ) {
    writer.writeRawXML("<br>");
    writer.writeString(String.format("Comparison 2 (%s): %s",
      params.getDocument3Label(), rawDoc3.getInputURI().getPath()));
  writer.writeString(".");
  writer.writeEndElement();
  writer.writeRawXML("<p>ED-Score = Edit distance score, FM-Score = Fuzzy Match score.<br/>For details see: "
    +"<a href='"+WIKIURL+"'>"+WIKIURL+"</a>.</p>");

代码示例来源:origin: net.sf.okapi.steps/okapi-step-translationcomparison

writer.writeEndElement(); // table
writer.writeElementString("p", String.format("", itemCount));
if ( itemCount > 0 ) {
  writer.writeStartElement("h2"); //$NON-NLS-1$
  writer.writeAttributeString("id", "summary");
  writer.writeString("Summary");
  writer.writeEndElement();
  writer.writeElementString("p", String.format("Repartition for %s to %s:", params.getDocument1Label(), params.getDocument2Label()));
  writer.writeRawXML("<table border=1 cellspacing=0 cellpadding=5>"); //$NON-NLS-1$
  writer.writeRawXML("<tr><th rowspan=2>Scores</th><th colspan=4>ED-Scores</th><th colspan=4>FM-Scores</th></tr>");
  writer.writeRawXML("<tr>"
      + "<th style=\"text-align: right; width: 100px;\">Segments </th>"
      + "<th style=\"text-align: right; width: 100px;\">% </th>"
  printBracket(1, "10 - 19");
  printBracket(0, "0 - 9");
  writer.writeRawXML("<tr><td>Total</td>"); //$NON-NLS-1$
  writer.writeRawXML(String.format("<td align='right'>%d</td>", itemCount)); //$NON-NLS-1$    			
  writer.writeRawXML("<td align='right'>100%</td>"); //$NON-NLS-1$
  writer.writeRawXML(String.format("<td align='right'>%d</td>", wcTotal)); //$NON-NLS-1$
  writer.writeRawXML("<td align='right'>100%</td>"); //$NON-NLS-1$
  writer.writeRawXML(String.format("<td align='right'>%d</td>", itemCount)); //$NON-NLS-1$    			
  writer.writeRawXML("<td align='right'>100%</td>"); //$NON-NLS-1$
  writer.writeRawXML(String.format("<td align='right'>%d</td>", wcTotal)); //$NON-NLS-1$
  writer.writeRawXML("<td align='right'>100%</td>"); //$NON-NLS-1$
  writer.writeRawXML("</tr>\n"); //$NON-NLS-1$

代码示例来源:origin: net.sf.okapi.steps/okapi-step-gttbatchtranslation

htmlWriter.writeStartElement("p");
String out = String.format("%d:%s:%s", subDocId, tu.getId(), seg.id);
count += (out.length() + 10);
htmlWriter.writeAttributeString("id", out);
out = qutil.toCodedHTML(seg.text);
try {
htmlWriter.writeRawXML(out);
htmlWriter.writeEndElementLineBreak(); // p

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

writer = new XMLWriter(xliffPath);                         
} else if ( outputStream != null ) {            
  writer = new XMLWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8));            
writer.writeStartDocument();
writer.writeStartElement("xliff");
writer.writeAttributeString("version", "1.2");
writer.writeAttributeString("xmlns", Namespaces.NS_XLIFF12);
writer.writeAttributeString("xmlns:okp", Namespaces.NS_XLIFFOKAPI);
if ( params.getIncludeIts() ) {
  writer.writeAttributeString("xmlns:"+Namespaces.ITS_NS_PREFIX, Namespaces.ITS_NS_URI); 
  writer.writeAttributeString("xmlns:"+Namespaces.ITSXLF_NS_PREFIX, Namespaces.ITSXLF_NS_URI); 
  writer.writeAttributeString(Namespaces.ITS_NS_PREFIX+":version", "2.0");
  writer.writeLineBreak();
  writer.writeComment(message, false);
writer.writeLineBreak();

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

writer.writeStartDocument();
writer.writeStartElement("tmx");
writer.writeAttributeString("version", "1.4");
writer.writeStartElement("header");
writer.writeAttributeString("creationtool",
  (creationTool == null) ? "unknown" : creationTool);
writer.writeAttributeString("creationtoolversion",
  (creationToolVersion == null) ? "unknown" : creationToolVersion);
writer.writeAttributeString("segtype",
  (segType == null) ? "paragraph" : segType);
writer.writeAttributeString("o-tmf",
  (originalTMFormat == null) ? "unknown" : originalTMFormat);
writer.writeAttributeString("adminlang", "en");
writer.writeAttributeString("srclang", srcLoc.toBCP47());
writer.writeAttributeString("datatype",
  (dataType == null) ? "unknown" : dataType);
    Property p = startDocument.getProperty(n);
    if ("note".equalsIgnoreCase(p.getName())) {
      writer.writeStartElement("note");
      writer.writeString(p.getValue());
      writer.writeEndElement();
    } else {
      writer.writeStartElement("prop");
      writer.writeAttributeString("type", p.getName());                    
      writer.writeString(p.getValue());
      writer.writeEndElement();

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

writer.writeStartElement("trans-unit");
writer.writeAttributeString("id", tu.getId());
String tmp = tu.getName();
if ( !Util.isEmpty(tmp) ) {
  writer.writeAttributeString("resname", tmp);
  writer.writeAttributeString("coord", tu.getProperty(Property.COORDINATES).getValue());
    writer.writeAttributeString("restype", tmp);
    writer.writeAttributeString("restype", "x-"+tmp);
  writer.writeAttributeString("translate", "no");
      String value = ann.getString(GenericAnnotationType.LOCFILTER_VALUE);
      if ( !ITSContent.isExtendedMatch(value, trgLoc.toBCP47()) ) {
        writer.writeAttributeString("translate", "no");
  writer.writeAttributeString("phase-name", phaseName);
  if ( tu.hasTargetProperty(trgLoc, Property.APPROVED) ) {
    if ( tu.getTargetProperty(trgLoc, Property.APPROVED).getValue().equals("yes") ) {
      writer.writeAttributeString(Property.APPROVED, "yes");
  writer.writeAttributeString("xml:space", "preserve");
  writer.appendRawXML(sbITS.toString());
writer.writeLineBreak();

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

protected void writeProp(String name, String value) {
  // Write out the property
  if (expandDuplicateProps) {
    StringTokenizer st = new StringTokenizer(value, propValueSep, false);
    while (st.hasMoreTokens()) {
      writer.writeStartElement("prop");
      writer.writeAttributeString("type", name);
      writer.writeString(st.nextToken());
      writer.writeEndElementLineBreak(); // prop
    }             
  } else {
    writer.writeStartElement("prop");
    writer.writeAttributeString("type", name);
    writer.writeString(value);
    writer.writeEndElementLineBreak(); // prop
  }
}

代码示例来源:origin: net.sf.okapi.steps/okapi-step-rainbowkit

report = new XMLWriter(reportPath);
report.writeStartDocument();
report.writeRawXML("<h1>Transifex Package Summary</h1>");
report.writeLineBreak();
report.writeRawXML(String.format("<p>Resources uploaded to Transifex in the project "
  + "<b><a target='_blank' href='%s'>%s</a></b></p>",
  options.getServerWithoutAPI() + "projects/p/" + options.getProjectId() + "/",
  options.getProjectName()));
report.writeLineBreak();
report.writeRawXML("<table border='1' cellspacing='0' cellpadding='5'>");
report.writeRawXML("<tr><th>Transifex Resource</th><th>Original Source File</th></tr>");
report.writeLineBreak();
  report.writeRawXML(String.format("<tr><td><a target='_blank' href=\"%s\">%s</a></td>",
    options.getServerWithoutAPI() + "projects/p/" + options.getProjectId() + "/language/"+manifest.getSourceLocale().toPOSIXLocaleId()+"/",
    resourceFile));
  report.writeRawXML(String.format("<td>%s</td></tr>", info.getRelativeInputPath()));
  report.writeLineBreak();
report.writeRawXML("</table>");
report.writeRawXML("<p>For more information about this package, see: "
  + "<a target='_blank' href='http://www.opentag.com/okapi/wiki/index.php?title=Rainbow_TKit_-_Transifex_Project'>"
  + "Rainbow TKit - Transifex Project</a>.");
report.writeRawXML("<p><font size='2'>Note: This report was generated when creating the translation package, "
  + "the Transifex project may have been updated with other files since.</font></p>");
report.close();
if ( report != null ) report.close();
if ( pw != null ) pw.close();

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

writer.writeStartElement("tu");
if ( srcCont.contentIsOneSegment() ) {
  writer.writeAttributeString("tuid", tuid);
  writer.writeAttributeString("tuid", String.format("%s_%s", tuid, srcSeg.id));
writer.writeLineBreak();
writer.writeEndElementLineBreak(); // tu
writer.flush();

代码示例来源:origin: net.sf.okapi.steps/okapi-step-leveraging

private void finishTemporaryFiles (XMLWriter htmlWriter) {
  // Close the temporary source input
  if ( htmlWriter != null ) {
    htmlWriter.writeEndElement(); // html
    htmlWriter.writeEndDocument();
    htmlWriter.close();
    // htmlWriter should be reset to null by the caller 
  }
  
  // Close the original entry store
  if ( store != null ) {
    store.close();
  }
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com