本文整理汇总了Java中com.ximpleware.VTDNav类的典型用法代码示例。如果您正苦于以下问题:Java VTDNav类的具体用法?Java VTDNav怎么用?Java VTDNav使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VTDNav类属于com.ximpleware包,在下文中一共展示了VTDNav类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showToken
import com.ximpleware.VTDNav; //导入依赖的package包/类
public void showToken(){
if (vn==null)return;
textArea.setSelectedTextColor(Color.RED);
textArea.setSelectionColor(Color.DARK_GRAY);
int index = vn.getCurrentIndex();
int os = vn.getTokenOffset(index);
int len = vn.getTokenLength(index);
int type = vn.getTokenType(index);
if (type == VTDNav.TOKEN_STARTING_TAG
|| type == VTDNav.TOKEN_ATTR_NAME
|| type == VTDNav.TOKEN_ATTR_NS){
len = len & 0xff;
}
System.out.println("os --> "+os);
System.out.println("len --> "+len);
textArea.setSelectionStart(os);
textArea.setSelectionEnd(os + len );
textArea.requestFocus();
//repaint();
}
示例2: getLen
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
*
* @param ch
* @param output_encoding
* @return
* @throws TranscodeException
*
*/
public static final int getLen(int ch, int output_encoding)
throws TranscodeException {
switch (output_encoding) {
case VTDNav.FORMAT_ASCII:
return ASCII_Coder.getLen(ch);
case VTDNav.FORMAT_UTF8:
return UTF8_Coder.getLen(ch);
case VTDNav.FORMAT_ISO_8859_1:
return ISO8859_1Coder.getLen(ch);
case VTDNav.FORMAT_UTF_16LE:
return UTF16LE_Coder.getLen(ch);
case VTDNav.FORMAT_UTF_16BE:
return UTF16BE_Coder.getLen(ch);
default:
throw new com.ximpleware.TranscodeException("Unsupported encoding");
}
}
示例3: decode
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
*
* @param input
* @param offset
* @param input_encoding
* @return
* @throws TranscodeException
*
*/
public static final long decode(byte[] input, int offset, int input_encoding)
throws TranscodeException {
switch (input_encoding) {
case VTDNav.FORMAT_ASCII:
return ASCII_Coder.decode(input, offset);
case VTDNav.FORMAT_UTF8:
return UTF8_Coder.decode(input, offset);
case VTDNav.FORMAT_ISO_8859_1:
return ISO8859_1Coder.decode(input, offset);
case VTDNav.FORMAT_UTF_16LE:
return UTF16LE_Coder.decode(input, offset);
case VTDNav.FORMAT_UTF_16BE:
return UTF16BE_Coder.decode(input, offset);
default:
throw new com.ximpleware.TranscodeException("Unsupported encoding");
}
}
示例4: encode
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
*
* @param output
* @param offset
* @param ch
* @param output_encoding
* @return
* @throws TranscodeException
*
*/
public static final int encode(byte[] output, int offset, int ch,
int output_encoding) throws TranscodeException {
switch (output_encoding) {
case VTDNav.FORMAT_ASCII:
return ASCII_Coder.encode(output, offset, ch);
case VTDNav.FORMAT_UTF8:
return UTF8_Coder.encode(output, offset, ch);
case VTDNav.FORMAT_ISO_8859_1:
return ISO8859_1Coder.encode(output, offset, ch);
case VTDNav.FORMAT_UTF_16LE:
return UTF16LE_Coder.encode(output, offset, ch);
case VTDNav.FORMAT_UTF_16BE:
return UTF16BE_Coder.encode(output, offset, ch);
default:
throw new com.ximpleware.TranscodeException("Unsupported encoding");
}
}
示例5: encodeAndWrite
import com.ximpleware.VTDNav; //导入依赖的package包/类
public static final void encodeAndWrite(OutputStream os, int ch,
int output_encoding) throws TranscodeException, IOException {
switch (output_encoding) {
case VTDNav.FORMAT_ASCII:
ASCII_Coder.encodeAndWrite(os, ch);
return;
case VTDNav.FORMAT_UTF8:
UTF8_Coder.encodeAndWrite(os, ch);
return;
case VTDNav.FORMAT_ISO_8859_1:
ISO8859_1Coder.encodeAndWrite(os, ch);
return;
case VTDNav.FORMAT_UTF_16LE:
UTF16LE_Coder.encodeAndWrite(os, ch);
return;
case VTDNav.FORMAT_UTF_16BE:
UTF16BE_Coder.encodeAndWrite(os, ch);
return;
default:
throw new com.ximpleware.TranscodeException("Unsupported encoding");
}
}
示例6: getSiblingElementFragments
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
* Return the byte offset and length of up to i sibling fragments. If
* there is a i+1 sibling element, the cursor element would
* move to it; otherwise, there is no cursor movement. If the cursor isn't
* positioned at an element (due to XPath evaluation), then -1 will be
* returned
* @param i number of silbing elements including the cursor element
* @return a long[2] encoding byte offset (lower 64 bits), length (
* upper 64 bits) of those fragments
* @throws NavExceptionHuge
*/
public long[] getSiblingElementFragments(int i) throws NavExceptionHuge{
if (i<=0)
throw new IllegalArgumentException(" # of sibling can be less or equal to 0");
// get starting char offset
if(atTerminal==true)
return null;
// so is the char offset
long so = getTokenOffset(getCurrentIndex())-1;
// char offset to byte offset conversion
if (encoding>=FORMAT_UTF_16BE)
so = so<<1;
BookMarkHuge bmh = new BookMarkHuge(this);
bmh.recordCursorPosition();
while(i>1 && toElement(VTDNav.NEXT_SIBLING)){
i--;
}
long[] l= getElementFragment();
long len = l[0]+l[1]-so;
if (i==1 && toElement(VTDNav.NEXT_SIBLING)){
}else
bmh.setCursorPosition();
l[0] = so; l[1]=len;
return l;
}
示例7: insertVersionIntoOriginalIfNecessary
import com.ximpleware.VTDNav; //导入依赖的package包/类
private void insertVersionIntoOriginalIfNecessary(final String pOwnVersionOrNull)
throws ModifyException, NavException, UnsupportedEncodingException, IOException, TranscodeException {
if (pOwnVersionOrNull != null) {
final VTDGen gen = new VTDGen();
gen.enableIgnoredWhiteSpace(true);
final XMLModifier modifier = new XMLModifier();
if (gen.parseFile(file.getAbsolutePath(), false)) {
final VTDNav vn = gen.getNav();
modifier.bind(vn);
if (vn.toElement(FC, ARTIFACT_ID)) {
final long l = vn.expandWhiteSpaces(vn.getElementFragment(), WS_LEADING);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
vn.dumpFragment(l, out);
final String version = new String(out.toByteArray()).replaceAll(ARTIFACT_ID_PATTERN,
format(VERSION_FORMAT, pOwnVersionOrNull));
modifier.insertAfterElement(version);
}
}
try (final FileOutputStream out = new FileOutputStream(file)) {
modifier.output(out);
}
}
}
示例8: showToken
import com.ximpleware.VTDNav; //导入依赖的package包/类
public void showToken() {
if (vn == null)
return;
textArea.setSelectedTextColor(Color.RED);
textArea.setSelectionColor(Color.DARK_GRAY);
int index = vn.getCurrentIndex();
int os = vn.getTokenOffset(index);
int len = vn.getTokenLength(index);
int type = vn.getTokenType(index);
if (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS) {
len = len & 0xff;
}
System.out.println("os --> " + os);
System.out.println("len --> " + len);
textArea.setSelectionStart(os);
textArea.setSelectionEnd(os + len);
textArea.requestFocus();
// repaint();
}
示例9: getElementAttribute
import com.ximpleware.VTDNav; //导入依赖的package包/类
public String getElementAttribute(String elementXPath, String attributeName, VTDNav vn) throws XPathParseException,
XPathEvalException, NavException {
String text = null;
AutoPilot ap = new AutoPilot(vn);
ap.declareXPathNameSpace(PREFIX_A, NAMESPACE_A);
ap.declareXPathNameSpace(PREFIX_P, NAMESPACE_P);
ap.selectXPath(elementXPath);
vn.push();
if (ap.evalXPath() != -1) {
int inx = vn.getAttrVal(attributeName);
if (inx != -1) {
text = vn.toString(inx);
}
}
vn.pop();
return text;
}
示例10: getNonTransElementsRegex
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
* 只获取非译元素的正则表达式
* @param filePath
* @return
*/
public List<String> getNonTransElementsRegex(String filePath){
List<String> regexList = new ArrayList<String>();
VTDNav vn = vnMap.get(filePath);
AutoPilot ap = new AutoPilot(vn);
validNull(vn, ap, filePath);
try {
VTDUtils vUtils = new VTDUtils(vn);
ap.selectXPath("/nonTrans/element/regular");
while (ap.evalXPath() != -1) {
regexList.add(vUtils.getElementContent());
}
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger19"), e);
}
return regexList;
}
示例11: loadSegment
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
* 解析 XLIFF 文件,获取所有文本段集合
* @throws NavException
* @throws XPathParseException
* @throws XPathEvalException
*/
private void loadSegment() throws NavException, XPathParseException, XPathEvalException {
VTDGen vg = new VTDGen();
if (vg.parseFile(strXLIFFPath, true)) {
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/xliff/file/body//trans-unit");
while (ap.evalXPath() != -1) {
String strTuId = vu.getCurrentElementAttribut("id", null);
String strSource = vu.getElementContent("./source");
String strTarget = vu.getElementContent("./target");
mapSegment.put(strTuId, new String[] { strSource, strTarget });
}
}
}
示例12: getFullAndPureText
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
* 获取trans-unit节点下source或target节点的全文本或纯文本 robert 2011-12-14
* @param xlfPath
* : xliff文件路径
* @param nodeXpath
* : trans-unit子节点source或target的xpath值 如果返回null,则证明这个节点是个空节点,要么没有这个节点,要么这个节点没有值
* @return textMap:两个值,key1 --> fullText:全文本,key2 --> pureText:纯文本。
*/
public Map<String, String> getFullAndPureText(String xlfPath, String nodeXpath) {
Map<String, String> textMap = new HashMap<String, String>();
VTDNav vn = vnMap.get(xlfPath);
vn.push();
AutoPilot ap = new AutoPilot(vn);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
VTDUtils vUtils = new VTDUtils(vn);
ap.selectXPath(nodeXpath);
if (ap.evalXPath() != -1) {
String content = vUtils.getElementContent();
if (content != null && !"".equals(content)) {
textMap.put("fullText", content);
textMap.put("pureText", getTUPureText(vn));
}
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
vn.pop();
return textMap;
}
示例13: getTUPureTextByRowId
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
* 根据rowId获取trans-unit节点源文本的纯文本
* @param rowId
* @param isSrc
* 是否获取源文本,true:获取源文本,false:获取目标文本
* @return ;
*/
public String getTUPureTextByRowId(String rowId, boolean isSrc) {
String xlfPath = RowIdUtil.getFileNameByRowId(rowId);
String tuXpath = RowIdUtil.parseRowIdToXPath(rowId);
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
vn.push();
AutoPilot ap = new AutoPilot(vn);
// /home/robert/workspace/runtime-hs_ts.product/test1/XLIFF/translate test.txt.xlfC:\Documents and
// Settings\Administrator\桌面\translate test.txt2
String childXpath = isSrc ? "/source" : "/target";
try {
ap.selectXPath(tuXpath + childXpath);
if (ap.evalXPath() != -1) {
return getTUPureText(vn);
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
} finally {
vn.pop();
}
return null;
}
示例14: getNodeText
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
* 获取指定节点的值(针对节点值为文本段)
* @param xmlPath
* @param nodeXpath
* @return ;
*/
public String getNodeText(String xmlPath, String nodeXpath, String defaultValue){
String aspellCommand = "";
VTDNav vn = vnMap.get(xmlPath);
Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xmlPath);
AutoPilot ap = new AutoPilot(vn);
try {
ap.selectXPath(nodeXpath);
if (ap.evalXPath() != -1) {
int commandIndex = vn.getText();
if (commandIndex != -1) {
aspellCommand = vn.toString(commandIndex);
}else {
return defaultValue;
}
}else {
return defaultValue;
}
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger16"), e);
}
return aspellCommand;
}
示例15: analysisTuMrkStatus
import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
* 分析每一个文本段的状态
* @param vn
* @param vu
* @param tgtBean
* @param mid target节点下子节点mrk的mid属性,即唯一id值
*/
private void analysisTuMrkStatus(VTDNav vn, VTDUtils vu, TuMrkBean tgtBean, String mid, boolean isApproved) throws Exception {
vn.push();
String status = ""; //一个空字符串代表未翻译
if (isApproved) {
status = "finish";
}else {
String xpath = "ancestor::target";
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath(xpath);
if(ap.evalXPath() != -1){
int attrIdx = -1;
if ((attrIdx = vn.getAttrVal("state")) != -1) {
status = vn.toString(attrIdx);
}
}
}
tgtBean.setStatus(status);
vn.pop();
}