• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java VTDNav类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.ximpleware.VTDNav的典型用法代码示例。如果您正苦于以下问题:Java VTDNav类的具体用法?Java VTDNav怎么用?Java VTDNav使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



VTDNav类属于com.ximpleware包,在下文中一共展示了VTDNav类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
 
开发者ID:CoolBalance,项目名称:vtd-xml,代码行数:21,代码来源:XPathDemo.java


示例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");
    }
}
 
开发者ID:CoolBalance,项目名称:vtd-xml,代码行数:26,代码来源:Transcoder.java


示例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");
    }
}
 
开发者ID:CoolBalance,项目名称:vtd-xml,代码行数:27,代码来源:Transcoder.java


示例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");
    }
}
 
开发者ID:CoolBalance,项目名称:vtd-xml,代码行数:28,代码来源:Transcoder.java


示例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");
    }
}
 
开发者ID:CoolBalance,项目名称:vtd-xml,代码行数:23,代码来源:Transcoder.java


示例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;
}
 
开发者ID:CoolBalance,项目名称:vtd-xml,代码行数:36,代码来源:VTDNavHuge.java


示例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);
		}
	}
}
 
开发者ID:SourcePond,项目名称:release-maven-plugin-parent,代码行数:27,代码来源:VersionTransferWriter.java


示例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();
}
 
开发者ID:dongritengfei,项目名称:VTD-XML,代码行数:20,代码来源:XPathDemo.java


示例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;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:18,代码来源:PPTX2XLIFF.java


示例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;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:23,代码来源:QAXmlHandler.java


示例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 });
		}
	}
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:22,代码来源:XLIFF2PPTX.java


示例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;
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:33,代码来源:XLFHandler.java


示例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.xlf￱C:\Documents and
	// Settings\Administrator\桌面\translate test.txt￱2
	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;
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:33,代码来源:XLFHandler.java


示例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;
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:31,代码来源:QAXmlHandler.java


示例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();
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:27,代码来源:Du2Xliff.java


示例16: getRowIdByXpath

import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
 * 通过文件名,与给定的xpath获取某个特定的tu节点的rowId,备注,只返回第一个ROWID robert 2012-04-28
 * @param xlfPath
 * @param xpath
 * @return ;
 */
public String getRowIdByXpath(String xlfPath, String xpath) {
	VTDNav vn = vnMap.get(xlfPath);
	AutoPilot ap = new AutoPilot(vn);
	ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
	ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
	try {
		ap.selectXPath(xpath);
		if (ap.evalXPath() != -1) {
			return RowIdUtil.getRowId(vn, xlfPath);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:22,代码来源:XLFHandler.java


示例17: changeTranslateProp

import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
 * 改变translate属性的值
 * @param translateValue
 *            可选值:“yes”、“no”
 * @param xm
 *            XMLModifier对象;
 * @throws NavException
 * @throws UnsupportedEncodingException
 * @throws ModifyException
 * @throws XPathParseException
 * @throws XPathEvalException
 */
private boolean changeTranslateProp(VTDNav vn, String translateValue, XMLModifier xm) throws NavException,
		ModifyException, UnsupportedEncodingException, XPathParseException, XPathEvalException {
	if (translateValue == null) {
		return false;
	}

	vn.push();
	boolean isChanged = false; // 当前的TransUnit的translate属性是否执行了修改
	int attrIdx = vn.getAttrVal("translate");
	if (attrIdx != -1) { // 存在translate属性
		String translate = vn.toString(attrIdx);
		if (!translate.equals(translateValue)) { // translate属性值不为指定的translateValue
			xm.updateToken(attrIdx, translateValue);
			isChanged = true;
		}
	} else {
		xm.insertAttribute(" translate=\"" + translateValue + "\" ");
		if (translateValue.equals("no")) { // 默认值为yes
			isChanged = true;
		}
	}
	vn.pop();
	return isChanged;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:37,代码来源:XLFHandler.java


示例18: setTMXString

import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
 * 得到Tmx的前部分内容
 * @return ;
 */
private void setTMXString() {
	if (-1 != vtdUtil.pilot("/tmx/body/tu[last()]")) {
		try {
			VTDNav vn = vtdUtil.getVTDNav();
			long l;
			l = vn.getElementFragment();
			int os = (int) l + (int) (l >> 32);
			offset = os;
			int len = vn.getXML().length() - os;
			tmxBegainString = "";// vn.toRawString(0, os);
			tmxEndString = vn.toRawString(os, len);

		} catch (NavException e) {
			LOGGER.error(" R:Wrong XML format", e);
			e.printStackTrace();
		}

	}

}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:25,代码来源:AppendTmxWriter.java


示例19: addDataToXml

import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
 * 将数据添加到文件中,并且是添加到指定节点的尾部
 * @param newXlfPath
 * @param data	要添加的内容
 * @param toXpath	要添加的位置
 */
public boolean addDataToXml(String filePath, String toXpath, String data){
	VTDNav vn = vnMap.get(filePath);
	Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + filePath);
	try {
		AutoPilot ap = new AutoPilot(vn);
		ap.selectXPath(toXpath);
		if (ap.evalXPath() != -1) {
			XMLModifier xm = new XMLModifier(vn);
			xm.insertBeforeTail((data + "\n").getBytes("UTF-8"));
			//更新新生成的xliff文件,并重新加载并更新VTDVNav
			return saveAndReparse(xm, filePath);
		}
	} catch (Exception e) {
		e.printStackTrace();
		logger.error("", e);
	}
	return false;
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:25,代码来源:QAXmlHandler.java


示例20: deleteNode

import com.ximpleware.VTDNav; //导入依赖的package包/类
/**
 * 删除指定的节点,且并重新解析
 * @param filePath
 * @param nodeXpath
 * @return
 */
public boolean deleteNode(String filePath, String nodeXpath){
	VTDNav vn = vnMap.get(filePath);
	Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + filePath);
	try {
		AutoPilot ap = new AutoPilot(vn);
		ap.selectXPath(nodeXpath);
		if (ap.evalXPath() != -1) {
			VTDUtils vu = new VTDUtils(vn);
			XMLModifier xm = vu.update(nodeXpath, "");
			return saveAndReparse(xm, filePath);
		}
	} catch (Exception e) {
		e.printStackTrace();
		logger.error("", e);
	}
	
	return false;
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:25,代码来源:QAXmlHandler.java



注:本文中的com.ximpleware.VTDNav类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Config类代码示例发布时间:2022-05-22
下一篇:
Java LoadBalancerBuilder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap