com.ximpleware.NavException Java Examples

The following examples show how to use com.ximpleware.NavException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VTDUtils.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 得到当前节点的纯文本。实体会被转义。若无文本内容返回 null。
 * @exception XPathParseException
 *                ,XPathEvalException,NavException
 */
public String getElementPureText() throws XPathParseException, XPathEvalException, NavException {
	String txtNode = "./text()";
	AutoPilot ap = new AutoPilot(vn);
	StringBuilder result = new StringBuilder();
	ap.selectXPath(txtNode);
	int txtIndex = -1;
	boolean isNull = true;
	while ((txtIndex = ap.evalXPath()) != -1) {
		result.append(vn.toString(txtIndex));
		if (isNull) {
			isNull = false;
		}
	}

	return isNull ? null : result.toString();
}
 
Example #2
Source File: XliffUtil.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 通过可组成 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();
		}
	}
}
 
Example #3
Source File: PreMachineTranslation.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
private TransUnitInfo2TranslationBean getTransUnitInfo(VTDUtils vu) throws XPathParseException, XPathEvalException,
		NavException {
	TransUnitInfo2TranslationBean tuInfo = new TransUnitInfo2TranslationBean();

	vu.getVTDNav().push();
	AutoPilot sourceAp = new AutoPilot(vu.getVTDNav());
	sourceAp.selectXPath("./source");
	String fullText = "";
	String pureText = "";
	if (sourceAp.evalXPath() != -1) {
		fullText = vu.getElementContent();
		pureText = xlfHandler.getTUPureText(vu.getVTDNav());
	}
	vu.getVTDNav().pop();

	if (fullText == null || fullText.equals("") || pureText.equals("")) {
		return null;
	}
	tuInfo.setSrcFullText(fullText);
	tuInfo.setSrcPureText(pureText);
	return tuInfo;
}
 
Example #4
Source File: XLIFF2PPTX.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 解析 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 });
		}
	}
}
 
Example #5
Source File: VTDUtils.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 得到当前节点的纯文本。实体不会被转义。若无文本内容返回 null。
 * @exception XPathParseException
 *                ,XPathEvalException,NavException
 */
public String getElementRawPureText() throws XPathParseException, XPathEvalException, NavException {
	String txtNode = "./text()";
	AutoPilot ap = new AutoPilot(vn);
	StringBuilder result = new StringBuilder();
	ap.selectXPath(txtNode);
	int txtIndex = -1;
	while ((txtIndex = ap.evalXPath()) != -1) {
		result.append(vn.toRawString(txtIndex));
	}

	if (result.length() == 0) {
		return null;
	} else {
		return result.toString();
	}
}
 
Example #6
Source File: TmxLargeFileContainer.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private void initTmxVersion(VTDNav vn) throws NavException {
	vn.toElement(VTDNav.ROOT);
	int rootIdx = vn.getCurrentIndex();
	if (vn.toString(rootIdx).equalsIgnoreCase("tmx")) {
		int t = vn.getAttrVal("version");
		if (t != -1) {
			tmxVersion = vn.toString(t);
		}
	}
	for (int i = 0; i < rootIdx; i++) {
		int ty = vn.getTokenType(i);
		if (ty == VTDNav.TOKEN_DTD_VAL) {
			doctypeContent = vn.toString(i);
		}
	}
}
 
Example #7
Source File: VTDUtils.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获得整个节点的段落
 * @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;
}
 
Example #8
Source File: VTDUtils.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取当前节点下所有指定元素名称的文本内容,含内部标记等子节点内容。
 * @param elementName
 *            子节点名称
 * @throws XPathParseException
 * @throws NavException
 * @throws XPathEvalException
 */
public Vector<String> getChildrenContent(String elementName) throws XPathParseException, XPathEvalException,
		NavException {
	Vector<String> texts = new Vector<String>();
	AutoPilot ap = new AutoPilot(vn);
	ap.selectXPath("./" + elementName);
	while (ap.evalXPath() != -1) {
		vn.push();
		texts.add(getElementContent());
		vn.pop();
	}

	if (texts.isEmpty()) {
		texts = null;
	}
	return texts;
}
 
Example #9
Source File: ProjectConfiger.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取配置文件中的项目文本字段信息
 * @return
 * @throws XPathParseException
 * @throws XPathEvalException
 * @throws NavException ;
 */
