use of net.heartsome.cat.ts.ui.docx.common.CommentBean in project translationstudio8 by heartsome.
the class ExportDocx method createComment.
/**
* 生成批注
* @param commentList
* @return
*/
private String createComment(List<CommentBean> commentList) {
StringBuffer rowSB = new StringBuffer();
for (CommentBean bean : commentList) {
rowSB.append("<w:p>");
rowSB.append("<w:pPr><w:rPr>");
rowSB.append(FONTSTR);
rowSB.append("<w:sz w:val=\"22\" />");
rowSB.append("</w:rPr></w:pPr>");
rowSB.append("<w:r>\n");
rowSB.append("<w:fldChar w:fldCharType=\"begin\"/>\n");
rowSB.append("</w:r>\n");
rowSB.append("<w:r>\n");
rowSB.append("<w:rPr>\n");
rowSB.append("<w:webHidden/>\n");
rowSB.append("</w:rPr>\n");
String userAndTimeStr = bean.getUser() + DocxConstant.COMMENT_SPLIT + bean.getTime();
rowSB.append("<w:instrText>" + TextUtil.cleanSpecialString(userAndTimeStr) + "</w:instrText>\n");
rowSB.append("</w:r>\n");
rowSB.append("<w:r>\n");
rowSB.append("<w:fldChar w:fldCharType=\"end\"/>\n");
rowSB.append("</w:r>\n");
rowSB.append("<w:r>");
rowSB.append("<w:rPr>");
rowSB.append(FONTSTR);
rowSB.append("<w:sz w:val=\"22\" /></w:rPr>");
rowSB.append("<w:t xml:space=\"preserve\">" + TextUtil.cleanSpecialString(bean.getText()) + "</w:t>");
rowSB.append("</w:r>");
rowSB.append("</w:p>");
}
if (rowSB.length() <= 0) {
rowSB.append("<w:p>");
rowSB.append("<w:pPr><w:rPr>");
rowSB.append(FONTSTR);
rowSB.append("<w:sz w:val=\"22\" />");
rowSB.append("</w:rPr></w:pPr>");
rowSB.append("<w:r>");
rowSB.append("<w:rPr>");
rowSB.append(FONTSTR);
rowSB.append("<w:sz w:val=\"22\" /></w:rPr>");
rowSB.append("<w:t></w:t>");
rowSB.append("</w:r>");
rowSB.append("</w:p>");
}
return rowSB.toString();
}
use of net.heartsome.cat.ts.ui.docx.common.CommentBean in project translationstudio8 by heartsome.
the class ImportDocxDialog method ananysisStatusAndComment.
/**
* 处理状态以及批注
* @param rowList
*/
private void ananysisStatusAndComment(List<RowBean> rowList) throws Exception {
String rowId = "";
for (RowBean bean : rowList) {
if (bean.isLocked()) {
continue;
}
rowId = bean.getRowId();
if (rowId == null || rowId.length() <= 0) {
continue;
}
int status = -1;
boolean targetNull = true;
ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
if (ap.evalXPath() != -1) {
// 先处理状态
// 检查 target 是否为空
vn.push();
ap.selectXPath("./target[text()!='' or *]");
if (ap.evalXPath() != -1) {
targetNull = false;
}
vn.pop();
// 如果译文为空,那状态应为未翻译,如果译文不为空,那状态应不为未翻译
if (targetNull) {
status = DocxConstant.STATUS_unstrans;
}
setOtherStatus(status);
if (hasComment) {
// 处理批注的问题。
// 首先删除所有批注
vn.push();
ap.selectXPath("./note");
while (ap.evalXPath() != -1) {
xm.remove();
}
StringBuffer commentSB = new StringBuffer();
if (bean.getComment() != null) {
for (CommentBean commentBean : bean.getComment()) {
// <note from='Mac'>2013-05-13:test</note>
commentSB.append("<note from='");
commentSB.append(commentBean.getUser() + "'>");
commentSB.append(commentBean.getTime() + ":" + commentBean.getText());
commentSB.append("</note>");
}
}
vn.pop();
if (commentSB.length() > 0) {
xm.insertBeforeTail(commentSB.toString());
}
}
}
}
}
use of net.heartsome.cat.ts.ui.docx.common.CommentBean in project translationstudio8 by heartsome.
the class ExportDocxDialog method getComments.
/**
* 获取批注
* @param vn
* @param bean
*/
private void getComments(VTDNav vn, VTDUtils vu, TUBean bean) throws Exception {
vn.push();
List<CommentBean> commentList = new ArrayList<CommentBean>();
otherAP.selectXPath("./note");
String content = "";
String user = "";
String time = "";
String text = "";
int index = -1;
while (otherAP.evalXPath() != -1) {
// <note from='Mac'>2013-05-13:test</note>
if ((index = vn.getAttrVal("from")) != -1) {
user = vn.toString(index);
}
content = vu.getElementContent();
if (content == null || content.length() <= 0) {
continue;
}
if ((index = content.indexOf(":")) != -1) {
time = content.substring(0, index);
text = content.substring(index + 1, content.length());
} else {
text = content;
}
commentList.add(new CommentBean(user, time, text));
}
bean.setComment(commentList);
vn.pop();
}
use of net.heartsome.cat.ts.ui.docx.common.CommentBean in project translationstudio8 by heartsome.
the class ImportDocx method getComments.
/**
* 获取批注相关信息
* @param bean
* @throws Exception
*/
private void getComments(RowBean bean) throws Exception {
vn.push();
StringBuffer commentTextSB = new StringBuffer();
StringBuffer userTimeSB = new StringBuffer();
String user = "";
String time = "";
commentAP.selectXPath("./descendant::w:p");
List<CommentBean> commentList = new ArrayList<CommentBean>();
while (commentAP.evalXPath() != -1) {
commentTextSB = new StringBuffer();
userTimeSB = new StringBuffer();
user = "";
time = "";
extendAP.selectXPath("./descendant::w:r");
boolean isUserAndTime = false;
String text = "";
int index = -1;
while (extendAP.evalXPath() != -1) {
vn.push();
otherAP.selectXPath("./w:fldChar");
if (otherAP.evalXPath() != -1) {
if ((index = vn.getAttrVal("w:fldCharType")) != -1) {
if ("begin".equals(vn.toString(index))) {
isUserAndTime = true;
} else if ("end".equals(vn.toString(index))) {
isUserAndTime = false;
}
}
}
vn.pop();
vn.push();
otherAP.selectXPath("./w:t|w:instrText");
if (otherAP.evalXPath() != -1) {
if ((index = vn.getText()) != -1) {
text = vn.toRawString(index);
if (isUserAndTime) {
userTimeSB.append(text);
} else {
commentTextSB.append(text);
}
}
}
vn.pop();
}
if (commentTextSB.toString().trim().length() > 0) {
if ((index = userTimeSB.toString().indexOf(DocxConstant.COMMENT_SPLIT)) != -1) {
user = userTimeSB.toString().substring(0, index);
user = TextUtil.resetSpecialString(user);
time = userTimeSB.toString().substring(index + 1, userTimeSB.length());
time = TextUtil.resetSpecialString(time);
}
if (user.length() <= 0) {
user = System.getProperty("user.name");
}
if (time.length() <= 0) {
time = DateUtils.getStringDateShort();
}
commentList.add(new CommentBean(user, time, TextUtil.resetSpecialString(commentTextSB.toString())));
}
}
bean.setComment(commentList);
vn.pop();
}
Aggregations