Search in sources :

Example 76 with VTDNav

use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.

the class XLFHandler method getTUFragByRowId.

/**
	 * 获取给定rowId的完整内容,包括头与尾
	 * @param rowId
	 * @return ;
	 */
public String getTUFragByRowId(String rowId) {
    String nodeStr = null;
    String xlfPath = RowIdUtil.getFileNameByRowId(rowId);
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
    String xpath = RowIdUtil.parseRowIdToXPath(rowId);
    AutoPilot ap = new AutoPilot(vn);
    try {
        VTDUtils vu = new VTDUtils(vn);
        ap.selectXPath(xpath);
        if (ap.evalXPath() != -1) {
            nodeStr = vu.getElementFragment();
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return nodeStr;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) FileNotFoundException(java.io.FileNotFoundException) XQException(javax.xml.xquery.XQException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Example 77 with VTDNav

use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.

the class XLFHandler method getSegmentIndex.

/**
	 * 得到文本段的索引
	 * @param currentRowIndex
	 * @param relativeXPath
	 * @param isNext
	 *            是否是找下一个。<br/>
	 *            <code>true</code>: 下一个;<code>false</code>: 上一个。
	 * @return 文本段的索引;
	 */
private int getSegmentIndex(int currentRowIndex, String relativeXPath, boolean isNext) {
    int step = isNext ? 1 : -1;
    currentRowIndex += step;
    AutoPilot ap = new AutoPilot();
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    while (currentRowIndex >= 0 && currentRowIndex < rowIds.size()) {
        String rowId = getRowId(currentRowIndex);
        VTDNav vn = getVTDNavByRowId(rowId);
        ap.bind(vn);
        String xpath = RowIdUtil.parseRowIdToXPath(rowId);
        try {
            ap.selectXPath(xpath + relativeXPath);
            if (ap.evalXPath() != -1) {
                return currentRowIndex;
            }
        } catch (XPathEvalException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        } catch (NavException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        } catch (XPathParseException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        }
        currentRowIndex += step;
    }
    return -1;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav)

Example 78 with VTDNav

use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.

the class XLFHandler method addNote.

/**
	 * 添加批注
	 * @param rowId
	 *            行的唯一标识
	 * @param note
	 *            批注内容;
	 */
public void addNote(Map<String, List<String>> mapRowIdByFileName, String note, String from, boolean isApplyCurrent) {
    try {
        StringBuffer insertValue = new StringBuffer("<note");
        if (from != null) {
            insertValue.append(" from='").append(from).append("'");
        }
        if (!isApplyCurrent) {
            insertValue.append(" hs:apply-current='No'");
        }
        insertValue.append(">").append(StringUtilsBasic.checkNullStr(note)).append("</note>");
        VTDUtils vu = new VTDUtils();
        XMLModifier xm = new XMLModifier();
        Iterator<Entry<String, List<String>>> it = mapRowIdByFileName.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, List<String>> entry = it.next();
            String fileName = entry.getKey();
            VTDNav vn = vnMap.get(fileName);
            vu.bind(vn);
            xm.bind(vn);
            for (String rowId : entry.getValue()) {
                StringBuffer xpath = new StringBuffer(RowIdUtil.parseRowIdToXPath(rowId));
                xm = vu.insert(null, xm, xpath.append("/text()").toString(), insertValue.toString());
            }
            saveAndReparse(xm, fileName);
        }
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (ModifyException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) Entry(java.util.Map.Entry) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) NavException(com.ximpleware.NavException) ModifyException(com.ximpleware.ModifyException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) VTDNav(com.ximpleware.VTDNav)

Example 79 with VTDNav

use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.

the class XLFHandler method getFileInfo.

/**
	 * 获取xliff文件的file节点的信息,保存到LinkedHashMap中, 第一个值为file节点的序列,从1开始,第二个值为该file节点下trans-unit的个数
	 * @param xlfPath
	 * @return robert 2011-10-21
	 */
public Map<Integer, Integer> getFileInfo(String xlfPath) {
    Map<Integer, Integer> fileInfo = new LinkedHashMap<Integer, Integer>();
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
    // 备注,这是从1开始。
    int fileIndex = 1;
    int transUnitNum = 0;
    try {
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath("/xliff/file");
        while (ap.evalXPath() != -1) {
            AutoPilot ap2 = new AutoPilot(vn);
            ap2.selectXPath("count(./body/trans-unit)");
            transUnitNum = (int) ap2.evalXPathToNumber();
            fileInfo.put(fileIndex, transUnitNum);
            fileIndex++;
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return fileInfo;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) FileNotFoundException(java.io.FileNotFoundException) XQException(javax.xml.xquery.XQException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException) LinkedHashMap(java.util.LinkedHashMap)

Example 80 with VTDNav

use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.

the class XLFHandler method getOldSplitInfo.

/**
	 * 获取该xliff文件的最终分割信息(针对已经分割的文件)
	 * @param xlfPath
	 * @return robert 2011-10-20
	 */
public Map<String, String> getOldSplitInfo(String xlfPath) {
    Map<String, String> oldSplitInfo = new HashMap<String, String>();
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
    try {
        AutoPilot ap = new AutoPilot(vn);
        ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
        // --robert split
        ap.selectXPath("/xliff/file/header/hs:splitInfos/hs:splitInfo[last()]");
        while (ap.evalXPath() != -1) {
            VTDUtils vu = new VTDUtils(vn);
            oldSplitInfo = vu.getCurrentElementAttributs(hsNSPrefix, hsR7NSUrl);
        }
    } catch (Exception e) {
        LOGGER.error(Messages.getString("file.XLFHandler.logger18"), e);
    // TODO: handle exception
    }
    return oldSplitInfo;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) FileNotFoundException(java.io.FileNotFoundException) XQException(javax.xml.xquery.XQException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Aggregations

VTDNav (com.ximpleware.VTDNav)206 AutoPilot (com.ximpleware.AutoPilot)177 NavException (com.ximpleware.NavException)128 XPathParseException (com.ximpleware.XPathParseException)115 XPathEvalException (com.ximpleware.XPathEvalException)110 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)99 IOException (java.io.IOException)85 ModifyException (com.ximpleware.ModifyException)81 TranscodeException (com.ximpleware.TranscodeException)69 CoreException (org.eclipse.core.runtime.CoreException)69 XMLModifier (com.ximpleware.XMLModifier)53 UnsupportedEncodingException (java.io.UnsupportedEncodingException)49 FileNotFoundException (java.io.FileNotFoundException)46 VTDGen (com.ximpleware.VTDGen)45 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)43 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)27 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)25 LinkedList (java.util.LinkedList)23