private LinkedHashMap<String, String> getFieldMap() throws XPathParseException, XPathEvalException, NavException {
	AutoPilot ap = new AutoPilot(vu.getVTDNav());
	Map<String, String> mapField = new HashMap<String, String>();
	ap.selectXPath("/projectDescription/hs//fieldList/field");
	while (ap.evalXPath() != -1) {
		String fieldName = TextUtil.stringToXML(vu.getCurrentElementAttribut("name", ""));
		String fieldValue = vu.getElementContent();
		mapField.put(fieldName, fieldValue);
	}
	List<Entry<String, String>> lstAttr = new ArrayList<Entry<String, String>>(mapField.entrySet());
	final Collator collatorChinese = Collator.getInstance(java.util.Locale.CHINA);
	Collections.sort(lstAttr, new Comparator<Entry<String, String>>() {

		public int compare(Entry<String, String> arg0, Entry<String, String> arg1) {
			return collatorChinese.compare(arg0.getKey(), arg1.getKey());
		}
	});
	LinkedHashMap<String, String> linkedMapAttr = new LinkedHashMap<String, String>();
	for (Entry<String, String> entry : lstAttr) {
		linkedMapAttr.put(entry.getKey(), entry.getValue());
	}
	return linkedMapAttr;
}
 
Example #10
Source File: Wf2Xliff.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * <div style='color:red;'>这个方法是从 VTDUtils 类中考贝的,主要是要有一定的顺序</div>
 * @param vn
 * @return
 * @throws XPathParseException
 * @throws XPathEvalException
 * @throws NavException
 */
private Map<String, String> getElementAttributs(VTDNav vn)
		throws XPathParseException, XPathEvalException, NavException {
	vn.push();
	Map<String, String> attributes = new LinkedHashMap<String, String>();
	AutoPilot apAttributes = new AutoPilot(vn);
	apAttributes.selectXPath("@*");

	int inx = -1;
	while ((inx = apAttributes.evalXPath()) != -1) {
		String name = vn.toString(inx);
		inx = vn.getAttrVal(name);
		String value = inx != -1 ? vn.toString(inx) : "";
		attributes.put(name, value);
	}
	apAttributes.resetXPath();

	if (attributes.isEmpty()) {
		attributes = null;
	}
	vn.pop();
	return attributes;
}
 
Example #11
Source File: QAXmlHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 通过rowId获取当前翻译单元的上下文
 * @param rowId 
 * @param num 上下文个数
 * @return ;
 */
public Map<String, String> getTransUnitContext(String rowId, int num) {

	Map<String, String> result = new HashMap<String, String>();
	if (tuSizeMap == null || rowId == null) {
		return null;
	}

	VTDUtils vu = null;
	VTDNav vn = getVTDNavByRowId(rowId);
	try {
		vu = new VTDUtils(vn);
	} catch (NavException e1) {
		String errorMsg = Messages.getString("qa.QAXmlHandler.logger21");
		logger.error(errorMsg, e1);
		return null;
	}
	AutoPilot ap = new AutoPilot(vu.getVTDNav());
	result.put("x-preContext", getContext(vu, ap, num, true));
	result.put("x-nextContext", getContext(vu, ap, num, false));
	return result;
}
 
Example #12
Source File: Martif2Tbx.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 得到当前子节点的纯文本。实体会被转义。若无文本内容返回 null。
 * @exception XPathParseException
 *                ,XPathEvalException,NavException
 */
public String getChildElementPureText(VTDNav vn) throws XPathParseException, XPathEvalException, NavException {
	String txtNode = ".//text()";
	AutoPilot ap = new AutoPilot(vn);
	StringBuilder result = new StringBuilder();
	ap.selectXPath(txtNode);
	int txtIndex = -1;
	boolean isNull = true;
	while ((txtIndex = ap.evalXPath()) != -1) {
		result.append(vn.toString(txtIndex));
		if (isNull) {
			isNull = false;
		}
	}

	return isNull ? null : result.toString();
}
 
Example #13
Source File: AbstractVersionModifyingMojo.java    From revapi with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #14
Source File: VTDUtils.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 得到当前节点的完整内容,包含子节点及文本。若无文本内容返回 null。
 * @throws NavException
 */
public String getElementContent() throws NavException {
	String result = null;
	long l = vn.getContentFragment();
	if (l == -1) {
		return null;
	}

	int offset = (int) l;
	int len = (int) (l >> 32);
	if (offset != -1 && len != -1) {
		if (vn.getEncoding() > VTDNav.FORMAT_WIN_1258) {
			offset = offset >> 1;
			len = len >> 1;
		}
		result = vn.toRawString(offset, len);
	}
	return result;
}
 
Example #15
Source File: AppendTmxWriter.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 得到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();
		}

	}

}
 
