use of de.janrufmonitor.framework.configuration.IConfigManager in project janrufmonitor by tbrandt77.
the class InfHandler method addInfData.
public void addInfData(Properties infData) {
try {
IConfigManager cpm = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager();
Iterator iter = infData.keySet().iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
StringTokenizer st = new StringTokenizer(key, this.NAMESPACE_SEPARATOR);
String namespace = st.nextToken();
String parameter = st.nextToken();
String metainfo = st.nextToken();
// remove
if (namespace.startsWith("-")) {
namespace = namespace.substring(1);
this.m_logger.info("Detected module config removal.");
this.m_logger.info("Removing " + namespace + "\\:" + parameter + "\\:" + metainfo);
cpm.removeProperty(namespace, parameter, metainfo);
// add value to current value
} else if (namespace.startsWith("+")) {
namespace = namespace.substring(1);
this.m_logger.info("Detected module config concatenation.");
this.m_logger.info("Concatenating values for " + namespace + "\\:" + parameter + "\\:" + metainfo);
String value = cpm.getProperty(namespace, parameter, metainfo);
if (value == null)
value = "";
// value += infData.getProperty(key);
value = this.concat(value, infData.getProperty(key));
// concatenating means allways overwrite !!
cpm.setProperty(namespace, parameter, metainfo, value, true);
// restore option: add always (force)
} else if (namespace.startsWith("~")) {
// added: 2007/07/09: for config restore capability
// restore option trigger
namespace = namespace.substring(1);
this.m_logger.info("Detected module config restore feature.");
this.m_logger.info("Preparing restore of values for " + namespace + "\\:" + parameter + "\\:" + metainfo);
String value = cpm.getProperty(namespace, parameter, metainfo);
if (value == null)
value = "";
if (value.length() > 0) {
// config restore means allways overwrite !!
cpm.setProperty("_" + namespace, parameter, metainfo, value, true);
}
value = infData.getProperty(key);
cpm.setProperty(namespace, parameter, metainfo, value, true);
// add, only if not already set
} else if (namespace.startsWith("?")) {
namespace = namespace.substring(1);
this.m_logger.info("Detected module config add only if not present feature.");
this.m_logger.info("Checking value for " + namespace + "\\:" + parameter + "\\:" + metainfo);
String value = cpm.getProperty(namespace, parameter, metainfo);
if (value == null) {
value = infData.getProperty(key);
cpm.setProperty(namespace, parameter, metainfo, value, true);
this.m_logger.info("Addings value for " + namespace + "\\:" + parameter + "\\:" + metainfo);
} else {
this.m_logger.info("Value for " + namespace + "\\:" + parameter + "\\:" + metainfo + " already exists.");
}
// add always (force)
} else if (namespace.startsWith("%")) {
namespace = namespace.substring(1);
this.m_logger.info("Detected module config add always (force) feature.");
this.m_logger.info("Forcing value for " + namespace + "\\:" + parameter + "\\:" + metainfo);
String value = infData.getProperty(key);
if (value == null)
value = "";
cpm.setProperty(namespace, parameter, metainfo, value, true);
} else {
String value = infData.getProperty(key);
cpm.setProperty(namespace, parameter, metainfo, value, overwriteConfig);
}
}
cpm.saveConfiguration();
} catch (NullPointerException ex) {
this.m_logger.severe("Configuration is invalid: " + ex.getMessage());
} catch (NoSuchElementException ex) {
this.m_logger.severe("Configuration is invalid: " + ex.getMessage());
}
}
use of de.janrufmonitor.framework.configuration.IConfigManager in project janrufmonitor by tbrandt77.
the class ConfigExport method createFieldEditors.
protected void createFieldEditors() {
this.noDefaultAndApplyButton();
// super.createFieldEditors();
FieldEditor bfe = new FieldEditor("check-button", "c", this.getFieldEditorParent()) {
protected void adjustForNumColumns(int arg0) {
}
protected void doFillIntoGrid(final Composite c, int numCols) {
GridData gd = new GridData();
gd.horizontalAlignment = GridData.FILL;
gd.grabExcessHorizontalSpace = true;
gd.horizontalSpan = numCols - 1;
gd.widthHint = 200;
new Label(c, SWT.NONE);
final II18nManager i18 = PIMRuntime.getInstance().getI18nManagerFactory().getI18nManager();
final String l = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE);
String text = i18.getString("ui.jface.configuration.pages.ConfigExport", "execute", "label", l);
Button up = new Button(c, SWT.PUSH);
up.setText(text);
up.pack();
up.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
DirectoryDialog d = new DirectoryDialog(c.getShell());
d.setText(i18.getString("ui.jface.configuration.pages.ConfigExport", "save", "label", l));
d.setMessage(i18.getString("ui.jface.configuration.pages.ConfigExport", "save", "description", l));
String dir = d.open();
if (dir != null && dir.trim().length() > 0) {
long id = System.currentTimeMillis();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_HHmm");
String current_date = formatter.format(new Date(id));
// descriptor data
Properties descriptor = new Properties();
descriptor.setProperty(InstallerConst.DESCRIPTOR_REQUIRED_MAJOR_VERSION, IJAMConst.VERSION_MAJOR);
descriptor.setProperty(InstallerConst.DESCRIPTOR_REQUIRED_MINOR_VERSION, IJAMConst.VERSION_MINOR);
descriptor.setProperty(InstallerConst.DESCRIPTOR_REQUIRED_PATCH_VERSION, IJAMConst.VERSION_PATCH);
descriptor.setProperty(InstallerConst.DESCRIPTOR_TYPE, "configuration");
descriptor.setProperty(InstallerConst.DESCRIPTOR_VERSION, "1.0.0");
descriptor.setProperty(InstallerConst.DESCRIPTOR_NAME, "mod-cfg-" + id);
descriptor.setProperty(InstallerConst.DESCRIPTOR_NAMESPACE, "cfg." + id);
descriptor.setProperty(InstallerConst.DESCRIPTOR_RESTART, "true");
descriptor.setProperty(InstallerConst.DESCRIPTOR_REMOVE, "false");
// inf data
Properties inf = new Properties();
IConfigManager cfgMan = getRuntime().getConfigManagerFactory().getConfigManager();
String[] namespaces = cfgMan.getConfigurationNamespaces();
Properties cfgData = null;
for (int i = 0; i < namespaces.length; i++) {
cfgData = cfgMan.getProperties(namespaces[i], true);
if (cfgData != null) {
Iterator iter = cfgData.keySet().iterator();
String key = null;
while (iter.hasNext()) {
key = (String) iter.next();
inf.setProperty("~" + namespaces[i] + ":" + key + ":value", cfgData.getProperty(key));
}
}
}
// i18n data
Properties i18n = new Properties();
i18n.setProperty("cfg." + id + ":title:label:de", "Benutzereinstellungen (Version " + IJAMConst.VERSION_MAJOR + "." + IJAMConst.VERSION_MINOR + "." + IJAMConst.VERSION_PATCH + ") vom " + new SimpleDateFormat("dd.MM.yyyy").format(new Date(id)));
i18n.setProperty("cfg." + id + ":label:label:de", "Benutzereinstellungen (Version " + IJAMConst.VERSION_MAJOR + "." + IJAMConst.VERSION_MINOR + "." + IJAMConst.VERSION_PATCH + ") vom " + new SimpleDateFormat("dd.MM.yyyy").format(new Date(id)));
i18n.setProperty("cfg." + id + ":title:label:en", "user settings (version " + IJAMConst.VERSION_MAJOR + "." + IJAMConst.VERSION_MINOR + "." + IJAMConst.VERSION_PATCH + ") of " + new SimpleDateFormat("yyyy/dd/MM").format(new Date(id)));
i18n.setProperty("cfg." + id + ":label:label:en", "user settings (version " + IJAMConst.VERSION_MAJOR + "." + IJAMConst.VERSION_MINOR + "." + IJAMConst.VERSION_PATCH + ") of " + new SimpleDateFormat("yyyy/dd/MM").format(new Date(id)));
// create jam.zip archive
File directory = new File(dir);
if (!directory.exists()) {
directory.mkdirs();
}
ZipArchive z = new ZipArchive(directory.getAbsolutePath() + File.separator + "cfg." + current_date + ".jam.zip");
try {
z.open();
// write descriptor
ByteArrayOutputStream bos = new ByteArrayOutputStream();
descriptor.store(bos, "");
bos.flush();
ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
z.add("~meta-inf/descriptor.properties", bin);
// write inf data
bos = new ByteArrayOutputStream();
inf.store(bos, "");
bos.flush();
bin = new ByteArrayInputStream(bos.toByteArray());
z.add("install/cfg." + id + ".inf", bin);
// write i18n data
bos = new ByteArrayOutputStream();
i18n.store(bos, "");
bos.flush();
bin = new ByteArrayInputStream(bos.toByteArray());
z.add("install/cfg." + id + ".i18n", bin);
z.close();
} catch (ZipArchiveException ex) {
m_logger.severe(ex.toString());
} catch (IOException ex) {
m_logger.severe(ex.toString());
}
}
}
});
}
protected void doLoad() {
}
protected void doLoadDefault() {
}
protected void doStore() {
}
public int getNumberOfControls() {
return 1;
}
};
addField(bfe);
}
use of de.janrufmonitor.framework.configuration.IConfigManager in project janrufmonitor by tbrandt77.
the class ConfigurationCommand method buildPageList.
private void buildPageList() {
Iterator iter = m_configuration.keySet().iterator();
IConfigManager cfgm = getRuntime().getConfigManagerFactory().getConfigManager();
boolean isExpertMode = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_CONFIG_EXPERT_MODE).equalsIgnoreCase("true");
String key = null;
String mode = null;
while (iter.hasNext()) {
key = (String) iter.next();
if (key.startsWith(PARAMETERNAME)) {
mode = cfgm.getProperty(getNamespace(), key, "mode");
if (!isExpertMode) {
if (mode.equalsIgnoreCase("expert"))
continue;
}
if (mode.equalsIgnoreCase("hidden"))
continue;
String className = m_configuration.getProperty(key);
try {
Class classObject = Thread.currentThread().getContextClassLoader().loadClass(className);
IConfigPage page = (IConfigPage) classObject.newInstance();
page.setNodeID(key.substring(PARAMETERNAME.length()));
this.m_pages.add(page);
} catch (ClassNotFoundException ex) {
this.m_logger.severe("Could not find class: " + className);
} catch (InstantiationException ex) {
this.m_logger.severe("Could not instantiate class: " + className);
} catch (IllegalAccessException ex) {
this.m_logger.severe("Could not access class: " + className);
} catch (NullPointerException ex) {
this.m_logger.severe(ex.getMessage());
} catch (Exception e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
// sort for position
Collections.sort(this.m_pages, this);
}
Aggregations