Search in sources :

Example 11 with ZipArchiveException

use of de.janrufmonitor.repository.zip.ZipArchiveException 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();
}
Also used : ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ZipArchive(de.janrufmonitor.repository.zip.ZipArchive) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 12 with ZipArchiveException

use of de.janrufmonitor.repository.zip.ZipArchiveException in project janrufmonitor by tbrandt77.

the class JamArchive method getDescritpor.

public Properties getDescritpor() throws JamArchiveException {
    if (!this.m_zip.available())
        throw new JamArchiveException("JamArchive not opened.");
    Properties p = null;
    try {
        List l = this.m_zip.list(new FilenameFilter() {

            public boolean accept(File p, String entry) {
                return entry.toLowerCase().endsWith(JamArchive.DESCRIPTOR);
            }
        });
        if (l.size() == 1) {
            InputStream in = this.m_zip.get((String) l.get(0));
            if (in != null) {
                BufferedInputStream bin = new BufferedInputStream(in);
                p = new Properties();
                p.load(bin);
                bin.close();
                return p;
            }
        } else if (l.size() > 1) {
            throw new JamArchiveException("More than 1 descriptor is not allowed in a *.jam.zip archive.");
        }
    } catch (ZipArchiveException e) {
        throw new JamArchiveException(e);
    } catch (IOException e) {
        throw new JamArchiveException(e.getMessage());
    }
    return p;
}
Also used : ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) List(java.util.List) Properties(java.util.Properties)

Example 13 with ZipArchiveException

use of de.janrufmonitor.repository.zip.ZipArchiveException 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;
}
Also used : ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) HashMap(java.util.HashMap) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Label(org.eclipse.swt.widgets.Label) FileNotFoundException(java.io.FileNotFoundException) ZipArchive(de.janrufmonitor.repository.zip.ZipArchive) Properties(java.util.Properties) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableColumn(org.eclipse.swt.widgets.TableColumn) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) AbstractTableLabelProvider(de.janrufmonitor.ui.jface.AbstractTableLabelProvider) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with ZipArchiveException

use of de.janrufmonitor.repository.zip.ZipArchiveException 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);
}
Also used : FieldEditor(org.eclipse.jface.preference.FieldEditor) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) Composite(org.eclipse.swt.widgets.Composite) IConfigManager(de.janrufmonitor.framework.configuration.IConfigManager) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ZipArchive(de.janrufmonitor.repository.zip.ZipArchive) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Properties(java.util.Properties) II18nManager(de.janrufmonitor.framework.i18n.II18nManager) Date(java.util.Date) Button(org.eclipse.swt.widgets.Button) ByteArrayInputStream(java.io.ByteArrayInputStream) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

ZipArchiveException (de.janrufmonitor.repository.zip.ZipArchiveException)14 ZipArchive (de.janrufmonitor.repository.zip.ZipArchive)13 File (java.io.File)13 SQLException (java.sql.SQLException)7 Properties (java.util.Properties)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 List (java.util.List)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 Map (java.util.Map)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridData (org.eclipse.swt.layout.GridData)3 Button (org.eclipse.swt.widgets.Button)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 FilenameFilter (java.io.FilenameFilter)2 InputStream (java.io.InputStream)2