use of de.janrufmonitor.repository.zip.ZipArchive in project janrufmonitor by tbrandt77.
the class DefaultJournal method shutdown.
public void shutdown() {
try {
if (this.getDatabaseHandler().isConnected())
this.getDatabaseHandler().disconnect();
String root = PathResolver.getInstance(this.getRuntime()).resolve(this.m_configuration.getProperty(CFG_DB, PathResolver.getInstance(this.getRuntime()).getDataDirectory() + "/journal.db"));
File db_raw = new File(root);
ZipArchive z = new ZipArchive(root);
z.open();
String[] entries = new String[2];
InputStream[] ins = new InputStream[2];
if (new File(db_raw.getAbsolutePath() + ".properties").exists()) {
entries[0] = db_raw.getName() + ".properties";
ins[0] = new FileInputStream(db_raw.getAbsolutePath() + ".properties");
}
if (new File(db_raw.getAbsolutePath() + ".script").exists()) {
entries[1] = db_raw.getName() + ".script";
ins[1] = new FileInputStream(db_raw.getAbsolutePath() + ".script");
}
z.add(entries, ins);
z.close();
} catch (ZipArchiveException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (FileNotFoundException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
super.shutdown();
}
use of de.janrufmonitor.repository.zip.ZipArchive in project janrufmonitor by tbrandt77.
the class Info method createContents.
protected Control createContents(Composite parent) {
this.setTitle(this.m_i18n.getString(this.getNamespace(), "title", "label", this.m_language));
this.noDefaultAndApplyButton();
final Composite c = new Composite(parent, SWT.NONE);
c.setLayout(new GridLayout(1, true));
Label l = new Label(c, SWT.NULL);
l.setText(this.m_i18n.getString(this.getNamespace(), "program", "label", this.m_language));
m_appViewer = new TableViewer(c);
m_appViewer.setContentProvider(new ContentProvider());
m_appViewer.setLabelProvider(new LabelProvider());
Table tb = m_appViewer.getTable();
tb.setLayoutData(new GridData(GridData.FILL_BOTH));
TableColumn tc = new TableColumn(tb, SWT.LEFT);
tc = new TableColumn(tb, SWT.LEFT);
m_appViewer.setInput(this.getAppList());
for (int i = 0, n = tb.getColumnCount(); i < n; i++) {
tb.getColumn(i).pack();
}
tb.setHeaderVisible(true);
tb.setLinesVisible(true);
l = new Label(c, SWT.NULL);
l.setText(this.m_i18n.getString(this.getNamespace(), "modules", "label", this.m_language));
m_moduleViewer = new TableViewer(c);
m_moduleViewer.setContentProvider(new ContentProvider());
m_moduleViewer.setLabelProvider(new LabelProvider());
tb = m_moduleViewer.getTable();
tb.setLayoutData(new GridData(GridData.FILL_BOTH));
tc = new TableColumn(tb, SWT.LEFT);
tc.setText(this.m_i18n.getString(this.getNamespace(), "module", "label", this.m_language));
tc = new TableColumn(tb, SWT.LEFT);
tc.setText(this.m_i18n.getString(this.getNamespace(), "version", "label", this.m_language));
m_moduleViewer.setInput(this.getModuleList());
for (int i = 0, n = tb.getColumnCount(); i < n; i++) {
tb.getColumn(i).pack();
}
tb.setHeaderVisible(true);
tb.setLinesVisible(true);
if (this.isExpertMode()) {
Button b = new Button(c, SWT.PUSH);
b.setText(this.m_i18n.getString(this.getNamespace(), "export", "label", this.m_language));
b.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dlg = new FileDialog(c.getShell(), SWT.SAVE);
dlg.setFilterExtensions(new String[] { "*.zip" });
dlg.setFileName("jam-info.zip");
String path = getRuntime().getConfigManagerFactory().getConfigManager().getProperty(getNamespace(), "last");
if (path == null || path.length() == 0) {
path = PathResolver.getInstance(getRuntime()).getUserhomeDirectory();
}
path = PathResolver.getInstance(getRuntime()).resolve(path);
dlg.setFilterPath(path);
if (dlg.open() != null) {
getRuntime().getConfigManagerFactory().getConfigManager().setProperty(getNamespace(), "last", dlg.getFilterPath());
StringBuffer sb = new StringBuffer();
Properties env = System.getProperties();
Iterator iter = env.keySet().iterator();
String key = null;
sb.append("Program information jAnrufmonitor:");
sb.append(IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
sb.append("version = " + IJAMConst.VERSION_DISPLAY + " (Build: " + IJAMConst.VERSION_BUILD + ")");
sb.append(IJAMConst.CRLF);
sb.append("install path = " + PathResolver.getInstance(getRuntime()).getInstallDirectory());
sb.append(IJAMConst.CRLF);
sb.append("user home path = " + PathResolver.getInstance(getRuntime()).getUserhomeDirectory());
sb.append(IJAMConst.CRLF);
sb.append("temp path = " + PathResolver.getInstance(getRuntime()).getTempDirectory());
sb.append(IJAMConst.CRLF);
sb.append("language = " + getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_LANGUAGE));
sb.append(IJAMConst.CRLF);
while (iter.hasNext()) {
key = (String) iter.next();
sb.append(key + " = " + env.getProperty(key));
sb.append(IJAMConst.CRLF);
}
sb.append(IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
String rkey = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("service.update.UpdateManager", "regkey");
if (rkey != null && rkey.trim().length() > 0) {
sb.append("registry key = " + rkey);
sb.append(IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
}
sb.append("Installed modules:");
sb.append(IJAMConst.CRLF);
sb.append(IJAMConst.CRLF);
List modules = InstallerEngine.getInstance().getModuleList();
Properties mod = null;
for (int i = 0, j = modules.size(); i < j; i++) {
mod = InstallerEngine.getInstance().getDescriptor((String) modules.get(i));
if (mod != null) {
sb.append(getNamespaceLabel((String) modules.get(i)) + " = " + mod.getProperty(InstallerConst.DESCRIPTOR_VERSION, "-"));
sb.append(IJAMConst.CRLF);
}
}
File f = new File(dlg.getFilterPath() + File.separator + dlg.getFileName());
f.getParentFile().mkdirs();
try {
ZipArchive zip = new ZipArchive(f, true);
zip.open();
Map entries = new HashMap();
// add program information
entries.put("info/jam-info.log", new ByteArrayInputStream(sb.toString().getBytes()));
// add configuration
File configDir = new File(PathResolver.getInstance(getRuntime()).getConfigDirectory());
if (configDir.exists() && configDir.isDirectory()) {
File[] files = configDir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
entries.put("config/" + files[i].getName(), new FileInputStream(files[i]));
}
}
}
// add logs
File logDir = new File(PathResolver.getInstance(getRuntime()).getLogDirectory());
if (logDir.exists() && logDir.isDirectory()) {
File[] files = logDir.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
entries.put("logs/" + files[i].getName(), new FileInputStream(files[i]));
}
}
}
zip.add(entries);
zip.close();
} catch (ZipArchiveException ex) {
m_logger.log(Level.SEVERE, ex.getMessage(), ex);
} catch (FileNotFoundException ex) {
m_logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
});
}
return c;
}
use of de.janrufmonitor.repository.zip.ZipArchive 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);
}
Aggregations