use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.
the class DBParameter method saveDatabases.
/**
*
* Save added database to plug-in preference
*
*/
public void saveDatabases() {
synchronized (this) {
XMLMemento memento = XMLMemento.createWriteRoot("databases");
for (DBParameter dbParameter : databaseMap.values()) {
String dbName = StringUtils.defaultString(dbParameter.getDbName());
String address = StringUtils.defaultString(dbParameter.getHostAddress());
String port = StringUtils.defaultString(dbParameter.getMonPort());
String dbUser = StringUtils.defaultString(dbParameter.getDBUser());
String password = StringUtils.defaultString(dbParameter.getPassword());
String jdbcAttrs = StringUtils.defaultString(dbParameter.getJdbcAttrs());
boolean savePassword = dbParameter.isSavePassword();
IXMLMemento child = memento.createChild("database");
child.putString("dbUser", dbUser);
child.putString("dbName", dbName);
child.putString("address", address);
child.putString("port", port);
child.putString("dbPassword", CipherUtils.encrypt(password));
child.putString("savePassword", String.valueOf(savePassword));
child.putString("jdbcAttrs", jdbcAttrs);
DatabaseEditorConfig editorConfig = QueryOptions.getEditorConfig(dbUser, dbName, address, port, null, true);
if (editorConfig != null) {
IXMLMemento editorConfigChild = child.createChild("editorConfig");
editorConfigChild.putString("database-comment", editorConfig.getDatabaseComment() == null ? "" : editorConfig.getDatabaseComment());
if (editorConfig.getBackGround() != null) {
RGB background = editorConfig.getBackGround();
int bgPos = EditorConstance.getBGPos(background);
editorConfigChild.putInteger("purpose-code", bgPos);
}
}
}
PersistUtils.saveXMLMemento(ApplicationUtil.CM_UI_PLUGIN_ID, DATABASE_XML_CONTENT, memento);
}
}
use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.
the class CMGroupNodePersistManager method loadGroupNode.
/**
* Load group nodes from local preference.
*
*/
private void loadGroupNode() {
synchronized (this) {
IXMLMemento memento = PersistUtils.getXMLMemento(ApplicationUtil.CM_UI_PLUGIN_ID, COM_CUBRID_MANAGER_HOSTGROUP);
loadGroupNode(memento);
}
}
use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.
the class CMGroupNodePersistManager method loadGroupNode.
/**
* Load group nodes from xml memento.
*
* @param memento IXMLMemento
*
*/
private void loadGroupNode(IXMLMemento memento) {
IXMLMemento[] children = memento == null ? null : memento.getChildren("group");
groupNodeList.clear();
for (int i = 0; children != null && i < children.length; i++) {
String id = children[i].getString("id");
String name = children[i].getString("name");
CubridGroupNode cgn = getGroupById(id);
if (cgn == null) {
cgn = new CubridGroupNode(id, name, DEFAULT_GROUP_NODE.getIconPath());
groupNodeList.add(cgn);
}
cgn.setLoader(DEFAULT_GROUP_NODE.getLoader());
IXMLMemento[] items = children[i].getChildren("item");
for (IXMLMemento item : items) {
String itemId = item.getString("id");
CubridServer cs = CMHostNodePersistManager.getInstance().getServer(itemId);
if (cs == null) {
continue;
}
cgn.addChild(cs);
}
}
//groupNodeList.size >=1
if (groupNodeList.isEmpty()) {
try {
groupNodeList.add((CubridGroupNode) DEFAULT_GROUP_NODE.clone());
List<CubridServer> servers = CMHostNodePersistManager.getInstance().getAllServers();
for (CubridServer server : servers) {
groupNodeList.get(0).addChild(server);
}
} catch (CloneNotSupportedException e) {
LOGGER.error(e.getMessage());
}
}
}
use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.
the class CMHostNodePersistManager method loadSevers.
/**
*
* Load added host from plugin preference
*
*/
protected void loadSevers() {
synchronized (this) {
// serverList.clear();
boolean isHasLocalHost = false;
boolean alreadyAddedLocalhostDefault = false;
IXMLMemento memento = PersistUtils.getXMLMemento(ApplicationUtil.CM_UI_PLUGIN_ID, SERVER_XML_CONTENT);
// For compatible for the version before 8.4.0
URL url = Platform.getInstanceLocation().getURL();
File file = new File(url.getFile());
String optionsPath = file.getAbsolutePath() + File.separator + ".metadata" + File.separator + ".plugins" + File.separator + "org.eclipse.core.runtime" + File.separator + ".settings" + File.separator;
//Load global preference setting
QueryOptions.load(optionsPath, null);
if (memento != null) {
alreadyAddedLocalhostDefault = memento.getBoolean("alreadyAddedLocalhostDefault");
}
isHasLocalHost = loadServers(memento, true, optionsPath);
if (!isHasLocalHost && !alreadyAddedLocalhostDefault) {
String id = "localhost";
String name = "localhost";
int port = 8001;
String userName = "admin";
ServerInfo serverInfo = new ServerInfo();
serverInfo.setServerName(name);
serverInfo.setHostAddress(name);
serverInfo.setHostMonPort(port);
serverInfo.setHostJSPort(port + 1);
serverInfo.setUserName(userName);
serverInfo.setUserPassword("");
CubridServer server = new CubridServer(id, name, "icons/navigator/host.png", "icons/navigator/host_connected.png");
server.setServerInfo(serverInfo);
server.setType(NodeType.SERVER);
server.setLoader(new CubridServerLoader());
serverList.add(0, server);
ServerManager.getInstance().addServer(serverInfo.getHostAddress(), serverInfo.getHostMonPort(), serverInfo.getUserName(), serverInfo);
/*Save the server list*/
saveServers();
}
}
}
use of com.cubrid.cubridmanager.core.common.xml.IXMLMemento in project cubrid-manager by CUBRID.
the class CMHostNodePersistManager method loadSevers.
/**
*
* Load added host from preference file path
*
* @param workspacePath String
* @return boolean whether import
*
*/
public boolean loadSevers(String workspacePath) {
synchronized (this) {
String settingPath = workspacePath + File.separator + ".metadata" + File.separator + ".plugins" + File.separator + "org.eclipse.core.runtime" + File.separator + ".settings" + File.separator;
//Load global preference setting
QueryOptions.load(settingPath, null);
String serverPath = settingPath + File.separator + "com.cubrid.cubridmanager.ui.prefs";
PreferenceStore preference = new PreferenceStore(serverPath);
int size = serverList.size();
try {
preference.load();
String xmlString = preference.getString(SERVER_XML_CONTENT);
if (xmlString == null || xmlString.trim().length() == 0) {
return false;
}
ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
IXMLMemento memento = XMLMemento.loadMemento(in);
loadServers(memento, true, settingPath);
} catch (IOException e) {
LOGGER.error(e.getMessage());
}
boolean isImported = size != serverList.size();
if (isImported) {
saveServers();
}
return isImported;
}
}
Aggregations