コード例 #1
0
  @Override
  public void chown(final Account u, final String group) throws XMLDBException {
    final XmldbURI collUri = collection.getPathURI();

    try {
      executeWithBroker(
          new BrokerOperation<Void>() {
            @Override
            public Void withBroker(final DBBroker broker)
                throws XMLDBException, LockException, PermissionDeniedException, IOException,
                    EXistException, TriggerException, SyntaxException {
              return modifyCollection(
                  broker,
                  collUri,
                  new DatabaseItemModifier<org.exist.collections.Collection, Void>() {
                    @Override
                    public Void modify(org.exist.collections.Collection collection)
                        throws PermissionDeniedException, SyntaxException, LockException {
                      final Permission permission = collection.getPermissions();
                      permission.setOwner(u);
                      permission.setGroup(group);
                      return null;
                    }
                  });
            }
          });
    } catch (final Exception e) {
      throw new XMLDBException(
          ErrorCodes.VENDOR_ERROR,
          "Failed to modify permission on Collection '" + collUri.toString() + "'",
          e);
    }
  }
コード例 #2
0
  @Override
  public void setPermissions(final Collection child, final Permission perm) throws XMLDBException {

    final XmldbURI childUri = XmldbURI.create(child.getName());

    try {
      executeWithBroker(
          new BrokerOperation<Void>() {
            @Override
            public Void withBroker(final DBBroker broker)
                throws XMLDBException, LockException, PermissionDeniedException, IOException,
                    EXistException, TriggerException, SyntaxException {
              return modifyCollection(
                  broker,
                  childUri,
                  new DatabaseItemModifier<org.exist.collections.Collection, Void>() {
                    @Override
                    public Void modify(org.exist.collections.Collection collection)
                        throws PermissionDeniedException, LockException {
                      collection.setPermissions(perm);
                      return null;
                    }
                  });
            }
          });
    } catch (final Exception e) {
      throw new XMLDBException(
          ErrorCodes.VENDOR_ERROR,
          "Failed to modify permission on Collection '" + childUri.toString() + "'",
          e);
    }
  }
コード例 #3
0
 public void copyResource(XmldbURI resourcePath, XmldbURI destinationPath, XmldbURI newName)
     throws XMLDBException {
   resourcePath = parent.getPathURI().resolveCollectionPath(resourcePath);
   if (destinationPath == null) destinationPath = resourcePath.removeLastSegment();
   else destinationPath = parent.getPathURI().resolveCollectionPath(destinationPath);
   if (newName == null) {
     newName = resourcePath.lastSegment();
   }
   Vector params = new Vector();
   params.addElement(resourcePath.toString());
   params.addElement(destinationPath.toString());
   params.addElement(newName.toString());
   try {
     client.execute("copyResource", params);
   } catch (XmlRpcException xre) {
     throw new XMLDBException(ErrorCodes.VENDOR_ERROR, xre.getMessage(), xre);
   } catch (IOException ioe) {
     throw new XMLDBException(ErrorCodes.VENDOR_ERROR, ioe.getMessage(), ioe);
   }
 }
コード例 #4
0
  private <R> R modifyCollection(
      DBBroker broker,
      XmldbURI collectionURI,
      DatabaseItemModifier<org.exist.collections.Collection, R> modifier)
      throws XMLDBException, LockException, PermissionDeniedException, IOException, EXistException,
          TriggerException, SyntaxException {
    final TransactionManager transact = broker.getBrokerPool().getTransactionManager();
    final Txn transaction = transact.beginTransaction();

    org.exist.collections.Collection coll = null;

    try {
      coll = broker.openCollection(collectionURI, Lock.WRITE_LOCK);
      if (coll == null) {
        throw new XMLDBException(
            ErrorCodes.INVALID_COLLECTION, "Collection " + collectionURI.toString() + " not found");
      }

      final R result = modifier.modify(coll);

      broker.saveCollection(transaction, coll);
      transact.commit(transaction);
      broker.flush();

      return result;

    } catch (final EXistException ee) {
      transact.abort(transaction);
      throw ee;
    } catch (final XMLDBException xmldbe) {
      transact.abort(transaction);
      throw xmldbe;
    } catch (final LockException le) {
      transact.abort(transaction);
      throw le;
    } catch (final PermissionDeniedException pde) {
      transact.abort(transaction);
      throw pde;
    } catch (final IOException ioe) {
      transact.abort(transaction);
      throw ioe;
    } catch (final TriggerException te) {
      transact.abort(transaction);
      throw te;
    } catch (final SyntaxException se) {
      transact.abort(transaction);
      throw se;
    } finally {
      transact.close(transaction);
      if (coll != null) {
        coll.release(Lock.WRITE_LOCK);
      }
    }
  }
