use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class Cell method loadCellText.
/**
* 加载Cell的文本内容
* @param content
* @return ;
*/
private String loadCellText(String content) {
String result = "";
VTDGen vg = new VTDGen();
vg.setDoc(content.getBytes());
VTDUtils vu = null;
try {
vg.parse(true);
vu = new VTDUtils(vg.getNav());
AutoPilot ap = new AutoPilot(vu.getVTDNav());
ap.selectXPath("/si/r");
if (ap.evalXPath() != -1) {
StringBuffer bf = new StringBuffer();
do {
String tVal = vu.getChildContent("t");
bf.append(tVal);
} while (ap.evalXPath() != -1);
result = bf.toString();
} else {
vu.pilot("/si/t");
result = vu.getElementContent();
}
} catch (VTDException e) {
e.printStackTrace();
}
return result;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class DrawingsPart method getAutoPilot.
private AutoPilot getAutoPilot() {
AutoPilot ap = new AutoPilot(vu.getVTDNav());
ap.declareXPathNameSpace(Constants.NAMESPACE_DRAWING_PREFIX_XDR, Constants.NAMESPACE_DRAWING_URL_XDR);
ap.declareXPathNameSpace(Constants.NAMESPACE_DRAWING_PREFIX_A, Constants.NAMESPACE_DRAWING_URL_A);
return ap;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class DrawingsPart method loadShapeAnchor.
private void loadShapeAnchor() {
cellAnchorList = new ArrayList<CellAnchor>();
AutoPilot ap = getAutoPilot();
try {
ap.selectXPath("/xdr:wsDr/xdr:twoCellAnchor | xdr:oneCellAnchor");
while (ap.evalXPath() != -1) {
String anchorXML = vu.getElementFragment();
String fromCol = vu.getElementContent("./xdr:from/xdr:col");
String fromRow = vu.getElementContent("./xdr:from/xdr:row");
CellAnchor a = new CellAnchor(anchorXML, fromRow, fromCol);
cellAnchorList.add(a);
}
} catch (VTDException e) {
}
// sort by row&col ASC
if (cellAnchorList.size() > 0) {
Collections.sort(cellAnchorList, new Comparator<CellAnchor>() {
public int compare(CellAnchor o1, CellAnchor o2) {
int o1r = Integer.parseInt(o1.getFromRow());
int o2r = Integer.parseInt(o2.getFromRow());
int o1c = Integer.parseInt(o1.getFromCol());
int o2c = Integer.parseInt(o2.getFromCol());
if (o1r != o2r) {
return o1r - o2r;
} else {
return o1c - o2c;
}
}
});
}
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ShareStringTablePart method getStringItemFragment.
public String getStringItemFragment(int index) {
index = index + 1;
String xpath = "/sst/si[" + index + "]";
try {
AutoPilot ap = new AutoPilot(vu.getVTDNav());
ap.selectXPath(xpath);
if (ap.evalXPath() != -1) {
String content = vu.getElementFragment();
return content;
} else {
// TODO error
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class PreTranslation method keepCurrentMatchs.
private void keepCurrentMatchs(VTDUtils vu, String srcLang, String tgtLang, XMLModifier xm, IProgressMonitor monitor) throws NavException, XPathParseException, XPathEvalException, ModifyException, UnsupportedEncodingException, InterruptedException {
AutoPilot tuAp = new AutoPilot(vu.getVTDNav());
tuAp.selectXPath("./body//trans-unit");
boolean needUpdateTgt = true;
while (tuAp.evalXPath() != -1) {
// 循环 Trans-unit
if (monitor != null && monitor.isCanceled()) {
throw new InterruptedException();
}
// skip locked segment
String locked = vu.getCurrentElementAttribut("translate", "yes");
if (locked.equals("no")) {
continue;
}
String tgtContent = vu.getElementContent("./target");
if (tgtContent != null && !tgtContent.trim().equals("")) {
needUpdateTgt = false;
}
TransUnitInfo2TranslationBean tuInfo = getTransUnitInfo(vu);
if (tuInfo == null) {
continue;
}
tuInfo.setSrcLanguage(srcLang);
tuInfo.setTgtLangugage(tgtLang);
getTuContext(vu, contextSize, tuInfo);
List<FuzzySearchResult> result = tmMatcher.executeFuzzySearch(currentProject, tuInfo);
updateXliffFile(vu, tuInfo, result, xm, needUpdateTgt);
needUpdateTgt = true;
monitor.worked(1);
}
}
Aggregations