Search in sources :

Example 11 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class Main method restoreWithoutGui.

private static void restoreWithoutGui(final String username, final String password, final Optional<String> dbaPassword, final Path f, final XmldbURI uri, final boolean rebuildRepo, final boolean quiet, final boolean overwriteApps) {
    final AggregatingConsoleRestoreServiceTaskListener listener = new AggregatingConsoleRestoreServiceTaskListener(quiet);
    try {
        final Collection collection = DatabaseManager.getCollection(uri.toString(), username, password);
        final EXistRestoreService service = (EXistRestoreService) collection.getService("RestoreService", "1.0");
        service.restore(f.toAbsolutePath().toString(), dbaPassword.orElse(null), listener, overwriteApps);
    } catch (final XMLDBException e) {
        listener.error(e.getMessage());
    }
    if (listener.hasProblems()) {
        System.err.println(listener.getAllProblems());
    }
    if (rebuildRepo) {
        System.out.println("Rebuilding application repository ...");
        System.out.println("URI: " + uri);
        try {
            final Collection root = DatabaseManager.getCollection(uri.toString(), username, dbaPassword.orElse(password));
            if (root != null) {
                ClientFrame.repairRepository(root);
                System.out.println("Application repository rebuilt successfully.");
            } else {
                System.err.println("Failed to retrieve root collection: " + uri);
            }
        } catch (final XMLDBException e) {
            reportError(e);
            System.err.println("Rebuilding application repository failed!");
        }
    } else {
        System.out.println("\nIf you restored collections inside /db/apps, you may want\n" + "to rebuild the application repository. To do so, run the following query\n" + "as admin:\n\n" + "import module namespace repair=\"http://exist-db.org/xquery/repo/repair\"\n" + "at \"resource:org/exist/xquery/modules/expathrepo/repair.xql\";\n" + "repair:clean-all(),\n" + "repair:repair()\n");
    }
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 12 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class Main method restoreWithGui.

private static void restoreWithGui(final String username, final String password, final Optional<String> dbaPassword, final Path f, final XmldbURI uri, boolean overwriteApps) {
    final GuiRestoreServiceTaskListener listener = new GuiRestoreServiceTaskListener();
    listener.info("Connecting ...");
    final Callable<Void> callable = () -> {
        try {
            final Collection collection = DatabaseManager.getCollection(uri.toString(), username, password);
            final EXistRestoreService service = (EXistRestoreService) collection.getService("RestoreService", "1.0");
            service.restore(f.toAbsolutePath().toString(), dbaPassword.orElse(null), listener, overwriteApps);
            listener.enableDismissDialogButton();
            if (JOptionPane.showConfirmDialog(null, "Would you like to rebuild the application repository?\nThis is only necessary if application packages were restored.", "Rebuild App Repository?", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                System.out.println("Rebuilding application repository ...");
                try {
                    final Collection root = DatabaseManager.getCollection(uri.toString(), username, dbaPassword.orElse(password));
                    ClientFrame.repairRepository(root);
                    listener.info("Application repository rebuilt successfully.");
                } catch (final XMLDBException e) {
                    reportError(e);
                    listener.info("Rebuilding application repository failed!");
                }
            }
        } catch (final Exception e) {
            // $NON-NLS-1$
            ClientFrame.showErrorMessage(e.getMessage(), null);
        } finally {
            if (listener.hasProblems()) {
                ClientFrame.showErrorMessage(listener.getAllProblems(), null);
            }
        }
        return null;
    };
    final ExecutorService executor = Executors.newSingleThreadExecutor(new NamedThreadFactory(null, null, "backup.restore-with-gui"));
    final Future<Void> future = executor.submit(callable);
    while (!future.isDone() && !future.isCancelled()) {
        try {
            future.get(100, TimeUnit.MILLISECONDS);
        } catch (final InterruptedException | TimeoutException ie) {
        } catch (final ExecutionException ee) {
            break;
        }
    }
}
Also used : NamedThreadFactory(org.exist.util.NamedThreadFactory) XMLDBException(org.xmldb.api.base.XMLDBException) StartException(org.exist.start.StartException) XMLDBException(org.xmldb.api.base.XMLDBException) IOException(java.io.IOException) Collection(org.xmldb.api.base.Collection)

Example 13 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class CreateBackupDialog method getAllCollections.

private void getAllCollections(final Collection collection, final Vector<String> collections) throws XMLDBException {
    collections.add(collection.getName());
    final String[] childCollections = collection.listChildCollections();
    Collection child = null;
    for (final String childCollection : childCollections) {
        try {
            child = collection.getChildCollection(childCollection);
        } catch (final XMLDBException xmldbe) {
            if (xmldbe.getCause() instanceof PermissionDeniedException) {
                continue;
            } else {
                throw xmldbe;
            }
        } catch (final Exception npe) {
            System.out.println("Corrupted resource/collection skipped: " + child != null ? child.getName() != null ? child.getName() : "unknown" : "unknown");
            continue;
        }
        try {
            getAllCollections(child, collections);
        } catch (final Exception ee) {
            System.out.println("Corrupted resource/collection skipped: " + child != null ? child.getName() != null ? child.getName() : "unknown" : "unknown");
            continue;
        }
    }
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) PermissionDeniedException(org.exist.security.PermissionDeniedException) XMLDBException(org.xmldb.api.base.XMLDBException) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Example 14 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class DocumentView method setupComponents.

private void setupComponents() throws XMLDBException {
    /* start of menubar */
    final JMenuBar menubar = new JMenuBar();
    // $NON-NLS-1$
    final JMenu fileMenu = new JMenu(Messages.getString("DocumentView.16"));
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menubar.add(fileMenu);
    JMenuItem item;
    // Save to database
    // $NON-NLS-1$
    item = new JMenuItem(Messages.getString("DocumentView.17"), KeyEvent.VK_S);
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    item.addActionListener(e -> save());
    fileMenu.add(item);
    /*
        // Refresh
        item = new JMenuItem("Refresh", KeyEvent.VK_R);
        item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
        		Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    refresh() ;
                } catch (XMLDBException u) {
                    u.printStackTrace();
                }
            }
        });
        fileMenu.add(item);
        */
    setJMenuBar(menubar);
    /* end of menubar */
    /* The icon toolbar */
    final JToolBar toolbar = new JToolBar();
    // Save button
    // $NON-NLS-1$
    URL url = getClass().getResource("icons/Save24.gif");
    saveButton = new JButton(new ImageIcon(url));
    saveButton.setToolTipText(// $NON-NLS-1$
    Messages.getString("DocumentView.20"));
    saveButton.addActionListener(e -> save());
    toolbar.add(saveButton);
    // Save As button
    // $NON-NLS-1$
    url = getClass().getResource("icons/SaveAs24.gif");
    saveAsButton = new JButton(new ImageIcon(url));
    saveAsButton.setToolTipText(// $NON-NLS-1$
    Messages.getString("DocumentView.22"));
    saveAsButton.addActionListener(e -> saveAs());
    toolbar.add(saveAsButton);
    // Export button
    // $NON-NLS-1$
    url = getClass().getResource("icons/Export24.gif");
    JButton button = new JButton(new ImageIcon(url));
    // $NON-NLS-1$
    button.setToolTipText(Messages.getString("DocumentView.24"));
    button.addActionListener(e -> {
        try {
            export();
        } catch (final XMLDBException u) {
            u.printStackTrace();
        }
    });
    toolbar.add(button);
    toolbar.addSeparator();
    // Copy button
    // $NON-NLS-1$
    url = getClass().getResource("icons/Copy24.gif");
    button = new JButton(new ImageIcon(url));
    // $NON-NLS-1$
    button.setToolTipText(Messages.getString("DocumentView.26"));
    button.addActionListener(e -> text.copy());
    toolbar.add(button);
    // Cut button
    // $NON-NLS-1$
    url = getClass().getResource("icons/Cut24.gif");
    button = new JButton(new ImageIcon(url));
    // $NON-NLS-1$
    button.setToolTipText(Messages.getString("DocumentView.28"));
    button.addActionListener(e -> text.cut());
    toolbar.add(button);
    // Paste button
    // $NON-NLS-1$
    url = getClass().getResource("icons/Paste24.gif");
    button = new JButton(new ImageIcon(url));
    // $NON-NLS-1$
    button.setToolTipText(Messages.getString("DocumentView.30"));
    button.addActionListener(e -> text.paste());
    toolbar.add(button);
    toolbar.addSeparator();
    // Refresh button
    // $NON-NLS-1$
    url = getClass().getResource("icons/Refresh24.gif");
    button = new JButton(new ImageIcon(url));
    // $NON-NLS-1$
    button.setToolTipText(Messages.getString("DocumentView.32"));
    button.addActionListener(e -> {
        try {
            refresh();
        } catch (final XMLDBException u) {
            u.printStackTrace();
        }
    });
    toolbar.add(button);
    getContentPane().add(toolbar, BorderLayout.NORTH);
    text = new RSyntaxTextArea(14, 80);
    text.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
    text.setCodeFoldingEnabled(true);
    textScrollPane = new RTextScrollPane(text);
    getContentPane().add(textScrollPane, BorderLayout.CENTER);
    final Box statusbar = Box.createHorizontalBox();
    statusbar.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    statusMessage = new JTextField(20);
    statusMessage.setEditable(false);
    statusMessage.setFocusable(false);
    // $NON-NLS-1$ //$NON-NLS-2$
    statusMessage.setText(Messages.getString("DocumentView.34") + URIUtils.urlDecodeUtf8(resource.getId()) + Messages.getString("DocumentView.35"));
    statusbar.add(statusMessage);
    progress = new JProgressBar();
    progress.setPreferredSize(new Dimension(200, 30));
    progress.setVisible(false);
    statusbar.add(progress);
    positionDisplay = new JTextField(5);
    positionDisplay.setEditable(false);
    positionDisplay.setFocusable(true);
    statusbar.add(positionDisplay);
    text.addCaretListener(e -> {
        final RSyntaxTextArea txt = (RSyntaxTextArea) e.getSource();
        positionDisplay.setText("Line: " + (txt.getCaretLineNumber() + 1) + " Column:" + (txt.getCaretOffsetFromLineStart() + 1));
    });
    getContentPane().add(statusbar, BorderLayout.SOUTH);
}
Also used : ImageIcon(javax.swing.ImageIcon) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) XMLDBException(org.xmldb.api.base.XMLDBException) Box(javax.swing.Box) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) URL(java.net.URL) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) JMenuItem(javax.swing.JMenuItem) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 15 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class DocumentView method unlockView.

