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");
}
}
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;
}
}
}
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;
}
}
}
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);
}
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();
}
}
Aggregations