use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class EditPropertiesDialog method btnSaveActionPerformed.
// </editor-fold>//GEN-END:initComponents
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
try {
for (final ResourceDescriptor desc : applyTo) {
final String newOwner;
if (MULTIPLE_INDICATOR.equals(lblOwnerValue.getText()) || desc.getOwner().equals(lblOwnerValue.getText())) {
newOwner = desc.getOwner();
} else {
newOwner = lblOwnerValue.getText();
}
final String newGroup;
if (MULTIPLE_INDICATOR.equals(lblGroupValue.getText()) || desc.getGroup().equals(lblGroupValue.getText())) {
newGroup = desc.getGroup();
} else {
newGroup = lblGroupValue.getText();
}
final Permission existingPermission = desc.getPermissions();
final ModeDisplay modeChanges = getBasicPermissionsTableModel().getMode();
final Permission updatedPermission = getUpdatedPermission(existingPermission, modeChanges);
final List<ACEAider> dlgAces = new ArrayList<>();
if (acl == null) {
if (existingPermission instanceof ACLPermission) {
final ACLPermission existingAclPermission = (ACLPermission) existingPermission;
for (int i = 0; i < existingAclPermission.getACECount(); i++) {
dlgAces.add(new ACEAider(existingAclPermission.getACEAccessType(i), existingAclPermission.getACETarget(i), existingAclPermission.getACEWho(i), existingAclPermission.getACEMode(i)));
}
}
} else {
for (int i = 0; i < tblAcl.getRowCount(); i++) {
final ACLPermission.ACE_TARGET target = ACLPermission.ACE_TARGET.valueOf((String) getAclTableModel().getValueAt(i, 0));
final String who = (String) getAclTableModel().getValueAt(i, 1);
final ACLPermission.ACE_ACCESS_TYPE access = ACLPermission.ACE_ACCESS_TYPE.valueOf((String) getAclTableModel().getValueAt(i, 2));
int mode = 0;
if ((Boolean) tblAcl.getValueAt(i, 3)) {
mode |= Permission.READ;
}
if ((Boolean) tblAcl.getValueAt(i, 4)) {
mode |= Permission.WRITE;
}
if ((Boolean) tblAcl.getValueAt(i, 5)) {
mode |= Permission.EXECUTE;
}
dlgAces.add(new ACEAider(access, target, who, mode));
}
}
if (desc.isCollection()) {
final Collection coll = parent.getChildCollection(desc.getName().toString());
getUserManagementService().setPermissions(coll, newOwner, newGroup, updatedPermission.getMode(), dlgAces);
} else {
final Resource res = parent.getResource(desc.getName().toString());
getUserManagementService().setPermissions(res, newOwner, newGroup, updatedPermission.getMode(), dlgAces);
}
}
setVisible(false);
dispose();
} catch (final PermissionDeniedException | XMLDBException e) {
JOptionPane.showMessageDialog(this, "Could not update properties: " + e.getMessage(), ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class EditUserDialog method updateUser.
private void updateUser() {
try {
final Optional<String> newPassword = setAccountFromFormProperties();
/**
* We update the account in three stages:
*
* 1) General account properties
* 2) Group memebrship
* 3) Optionally set changed password.
*
* The password is always changed last if needed,
* as it means the admin client must reconnect
* if we are changing the logged in users password.
*
* The reconnection is performed by the registered
* DialogCompleteWithResponse handler
*/
// 1) Update general account properties
getUserManagementService().updateAccount(getAccount());
// 2) Update group membership (has to be modified separately from (1))
modifyAccountGroupMembership();
// 3) Finally, optionally change the password
if (newPassword.isPresent()) {
final Account acct = getUserManagementService().getAccount(getAccount().getName());
acct.setPassword(newPassword.get());
getUserManagementService().updateAccount(acct);
}
} catch (final PermissionDeniedException | XMLDBException pde) {
JOptionPane.showMessageDialog(this, "Could not update user '" + txtUsername.getText() + "': " + pde.getMessage(), "Edit User Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class IndexDialog method setupComponents.
private void setupComponents() {
// Dialog Content Panel
final GridBagLayout grid = new GridBagLayout();
getContentPane().setLayout(grid);
// Constraints for Layout
final GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 2, 2, 2);
// collection label
final JLabel label = new JLabel("Collection");
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 1;
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.NONE;
c.weightx = 0;
c.weighty = 0;
grid.setConstraints(label, c);
getContentPane().add(label);
// get the collections but not system collections
final ArrayList alCollections = new ArrayList();
try {
final Collection root = client.getCollection(XmldbURI.ROOT_COLLECTION);
final ArrayList alAllCollections = getCollections(root, new ArrayList());
for (Object alAllCollection : alAllCollections) {
// TODO : use XmldbURIs !
if (alAllCollection.toString().contains(CollectionConfigurationManager.CONFIG_COLLECTION)) {
alCollections.add(alAllCollection);
}
}
} catch (final XMLDBException e) {
// showErrorMessage(e.getMessage(), e);
return;
}
// Create a combobox listing the collections
cmbCollections = new JComboBox(alCollections.toArray());
cmbCollections.addActionListener(e -> {
saveChanges(true);
final JComboBox cb = (JComboBox) e.getSource();
actionGetIndexes(cb.getSelectedItem().toString());
});
c.gridx = 1;
c.gridy = 0;
c.gridwidth = 1;
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1;
c.weighty = 0;
grid.setConstraints(cmbCollections, c);
getContentPane().add(cmbCollections);
// Panel to hold controls relating to the Range Indexes
final JPanel panelRangeIndexes = new JPanel();
panelRangeIndexes.setBorder(new TitledBorder("Range Indexes"));
final GridBagLayout panelRangeIndexesGrid = new GridBagLayout();
panelRangeIndexes.setLayout(panelRangeIndexesGrid);
// Table to hold the Range Indexes with Sroll bar
rangeIndexModel = new RangeIndexTableModel();
tblRangeIndexes = new JTable(rangeIndexModel);
tblRangeIndexes.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
tblRangeIndexes.setRowHeight(20);
tblRangeIndexes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumn colxsType = tblRangeIndexes.getColumnModel().getColumn(2);
colxsType.setCellEditor(new ComboBoxCellEditor(INDEX_TYPES));
colxsType.setCellRenderer(new ComboBoxCellRenderer(INDEX_TYPES));
colxsType = tblRangeIndexes.getColumnModel().getColumn(0);
colxsType.setCellEditor(new ComboBoxCellEditor(CONFIG_TYPE));
colxsType.setCellRenderer(new ComboBoxCellRenderer(CONFIG_TYPE));
final JScrollPane scrollRangeIndexes = new JScrollPane(tblRangeIndexes);
scrollRangeIndexes.setPreferredSize(new Dimension(350, 150));
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 2;
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
panelRangeIndexesGrid.setConstraints(scrollRangeIndexes, c);
panelRangeIndexes.add(scrollRangeIndexes);
// Toolbar with add/delete buttons for Range Index
final Box rangeIndexToolbarBox = Box.createHorizontalBox();
// add button
final JButton btnAddRangeIndex = new JButton("Add");
btnAddRangeIndex.addActionListener(e -> actionAddRangeIndex());
rangeIndexToolbarBox.add(btnAddRangeIndex);
// delete button
final JButton btnDeleteRangeIndex = new JButton("Delete");
btnDeleteRangeIndex.addActionListener(e -> actionDeleteRangeIndex());
rangeIndexToolbarBox.add(btnDeleteRangeIndex);
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 2;
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.BOTH;
c.weightx = 0;
c.weighty = 0;
panelRangeIndexesGrid.setConstraints(rangeIndexToolbarBox, c);
panelRangeIndexes.add(rangeIndexToolbarBox);
// add range index panel to content frame
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 2;
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1F / 3F;
grid.setConstraints(panelRangeIndexes, c);
getContentPane().add(panelRangeIndexes);
final Box mainBtnBox = Box.createHorizontalBox();
final JButton cancelBtn = new JButton("Cancel");
cancelBtn.addActionListener(e -> {
IndexDialog.this.setVisible(false);
IndexDialog.this.dispose();
});
final JButton saveBtn = new JButton("Save");
saveBtn.addActionListener(e -> {
saveChanges(false);
IndexDialog.this.setVisible(false);
IndexDialog.this.dispose();
});
mainBtnBox.add(saveBtn);
mainBtnBox.add(cancelBtn);
c.gridx = 0;
c.gridy = 3;
c.gridwidth = 2;
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.BOTH;
c.weightx = 0;
c.weighty = 0;
grid.setConstraints(mainBtnBox, c);
getContentPane().add(mainBtnBox);
pack();
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class DuplicateAttributesTest method appendStoredAttrOK.
/**
* Add attribute to element which has no conflicting attributes.
*/
@Test
public void appendStoredAttrOK() {
try {
XQueryService xqs = (XQueryService) testCollection.getService("XQueryService", "1.0");
String query = "let $a := \n" + "<node attr=\"a\" b=\"c\">{doc(\"/db/test/stored2.xml\")//@attr2}</node>" + "return $a";
ResourceSet result = xqs.query(query);
assertEquals(1, result.getSize());
assertEquals("<node attr=\"a\" b=\"c\" attr2=\"ab\"/>", result.getResource(0).getContent());
} catch (XMLDBException e) {
LOG.error(e.getMessage(), e);
fail(e.getMessage());
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class AbstractExtractFunction method eval.
@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
this.contextSequence = contextSequence;
if (args[0].isEmpty())
return Sequence.EMPTY_SEQUENCE;
// get the entry-filter function and check its types
if (!(args[1].itemAt(0) instanceof FunctionReference))
throw new XPathException("No entry-filter function provided.");
entryFilterFunction = (FunctionReference) args[1].itemAt(0);
FunctionSignature entryFilterFunctionSig = entryFilterFunction.getSignature();
if (entryFilterFunctionSig.getArgumentCount() < 3)
throw new XPathException("entry-filter function must take at least 3 arguments.");
filterParam = args[2];
// get the entry-data function and check its types
if (!(args[3].itemAt(0) instanceof FunctionReference))
throw new XPathException("No entry-data function provided.");
entryDataFunction = (FunctionReference) args[3].itemAt(0);
FunctionSignature entryDataFunctionSig = entryDataFunction.getSignature();
if (entryDataFunctionSig.getArgumentCount() < 3)
throw new XPathException("entry-data function must take at least 3 arguments");
storeParam = args[4];
try {
final Charset encoding;
if ((args.length >= 6) && !args[5].isEmpty()) {
encoding = Charset.forName(args[5].getStringValue());
} else {
encoding = StandardCharsets.UTF_8;
}
BinaryValue compressedData = ((BinaryValue) args[0].itemAt(0));
return processCompressedData(compressedData, encoding);
} catch (final UnsupportedCharsetException | XMLDBException e) {
throw new XPathException(this, e.getMessage(), e);
} finally {
entryDataFunction.close();
entryFilterFunction.close();
}
}
Aggregations