当前位置: 首页>>代码示例>>Java>>正文


Java VTDGen类代码示例

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


VTDGen类属于com.ximpleware包,在下文中一共展示了VTDGen类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: insertVersionIntoOriginalIfNecessary

import com.ximpleware.VTDGen; //导入依赖的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

示例2: getFileId

import com.ximpleware.VTDGen; //导入依赖的package包/类
private String getFileId(BufferedReader reader) throws IOException, VTDException {
    reader.mark(1024);
    String str = reader.readLine();
    str += "</FILE>";
    reader.reset();
    
    byte[] b = str.getBytes("UTF-8");
    VTDGen vg = new VTDGen();
    vg.setDoc(b);
    vg.parse(false);
    VTDNav vn = vg.getNav();
    require(vn.toElement(VTDNav.ROOT));
    String fileId = vn.toString(vn.getAttrVal(AgigaConstants.FILE_ID));
    
    return fileId;
}
 
开发者ID:mgormley,项目名称:agiga,代码行数:17,代码来源:StreamingVtdXmlReader.java

示例3: editPlugindata

import com.ximpleware.VTDGen; //导入依赖的package包/类
private void editPlugindata(PluginConfigBean bean) {
	VTDGen vg = new VTDGen();
	vg.parseFile(pluginXmlLocation, true);
	VTDNav vn = vg.getNav();
	AutoPilot ap = new AutoPilot(vn);
	try {
		ap.selectXPath(manage.buildXpath(curPluginBean));
		XMLModifier xm = new XMLModifier(vn);
		while (ap.evalXPath() != -1) {
			xm.remove();
			xm.insertAfterElement(manage.buildPluginData(bean));
			manage.updataPluginMenu(bean);
		}
		FileOutputStream fos = new FileOutputStream(pluginXmlLocation);
		BufferedOutputStream bos = new BufferedOutputStream(fos);
		xm.output(bos); // 写入文件
		bos.close();
		fos.close();
	} catch (Exception e) {
		LOGGER.error("", e);
	}
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:23,代码来源:PluginConfigManageDialog.java

示例4: copyMqSklToHsSkl

import com.ximpleware.VTDGen; //导入依赖的package包/类
/**
 * 将mq 的骨架文件拷到R8 的骨架文件中
 * @throws Exception
 */
private void copyMqSklToHsSkl(File mqSkeletonFile) throws Exception {
	VTDGen vg = new VTDGen();
	AutoPilot ap = new AutoPilot();
	String mqSklContent = "";
	String xpath = "/mq:externalparts";
	if(vg.parseFile(mqSkeletonFile.getAbsolutePath(), true)){
		VTDNav vn = vg.getNav();
		ap.bind(vn);
		VTDUtils vu = new VTDUtils(vn);
		ap.declareXPathNameSpace("mq", "MemoQ Xliff external parts");
		ap.selectXPath(xpath);
		if (ap.evalXPath() != -1) {
			mqSklContent = vu.getElementContent();
		}
	}
	
	//下面添加到 r8 的骨架文件中去
	ap.bind(sklVN);
	xpath = "/xliff/file/header/skl";
	ap.selectXPath(xpath);
	if (ap.evalXPath() != -1) {
		sklXM.insertAfterElement("<sklContent>" + mqSklContent + "</sklContent>");
		sklXM.output(skeletonFile);
	}
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:30,代码来源:Mq2Xliff.java

示例5: getNonTextContent

import com.ximpleware.VTDGen; //导入依赖的package包/类
/**
 * Get rPh & phoneticPr Element fragment
 * @return ;
 */
private String getNonTextContent(){
	StringBuffer result = new StringBuffer();
	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/rPh | phoneticPr");
		while(ap.evalXPath() != -1){
			result.append(vu.getElementFragment());
		}			
	} catch (VTDException e) {
		e.printStackTrace();
	}
	return result.toString();
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:24,代码来源:Cell.java

示例6: loadFile

import com.ximpleware.VTDGen; //导入依赖的package包/类
/**
 * 解析文件
 * @param nameSpaceMap	要申明的命名空间
 * @throws Exception
 */
protected void loadFile(Map<String, String> nameSpaceMap) throws Exception {
	VTDGen vg = new VTDGen();
	if (vg.parseFile(partPath, true)) {
		vn = vg.getNav();
		ap = new AutoPilot(vn);
		otherAP = new AutoPilot(vn);
		childAP = new AutoPilot(vn);
		extendAP = new AutoPilot(vn);
		vu = new VTDUtils(vn);
		xm = new XMLModifier(vn);
		// 给 ap 申明命名空间
		for(Entry<String, String> entry : nameSpaceMap.entrySet()){
			ap.declareXPathNameSpace(entry.getKey(), entry.getValue());
			childAP.declareXPathNameSpace(entry.getKey(), entry.getValue());
			otherAP.declareXPathNameSpace(entry.getKey(), entry.getValue());
			extendAP.declareXPathNameSpace(entry.getKey(), entry.getValue());
		}
	}else {
		throw new DocxConverterException(MessageFormat.format(Messages.getString("docxConvert.msg2"), partPath));
	}
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:27,代码来源:PartOperate.java

示例7: loadSegment

import com.ximpleware.VTDGen; //导入依赖的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

示例8: getTagId

import com.ximpleware.VTDGen; //导入依赖的package包/类
/**
 * 根据一个<g>标记的头部获取标记的 id 属性值
 * @param tagStr
 * @return
 */
private String getTagId(String tagStr) throws Exception {
	String tagId = "";
	VTDGen vg = new VTDGen();
	vg.setDoc(tagStr.getBytes());
	vg.parse(false);
	VTDNav vn = vg.getNav();
	tagAP = new AutoPilot(vn);
	tagAP.selectXPath("/g");
	int index = -1;
	if (tagAP.evalXPath() != -1) {
		if ((index = vn.getAttrVal("id")) != -1) {
			tagId = vn.toRawString(index);
		}
	}
	return tagId;
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:22,代码来源:Xliff2Ttx.java

示例9: XliffUtil

import com.ximpleware.VTDGen; //导入依赖的package包/类
/**
 * 直接通过 RowID 来定位,适用于最常见的在界面 NatTable 中显示的文本段。
 * @param rowID
 */
public XliffUtil(String rowID) {
	this.rowID = rowID;
	this.xlfFile = RowIdUtil.getFileNameByRowId(rowID);
	this.fileXPath = RowIdUtil.getFileXpathByRowId(rowID);
	this.tuid = RowIdUtil.getTUIdByRowId(rowID);
	this.vg = new VTDGen();
	if (vg.parseFile(xlfFile, true)) {
		VTDNav vn = vg.getNav();
		try {
			vu = new VTDUtils(vn);
		} catch (NavException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:20,代码来源:XliffUtil.java

示例10: XliffUtil

import com.ximpleware.VTDGen; //导入依赖的package包/类
/**
 * 通过可组成 RowID 的三个参数来定位,适用于不在界面 NatTable 中显示的文本段, 如合并后变为空的 trans-unit 节点。
 * @param xlfFile
 *            XLIFF 文件路径
 * @param originalFile
 *            源文件路径,建议从相邻文本段中用本类方法获取
 * @param tuid
 *            翻译单元 ID
 */
public XliffUtil(String xlfFile, String originalFile, String tuid) {
	this.xlfFile = xlfFile;
	this.fileXPath = "/xliff/file[@original=\"" + originalFile + "\"]";
	this.tuid = tuid;
	this.rowID = RowIdUtil.getRowId(xlfFile, originalFile, tuid);
	this.vg = new VTDGen();
	if (vg.parseFile(xlfFile, true)) {
		VTDNav vn = vg.getNav();
		try {
			vu = new VTDUtils(vn);
		} catch (NavException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:25,代码来源:XliffUtil.java

示例11: updateProjectParentVersion

import com.ximpleware.VTDGen; //导入依赖的package包/类
void updateProjectParentVersion(MavenProject project, Version version) throws MojoExecutionException {
    try {
        VTDGen gen = new VTDGen();
        gen.enableIgnoredWhiteSpace(true);
        gen.parseFile(project.getFile().getAbsolutePath(), true);

        VTDNav nav = gen.getNav();
        AutoPilot ap = new AutoPilot(nav);
        ap.selectXPath("namespace-uri(.)");
        String ns = ap.evalXPathToString();

        nav.toElementNS(VTDNav.FIRST_CHILD, ns, "parent");
        nav.toElementNS(VTDNav.FIRST_CHILD, ns, "version");
        int pos = nav.getText();

        XMLModifier mod = new XMLModifier(nav);
        mod.updateToken(pos, version.toString());

        try (OutputStream out = new FileOutputStream(project.getFile())) {
            mod.output(out);
        }
    } catch (IOException | ModifyException | NavException | XPathParseException | TranscodeException e) {
        throw new MojoExecutionException("Failed to update the parent version of project " + project, e);
    }
}
 
开发者ID:revapi,项目名称:revapi,代码行数:26,代码来源:AbstractVersionModifyingMojo.java

示例12: openFile

import com.ximpleware.VTDGen; //导入依赖的package包/类
/**
 * 打开指定的主文件和对应的子文件
 * @param mainFilePath
 *            主文件完整路径
 * @param subFiles
 *            子文件完整路径
 * @throws Exception
 *             ;
 */
public void openFile(String mainFilePath, List<String> subFiles, IProgressMonitor monitor) throws Exception {
	if (monitor == null) {
		monitor = new NullProgressMonitor();
	}
	this.mainfilePath = mainFilePath;
	File file = new File(mainFilePath);
	mainFileEncoding = FileEncodingDetector.detectFileEncoding(file);
	VTDGen vg = VTDLoader.loadVTDGen(file, mainFileEncoding);
	VTDNav vn = vg.getNav();
	initTmxVersion(vn);
	this.subFiles = subFiles;
	monitor.beginTask("", 10);
	openSubFiles(new SubProgressMonitor(monitor, 6));
	loadAllLang(new SubProgressMonitor(monitor, 2));
	monitor.worked(2);
	VTDUtils vu = vus.get(subFiles.get(0));
	loadTmxHeader(vu.getVTDNav());
	monitor.done();
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:29,代码来源:TmxLargeFileContainer.java

示例13: openSubFiles

import com.ximpleware.VTDGen; //导入依赖的package包/类
private void openSubFiles(IProgressMonitor monitor) throws Exception {
	if (subFiles == null || subFiles.size() == 0) {
		throw new FileNotFoundException(Messages.getString("tmxdata.TmxFileContainer.parseTmxFileNotFound"));
	}
	if (monitor == null) {
		monitor = new NullProgressMonitor();
	}
	monitor.beginTask("", subFiles.size());
	VTDGen vg = new VTDGen();
	for (String file : subFiles) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		File f = new File(file);
		if (!f.exists() || f.isDirectory()) {
			throw new FileNotFoundException(Messages.getString("tmxdata.TmxFileContainer.parseTmxFileNotFound"));
		}
		parseFile(vg, f, new SubProgressMonitor(monitor, 1));
		VTDUtils vu = new VTDUtils(vg.getNav());
		vus.put(file, vu);
		tuTotalNumber += countFileTuNumber(vu);
		vg.clear();
	}
	monitor.done();
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:26,代码来源:TmxLargeFileContainer.java

示例14: main

import com.ximpleware.VTDGen; //导入依赖的package包/类
public static void main(String[] args) throws XPathParseException, XPathEvalException, NavException {
		TSFileHandler ts = new TSFileHandler();
		VTDGen vg = new VTDGen();
		if (vg
				.parseFile(
						"/data/john/Workspaces/Other/net.heartsome.cat.ts.core/testSrc/net/heartsome/cat/ts/core/file/test/Test.txt.xlf",
						true)) {
			ts.openFile("/data/john/Workspaces/Other/net.heartsome.cat.ts.core/testSrc/net/heartsome/cat/ts/core/file/test/Test.txt.xlf");
			System.out.println(ts.getSourceLanguage(3));
			System.out.println(ts.getTargetLanguage(3));
//			System.out
//					.println(ts
//							.analysisTranslatorProgress(
//									vg.getNav(),
//									"/data/john/Workspaces/Other/net.heartsome.cat.ts.core/testSrc/net/heartsome/cat/ts/core/file/test/Test.txt.xlf",
//									0));
		}

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

示例15: getElementFragment

import com.ximpleware.VTDGen; //导入依赖的package包/类
/**
 * 获得整个节点的段落
 * @return 整个节点的段落,例如:&lt;ph id="1"&gt;a&lt;/ph&gt;
 * @throws NavException
 *             ;
 */
public String getElementFragment() throws NavException {
	long l = vn.getElementFragment();
	int offset = (int) l;
	int len = (int) (l >> 32);

	/* 区别编码。在解析 UTF-16 等部分编码的时候索引会变为2倍。 */
	if (vn.getEncoding() > VTDGen.FORMAT_WIN_1258) {
		offset = offset >> 1;
		len = len >> 1;
	}
	// 处理这种情况下获取内容错误的情况 <ph>...</ph> 1><ph>...</ph>	robert 2012-09-13
	String fragment = vn.toRawString(offset, len);
	int length = fragment.length();
	int realEndIdx = fragment.indexOf(">", fragment.lastIndexOf("<"));
	if (realEndIdx != length - 1) {
		fragment = fragment.substring(0, fragment.indexOf(">", fragment.lastIndexOf("<")) + 1);
	}
	return fragment;
}
 
开发者ID:heartsome,项目名称:tmxeditor8,代码行数:26,代码来源:VTDUtils.java


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