Index: src/edu/ucsb/nceas/metacat/AuthSession.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AuthSession.java	(revision 2044)
+++ src/edu/ucsb/nceas/metacat/AuthSession.java	(revision 2045)
@@ -53,6 +53,14 @@
     this.authClass = util.getOption("authclass");
     this.authService = (AuthInterface)createObject(authClass);
   }
+  
+  /**
+   * Get the new session
+   */
+  public HttpSession getSessions()
+  {
+    return this.session;
+  }
 
   /** 
    * determine if the credentials for this session are valid by 
@@ -72,7 +80,7 @@
         {
           groups = new String[0];
         }
-        this.session = getSession(request, username, password, groups);
+        this.session = createSession(request, username, password, groups);
         String sessionId = session.getId();
         message = "Authentication successful for user: " + username;
         this.statusMessage = formatOutput("login", message, sessionId);
@@ -94,7 +102,7 @@
   }
 
   /** Get new HttpSession and store username & password in it */
-  private HttpSession getSession(HttpServletRequest request, 
+  private HttpSession createSession(HttpServletRequest request, 
                                  String username, String password,
                                  String[] groups)  
                       throws IllegalStateException {
@@ -104,7 +112,13 @@
 
     // if it is still in use invalidate and get a new one
     if ( !session.isNew() ) {
+      MetaCatUtil.debugMessage("in session is not new", 40);
+      MetaCatUtil.debugMessage("the old session id is : " +
+                                session.getId(), 30);
+      MetaCatUtil.debugMessage("the old session username : " +
+                                session.getAttribute("username"), 30);
       session.invalidate();
+      MetaCatUtil.debugMessage("in session is not new", 40);
       session = request.getSession(true);
     }
     // store the username, password, and groupname (the first only)
@@ -115,7 +129,10 @@
     if ( groups.length > 0 ) {
       session.setAttribute("groupnames", groups);
     }
-    
+     MetaCatUtil.debugMessage("the new session id is : " +
+                                session.getId(), 30);
+     MetaCatUtil.debugMessage("the new session username : " +
+                                session.getAttribute("username"), 30);
     return session;
   }
 
Index: src/edu/ucsb/nceas/metacat/QuerySpecification.java
===================================================================
--- src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 2044)
+++ src/edu/ucsb/nceas/metacat/QuerySpecification.java	(revision 2045)
@@ -167,8 +167,16 @@
    * @param myName  the user name
    */
   public void setUserName(String myName)
