Search in sources :

Example 51 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils 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 52 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils 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 53 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils 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)

Example 54 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.

the class XLFHandler method getNodeAttribute.

/**
	 * 获取某属性名的属性值
	 * @param xlfPath
	 * @param nodeXpath
	 * @param attrName
	 * @return robert 2011-11-02
	 */
public String getNodeAttribute(String xlfPath, String nodeXpath, String attrName) {
    String attribute = "";
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
    try {
        AutoPilot ap = new AutoPilot(vn);
        VTDUtils vu = new VTDUtils(vn);
        ap.selectXPath(nodeXpath);
        while (ap.evalXPath() != -1) {
            attribute = vu.getCurrentElementAttribut(attrName, "");
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return attribute;
}
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 55 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.

the class XLFHandler method getTgtPropValue.

/**
	 * 得到Target节点属性的值
	 * @param rowId
	 *            行的唯一标识
	 * @return ;
	 */
public String getTgtPropValue(String rowId, String propName) {
    VTDNav vn = getVTDNavByRowId(rowId);
    String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
    try {
        VTDUtils vu = new VTDUtils(vn);
        return vu.getValue(tuXPath + "/target/@" + propName);
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return null;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav)

Aggregations

VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)137 AutoPilot (com.ximpleware.AutoPilot)112 NavException (com.ximpleware.NavException)103 VTDNav (com.ximpleware.VTDNav)99 XPathParseException (com.ximpleware.XPathParseException)83 XPathEvalException (com.ximpleware.XPathEvalException)81 IOException (java.io.IOException)64 ModifyException (com.ximpleware.ModifyException)62 TranscodeException (com.ximpleware.TranscodeException)49 CoreException (org.eclipse.core.runtime.CoreException)45 XMLModifier (com.ximpleware.XMLModifier)41 VTDGen (com.ximpleware.VTDGen)33 FileNotFoundException (java.io.FileNotFoundException)30 UnsupportedEncodingException (java.io.UnsupportedEncodingException)29 HashMap (java.util.HashMap)27 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)27 LinkedHashMap (java.util.LinkedHashMap)25 ArrayList (java.util.ArrayList)23 XQException (javax.xml.xquery.XQException)20 LinkedList (java.util.LinkedList)14