-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathZkConfigPersistence.java
More file actions
72 lines (62 loc) · 2.08 KB
/
Copy pathZkConfigPersistence.java
File metadata and controls
72 lines (62 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package org.mvnsearch.intellij.plugin.zookeeper;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.Nullable;
/**
* zookeeper configuration persistence
*
* @author linux_china
*/
@State(name = "ZooKeeperConfig", storages = {@Storage(id = "main", file = StoragePathMacros.PROJECT_CONFIG_DIR + "/zookeeper_config.xml")})
public class ZkConfigPersistence implements PersistentStateComponent<ZkConfigPersistence> {
public String host;
public Integer port;
public String charset;
public String whitePaths;
public boolean enabled;
public boolean tooltip;
public static ZkConfigPersistence getInstance(Project project) {
return ServiceManager.getService(project, ZkConfigPersistence.class);
}
@Nullable
@Override
public ZkConfigPersistence getState() {
return this;
}
@Override
public void loadState(ZkConfigPersistence state) {
XmlSerializerUtil.copyBean(state, this);
}
public boolean isAvailable() {
return enabled && StringUtil.isNotEmpty(host);
}
public String getZkUrl() {
if (host.contains(":")) {
return host;
} else if (host.contains(",")) {
return host.replaceAll("[\\s,]+", ":" + port + ",");
} else {
return host + ":" + port;
}
}
public String getFirstServer() {
String zkUrl = getZkUrl();
if (zkUrl.contains(",")) {
return zkUrl.substring(0, zkUrl.indexOf(","));
}
return zkUrl;
}
public String getTitle() {
String zkUrl = getZkUrl();
if (zkUrl.contains(",")) {
return zkUrl.substring(0, zkUrl.indexOf(","));
}
return zkUrl;
}
}