-  {
-    this.userName = myName;
+  { 
+    //to lower case
+    if (myName != null)
+    {
+      this.userName = myName.toLowerCase();
+    }
+    else
+    {
+      this.userName = myName;
+    }
   }
   
   /**
@@ -196,7 +204,7 @@
     ownerQuery = "SELECT docid FROM xml_documents WHERE ";
     if (userName != null && !userName.equals(""))
     {
-      ownerQuery = ownerQuery + "user_owner ='"+ userName +"'";
+      ownerQuery = ownerQuery + "lower(user_owner) ='"+ userName +"'";
     }
     
     MetaCatUtil.debugMessage("OwnerQuery: "+ownerQuery, 30);
@@ -226,12 +234,12 @@
      // add allow rule for user name
      if (userName != null && !userName.equals(""))
     {
-      allowQuery = allowQuery +"(principal_name = '" + userName 
+      allowQuery = allowQuery +"(lower(principal_name) = '" + userName 
                               +"' AND perm_type = 'allow'"
                               +" AND (permission='4' OR permission='7'))";
     }
     // add allow rule for public
-    allowQuery = allowQuery +"OR (principal_name = '" + PUBLIC 
+    allowQuery = allowQuery +"OR (lower(principal_name) = '" + PUBLIC 
                               +"' AND perm_type = 'allow'"
                               +" AND (permission='4' OR permission='7'))";
     
@@ -243,7 +251,8 @@
         String groupUint = group[i];
         if (groupUint != null && !groupUint.equals(""))
         {
-          allowQuery = allowQuery +" OR (principal_name = '" + groupUint 
+          groupUint = groupUint.toLowerCase();
+          allowQuery = allowQuery +" OR (lower(principal_name) = '" + groupUint 
                               +"' AND perm_type = 'allow'"
                               +" AND (permission='4' OR permission='7'))";
         }//if
@@ -275,13 +284,13 @@
     // add deny rule for user name
     if (userName != null && !userName.equals(""))
     {
-      denyQuery = denyQuery +"(principal_name = '" + userName 
+      denyQuery = denyQuery +"(lower(principal_name) = '" + userName 
                               +"' AND perm_type = 'deny' "
                               +"AND perm_order ='allowFirst'"
                               +" AND (permission='4' OR permission='7'))";
     }
     // add deny rule for public
-    denyQuery = denyQuery +"OR (principal_name = '" + PUBLIC 
+    denyQuery = denyQuery +"OR (lower(principal_name) = '" + PUBLIC 
                                +"' AND perm_type = 'deny' "
                                +"AND perm_order ='allowFirst'"
                                +" AND (permission='4' OR permission='7'))";
@@ -294,7 +303,8 @@
         String groupUint = group[i];
         if (groupUint != null && !groupUint.equals(""))
         {
-          denyQuery = denyQuery +" OR (principal_name = '" + groupUint 
+          groupUint = groupUint.toLowerCase();
+          denyQuery = denyQuery +" OR (lower(principal_name) = '" + groupUint 
                                 +"' AND perm_type = 'deny' "
                                 +"AND perm_order ='allowFirst'"
                                 +" AND (permission='4' OR permission='7'))";
@@ -715,11 +725,15 @@
       Enumeration en = ownerList.elements();
       while (en.hasMoreElements()) {
         String current = (String)en.nextElement();
+        if (current != null)
+        {
+          current = current.toLowerCase();
+        }
         if (first) {
            first = false;
-           self.append(" user_owner = '" + current + "'"); 
+           self.append(" lower(user_owner) = '" + current + "'"); 
         } else {
-          self.append(" OR user_owner = '" + current + "'"); 
+          self.append(" OR lower(user_owner) = '" + current + "'"); 
         }
       }
       self.append(") ");
@@ -774,7 +788,7 @@
     sql.append("(");
     sql.append("startnodeid NOT IN (SELECT startnodeid from xml_access, xml_documents ");
     sql.append(" WHERE xml_access.docid = xml_documents.docid");
-    sql.append(" AND xml_documents.user_owner ='");
+    sql.append(" AND lower(xml_documents.user_owner) ='");
     sql.append(userName);
     sql.append("' AND xml_access.startnodeid IS NOT NULL)"); 
     sql.append(")");
Index: src/edu/ucsb/nceas/metacat/DBQuery.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DBQuery.java	(revision 2044)
+++ src/edu/ucsb/nceas/metacat/DBQuery.java	(revision 2045)
@@ -814,8 +814,12 @@
    */
   private String getOwnerQuery(String owner)
   {
+    if (owner != null)
+    {
+      owner = owner.toLowerCase();
+    }
     StringBuffer self = new StringBuffer();
-
+  
     self.append("SELECT docid,docname,doctype,");
     self.append("date_created, date_updated, rev ");
     self.append("FROM xml_documents WHERE docid IN (");
@@ -825,7 +829,7 @@
     self.append(") \n");
     self.append(") ");
     self.append(" AND (");
-    self.append(" user_owner = '" + owner + "'");
+    self.append(" lower(user_owner) = '" + owner + "'");
     self.append(") ");
     return self.toString();
   }
Index: src/edu/ucsb/nceas/metacat/MetaCatUtil.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatUtil.java	(revision 2044)
+++ src/edu/ucsb/nceas/metacat/MetaCatUtil.java	(revision 2045)
@@ -419,7 +419,9 @@
 
     return docId;
   }//getDocIdFromString
+  
 
