log("Creating resource of type " + resourceType + " with mime-type: " + mime.getName(), Project.MSG_DEBUG);
log("Creating resource " + srcFile.getName() + " in collection " + col.getName() + " of type " + resourceType + " with mime-type: " + mime.getName(), Project.MSG_DEBUG);
  public void execute() throws BuildException  {    if (uri == null)      throw new BuildException("you have to specify an XMLDB collection URI");    if (fileSet == null && srcFile == null)      throw new BuildException("no file set specified");    registerDatabase();    int p = uri.indexOf(DBBroker.ROOT_COLLECTION);    if (p == Constants.STRING_NOT_FOUND)      throw new BuildException("invalid uri: '" + uri + "'");    try    {      String baseURI = uri.substring(0, p);      String path;      if (p == uri.length() - 3)        path = "";      else        path = uri.substring(p + 3);      Collection root = null;      if (createCollection)      {        root = DatabaseManager.getCollection(baseURI + DBBroker.ROOT_COLLECTION);        root = mkcol(root, baseURI, DBBroker.ROOT_COLLECTION, path);      } else        root = DatabaseManager.getCollection(uri, user, password);      if (root == null)        throw new BuildException("collection " + uri + " not found");      MimeType mime = null;      if (type != null) {          if (type.equals("xml"))              mime = MimeType.XML_TYPE;          else if (type.equals("binary"))              mime = MimeType.BINARY_TYPE;          else {              mime = MimeTable.getInstance().getContentType(type);          }      }            Resource res;      File file;      Collection col = root;      String relDir, prevDir = null, resourceType = "XMLResource";      if (srcFile != null)      {        log("Storing single file " + srcFile.getAbsolutePath(), Project.MSG_DEBUG);        // single file        if (mime == null)            mime = MimeTable.getInstance().getContentTypeFor(srcFile.getName());        resourceType = mime.isXMLType() ? "XMLResource" : "BinaryResource";        log("Creating resource of type " + resourceType + " with mime-type: " + mime.getName(), Project.MSG_DEBUG);        res = col.createResource(srcFile.getName(), resourceType);        res.setContent(srcFile);        ((EXistResource) res).setMimeType(mime.getName());        col.storeResource(res);      } else      {        log("Storing fileset", Project.MSG_DEBUG);        // using fileset        DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());        scanner.scan();        String[] files = scanner.getIncludedFiles();        log("Found " + files.length + " files.\n");         MimeType currentMime = mime;        for (int i = 0; i < files.length; i++)        {          file = new File(scanner.getBasedir() + File.separator + files[i]);          log("Storing " + files[i] + " ...\n");          //TODO : use dedicated function in XmldbURI          // check whether the relative file path contains file seps          p = files[i].lastIndexOf(File.separatorChar);                    if (p != Constants.STRING_NOT_FOUND)          {            relDir = files[i].substring(0, p);            // It's necessary to do this translation on Windows, and possibly MacOS:            relDir = relDir.replace(File.separatorChar, '/');            if (createSubcollections && (prevDir == null || (!relDir.equals(prevDir))))            {              //TODO : use dedicated function in XmldbURI              col = mkcol(root, baseURI, DBBroker.ROOT_COLLECTION + path, relDir);              prevDir = relDir;            }          }          if (mime == null)              currentMime = MimeTable.getInstance().getContentTypeFor(file.getName());          resourceType = currentMime.isXMLType() ? "XMLResource" : "BinaryResource";          log("Creating resource of type " + resourceType + " with mime-type: " + currentMime.getName());          res = col.createResource(file.getName(), resourceType);          res.setContent(file);          ((EXistResource) res).setMimeType(currentMime.getName());          col.storeResource(res);        }      }    } catch (XMLDBException e)    {      throw new BuildException("XMLDB exception caught: " + e.getMessage(), e);    }  }