Example #16
Source File: VTDUtils.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 得到当前节点的纯文本。实体不会被转义。若无文本内容返回 null。
 * @exception XPathParseException
 *                ,XPathEvalException,NavException
 */
public String getElementRawPureText() throws XPathParseException, XPathEvalException, NavException {
	String txtNode = "./text()";
	AutoPilot ap = new AutoPilot(vn);
	StringBuilder result = new StringBuilder();
	ap.selectXPath(txtNode);
	int txtIndex = -1;
	while ((txtIndex = ap.evalXPath()) != -1) {
		result.append(vn.toRawString(txtIndex));
	}

	if (result.length() == 0) {
		return null;
	} else {
		return result.toString();
	}
}
 
Example #17
Source File: VTDUtils.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取所有当前元素节点的全部属性。如果当前节点没有属性,返回 null。
 * @param nsPrefix
 *            需声明的名空间前缀,可与XML文件实际前缀不同。
 * @param nsUrl
 *            需声明的名空间地址,必须与 XML 文件中声明的地址一致。
 * @exception XPathEvalException
 *                ,XPathParseException,NavException
 */
public Hashtable<String, String> getCurrentElementAttributs(String nsPrefix, String nsUrl)
		throws XPathParseException, XPathEvalException, NavException {
	Hashtable<String, String> attributes = new Hashtable<String, String>();
	AutoPilot apAttributes = new AutoPilot(vn);
	apAttributes.declareXPathNameSpace(nsPrefix, nsUrl);
	apAttributes.selectXPath("@*");

	int inx = -1;
	while ((inx = apAttributes.evalXPath()) != -1) {
		String name = vn.toString(inx);
		inx = vn.getAttrVal(name);
		String value = inx != -1 ? vn.toString(inx) : "";
		attributes.put(name, value);
	}
	apAttributes.resetXPath();

	if (attributes.isEmpty()) {
		attributes = null;
	}
	return attributes;
}
 
Example #18
Source File: VTDUtils.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 得到当前节点的纯文本。实体会被转义。若无文本内容返回 null。
 * @exception XPathParseException
 *                ,XPathEvalException,NavException
 */
public String getElementPureText() throws XPathParseException, XPathEvalException, NavException {
	String txtNode = "./text()";
	AutoPilot ap = new AutoPilot(vn);
	StringBuilder result = new StringBuilder();
	ap.selectXPath(txtNode);
	int txtIndex = -1;
	boolean isNull = true;
	while ((txtIndex = ap.evalXPath()) != -1) {
		result.append(vn.toString(txtIndex));
		if (isNull) {
			isNull = false;
		}
	}

	return isNull ? null : result.toString();
}
 
Example #19
Source File: ProjectConfiger.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取配置文件中的项目文本字段信息
 * @return
 * @throws XPathParseException
 * @throws XPathEvalException
 * @throws NavException ;
 */
private LinkedHashMap<String, String> getFieldMap() throws XPathParseException, XPathEvalException, NavException {
	AutoPilot ap = new AutoPilot(vu.getVTDNav());
	Map<String, String> mapField = new HashMap<String, String>();
	ap.selectXPath("/projectDescription/hs//fieldList/field");
	while (ap.evalXPath() != -1) {
		String fieldName = TextUtil.stringToXML(vu.getCurrentElementAttribut("name", ""));
		String fieldValue = vu.getElementContent();
		mapField.put(fieldName, fieldValue);
	}
	List<Entry<String, String>> lstAttr = new ArrayList<Entry<String, String>>(mapField.entrySet());
	final Collator collatorChinese = Collator.getInstance(java.util.Locale.CHINA);
	Collections.sort(lstAttr, new Comparator<Entry<String, String>>() {

		public int compare(Entry<String, String> arg0, Entry<String, String> arg1) {
			return collatorChinese.compare(arg0.getKey(), arg1.getKey());
		}
	});
	LinkedHashMap<String, String> linkedMapAttr = new LinkedHashMap<String, String>();
	for (Entry<String, String> entry : lstAttr) {
		linkedMapAttr.put(entry.getKey(), entry.getValue());
	}
	return linkedMapAttr;
}
 
Example #20
Source File: IDML2XLIFF.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 加载 designmap.xml 文件,初始化 lstSpread 和 lstAllStory
 * @throws XPathParseException
 * @throws XPathEvalException
 * @throws NavException
 *             ;
 */