+
   /**
    * Utility method to get version number from a given string
    * @param string, the given string should be these two format:
@@ -516,6 +518,77 @@
   }//getVersionFromString
 
   /**
+   * This method will get docid from an AccessionNumber. There is no assumption
+   * the accessnumber will be str1.str2.str3. It can be more. So we think
+   * the docid will be get rid of last part
+   */
+   public static String getDocIdFromAccessionNumber(String accessionNumber)
+   {
+     String docid = null;
+     if (accessionNumber == null)
+     {
+       return docid;
+     }
+     String seperator=getOption("accNumSeparator");
+     int indexOfLastSeperator = accessionNumber.lastIndexOf(seperator);
+     docid=accessionNumber.substring(0, indexOfLastSeperator);
+     MetaCatUtil.debugMessage("after parsing accessionnumber, docid is " + 
+                              docid, 30);
+     return docid;
+   }
+   
+   /**
+    * This method will call both getDocIdFromString and
+    * getDocIdFromAccessionNumber. So first, if the string looks
+    * str1.str2, the docid will be str1.str2.
+    * If the string is str1.str2.str3, the docid will be str1.str2.
+    * If the string is str1.str2.str3.str4 or more, the docid will be
+    * str1.str2.str3.
+    * If the string look like str1, null will be returned
+    *
+    */
+    public static String getSmartDocId(String str)
+    {
+      String docid = null;
+      //call geDocIdFromString first. 
+      docid = getDocIdFromString(str);
+      // If docid is null, try to call getDocIdFromAccessionNumber
+      // it will handle the seperator more than2
+      if (docid == null)
+      {
+         docid = getDocIdFromAccessionNumber(str);        
+      }
+      MetaCatUtil.debugMessage("The docid get from smart docid getor is " +
+                                docid, 30);
+      return docid;
+    }
+   
+    /**
+   * This method will get revision from an AccessionNumber. There is no assumption
+   * the accessnumber will be str1.str2.str3. It can be more. So we think
+   * the docid will be get rid of last part
+   */
+   public static int getRevisionFromAccessionNumber(String accessionNumber)
+                                        throws NumberFormatException
+   {
+     String rev = null;
+     int revNumber =-1;
+     if (accessionNumber == null)
+     {
+       return revNumber;
+     }
+     String seperator=getOption("accNumSeparator");
+     int indexOfLastSeperator = accessionNumber.lastIndexOf(seperator);
+     rev =accessionNumber.substring(indexOfLastSeperator+1, 
+                                    accessionNumber.length());
+     revNumber = Integer.parseInt(rev);
+     MetaCatUtil.debugMessage("after parsing accessionnumber, rev is " + 
+                               revNumber, 30);
+     return revNumber;
+   }
+   
+  
+  /**
    * Method to get the name of local replication server
    */
    public static String getLocalReplicationServerName()
Index: src/edu/ucsb/nceas/metacat/MetaCatServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 2044)
+++ src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 2045)
@@ -315,25 +315,36 @@
         HttpSession sess = request.getSession(true);
         if (sess.isNew() && !params.containsKey("sessionid")) {
           // session expired or has not been stored b/w user requests
+          MetaCatUtil.debugMessage("in session is new or no sessionid", 40);
           username = "public";
           sess.setAttribute("username", username);
         }
         else
         {
+          MetaCatUtil.debugMessage("in session is not new or " + 
+                                    " has sessionid parameter", 40);
           try
           {
             if(params.containsKey("sessionid"))
             {
               sess_id = ((String[])params.get("sessionid"))[0];
+              MetaCatUtil.debugMessage("in has sessionid " + sess_id, 40);
               if(sessionHash.containsKey(sess_id))
               {
+                MetaCatUtil.debugMessage("find the id " + sess_id + 
+                                         " in hash table", 40);
                 sess = (HttpSession)sessionHash.get(sess_id);
               }
             }
             else
             {
+              // we already store the session in login, so we don't need here
+              /*MetaCatUtil.debugMessage("in no sessionid parameter ", 40);
               sess_id = (String)sess.getId();
-              sessionHash.put(sess_id, sess);
+              MetaCatUtil.debugMessage("storing the session id "+ sess_id +
+                  " which has username " + sess.getAttribute("username") + 
+                 " into session hash in handleGetOrPost method", 35);
+              sessionHash.put(sess_id, sess);*/
             }
           }
           catch(IllegalStateException ise)
@@ -344,17 +355,19 @@
           }
 
           username = (String)sess.getAttribute("username");
+          MetaCatUtil.debugMessage("The user name from session is: "+
+                                   username, 20);
           password = (String)sess.getAttribute("password");
           groupnames = (String[])sess.getAttribute("groupnames");
         }
-      }
       
-      //make user user username should be public
-      if (username == null || (username.trim().equals("")))
-      {
-        username = "public";
+        //make user user username should be public
+        if (username == null || (username.trim().equals("")))
+        {
+          username = "public";
+        }
+        MetaCatUtil.debugMessage("The user is : "+ username, 5);
       }
-
        // Now that we know the session is valid, we can delegate the request
       // to a particular action handler
       if(action.equals("query")) {
@@ -497,6 +510,7 @@
 
     AuthSession sess = null;
     String un = ((String[])params.get("username"))[0];
+    MetaCatUtil.debugMessage("user " + un + " try to login", 20);
     String pw = ((String[])params.get("password"))[0];
     String action = ((String[])params.get("action"))[0];
     String qformat = ((String[])params.get("qformat"))[0];
@@ -510,6 +524,18 @@
       return;
     }
     boolean isValid = sess.authenticate(request, un, pw);
