use of java.util.Hashtable in project translationstudio8 by heartsome.
the class TerminologyViewPart method createAction.
/**
* 创建视图工具栏的按钮。
*/
private void createAction() {
firstAction = new Action() {
@Override
public void run() {
if (rowIndex < 0) {
return;
}
if (tempEditor == null || rowIndex < 0) {
return;
}
TransUnitBean transUnit = tempEditor.getRowTransUnitBean(rowIndex);
Hashtable<String, String> tuProp = transUnit.getTuProps();
if (tuProp != null) {
String translate = tuProp.get("translate");
if (translate != null && translate.equalsIgnoreCase("no")) {
MessageDialog.openInformation(getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg1"));
return;
}
}
String tarTerm = "";
GridItem[] items = gridTable.getSelection();
if (items.length <= 0) {
return;
} else {
tarTerm = items[0].getText(2);
}
try {
tempEditor.insertCell(rowIndex, tempEditor.getTgtColumnIndex(), tarTerm);
// tempEditor.setFocus(); // 焦点给回编辑器
} catch (ExecutionException e) {
if (Constant.RUNNING_MODE == Constant.MODE_DEBUG) {
e.printStackTrace();
}
MessageDialog.openInformation(parent.getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg2") + e.getMessage());
}
}
};
firstAction.setText(Messages.getString("view.TerminologyViewPart.menu.inserttermtarget"));
firstAction.setImageDescriptor(Activator.getIconDescriptor(ImageConstants.ACCPTE_TERM));
firstAction.setToolTipText(Messages.getString("view.TerminologyViewPart.firstAction"));
firstAction.setEnabled(false);
//getViewSite().getActionBars().getToolBarManager().add(firstAction);
}
use of java.util.Hashtable in project translationstudio8 by heartsome.
the class TSFileHandler method openFile.
@Override
public Map<String, Object> openFile(File file, int tuCount) {
long start = System.currentTimeMillis();
// 验证文件是否存在
if (file == null || !file.exists()) {
String errorMsg = Messages.getString("file.TSFileHandler.logger5");
logger.error(errorMsg);
return getErrorResult(errorMsg, null);
}
// 判断是否还有缓存空间。
boolean canCache = tuCount < TU_CACHE_SIZE;
// 当前文件中解析并缓存翻译单元计数器。
int parsedTuCount = 0;
// 当前文件未解析缓存的翻译单元计数器。
int noParseTuCount = 0;
String filename = file.getAbsolutePath();
int fileIndex = 1;
// 解析文件并获取索引
VTDGen vgRead = new VTDGen();
if (vgRead.parseFile(filename, true)) {
VTDNav vnRead = vgRead.getNav();
VTDUtils vu = null;
try {
vu = new VTDUtils(vnRead);
// 创建临时文件
File tmpFile = createTmpFile();
XMLModifier xm = new XMLModifier(vnRead);
FileOutputStream fos = new FileOutputStream(tmpFile);
xm.output(fos);
fos.close();
tmpFileMap.put(filename, tmpFile.getAbsolutePath());
filesChangeStatus.put(filename, false);
} catch (ModifyException e) {
String errorMsg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger6"), filename);
logger.error(errorMsg, e);
return getErrorResult(errorMsg, e);
} catch (TranscodeException e) {
String errorMsg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger7"), filename);
logger.error(errorMsg, e);
return getErrorResult(errorMsg, e);
} catch (IOException e) {
String errorMsg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger8"), filename);
logger.error(errorMsg, e);
return getErrorResult(errorMsg, e);
} catch (NavException e) {
String errorMsg = Messages.getString("file.TSFileHandler.logger9");
logger.error(errorMsg, e);
return getErrorResult(errorMsg, e);
}
// 创建翻译单元集合缓存。
Vector<TransUnitBean> tusCache = new Vector<TransUnitBean>();
// 创建翻译单元索引集合缓存。
Vector<String> tuIndexCache = new Vector<String>();
// 初始化文件节点属性集合。
fileAttrs = new Hashtable<Integer, Hashtable<String, String>>();
AutoPilot apFile = new AutoPilot(vnRead);
String fileNode = "/xliff/file";
try {
apFile.selectXPath(fileNode);
while (apFile.evalXPath() != -1) {
fileAttrs.put(fileIndex, vu.getCurrentElementAttributs());
AutoPilot apTU = new AutoPilot(vnRead);
apTU.selectXPath("body//trans-unit");
vnRead.push();
while (apTU.evalXPath() != -1) {
// 如果缓冲区未满,则解析文件内容并缓存,否则只计数,不解析内容。
if (canCache) {
String tuid = "";
String srcText = "";
String srcContent = "";
String tgtText = "";
String tgtContent = "";
Hashtable<String, String> srcProps = null;
Hashtable<String, String> tgtProps = null;
// 取翻译单元所有属性
String tmpNode = "";
vnRead.push();
Hashtable<String, String> tuProps = vu.getCurrentElementAttributs();
vnRead.pop();
tuid = tuProps.get("id");
// 取翻译单元源节点完整文本,含内部标记。
vnRead.push();
tmpNode = "./source";
srcContent = vu.getElementContent(tmpNode);
// vnRead.pop();
// 取翻译单元源文本。
// vnRead.push();
srcText = vu.getElementPureText();
// 取翻译单元源节点属性。
srcProps = vu.getCurrentElementAttributs();
vnRead.pop();
// 取翻译单元目标节点完整文本,含内部标记。
vnRead.push();
tmpNode = "./target";
tgtContent = vu.getElementContent(tmpNode);
// vnRead.pop();
// 取翻译单元目标文本。
// vnRead.push();
tgtText = vu.getElementPureText();
// 取翻译单元目标节点属性。
tgtProps = vu.getCurrentElementAttributs();
vnRead.pop();
// 获取所有的 alttrans 匹配节点。
vnRead.push();
Vector<AltTransBean> matches = getAltTrans(vu);
vnRead.pop();
// 构建翻译单元对象,存储节点信息
TransUnitBean tub = new TransUnitBean(tuid, srcContent, srcText);
tub.setTuProps(tuProps);
tub.setSrcProps(srcProps);
tub.setTgtContent(tgtContent);
tub.setTgtText(tgtText);
tub.setTgtProps(tgtProps);
tub.setMatches(matches);
vnRead.push();
tub.setNotes(getNotes(vu));
vnRead.pop();
vnRead.push();
tub.setPropgroups(getPrpoGroups(vu));
vnRead.pop();
tusCache.add(tub);
tuIndexCache.add(filename + ";" + fileIndex + ";" + tuid);
// 解析的翻译单元节点计数
parsedTuCount++;
if (tuCount + parsedTuCount == TU_CACHE_SIZE) {
canCache = false;
}
} else {
// 未解析的翻译单元节点计数
noParseTuCount++;
}
}
vnRead.pop();
// 文件节点索引计数
fileIndex++;
}
transunits.put(filename, tusCache);
tuIndexs.put(filename, tuIndexCache);
actualTuCount.put(filename, parsedTuCount + noParseTuCount);
accessHistory.put(filename, "");
} catch (XPathEvalException e) {
String errorMsg = Messages.getString("file.TSFileHandler.logger10");
logger.error(errorMsg, e);
return getErrorResult(errorMsg, e);
} catch (NavException e) {
String errorMsg = Messages.getString("file.TSFileHandler.logger11");
logger.error(errorMsg, e);
return getErrorResult(errorMsg, e);
} catch (XPathParseException e) {
String errorMsg = Messages.getString("file.TSFileHandler.logger12");
logger.error(errorMsg, e);
return getErrorResult(errorMsg, e);
}
} else {
String errorMsg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger13"), filename);
logger.error(errorMsg);
return getErrorResult(errorMsg, null);
}
long end = System.currentTimeMillis();
// 输出结果
long resultMS = end - start;
long resultS = resultMS / 1000;
long resultM = resultMS / (1000 * 60);
System.gc();
logger.info(Messages.getString("file.TSFileHandler.logger14"), new Object[] { resultM, resultS, resultMS });
Map<String, Object> result = getSuccessResult();
result.put("CurCachedTuCount", Integer.valueOf(parsedTuCount));
result.put("TotalCachedTuCount", Integer.valueOf(parsedTuCount + tuCount));
return result;
}
use of java.util.Hashtable in project translationstudio8 by heartsome.
the class XLFHandler method getNodeAttributes.
/**
* 获取指定xpath节点的所有属性,如果没有属性,则返回null
* @param xlfPath
* @param nodeXpath
* @return ;
*/
public Hashtable<String, String> getNodeAttributes(String xlfPath, String nodeXpath) {
Hashtable<String, String> attributes = new Hashtable<String, String>();
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
AutoPilot ap = new AutoPilot(vn);
VTDUtils vu = new VTDUtils(vn);
ap.selectXPath(nodeXpath);
while (ap.evalXPath() != -1) {
attributes = vu.getCurrentElementAttributs();
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
return attributes;
}
use of java.util.Hashtable in project camel by apache.
the class CamelKarafTestSupport method getJMXConnector.
public JMXConnector getJMXConnector(String userName, String passWord) throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/karaf-root");
Hashtable<String, Object> env = new Hashtable<>();
String[] credentials = new String[] { userName, passWord };
env.put("jmx.remote.credentials", credentials);
JMXConnector connector = JMXConnectorFactory.connect(url, env);
return connector;
}
use of java.util.Hashtable in project camel by apache.
the class Activator method updateAvailableScriptLanguages.
private void updateAvailableScriptLanguages() {
ServiceReference<LanguageResolver> ref = null;
try {
Collection<ServiceReference<LanguageResolver>> references = context.getServiceReferences(LanguageResolver.class, "(resolver=default)");
if (references.size() == 1) {
// Unregistry the old language resolver first
if (registration != null) {
registration.unregister();
registration = null;
}
ref = references.iterator().next();
LanguageResolver resolver = context.getService(ref);
Dictionary props = new Hashtable();
// Just publish the language resolve with the language we found
props.put("language", getAvailableScriptNames());
registration = context.registerService(LanguageResolver.class, resolver, props);
}
} catch (InvalidSyntaxException e) {
LOG.error("Invalid syntax for LanguageResolver service reference filter.");
} finally {
if (ref != null) {
context.ungetService(ref);
}
}
}
Aggregations