Search in sources :

Example 1 with ExportRootElement

use of org.jcryptool.crypto.flexiprovider.operations.xml.ExportRootElement in project core by jcryptool.

the class OperationsManager method export.

public void export(long timestamp, String fileName) {
    try {
        IFileStore store = EFS.getStore(URIUtil.toURI(fileName));
        OutputStream os = store.openOutputStream(SWT.NONE, null);
        Document exportee = new Document(new ExportRootElement(newOperations.get(timestamp)));
        new XMLOutputter(Format.getPrettyFormat()).output(exportee, os);
        os.close();
    } catch (CoreException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "CoreException while exporting an operation", e, false);
    } catch (IOException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "IOException while exporting an operation", e, false);
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) CoreException(org.eclipse.core.runtime.CoreException) ExportRootElement(org.jcryptool.crypto.flexiprovider.operations.xml.ExportRootElement) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) Document(org.jdom.Document)

Example 2 with ExportRootElement

use of org.jcryptool.crypto.flexiprovider.operations.xml.ExportRootElement in project core by jcryptool.

the class OperationsManager method importOperation.

public void importOperation(String fileName) {
    try {
        // $NON-NLS-1$
        LogUtil.logInfo("1");
        IFileStore store = EFS.getStore(URIUtil.toURI(fileName));
        // $NON-NLS-1$
        LogUtil.logInfo("2");
        InputStream is = store.openInputStream(SWT.NONE, null);
        // $NON-NLS-1$
        LogUtil.logInfo("3");
        SAXBuilder sax = new SAXBuilder();
        // $NON-NLS-1$
        LogUtil.logInfo("4");
        Document doc = sax.build(is);
        // $NON-NLS-1$
        LogUtil.logInfo("5");
        is.close();
        // $NON-NLS-1$
        LogUtil.logInfo("6");
        ExportRootElement root = new ExportRootElement(doc.getRootElement());
        // $NON-NLS-1$
        LogUtil.logInfo("7");
        IFlexiProviderOperation importEntry = root.getEntryNode();
        // $NON-NLS-1$
        LogUtil.logInfo("8");
        newOperations.put(importEntry.getTimestamp(), importEntry);
        // $NON-NLS-1$
        LogUtil.logInfo("9");
        Iterator<IOperationChangedListener> it = listeners.iterator();
        while (it.hasNext()) {
            it.next().addOperation();
        }
        // $NON-NLS-1$
        LogUtil.logInfo("10");
    } catch (CoreException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "CoreException while importing an operation", e, true);
    } catch (JDOMException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "JDOMException while importing an operation", e, true);
    } catch (IOException e) {
        LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "IOException while importing an operation", e, false);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) CoreException(org.eclipse.core.runtime.CoreException) ExportRootElement(org.jcryptool.crypto.flexiprovider.operations.xml.ExportRootElement) InputStream(java.io.InputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) Document(org.jdom.Document) IOperationChangedListener(org.jcryptool.crypto.flexiprovider.operations.ui.listeners.IOperationChangedListener) JDOMException(org.jdom.JDOMException) IFlexiProviderOperation(org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)

Aggregations

IOException (java.io.IOException)2 IFileStore (org.eclipse.core.filesystem.IFileStore)2 CoreException (org.eclipse.core.runtime.CoreException)2 ExportRootElement (org.jcryptool.crypto.flexiprovider.operations.xml.ExportRootElement)2 Document (org.jdom.Document)2 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 IFlexiProviderOperation (org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)1 IOperationChangedListener (org.jcryptool.crypto.flexiprovider.operations.ui.listeners.IOperationChangedListener)1 JDOMException (org.jdom.JDOMException)1 SAXBuilder (org.jdom.input.SAXBuilder)1 XMLOutputter (org.jdom.output.XMLOutputter)1