+    
+    //if it is authernticate is true, store the session
+    if (isValid)
+    {
+      HttpSession session = sess.getSessions();
+      String id = session.getId();
+      MetaCatUtil.debugMessage("Store session id " + id + 
+               "which has username" + session.getAttribute("username")+
+               " into hash in login method", 35);
+      sessionHash.put(id, session);
+    }
+    
     // format and transform the output
     if (qformat.equals("xml")) {
       response.setContentType("text/xml");
@@ -543,7 +569,16 @@
 
     // close the connection
     HttpSession sess = request.getSession(false);
-    if (sess != null) { sess.invalidate();  }
+    MetaCatUtil.debugMessage("After get session in logout request", 40);
+    if (sess != null) 
+    {
+     MetaCatUtil.debugMessage("The session id " + sess.getId() + 
+                              " will be invalidate in logout action", 30);
+     MetaCatUtil.debugMessage("The session contains user " + 
+                               sess.getAttribute("username") +
+                               " will be invalidate in logout action", 30);
+      sess.invalidate();  
+    }
 
     // produce output
     StringBuffer output = new StringBuffer();
Index: src/edu/ucsb/nceas/metacat/EmlSAXHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/EmlSAXHandler.java	(revision 2044)
+++ src/edu/ucsb/nceas/metacat/EmlSAXHandler.java	(revision 2045)
@@ -140,7 +140,8 @@
      // Get the unchangable subtrees (user doesn't have write permission)
      try
      {
-       PermissionController control = new PermissionController(docid);
+       PermissionController control = new PermissionController(docid+
+                             MetaCatUtil.getOption("accNumSeparator")+revision);
        //unChangableSubTreeHash = getUnchangableSubTree(control, user, groups);
        
        
Index: src/edu/ucsb/nceas/metacat/PermissionController.java
===================================================================
--- src/edu/ucsb/nceas/metacat/PermissionController.java	(revision 2044)
+++ src/edu/ucsb/nceas/metacat/PermissionController.java	(revision 2045)
@@ -52,7 +52,7 @@
    public PermissionController(String myDocid) throws McdbException
    {
      // Get rid of rev number
-     docId = MetaCatUtil.getDocIdFromString(myDocid);
+     docId = MetaCatUtil.getSmartDocId(myDocid);
      hasSubTreeAccessControl = checkSubTreeAccessControl();
    }
    
@@ -523,7 +523,7 @@
       serialNumber=conn.getCheckOutSerialNumber();
       pStmt = conn.prepareStatement(
                 "SELECT 'x' FROM xml_documents " +
-                "WHERE docid = ? AND user_owner = ?"); 
+                "WHERE docid = ? AND lower(user_owner) = ?"); 
       //check every element in the string array too see if it conatains
       //the owner of document
       for (int i=0; i<lengthOfArray; i++)
@@ -532,6 +532,8 @@
         // Bind the values to the query
         pStmt.setString(1, docId);
         pStmt.setString(2, principals[i]);
+        MetaCatUtil.debugMessage("the principle stack is : " +  
+                                  principals[i], 40);
 
         pStmt.execute();
         ResultSet rs = pStmt.getResultSet();
@@ -539,6 +541,7 @@
         if (hasRow) 
         {
           pStmt.close();
+           MetaCatUtil.debugMessage("find the owner", 40);
           return true;
         }//if    
      
@@ -588,13 +591,13 @@
       //top level
       topLever = true;
       sql = "SELECT perm_order FROM xml_access " +
-            "WHERE principal_name= ? AND docid = ? AND startnodeid is NULL";
+    "WHERE lower(principal_name) = ? AND docid = ? AND startnodeid is NULL";
     }
     else
     {
       //sub tree level
       sql = "SELECT perm_order FROM xml_access " +
-            "WHERE principal_name= ? AND docid = ? AND startnodeid = ?";
+        "WHERE lower(principal_name)= ? AND docid = ? AND startnodeid = ?";
     }
     
     try
@@ -693,13 +696,13 @@
      // for toplevel
      topLever = true;
      sql = "SELECT permission FROM xml_access WHERE docid = ? " +  