コード例 #5
0
 /* (non-Javadoc)
  * @see org.xmldb.api.base.Resource#getContent()
  */
 public Object getContent() throws XMLDBException {
   if (data != null) return data;
   Vector params = new Vector();
   params.addElement(path.toString());
   try {
     data = (byte[]) parent.getClient().execute("getBinaryResource", params);
   } catch (XmlRpcException e) {
     throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e.getMessage(), e);
   } catch (IOException e) {
     throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
   }
   return data;
 }
コード例 #6
0
  public void removeCollection(XmldbURI collName) throws XMLDBException {
    if (parent != null) collName = parent.getPathURI().resolveCollectionPath(collName);

    Vector params = new Vector();
    params.addElement(collName.toString());
    try {
      client.execute("removeCollection", params);
    } catch (XmlRpcException xre) {
      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, xre.getMessage(), xre);
    } catch (IOException ioe) {
      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, ioe.getMessage(), ioe);
    }
    parent.removeChildCollection(collName);
  }
コード例 #7
0
  @Override
  public void setPermissions(
      Collection child,
      final String owner,
      final String group,
      final int mode,
      final List<ACEAider> aces)
      throws XMLDBException {

    final XmldbURI childUri = XmldbURI.create(child.getName());

    try {
      executeWithBroker(
          new BrokerOperation<Void>() {
            @Override
            public Void withBroker(final DBBroker broker)
                throws XMLDBException, LockException, PermissionDeniedException, IOException,
                    EXistException, TriggerException, SyntaxException {
              return modifyCollection(
                  broker,
                  childUri,
                  new DatabaseItemModifier<org.exist.collections.Collection, Void>() {
                    @Override
                    public Void modify(org.exist.collections.Collection collection)
                        throws PermissionDeniedException, LockException {
                      final Permission permission = collection.getPermissions();
                      permission.setOwner(owner);
                      permission.setGroup(group);
                      permission.setMode(mode);
                      if (permission instanceof ACLPermission) {
                        final ACLPermission aclPermission = (ACLPermission) permission;
                        aclPermission.clear();
                        for (final ACEAider ace : aces) {
                          aclPermission.addACE(
                              ace.getAccessType(), ace.getTarget(), ace.getWho(), ace.getMode());
                        }
                      }
                      return null;
                    }
                  });
            }
          });
    } catch (final Exception e) {
      throw new XMLDBException(
          ErrorCodes.VENDOR_ERROR,
          "Failed to modify permission on Collection '" + childUri.toString() + "'",
          e);
    }
  }
コード例 #8
0
  public Collection createCollection(XmldbURI collName, Date created) throws XMLDBException {
    if (parent != null) collName = parent.getPathURI().resolveCollectionPath(collName);

    Vector params = new Vector();
    params.addElement(collName.toString());

    if (created != null) {
      params.addElement(created);
    }

    try {
      client.execute("createCollection", params);
    } catch (XmlRpcException xre) {
      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, xre.getMessage(), xre);
    } catch (IOException ioe) {
      throw new XMLDBException(ErrorCodes.VENDOR_ERROR, ioe.getMessage(), ioe);
    }
    RemoteCollection collection = new RemoteCollection(client, (RemoteCollection) parent, collName);
    parent.addChildCollection(collection);
    return collection;
  }
コード例 #9
0
  private <R> R readCollection(
      DBBroker broker,
      XmldbURI collectionURI,
      DatabaseItemReader<org.exist.collections.Collection, R> reader)
      throws XMLDBException, PermissionDeniedException {
    org.exist.collections.Collection coll = null;

    try {
      coll = broker.openCollection(collectionURI, Lock.READ_LOCK);
      if (coll == null) {
        throw new XMLDBException(
            ErrorCodes.INVALID_COLLECTION, "Collection " + collectionURI.toString() + " not found");
      }

      return reader.read(coll);

    } finally {
      if (coll != null) {
        coll.release(Lock.READ_LOCK);
      }
    }
  }