Search in sources :

Example 51 with AutoPilot

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;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen)

Example 52 with AutoPilot

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;
}
Also used : AutoPilot(com.ximpleware.AutoPilot)

Example 53 with AutoPilot

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;
                }
            }
        });
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) CellAnchor(net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor)

Example 54 with AutoPilot

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;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException) IOException(java.io.IOException) VTDException(com.ximpleware.VTDException) FileNotFoundException(java.io.FileNotFoundException)

Example 55 with AutoPilot

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);
    }
}
Also used : FuzzySearchResult(net.heartsome.cat.common.bean.FuzzySearchResult) AutoPilot(com.ximpleware.AutoPilot) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)

Aggregations

AutoPilot (com.ximpleware.AutoPilot)308 VTDNav (com.ximpleware.VTDNav)173 NavException (com.ximpleware.NavException)150 XPathParseException (com.ximpleware.XPathParseException)145 XPathEvalException (com.ximpleware.XPathEvalException)137 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)112 IOException (java.io.IOException)103 ModifyException (com.ximpleware.ModifyException)95 TranscodeException (com.ximpleware.TranscodeException)82 CoreException (org.eclipse.core.runtime.CoreException)76 UnsupportedEncodingException (java.io.UnsupportedEncodingException)58 VTDGen (com.ximpleware.VTDGen)50 FileNotFoundException (java.io.FileNotFoundException)49 XMLModifier (com.ximpleware.XMLModifier)46 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)44 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)39 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)34 LinkedList (java.util.LinkedList)25