Index: src/edu/ucsb/nceas/metacat/MetacatReplication.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetacatReplication.java	(revision 4418)
+++ src/edu/ucsb/nceas/metacat/MetacatReplication.java	(revision 4419)
@@ -682,6 +682,15 @@
                                dbaction, docid, user, null, homeServer, 
                                server, createdDate, updatedDate);
 
+      //process extra access rules
+      Vector accessControlList = (Vector) docinfoHash.get("accessControl");
+      if (accessControlList != null) {
+    	  for (int i = 0; i < accessControlList.size(); i++) {
+        	  AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i);
+        	  acfsf.insertPermissions();
+          }
+      }
+      
       MetacatReplication.replLog("document " + docid + " added to DB with " +
                                  "action " + dbaction);
       EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid, dbaction);
@@ -832,6 +841,15 @@
         DocumentImpl.writeDataFileInReplication(url.openStream(), datafilePath,
                             docName, docType, docid, user,docHomeServer,server, 
                             DocumentImpl.DOCUMENTTABLE, false, createdDate, updatedDate);
+        //process extra access rules
+        Vector accessControlList = (Vector) docinfoHash.get("accessControl");
+        if (accessControlList != null) {
+      	  for (int i = 0; i < accessControlList.size(); i++) {
+          	  AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i);
+          	  acfsf.insertPermissions();
+            }
+        }
+        
                             //false means non-timed replication
         MetacatReplication.replLog("datafile " + docid + " added to DB with " +
                 "action " + dbaction);
@@ -945,7 +963,19 @@
       sb.append("</home_server>");
       sb.append("<public_access>").append(doc.getPublicaccess());
       sb.append("</public_access><rev>").append(doc.getRev());
-      sb.append("</rev></documentinfo>");
+      sb.append("</rev>");
+      
+      //permissions on the document
+      PermissionController permController = new PermissionController(docid);
+      Vector accessControlList = permController.getAccessControl();
+      sb.append("<accessControl>");
+      for (int i = 0; i < accessControlList.size(); i++) {
+    	  AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i);
+    	  sb.append(acfsf.getAccessString());
+      }
+      sb.append("</accessControl>");
+      
+      sb.append("</documentinfo>");
       response.setContentType("text/xml");
       out.println(sb.toString());
 
Index: src/edu/ucsb/nceas/metacat/MetaCatServlet.java
===================================================================
--- src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 4418)
+++ src/edu/ucsb/nceas/metacat/MetaCatServlet.java	(revision 4419)
@@ -3589,6 +3589,15 @@
                     continue;
                 }
             }
+            
+            //force replication when this action is called
+            boolean isXml = true;
+            if (publicId.equalsIgnoreCase("BIN")) {
+            	isXml = false;
+            }
+            ForceReplicationHandler frh = 
+            	new ForceReplicationHandler(accessionNumber, isXml, null);
+            
         }
         outputResponse(successList, errorList, out);
     }
Index: src/edu/ucsb/nceas/metacat/PermissionController.java
===================================================================
--- src/edu/ucsb/nceas/metacat/PermissionController.java	(revision 4418)
+++ src/edu/ucsb/nceas/metacat/PermissionController.java	(revision 4419)
@@ -646,6 +646,92 @@
 
   }//isAllowFirst
 