private void initSpreadAllStory(IProgressMonitor monitor) throws XPathParseException, XPathEvalException,
		NavException {
	monitor.beginTask("", 1);
	monitor.subTask(MessageFormat.format(Messages.getString("idml.IDML2XLIFF.task5"), "designmap.xml"));
	VTDGen vg = new VTDGen();
	if (vg.parseZIPFile(strSrcPath, "designmap.xml", true)) {
		VTDNav vn = vg.getNav();
		AutoPilot ap = new AutoPilot(vn);
		ap.declareXPathNameSpace(IDML_PREFIX, IDML_NAMESPACE);
		ap.selectXPath("/Document/node()");
		while (ap.evalXPath() != -1) {
			int curIndex = vn.getCurrentIndex();
			int tokenType = vn.getTokenType(curIndex);
			String name = vn.toString(curIndex);
			// 节点
			if (tokenType == 0) {
				if (name.equals("idPkg:Spread")) {
					String strSpread = vn.toString(vn.getAttrVal("src"));
					lstSpread.add(strSpread);
				} else if (name.equals("idPkg:Story")) {
					String strStory = vn.toString(vn.getAttrVal("src"));
					lstAllStory.add(strStory);
				} else if (name.equals("idPkg:MasterSpread")) {
					String strMasterSpread = vn.toString(vn.getAttrVal("src"));
					lstMasterSpread.add(strMasterSpread);
				}
			}
		}
	}
	monitor.worked(1);
	monitor.done();
}
 
Example #21
Source File: VTDUtilsTest.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testGetElementPureText() throws XPathParseException, XPathEvalException, NavException{
	AutoPilot ap = new AutoPilot(vn);
	ap.selectXPath("//trans-unit[position()=1]/source");
	int inx = ap.evalXPath();
	assertNotSame(-1, inx);
	String txt = vu.getElementPureText();
	assertEquals("This is the first test.", txt);
}
 
Example #22
Source File: XliffUtil.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param xlfFile
 *            XLIFF 文件路径
 * @return VTDUtils
 */
public static VTDUtils getVU(String xlfFile) {
	VTDGen vg = new VTDGen();
	if (vg.parseFile(xlfFile, true)) {
		VTDNav vn = vg.getNav();
		try {
			return new VTDUtils(vn);
		} catch (NavException e) {
			e.printStackTrace();
		}
	}
	return null;
}
 
Example #23
Source File: VTDUtils.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 将一个 VTDNav 实例附加到此 VTDUtils 实例,以便之后发生的所有操作都是基于这个 VTDNav 实例
 * @param masterDocument
 *            VTDNav 实例
 * @throws NavException
 */
public void bind(VTDNav vn) throws NavException {
	if (vn == null) {
		throw new NavException(Messages.getString("vtdimpl.VTDUtils.logger1"));
	}
	this.vn = vn;
}
 
Example #24
Source File: VTDUtilsTest.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testGetElementFragment() throws XPathParseException, XPathEvalException, NavException{
	AutoPilot ap = new AutoPilot(vn);
	ap.selectXPath("/xliff/file/header/tool");
	ap.evalXPath();
	String str = vu.getElementFragment();
	assertEquals(str, "<tool tool-id=\"XLFEditor auto-Quick Translation\" tool-name=\"HSStudio\" />");
}
 
Example #25
Source File: VTDUtils.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 返回当前节点下一级子节点的个数。
 * @return
 * @throws XPathParseException
 * @throws XPathEvalException
 * @throws NavException
 *             ;
 */
public int getChildElementsCount() throws XPathParseException, XPathEvalException, NavException {
	int result = 0;
	AutoPilot ap = new AutoPilot(vn);
	ap.selectXPath("./*");
	vn.push();
	while (ap.evalXPath() != -1) {
		result++;
	}
	vn.pop();
	return result;
}
 
Example #26
Source File: PPTX2XLIFF.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 解析 slideLayoutN.xml 文件,获取坐标值,因为有的幻灯片中节点的坐标是存放在此文件中的
 * @throws NavException
 * @throws XPathParseException
 * @throws XPathEvalException
 */
