use of net.heartsome.cat.database.tmx.LanguageTMX in project translationstudio8 by heartsome.
the class DBOperator method getConcordanceSearchResult.
// TODO ======================匹配相关(结束) ======================//
/**
* 执行相关搜索
* @param strSearch
* 搜索文本
* @param isCaseSensitive
* 是否区分大小写
* @param isApplyRegular
* 是否使用正则表达式
* @param isIgnoreMark
* 是否忽略标记
* @param strLang
* 源语言
* @param lstLangs
* 语言集合(包括源语言)
* @param startIndex
* 开始行号
* @param intMax
* 最大查找结果数
* @return ;
*/
public List<ConcordanceBean> getConcordanceSearchResult(String strSearch, boolean isCaseSensitive, boolean isApplyRegular, boolean isIgnoreMark, String strLang, List<String> lstLangs, List<Integer> subList) {
String sql = getTMSearchSql(dbConfig.getOperateDbSQL("search-Corcondance"), isIgnoreMark, lstLangs, subList);
if (sql == null) {
return null;
}
List<ConcordanceBean> lstConcordance = new ArrayList<ConcordanceBean>();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
ArrayList<Integer> lstTuId = new ArrayList<Integer>();
while (rs.next()) {
Integer tuId = rs.getInt("TUID");
if (lstTuId.contains(tuId)) {
ConcordanceBean bean = lstConcordance.get(lstTuId.indexOf(tuId));
LanguageTMX lang = new LanguageTMX();
lang.setLanguageCode(rs.getString("LANG"));
lang.setText(rs.getString("TMTEXT"));
bean.getLanguageList().add(lang);
} else {
lstTuId.add(tuId);
ConcordanceBean bean = new ConcordanceBean();
bean.setId(tuId);
bean.setCreationId(rs.getString("CREATIONID"));
String creationDate = "";
Timestamp tempCreationDate = rs.getTimestamp("CREATIONDATE");
if (tempCreationDate != null) {
creationDate = DateUtils.formatLongTime(tempCreationDate.getTime(), "yyyy-MM-dd HH:mm:ss");
}
bean.setCreationDate(creationDate);
bean.setChangeId(rs.getString("CHANGEID"));
String changeDate = "";
Timestamp tempChangeDate = rs.getTimestamp("CHANGEDATE");
if (tempChangeDate != null) {
changeDate = DateUtils.formatLongTime(tempChangeDate.getTime(), "yyyy-MM-dd HH:mm:ss");
}
bean.setChangeDate(changeDate);
bean.setBlnIsFlag(rs.getString("MPPKID") != null);
List<LanguageTMX> lstLang = new ArrayList<LanguageTMX>();
LanguageTMX lang = new LanguageTMX();
lang.setLanguageCode(rs.getString("LANG"));
lang.setText(rs.getString("TMTEXT"));
lstLang.add(lang);
bean.setLanguageList(lstLang);
bean.setAttributeList(getTuMprops(tuId, "TU"));
lstConcordance.add(bean);
}
}
} catch (SQLException e) {
LOGGER.error("", e);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
LOGGER.error("", e);
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
return lstConcordance;
}
use of net.heartsome.cat.database.tmx.LanguageTMX in project translationstudio8 by heartsome.
the class ConcordanceSearchDialog method createItem.
/**
* 向表格中添加记录
* @param metaData
* @param map
* ;
*/
private void createItem(MetaData metaData, ConcordanceBean bean, int rowNum, HashMap<IRow, ArrayList<int[]>> mapStyle) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", String.valueOf(bean.getId()));
map.put("changeDate", bean.getChangeDate());
map.put("changeId", bean.getChangeId());
map.put("creationDate", bean.getCreationDate());
map.put("creationId", bean.getCreationId());
map.put("flag", bean.isBlnIsFlag() ? "1" : "0");
for (LanguageTMX lang : bean.getLanguageList()) {
map.put(lang.getLanguageCode(), lang.getText());
}
map.put("dbName", metaData.getDatabaseName());
map.put("dbType", metaData.getDbType());
map.put("severName", metaData.getServerName());
List<TmxProp> lstAttr = bean.getAttributeList();
StringBuffer sbAttr = new StringBuffer();
ArrayList<int[]> lstAttrIndex = new ArrayList<int[]>();
for (TmxProp attr : lstAttr) {
if (attr.getName() != null && !attr.getName().trim().equals("") && !attr.getName().equals("x-flag")) {
String attrName = TextUtil.xmlToString(attr.getName());
int index = attrName.indexOf("::");
if (index != -1) {
attrName = attrName.substring(index + 2, attrName.length());
}
sbAttr.append(" ").append(attrName).append(Messages.getString("dialog.ConcordanceSearchDialog.colon"));
int startIndex = sbAttr.length();
sbAttr.append(TextUtil.xmlToString(attr.getValue()));
int endIndex = sbAttr.length();
lstAttrIndex.add(new int[] { startIndex, endIndex });
}
}
String creationDate = checkString(bean.getCreationDate());
String creationId = checkString(bean.getCreationId());
String changeDate = checkString(bean.getChangeDate());
String changeId = checkString(bean.getChangeId());
String attribute = MessageFormat.format(strMsg, creationDate, creationId, changeDate, changeId, sbAttr.toString());
ArrayList<int[]> lstFieldIndex = new ArrayList<int[]>();
int creationStart = attribute.indexOf(creationDate);
lstFieldIndex.add(new int[] { creationStart, creationStart + creationDate.length() });
int creationIdStart = attribute.indexOf(creationId, creationStart);
lstFieldIndex.add(new int[] { creationIdStart, creationIdStart + creationId.length() });
int changeDateStart = attribute.indexOf(changeDate, creationIdStart);
lstFieldIndex.add(new int[] { changeDateStart, changeDateStart + changeDate.length() });
int changeIdStart = attribute.indexOf(changeId, changeDateStart);
lstFieldIndex.add(new int[] { changeIdStart, changeIdStart + changeId.length() });
if (lstAttrIndex.size() > 0) {
int index = attribute.indexOf(sbAttr.toString());
for (int[] attrIndex : lstAttrIndex) {
lstFieldIndex.add(new int[] { attrIndex[0] + index, attrIndex[1] + index });
}
}
String source = map.get(strSrcLang) == null ? "" : map.get(strSrcLang);
StringBuffer sourceBf = new StringBuffer(source);
TreeMap<String, InnerTagBean> sourceTags = InnerTagUtil.parseXmlToDisplayValue(sourceBf, TagStyle.getDefault(false));
source = InnerTagUtil.resolveTag(sourceBf.toString());
source = InnerTagUtil.parseDisplayToXmlValue(sourceTags, source);
String target = map.get(strTgtLang) == null ? "" : map.get(strTgtLang);
StringBuffer tgtBf = new StringBuffer(target);
TreeMap<String, InnerTagBean> tgtTags = InnerTagUtil.parseXmlToDisplayValue(tgtBf, TagStyle.getDefault(false));
target = InnerTagUtil.resolveTag(tgtBf.toString());
target = InnerTagUtil.parseDisplayToXmlValue(tgtTags, target);
ArrayList<String> lstTarget = new ArrayList<String>();
for (String lang : lstLangs) {
String _tgt = map.get(lang);
_tgt = _tgt == null ? "" : _tgt;
StringBuffer _tgtBf = new StringBuffer(_tgt);
TreeMap<String, InnerTagBean> _tgtTags = InnerTagUtil.parseXmlToDisplayValue(_tgtBf, TagStyle.getDefault(false));
_tgt = InnerTagUtil.resolveTag(_tgtBf.toString());
_tgt = InnerTagUtil.parseDisplayToXmlValue(_tgtTags, _tgt);
lstTarget.add(_tgt);
}
try {
if (tableModel.getRow(rowNum) == null) {
XPropRow row = new XPropRow(bean.isBlnIsFlag(), source, lstTarget, target, attribute);
row.setDataMap(map);
if (metaData != null) {
row.setData("metaData", metaData);
}
tableModel.addRow(row);
mapStyle.put(row, lstFieldIndex);
} else {
tableModel.setValue(tableModel.getRow(rowNum), tableModel.getColumn(0), bean.isBlnIsFlag());
tableModel.setValue(tableModel.getRow(rowNum), tableModel.getColumn(1), source);
tableModel.setValue(tableModel.getRow(rowNum), tableModel.getColumn(2), target);
int i = 0;
for (; i < lstTarget.size(); i++) {
tableModel.setValue(tableModel.getRow(rowNum), tableModel.getColumn(3 + i), lstTarget.get(i));
}
tableModel.setValue(tableModel.getRow(rowNum), tableModel.getColumn(3 + i), attribute);
XPropRow row = (XPropRow) tableModel.getRow(rowNum);
row.setDataMap(map);
if (metaData != null) {
row.setData("metaData", metaData);
}
mapStyle.put(row, lstFieldIndex);
}
} catch (Exception e) {
XPropRow row = new XPropRow(bean.isBlnIsFlag(), source, lstTarget, target, attribute);
row.setDataMap(map);
if (metaData != null) {
row.setData("metaData", metaData);
}
tableModel.addRow(row);
mapStyle.put(row, lstFieldIndex);
}
}
Aggregations