private void unlockView() {
    if (readOnly) {
        return;
    }
    try {
        final UserManagementService service = (UserManagementService) collection.getService("UserManagementService", // $NON-NLS-1$ //$NON-NLS-2$
        "1.0");
        service.unlockResource(resource);
    } catch (final XMLDBException e) {
        e.printStackTrace();
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Aggregations

XMLDBException (org.xmldb.api.base.XMLDBException)174 Collection (org.xmldb.api.base.Collection)66 Resource (org.xmldb.api.base.Resource)34 URISyntaxException (java.net.URISyntaxException)30 XMLResource (org.xmldb.api.modules.XMLResource)30 ResourceSet (org.xmldb.api.base.ResourceSet)23 BuildException (org.apache.tools.ant.BuildException)21 IOException (java.io.IOException)19 XPathException (org.exist.xquery.XPathException)18 PermissionDeniedException (org.exist.security.PermissionDeniedException)16 SAXException (org.xml.sax.SAXException)16 EXistException (org.exist.EXistException)15 UserManagementService (org.exist.xmldb.UserManagementService)15 XPathQueryService (org.xmldb.api.modules.XPathQueryService)13 BinaryResource (org.xmldb.api.modules.BinaryResource)12 ArrayList (java.util.ArrayList)11 Account (org.exist.security.Account)11 EXistResource (org.exist.xmldb.EXistResource)10 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)10 Properties (java.util.Properties)9