-           "AND principal_name = ? AND perm_type = ? AND startnodeid is NULL";
+   "AND lower(principal_name) = ? AND perm_type = ? AND startnodeid is NULL";
    }
    else
    {
      topLever =false;
      sql = "SELECT permission FROM xml_access WHERE docid = ? " +  
-           "AND principal_name = ? AND perm_type = ? AND startnodeid = ?";
+      "AND lower(principal_name) = ? AND perm_type = ? AND startnodeid = ?";
    }
    try
    {
@@ -792,13 +795,13 @@
    {
      topLevel = true;
      sql = "SELECT permission FROM xml_access WHERE docid = ? " + 
-            "AND principal_name = ? AND perm_type = ? AND startnodeid is NULL";
+    "AND lower(principal_name) = ? AND perm_type = ? AND startnodeid is NULL";
    }
    else
    {
      topLevel = false;
      sql = "SELECT permission FROM xml_access WHERE docid = ? " + 
-            "AND principal_name = ? AND perm_type = ? AND startnodeid = ?";
+     "AND lower(principal_name) = ? AND perm_type = ? AND startnodeid = ?";
    }
    
    try
@@ -878,13 +881,30 @@
         lengthOfPackage=(groups.length)+2;
         usersPackage=new String [lengthOfPackage];
         //the first two elements is user self and public
-        usersPackage[0]=user;
+        //in order to ignore case sensitive, we transfer user to lower case
+        if (user != null)
+        {
+          usersPackage[0]= user.toLowerCase();
+          MetaCatUtil.debugMessage("after transfer to lower case(not null): "+
+                                     usersPackage[0], 45); 
+        }
+        else
+        {
+          usersPackage[0] = user;
+          usersPackage[0]= user.toLowerCase();
+          MetaCatUtil.debugMessage("after transfer to lower case(null): "+
+                                     usersPackage[0], 45);
+        }
         usersPackage[1]=AccessControlInterface.PUBLIC;
         //put groups element from index 0 to lengthOfPackage-3 into userPackage
         //from index 2 to lengthOfPackage-1
         for (int i=2; i<lengthOfPackage; i++)
         {
-          usersPackage[i]=groups[i-2];
+          //tansfer group to lower case too
+          if (groups[i-2] != null)
+          {
+            usersPackage[i]=groups[i-2].toLowerCase();
+          }
         } //for
       }//if user!=public
       else//use=public
@@ -897,7 +917,10 @@
         //from index 1 to lengthOfPackage-1
         for (int i=1; i<lengthOfPackage; i++)
         {
-          usersPackage[i]=groups[i-1];
+          if (groups[i-1] != null)
+          {
+            usersPackage[i]=groups[i-1].toLowerCase();
+          }
         } //for
       }//else user=public
        
@@ -910,7 +933,14 @@
       {
         lengthOfPackage=2;
         usersPackage=new String [lengthOfPackage];
-        usersPackage[0]=user;
+        if (user != null)
+        {
+          usersPackage[0]=user.toLowerCase();
+        }
+        else
+        {
+          usersPackage[0]=user;
+        }
         usersPackage[1]=AccessControlInterface.PUBLIC;
       }//if user!=public
       else //user==public
@@ -976,27 +1006,5 @@
     return dataSetId;
   }//getDataPackageId() 
   
-  /**
-    * To create a part of query: "docid like '" +str1+ "', " +"docid like '" 
-    * +str2+"'" ... We need to check user, group and public together for the 
-    * permission. So we need the principal in an array and according the array
-    * to create a part of query which will be used in other methods
-    * @param principals, a string array storing the username, groups name and
-    * public.
-    */
-   private String partQueryAboutDocId( String [] principals)
-   {
-     String partQuery="";
-     int lengthOfArray=principals.length;
-     
-     for (int i=0;i<(lengthOfArray-1);i++)
-     {
-        partQuery=partQuery+"docid like '"+principals[i]+"',";
-     }
-     
-     //the last one dosen't has "'"
-     partQuery=partQuery+"docid like '"+principals[(lengthOfArray-1)]+"'";
-     return partQuery;
-     
-   }
+  
 }
Index: src/edu/ucsb/nceas/metacat/DocumentImpl.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 2044)
+++ src/edu/ucsb/nceas/metacat/DocumentImpl.java	(revision 2045)
@@ -409,13 +409,13 @@
        dbconn=DBConnectionPool.
                   getDBConnection("DocumentImpl.registerDocumentInReplication");
       serialNumber=dbconn.getCheckOutSerialNumber();