+/**
+    * Check if the permission order for user at that documents is allowFirst
+    * @param principals, list of names of principals to check for
+    * @param docid, document identifier to check for
+    */
+  public Vector getAccessControl()
+                  throws SQLException, Exception
+  {
+	  Vector accessControl = new Vector();
+    boolean hasRow;
+    PreparedStatement pStmt = null;
+    DBConnection conn = null;
+    int serialNumber = -1;
+    String sql = null;
+    boolean topLever =false;
+    sql = "SELECT principal_name, permission, perm_type, perm_order FROM xml_access ";
+
+    //TODO, need this?
+    long startId = 0;
+    if (startId == TOPLEVELSTARTNODEID)
+    {
+      //top level
+      topLever = true;
+      sql += "WHERE docid = ? AND startnodeid is NULL";
+    }
+    else
+    {
+      //sub tree level
+      sql += "WHERE docid = ? AND startnodeid = ?";
+    }
+
+    try
+    {
+      //check out DBConnection
+      conn=DBConnectionPool.getDBConnection("AccessControlList.getPermissions");
+      serialNumber=conn.getCheckOutSerialNumber();
+
+      //select permission order from database
+      pStmt = conn.prepareStatement(sql);
+
+        //bind value
+        pStmt.setString(1, docId);//docid
+
+        // if subtree, we need set subtree id
+        if (!topLever)
+        {
+          pStmt.setLong(2, startId);
+        }
+
+        pStmt.execute();
+        ResultSet rs = pStmt.getResultSet();
+        while (rs.next())
+        {
+          //get the permission order from data base
+          String principalName=rs.getString(1);
+          String permission=rs.getString(2);
+          String permType=rs.getString(3);
+          String permOrder=rs.getString(4);
+          
+          //make it into an object
+          AccessControlForSingleFile acfsf = 
+        	  new AccessControlForSingleFile(docId, principalName, permission, permType, permOrder);
+          accessControl.add(acfsf);
+        }
+        pStmt.close();
+    }//try
+    catch (SQLException e)
+    {
+      throw e;
+    }
+    finally
+    {
+      try
+      {
+        pStmt.close();
+      }
+      finally
+      {
+        DBConnectionPool.returnDBConnection(conn, serialNumber);
+      }
+    }
+    
+    return accessControl;
+
+  }//getPermissions
+
   /**
     * Check if the users array has allow rules for given users, docid and
     * permission.
Index: src/edu/ucsb/nceas/metacat/ReplicationHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/ReplicationHandler.java	(revision 4418)
+++ src/edu/ucsb/nceas/metacat/ReplicationHandler.java	(revision 4419)
@@ -365,6 +365,16 @@
                               remoteserver, tableName, true,// true is for time replication 
                               createdDate,
                               updatedDate);
+      
+      //process extra access rules
+      Vector accessControlList = (Vector) docinfoHash.get("accessControl");
+      if (accessControlList != null) {
+    	  for (int i = 0; i < accessControlList.size(); i++) {
+        	  AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i);
+        	  acfsf.insertPermissions();
+          }
+      }
+      
       logMetacat.info("Successfully replicated doc " + accNumber);
       if (tableName.equals(DocumentImpl.DOCUMENTTABLE))
       {
@@ -481,6 +491,15 @@
                                                 createdDate,
                                                 updatedDate);
                                          
+        //process extra access rules
+        Vector accessControlList = (Vector) docinfoHash.get("accessControl");
+        if (accessControlList != null) {
+      	  for (int i = 0; i < accessControlList.size(); i++) {
+          	  AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i);
+          	  acfsf.insertPermissions();
+            }
+        }
+        
         logMetacat.info("Successfully to write datafile " + accNumber);
         /*MetacatReplication.replLog("wrote datafile " + accNumber + " from " +
                                     remoteserver);*/
Index: src/edu/ucsb/nceas/metacat/AccessControlForSingleFile.java
===================================================================
--- src/edu/ucsb/nceas/metacat/AccessControlForSingleFile.java	(revision 4418)
+++ src/edu/ucsb/nceas/metacat/AccessControlForSingleFile.java	(revision 4419)
@@ -184,6 +184,32 @@
     }
    
   }
+  
+  public String getAccessString() {
+	  StringBuffer sb = new StringBuffer();
+	  sb.append("<access>");
+	  
+		  sb.append("<permOrder>");
+		  sb.append(this.permOrder);
+		  sb.append("</permOrder>");
+		  
+		  sb.append("<permType>");
+		  sb.append(this.permType);
+		  sb.append("</permType>");
+		  
+		  sb.append("<permission>");
+		  sb.append(this.permission);
+		  sb.append("</permission>");
+		  
+		  sb.append("<principal>");
+		  sb.append(this.principal);
+		  sb.append("</principal>");
 
+	  sb.append("</access>");
+	  
+	  return sb.toString();
+	  
+  }
 
+
 }
Index: src/edu/ucsb/nceas/metacat/DocInfoHandler.java
===================================================================
--- src/edu/ucsb/nceas/metacat/DocInfoHandler.java	(revision 4418)
+++ src/edu/ucsb/nceas/metacat/DocInfoHandler.java	(revision 4419)
@@ -49,6 +49,8 @@
   private Hashtable docinfo = new Hashtable();
   private String currentTag = null;
   
+  private Vector acccessControlList = new Vector();
+  
   public DocInfoHandler()
   {
   }
@@ -62,6 +64,31 @@
     currentTag = localName;
   }
   
+  public void endElement (String uri, String localName, String qName)
+	throws SAXException
+  {
+	  if (currentTag.equals("access")) {
+		  //harvest the latest values from the Map
+		  String docid = (String) docinfo.get("docid");
+		  String principal = (String) docinfo.get("principal");
+          String permission = (String) docinfo.get("permission");
+          String permType = (String) docinfo.get("permType");
+          String permOrder = (String) docinfo.get("permOrder");
+          AccessControlForSingleFile acfsf = null;
+		try {
+			acfsf = new AccessControlForSingleFile(docid, principal, permission, permType, permOrder);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}	
+          acccessControlList.add(acfsf);
+	  }
+	  //save the list when we are done
+	  if (currentTag.equals("acccessControl")) {
+		  docinfo.put("acccessControl", acccessControlList);
+	  }
+  }
+  
   /**
    * put the content and the name of the tag into the hashtable.  the name of
    * the tag is the key.