private void parseSlideLayout() throws NavException, XPathParseException, XPathEvalException {
	File slideLayoutDic = new File(strTmpFolderPath + File.separator + "ppt" + File.separator + "slideLayouts");
	if (slideLayoutDic.isDirectory()) {
		VTDGen vg = new VTDGen();
		AutoPilot ap = new AutoPilot();
		ap.declareXPathNameSpace(PREFIX_A, NAMESPACE_A);
		ap.declareXPathNameSpace(PREFIX_P, NAMESPACE_P);
		VTDUtils vu = new VTDUtils();
		File[] arrSlideLayoutFile = slideLayoutDic.listFiles();
		for (File slideLayoutFile : arrSlideLayoutFile) {
			if (slideLayoutFile.isFile() && slideLayoutFile.getName().toLowerCase().endsWith(".xml")) {
				if (vg.parseFile(slideLayoutFile.getAbsolutePath(), true)) {
					String name = slideLayoutFile.getName();
					VTDNav vn = vg.getNav();
					ap.bind(vn);
					vu.bind(vn);
					ap.selectXPath("/p:sldLayout/p:cSld/p:spTree//p:sp[descendant::p:ph[not(@type='dt') and not(@type='sldNum')]]");
					ArrayList<String[]> lstPH = new ArrayList<String[]>();
					while (ap.evalXPath() != -1) {
						String strType = getElementAttribute(".//p:ph", "type", vn);
						String idx = getElementAttribute(".//p:ph", "idx", vn);
						if (strType == null && idx == null) {
							continue;
						}

						String strX = getElementAttribute(".//a:xfrm/a:off", "x", vn);
						String strY = getElementAttribute(".//a:xfrm/a:off", "y", vn);
						if (strX != null && strY != null) {
							lstPH.add(new String[] { strType, idx, strX, strY });
						}
					}
					if (lstPH.size() > 0) {
						mapSldLayoutPH.put(name, lstPH);
					}
				}
			}
		}
	}
}
 
Example #27
Source File: VTDUtils.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获取所有当前元素节点的全部属性。如果当前节点没有属性,返回 null。
 * @param ns
 *            需声明的名空间,键为地址,必须与 XML 文件中声明的地址一致。值为前缀,可与XML文件实际前缀不同。
 * @exception XPathEvalException
 *                ,XPathParseException,NavException
 */
public Hashtable<String, String> getCurrentElementAttributs(Hashtable<String, String> ns)
		throws XPathParseException, XPathEvalException, NavException {
	Hashtable<String, String> attributes = new Hashtable<String, String>();
	AutoPilot apAttributes = new AutoPilot(vn);
	if (ns != null) {
		Iterator<String> nsIt = ns.keySet().iterator();
		while (nsIt.hasNext()) {
			String nsUrl = nsIt.next();
			String nsPrefix = ns.get(nsUrl);
			apAttributes.declareXPathNameSpace(nsPrefix, nsUrl);
		}
	}

	apAttributes.selectXPath("@*");

	int inx = -1;
	while ((inx = apAttributes.evalXPath()) != -1) {
		String name = vn.toString(inx);
		inx = vn.getAttrVal(name);
		String value = inx != -1 ? vn.toString(inx) : "";
		attributes.put(name, value);
	}
	apAttributes.resetXPath();

	if (attributes.isEmpty()) {
		attributes = null;
	}
	return attributes;
}
 
Example #28
Source File: VTDUtils.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获得指定节点下一级子节点的个数
 * @param xpath
 *            指定节点的 XPath
 * @return
 * @throws XPathParseException
 * @throws XPathEvalException
 * @throws NavException
 *             ;
 */
public int getChildElementsCount(String xpath) throws XPathParseException, XPathEvalException, NavException {
	int result = 0;
	AutoPilot ap = new AutoPilot(vn);
	ap.selectXPath(xpath);
	vn.push();
	if (ap.evalXPath() != -1) {
		result = getChildElementsCount();
	}
	vn.pop();
	return result;
}
 
Example #29
Source File: VTDUtils.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 得到指定节点的完整内容,包含子节点及文本。若无文本内容返回 null。
 * @param xpath
 *            指定节点的XPath。
 * @throws XPathParseException
 * @throws XPathEvalException
 * @throws NavException
 * @exception XPathParseException
 *                ,XPathEvalException,NavException
 */
public String getElementContent(String xpath) throws NavException, XPathParseException, XPathEvalException {
	String text = null;
	if (xpath != null && !xpath.equals("")) {
		AutoPilot ap = new AutoPilot(vn);
		ap.selectXPath(xpath);
		vn.push();
		if (ap.evalXPath() != -1) {
			text = getElementContent();
		}
		vn.pop();
	}
	return text;
}
 
Example #30
Source File: VTDUtils.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获取当前节点下所有指定元素名称的文本内容,含内部标记等子节点内容。
 * @param elementName
 *            子节点名称
 * @return String 指定子节点内容,无内容返回 null。
 * @throws XPathParseException
 * @throws NavException
 * @throws XPathEvalException
 */
public String getChildContent(String elementName) throws XPathParseException, XPathEvalException, NavException {
	String text = null;
	AutoPilot ap = new AutoPilot(vn);
	ap.selectXPath("./" + elementName);
	vn.push();
	if (ap.evalXPath() != -1) {
		text = getElementContent();
	}
	vn.pop();
	return text;
}