summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/cmscore
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-09-19 10:15:02 -0400
committerEndi S. Dewata <edewata@redhat.com>2013-09-20 12:37:08 -0400
commit5874cad1abe832a4a74cb37a4c22f0e18cf9bd8e (patch)
treead0e88129530f4abcfb588a516c17ab5e0573eb9 /base/common/src/com/netscape/cmscore
parent4c17e821a99318a1cf62ca0862ce9ee404ea5f6a (diff)
downloadpki-5874cad1abe832a4a74cb37a4c22f0e18cf9bd8e.tar.gz
pki-5874cad1abe832a4a74cb37a4c22f0e18cf9bd8e.tar.xz
pki-5874cad1abe832a4a74cb37a4c22f0e18cf9bd8e.zip
Added TPS config resource.
A new REST service and clients have been added to manage the TPS configuration in CS.cfg. When the configuration is updated, the previous configuration will be stored as a backup. Ticket #652
Diffstat (limited to 'base/common/src/com/netscape/cmscore')
-rw-r--r--base/common/src/com/netscape/cmscore/base/FileConfigStore.java63
-rw-r--r--base/common/src/com/netscape/cmscore/base/PropConfigStore.java73
2 files changed, 38 insertions, 98 deletions
diff --git a/base/common/src/com/netscape/cmscore/base/FileConfigStore.java b/base/common/src/com/netscape/cmscore/base/FileConfigStore.java
index a91acdbcb..b77f86d78 100644
--- a/base/common/src/com/netscape/cmscore/base/FileConfigStore.java
+++ b/base/common/src/com/netscape/cmscore/base/FileConfigStore.java
@@ -24,8 +24,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
-import java.util.Enumeration;
-import java.util.Vector;
+import java.util.Map;
import com.netscape.certsrv.apps.CMS;
import com.netscape.certsrv.base.EBaseException;
@@ -157,66 +156,20 @@ public class FileConfigStore extends PropConfigStore implements
*/
public void save(String fileName) throws EBaseException {
try {
+ Map<String, String> map = getProperties();
+
FileOutputStream fo = new FileOutputStream(fileName);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(fo));
- printSubStore(writer, this, "");
+ for (String name : map.keySet()) {
+ String value = map.get(name);
+ writer.println(name + "=" + value);
+ }
+
writer.close();
fo.close();
} catch (IOException e) {
throw new EBaseException("output stream error " + fileName, e);
}
}
-
- private void printSubStore(PrintWriter writer, IConfigStore store,
- String name) throws EBaseException,
- IOException {
- // print keys
- Enumeration<String> e0 = store.getPropertyNames();
- Vector<String> v = new Vector<String>();
-
- while (e0.hasMoreElements()) {
- v.addElement(e0.nextElement());
- }
-
- // sorting them lexicographically
- while (v.size() > 0) {
- String pname = v.firstElement();
- int j = 0;
-
- for (int i = 1; i < v.size(); i++) {
- String s = v.elementAt(i);
-
- if (pname.compareTo(s) > 0) {
- j = i;
- pname = v.elementAt(i);
- }
- }
- v.removeElementAt(j);
- writer.println(name + pname + "=" + store.getString(pname));
- }
-
- // print substores
- Enumeration<String> e1 = store.getSubStoreNames();
-
- while (e1.hasMoreElements()) {
- v.addElement(e1.nextElement());
- }
- while (v.size() > 0) {
- String pname = v.firstElement();
- int j = 0;
-
- for (int i = 1; i < v.size(); i++) {
- String s = v.elementAt(i);
-
- if (pname.compareTo(s) > 0) {
- j = i;
- pname = v.elementAt(i);
- }
- }
- v.removeElementAt(j);
- printSubStore(writer, store.getSubStore(pname), name +
- pname + ".");
- }
- }
}
diff --git a/base/common/src/com/netscape/cmscore/base/PropConfigStore.java b/base/common/src/com/netscape/cmscore/base/PropConfigStore.java
index 161f549f2..eb3f6c312 100644
--- a/base/common/src/com/netscape/cmscore/base/PropConfigStore.java
+++ b/base/common/src/com/netscape/cmscore/base/PropConfigStore.java
@@ -26,6 +26,8 @@ import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.Map;
+import java.util.TreeMap;
import java.util.Vector;
import org.mozilla.jss.util.Base64OutputStream;
@@ -138,7 +140,7 @@ public class PropConfigStore implements IConfigStore, Cloneable {
* @param name property name
* @return property value
*/
- private Object nakedGet(String name) {
+ private String nakedGet(String name) {
return mSource.get(name);
}
@@ -172,42 +174,39 @@ public class PropConfigStore implements IConfigStore, Cloneable {
* @see java.util.Enumeration
*/
public Enumeration<String> keys() {
- Hashtable<String, Object> h = new Hashtable<String, Object>();
-
+ Hashtable<String, String> h = new Hashtable<String, String>();
enumerate(h);
return h.keys();
}
/**
- * Retrieves the hashtable where all the properties are kept.
+ * Retrieves lexicographically sorted properties as a map.
*
- * @return hashtable
+ * @return map
*/
- public Hashtable<String, Object> hashtable() {
- Hashtable<String, Object> h = new Hashtable<String, Object>();
-
- enumerate(h);
- return h;
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new TreeMap<String, String>();
+ enumerate(map);
+ return map;
}
/**
* Return the number of items in this substore
*/
public int size() {
- Hashtable<String, Object> h = new Hashtable<String, Object>();
-
+ Hashtable<String, String> h = new Hashtable<String, String>();
enumerate(h);
return h.size();
}
/**
- * Fills the given hash table with all key/value pairs in the current
+ * Fills the given map with all key/value pairs in the current
* config store, removing the config store name prefix
* <P>
*
- * @param h the hashtable
+ * @param map the map
*/
- private synchronized void enumerate(Hashtable<String, Object> h) {
+ private synchronized void enumerate(Map<String, String> map) {
Enumeration<String> e = mSource.keys();
// We only want the keys which match the current substore name
// without the current substore prefix. This code works even
@@ -219,7 +218,7 @@ public class PropConfigStore implements IConfigStore, Cloneable {
String key = e.nextElement();
if (key.startsWith(fullName)) {
- h.put(key.substring(kIndex), nakedGet(key));
+ map.put(key.substring(kIndex), nakedGet(key));
}
}
}
@@ -648,24 +647,17 @@ public class PropConfigStore implements IConfigStore, Cloneable {
*/
public Enumeration<String> getPropertyNames() {
// XXX - this operation is expensive!!!
- Hashtable<String, Object> h = new Hashtable<String, Object>();
+ Map<String, String> map = getProperties();
- enumerate(h);
- Enumeration<String> e = h.keys();
Vector<String> v = new Vector<String>();
+ for (String name : map.keySet()) {
+ int i = name.indexOf('.'); // substores have "."
+ if (i >= 0) continue;
+ if (v.contains(name)) continue;
- while (e.hasMoreElements()) {
- String pname = e.nextElement();
- int i = pname.indexOf('.'); // substores have "."
-
- if (i == -1) {
- String n = pname;
-
- if (!v.contains(n)) {
- v.addElement(n);
- }
- }
+ v.addElement(name);
}
+
return v.elements();
}
@@ -677,24 +669,19 @@ public class PropConfigStore implements IConfigStore, Cloneable {
*/
public Enumeration<String> getSubStoreNames() {
// XXX - this operation is expensive!!!
- Hashtable<String, Object> h = new Hashtable<String, Object>();
+ Map<String, String> map = getProperties();
- enumerate(h);
- Enumeration<String> e = h.keys();
Vector<String> v = new Vector<String>();
+ for (String name : map.keySet()) {
+ int i = name.indexOf('.'); // substores have "."
+ if (i < 0) continue;
- while (e.hasMoreElements()) {
- String pname = e.nextElement();
- int i = pname.indexOf('.'); // substores have "."
-
- if (i != -1) {
- String n = pname.substring(0, i);
+ name = name.substring(0, i);
+ if (v.contains(name)) continue;
- if (!v.contains(n)) {
- v.addElement(n);
- }
- }
+ v.addElement(name);
}
+
return v.elements();
}