use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class ClientFrame method backupAction.
private void backupAction(final ActionEvent ev) {
// get the collection to highlight in the backup dialog
final String defaultSelectedCollection;
final ResourceDescriptor[] selResources = getSelectedResources();
if (selResources != null) {
if (selResources.length == 1 && selResources[0].isCollection()) {
// use the selected collection
defaultSelectedCollection = path.toString() + "/" + selResources[0].getName().toString();
} else {
// use the current collection
defaultSelectedCollection = path.toString();
}
} else {
defaultSelectedCollection = path.toString();
}
final CreateBackupDialog dialog = new CreateBackupDialog(properties.getProperty(InteractiveClient.URI, "xmldb:exist://"), properties.getProperty(InteractiveClient.USER, SecurityManager.DBA_USER), properties.getProperty(InteractiveClient.PASSWORD, null), Paths.get(preferences.get("directory.backup", System.getProperty("user.home"))), defaultSelectedCollection);
if (JOptionPane.showOptionDialog(this, dialog, Messages.getString("ClientFrame.157"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null) == JOptionPane.YES_OPTION) {
final String collection = dialog.getCollection();
final String backuptarget = dialog.getBackupTarget();
final boolean deduplicateBlobs = dialog.getDeduplicateBlobs();
final Path target = Paths.get(backuptarget).normalize();
if (Files.exists(target)) {
final int response = JOptionPane.showConfirmDialog(this, String.format("%s %s %s", Messages.getString("CreateBackupDialog.6a"), backuptarget, Messages.getString("CreateBackupDialog.6b")), Messages.getString("CreateBackupDialog.6c"), JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION) {
// User wants file/directory to be removed
deleteDirectory(target);
} else {
JOptionPane.showMessageDialog(null, "Backup aborted, backup has not been deleted.");
return;
}
}
try {
final Backup backup = new Backup(properties.getProperty(InteractiveClient.USER, SecurityManager.DBA_USER), properties.getProperty(InteractiveClient.PASSWORD, null), Paths.get(backuptarget), XmldbURI.xmldbUriFor(properties.getProperty(InteractiveClient.URI, "xmldb:exist://") + collection), null, deduplicateBlobs);
backup.backup(true, this);
} catch (final XMLDBException | IOException | SAXException | URISyntaxException e) {
showErrorMessage(e.getClass().getSimpleName() + ": " + e.getMessage(), e);
}
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class ClientFrame method createMenuBar.
private JMenuBar createMenuBar() {
final JMenuBar menubar = new JMenuBar();
// $NON-NLS-1$
final JMenu fileMenu = new JMenu(Messages.getString("ClientFrame.31"));
fileMenu.setMnemonic(KeyEvent.VK_F);
menubar.add(fileMenu);
// $NON-NLS-1$
JMenuItem item = new JMenuItem(Messages.getString("ClientFrame.32"), KeyEvent.VK_S);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::uploadAction);
fileMenu.add(item);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.34"), KeyEvent.VK_N);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::newCollectionAction);
fileMenu.add(item);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.36"), KeyEvent.VK_B);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::newBlankDocument);
fileMenu.add(item);
fileMenu.addSeparator();
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.40"));
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::removeAction);
fileMenu.add(item);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.42"), KeyEvent.VK_C);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::copyAction);
fileMenu.add(item);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.44"), KeyEvent.VK_M);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::moveAction);
fileMenu.add(item);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.46"), KeyEvent.VK_R);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::renameAction);
fileMenu.add(item);
item = new JMenuItem(Messages.getString("ClientFrame.47"), KeyEvent.VK_E);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::exportAction);
fileMenu.add(item);
fileMenu.addSeparator();
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.48"), KeyEvent.VK_I);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::reindexAction);
fileMenu.add(item);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.50"));
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(e -> {
try {
setPermAction(e);
} catch (final PermissionDeniedException pde) {
showErrorMessage(pde.getMessage(), pde);
}
});
fileMenu.add(item);
fileMenu.addSeparator();
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.52"), KeyEvent.VK_Q);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(e -> close());
fileMenu.add(item);
// $NON-NLS-1$
final JMenu toolsMenu = new JMenu(Messages.getString("ClientFrame.54"));
toolsMenu.setMnemonic(KeyEvent.VK_T);
menubar.add(toolsMenu);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.55"), KeyEvent.VK_F);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::findAction);
toolsMenu.add(item);
toolsMenu.addSeparator();
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.57"), KeyEvent.VK_U);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::editUsersAction);
toolsMenu.add(item);
// Disable "Edit Indexes" menu item.
// item = new JMenuItem(Messages.getString("ClientFrame.59"), KeyEvent.VK_I); //$NON-NLS-1$
// item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I,
// Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
// item.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// editIndexesAction(e);
// }
// });
// toolsMenu.add(item);
item = new JMenuItem(Messages.getString("ClientFrame.60"), KeyEvent.VK_T);
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
item.addActionListener(this::editTriggersAction);
toolsMenu.add(item);
toolsMenu.addSeparator();
item = new JMenuItem(Messages.getString("ClientFrame.62a"));
item.addActionListener(e -> {
try {
final DatabaseInstanceManager service = (DatabaseInstanceManager) client.current.getService("DatabaseInstanceManager", "1.0");
service.enterServiceMode();
} catch (final XMLDBException ex) {
showErrorMessage(ex.getMessage(), ex);
}
});
toolsMenu.add(item);
item = new JMenuItem(Messages.getString("ClientFrame.62b"));
item.addActionListener(e -> {
try {
final DatabaseInstanceManager service = (DatabaseInstanceManager) client.current.getService("DatabaseInstanceManager", "1.0");
service.exitServiceMode();
} catch (final XMLDBException ex) {
showErrorMessage(ex.getMessage(), ex);
}
});
toolsMenu.add(item);
toolsMenu.addSeparator();
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.63"), KeyEvent.VK_B);
item.addActionListener(this::backupAction);
toolsMenu.add(item);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.64"), KeyEvent.VK_R);
item.addActionListener(this::restoreAction);
toolsMenu.add(item);
// $NON-NLS-1$
final JMenu connectMenu = new JMenu(Messages.getString("ClientFrame.65"));
connectMenu.setMnemonic(KeyEvent.VK_D);
menubar.add(connectMenu);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.66"), KeyEvent.VK_S);
item.addActionListener(e -> {
// $NON-NLS-1$
display(Messages.getString("ClientFrame.67"));
// $NON-NLS-1$
processRunnable.setAction("shutdown");
});
connectMenu.add(item);
// Show LoginPanel to Reconnect
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.69"), KeyEvent.VK_U);
// $NON-NLS-1$
item.setToolTipText(Messages.getString("ClientFrame.70"));
item.addActionListener(e -> {
// load properties modified by the login panel
final Properties loginData = getLoginData(properties);
reconnectClient(loginData);
});
connectMenu.add(item);
// $NON-NLS-1$
final JMenu optionsMenu = new JMenu(Messages.getString("ClientFrame.80"));
optionsMenu.setMnemonic(KeyEvent.VK_O);
menubar.add(optionsMenu);
// $NON-NLS-1$
JCheckBoxMenuItem check = new JCheckBoxMenuItem(Messages.getString("ClientFrame.81"), "yes".equals(properties.getProperty(OutputKeys.INDENT)));
check.addActionListener(e -> {
properties.setProperty(OutputKeys.INDENT, ((JCheckBoxMenuItem) e.getSource()).isSelected() ? // $NON-NLS-1$
"yes" : // $NON-NLS-1$
"no");
try {
client.getResources();
} catch (final XMLDBException e1) {
// TODO report error
}
});
optionsMenu.add(check);
// $NON-NLS-1$
check = new JCheckBoxMenuItem(Messages.getString("ClientFrame.85"), "yes".equals(properties.getProperty(EXistOutputKeys.EXPAND_XINCLUDES)));
check.addActionListener(e -> {
properties.setProperty(EXistOutputKeys.EXPAND_XINCLUDES, ((JCheckBoxMenuItem) e.getSource()).isSelected() ? // $NON-NLS-1$
"yes" : // $NON-NLS-1$
"no");
try {
client.getResources();
} catch (final XMLDBException e1) {
// TODO report error
}
});
optionsMenu.add(check);
// $NON-NLS-1$
final JMenu HelpMenu = new JMenu(Messages.getString("ClientFrame.89"));
HelpMenu.setMnemonic(KeyEvent.VK_H);
menubar.add(HelpMenu);
// $NON-NLS-1$
item = new JMenuItem(Messages.getString("ClientFrame.90"), KeyEvent.VK_A);
item.addActionListener(e -> AboutAction());
HelpMenu.add(item);
return menubar;
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class QueryDialog method getCollections.
private List<String> getCollections(final Collection root, final Collection collection, final List<String> collectionsList) throws XMLDBException {
if (!collection.getName().equals(root.getName())) {
collectionsList.add(root.getName());
}
final String[] childCollections = root.listChildCollections();
Collection child = null;
for (String childCollection : childCollections) {
try {
child = root.getChildCollection(childCollection);
} catch (final XMLDBException xmldbe) {
if (xmldbe.getCause() instanceof PermissionDeniedException) {
continue;
} else {
throw xmldbe;
}
} catch (Exception npe) {
System.out.println("Corrupted resource/collection skipped: " + child != null ? child.getName() != null ? child.getName() : "unknown" : "unknown");
continue;
}
try {
getCollections(child, collection, collectionsList);
} catch (Exception ee) {
System.out.println("Corrupted resource/collection skipped: " + child != null ? child.getName() != null ? child.getName() : "unknown" : "unknown");
continue;
}
}
return collectionsList;
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class QueryDialog method createQueryBox.
private JComponent createQueryBox() {
final JTabbedPane tabs = new JTabbedPane();
final JPanel inputVBox = new JPanel();
inputVBox.setLayout(new BorderLayout());
tabs.add(Messages.getString("QueryDialog.inputtab"), inputVBox);
final Box historyBox = Box.createHorizontalBox();
JLabel label = new JLabel(Messages.getString("QueryDialog.historylabel"));
historyBox.add(label);
final JComboBox<String> historyList = new JComboBox<>(history);
for (final String query : client.queryHistory) {
addQuery(query);
}
// by default - we are not using anything from the history!
historyList.setSelectedIndex(-1);
historyList.addItemListener(itemEvent -> {
if (itemEvent.getStateChange() == ItemEvent.SELECTED) {
final JComboBox<String> list = (JComboBox<String>) itemEvent.getSource();
final int idx = list.getSelectedIndex();
query.setText(client.queryHistory.get(idx));
}
});
historyBox.add(historyList);
inputVBox.add(historyBox, BorderLayout.NORTH);
query = new RSyntaxTextArea(14, 80);
query.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
query.setCodeFoldingEnabled(true);
queryScrollPane = new RTextScrollPane(query);
inputVBox.add(queryScrollPane, BorderLayout.CENTER);
final Box optionsPanel = Box.createHorizontalBox();
label = new JLabel(Messages.getString("QueryDialog.contextlabel"));
optionsPanel.add(label);
final List<String> data = new ArrayList<>();
try {
final Collection root = client.getCollection(XmldbURI.ROOT_COLLECTION);
data.add(collection.getName());
getCollections(root, collection, data);
} catch (final XMLDBException e) {
ClientFrame.showErrorMessage(Messages.getString("QueryDialog.collectionretrievalerrormessage") + ".", e);
}
collections = new JComboBox<>(new java.util.Vector<>(data));
collections.setSelectedIndex(0);
collections.addActionListener(e -> {
final int p = collections.getSelectedIndex();
final String context;
if (p == -1) {
context = "/db";
} else {
context = data.get(p);
}
try {
collection = client.getCollection(context);
} catch (final XMLDBException e1) {
}
});
optionsPanel.add(collections);
label = new JLabel(Messages.getString("QueryDialog.maxlabel"));
optionsPanel.add(label);
count = new SpinnerNumberModel(100, 1, 10000, 50);
final JSpinner spinner = new JSpinner(count);
spinner.setMaximumSize(new Dimension(400, 100));
optionsPanel.add(spinner);
inputVBox.add(optionsPanel, BorderLayout.SOUTH);
return tabs;
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class TriggersDialog method getCollections.
// THIS IS A COPY FROM ClientFrame
// TODO: share this code between the two classes
private List<PrettyXmldbURI> getCollections(final Collection root, final List<PrettyXmldbURI> collectionsList) throws XMLDBException {
collectionsList.add(new PrettyXmldbURI(XmldbURI.create(root.getName())));
final String[] childCollections = root.listChildCollections();
Collection child;
for (String childCollection : childCollections) {
try {
child = root.getChildCollection(childCollection);
} catch (final XMLDBException xmldbe) {
if (xmldbe.getCause() instanceof PermissionDeniedException) {
continue;
} else {
throw xmldbe;
}
}
getCollections(child, collectionsList);
}
return collectionsList;
}
Aggregations