Java Code Examples for com.ximpleware.VTDGen#parseZIPFile()
The following examples show how to use
com.ximpleware.VTDGen#parseZIPFile() .
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: ExportConfig.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * sdl 双语样式。 * @throws ExportExternalException * 模板错误或者程序内部错误 */ private void addSDLStyle() throws ExportExternalException { VTDGen vg = new VTDGen(); if (!vg.parseZIPFile(templateDocxFile, "word/styles.xml", true)) { throw new ExportExternalException(Messages.getString("ExportExternal.error.templateError")); } VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.declareXPathNameSpace("w", ExportExternal.NAMESPACE_W); String styleCode = "<w:style w:type=\"character\" w:customStyle=\"1\" w:styleId=\"tw4winMark\"><w:name w:val=\"tw4winMark\"/>" + "<w:rPr><w:rFonts w:ascii=\"Courier New\" w:hAnsi=\"Courier New\" w:cs=\"Courier New\"/><w:vanish/><w:color w:val=\"800080\"/>" + "</w:rPr></w:style>\n"; String styleCode_tag = "<w:style w:type=\"character\" w:styleId=\"Tag\" w:customStyle=\"true\">" + "<w:name w:val=\"Tag\"/><w:basedOn w:val=\"DefaultParagraphFont\"/><w:uiPriority w:val=\"1\"/><w:qFormat/><w:rPr><w:i/><w:color w:val=\"FF0066\"/></w:rPr></w:style>"; String rowidStyle = "<w:style w:type=\"character\" w:styleId=\"HSRow\" w:customStyle=\"true\">" + "<w:name w:val=\"HSRow\" />" + "<w:rPr><w:rFonts w:ascii=\"Consolas\"/><w:color w:val=\"0070C0\"/><w:b /></w:rPr></w:style>"; try { ap.selectXPath("/w:styles/w:style[last()]"); if (ap.evalXPath() != -1) { XMLModifier xm = new XMLModifier(vn); xm.insertAfterElement(styleCode + styleCode_tag + rowidStyle); xm.output(tmpUnzipFolder + "/word/styles.xml"); } } catch (Exception e) { LOGGER.error("", e); throw new ExportExternalException(e.getMessage(), e); } }
Example 2
Source File: ExportConfig.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
private void writeDocumentxml(XliffBean bean) throws ExportExternalException { VTDGen vg = new VTDGen(); if (!vg.parseZIPFile(templateDocxFile, "word/document.xml", true)) { canceled(); throw new ExportExternalException(Messages.getString("ExportExternal.error.templateError")); } try { VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.declareXPathNameSpace("w", ExportExternal.NAMESPACE_W); ap.selectXPath("/w:document"); if (ap.evalXPath() == -1) { throw new ExportExternalException(Messages.getString("ExportExternal.error.templateError")); } long l = vn.getElementFragment(); int dOffset = (int) l; int dLength = (int) (l >> 32); ap.selectXPath("/w:document/w:body/w:p"); if (ap.evalXPath() == -1) { // we should write in body!! canceled(); throw new ExportExternalException(Messages.getString("ExportExternal.error.templateError")); } else { l = vn.getElementFragment(); int offset = (int) l; int length = (int) (l >> 32); String str = vn.toString(0, length + offset); docxmlWriter.write(str); doc_end_fragment = vn.toString(length + offset, dOffset + dLength - offset - length); } //we should export some info about this unclean } catch (Exception e) { LOGGER.error("", e); canceled(); throw new ExportExternalException(e.getMessage(), e); } }
Example 3
Source File: IDML2XLIFF.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * 加载 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 4
Source File: Tmx2Docx.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public StyleXml(String template) throws Exception { VTDGen vg = new VTDGen(); vg.parseZIPFile(template, "word/styles.xml", true); vn = vg.getNav(); ap = new AutoPilot(vn); ap.declareXPathNameSpace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); try { xm = new XMLModifier(vn); } catch (ModifyException e) { Exception e1 = new Exception(Messages.getString("converter.tmx2docx.template.notfound")); throw e1; } }
Example 5
Source File: IDML2XLIFF.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * 加载 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 6
Source File: ImportExternalDialog.java From translationstudio8 with GNU General Public License v2.0 | votes |
private int testUncelan(String path) { VTDGen vg = new VTDGen(); if (!vg.parseZIPFile(path, "word/styles.xml", true)) { alertParseError(path); return -2; } VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.declareXPathNameSpace("w", ExportExternal.NAMESPACE_W); try { ap.selectXPath("/w:styles/w:style[@w:styleId=\"tw4winMark\"]"); } catch (XPathParseException e) { LOGGER.error("", e); return -2; } return ap.evalXPathToBoolean() ? ExportExternal.EXPORT_SDLUNCLEAN : -1; }
Example 7
Source File: ImportExternalDialog.java From translationstudio8 with GNU General Public License v2.0 | votes |
private int testHsproof(String path) { StringBuilder builder = new StringBuilder(); // hs proof VTDGen vg = new VTDGen(); if (!vg.parseZIPFile(path, "word/document.xml", true)) { alertParseError(path); return -2; } VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); AutoPilot _ap = new AutoPilot(vn); ap.declareXPathNameSpace("w", ExportExternal.NAMESPACE_W); _ap.declareXPathNameSpace("w", ExportExternal.NAMESPACE_W); try { ap.selectXPath("count(/w:document/w:body/w:tbl/w:tr[1]/w:tc)"); if (!ap.evalXPathToBoolean()) { return -1; } ap.selectXPath("/w:document/w:body/descendant::w:r"); boolean inBegin = false; while (ap.evalXPath() != -1) { if (inBegin) { vn.push(); _ap.selectXPath("./w:instrText/text()"); while (_ap.evalXPath() != -1) { builder.append(vn.toString(vn.getCurrentIndex())); } vn.pop(); _ap.selectXPath("./w:fldChar[@w:fldCharType='end']"); if (_ap.evalXPathToBoolean()) { if (builder.toString().trim().contains(DocxConstant.HSDOCX_FLAG)) { return ExportExternal.EXPORT_HSPROOF; } else { builder.setLength(0); } } } else { _ap.selectXPath("./w:fldChar[@w:fldCharType='begin']"); inBegin = _ap.evalXPathToBoolean(); if (inBegin) { vn.push(); _ap.selectXPath("./w:instrText/text()"); while (_ap.evalXPath() != -1) { builder.append(vn.toString(vn.getCurrentIndex())); } vn.pop(); } } } } catch (Exception e) { LOGGER.error("", e); return -2; } return -1; }