-      String docIdWithoutRev=MetaCatUtil.getDocIdFromString(accnum);
-      int userSpecifyRev=MetaCatUtil.getVersionFromString(accnum);
+      String docIdWithoutRev=MetaCatUtil.getDocIdFromAccessionNumber(accnum);
+      int userSpecifyRev=MetaCatUtil.getRevisionFromAccessionNumber(accnum);
       int revInDataBase=getLatestRevisionNumber(docIdWithoutRev);
       //revIndataBase=-1, there is no record in xml_documents table
       //the data file is a new one, inert it into table
       //user specified rev should be great than 0
-      if (revInDataBase==-1 && userSpecifyRev>0 )
+      if (revInDataBase==-1 && userSpecifyRev>=0 )
       {
        
         ac = new AccessionNumber(accnum, "insert");
@@ -1590,9 +1590,10 @@
 
         // Save the old document publicaccessentry in a backup table
         DocumentImpl.archiveDocRevision(connection, docid, user );
+        MetaCatUtil.debugMessage("after archiveDoc", 40);
         DocumentImpl thisdoc = new DocumentImpl(docid, false);
         int thisrev = thisdoc.getRev();
-        
+        MetaCatUtil.debugMessage("this revsion is: "+thisrev, 40);
         //if the updated vesion is not greater than current one,
         //throw it into a exception
         if (Integer.parseInt(updatedVersion)<=thisrev)
@@ -1605,11 +1606,13 @@
           //set the user specified revision 
           thisrev=Integer.parseInt(updatedVersion);
         }
-        
+        MetaCatUtil.debugMessage("final revsion is: "+thisrev, 40);
+        MetaCatUtil.debugMessage("before delete", 40);
         // Delete index for the old version of docid
         // The new index is inserting on the next calls to DBSAXNode
         pstmt = connection.prepareStatement(
                 "DELETE FROM xml_index WHERE docid='" + this.docid + "'");
+        MetaCatUtil.debugMessage("after delete", 40);
         // Increase dbconnection usage count
         connection.increaseUsageCount(1);
         
@@ -1746,7 +1749,7 @@
       char istreamChar;
      
       // check for 'write' permission for 'user' to update this document
-      if ( !hasWritePermission(user, groups, docid) ) {
+      if ( !hasWritePermission(user, groups, accnum) ) {
         throw new Exception("User " + user + 
               " does not have permission to update XML Document #" + accnum);
       }        
@@ -1832,7 +1835,7 @@
     if ( action.equals("UPDATE") ) {
       // check for 'write' permission for 'user' to update this document
 
-      if ( !hasWritePermission(user, groups, docid) ) {
+      if ( !hasWritePermission(user, groups, accnum) ) {
         throw new Exception("User " + user + 
               " does not have permission to update XML Document #" + accnum);
       }          
@@ -1908,12 +1911,15 @@
                                         String ruleBase, boolean needValidation)
                                         throws Exception
   {
+    MetaCatUtil.debugMessage("user in replication"+ user, 30);
     // Docid without revision
-    String docid=MetaCatUtil.getDocIdFromString(accnum);
+    String docid=MetaCatUtil.getDocIdFromAccessionNumber(accnum);
     // Revision specified by user (int)
-    int userSpecifyRev=MetaCatUtil.getVersionFromString(accnum);
+    int userSpecifyRev=MetaCatUtil.getRevisionFromAccessionNumber(accnum);
+    MetaCatUtil.debugMessage("The user specifyRev: " + userSpecifyRev, 30);
     // Revision for this docid in current database
     int revInDataBase=getLatestRevisionNumber(docid);
+    MetaCatUtil.debugMessage("The rev in data base: "+revInDataBase, 30);
     // String to store the revision
     String rev = null;
    
@@ -1930,7 +1936,7 @@
     }
     //rev is greater the last revsion number and revInDataBase isn't -1
     // it is a updated  file
-    else if (userSpecifyRev>revInDataBase && revInDataBase>0)
+    else if (userSpecifyRev>revInDataBase && revInDataBase>=0)
     {
        // rev equals user specified
        rev=(new Integer(userSpecifyRev)).toString();
@@ -2183,7 +2189,7 @@
     
       MetaCatUtil.debugMessage("Start deleting doc "+docid+ "...", 20);
     // check for 'write' permission for 'user' to delete this document
-      if ( !hasWritePermission(user, groups, docid) ) {
+      if ( !hasWritePermission(user, groups, accnum) ) {
         throw new Exception("User " + user + 
               " does not have permission to delete XML Document #" + accnum);
       }
