Index: lib/spatial/geoserver/data/styles/data_bounds_style.sld
===================================================================
--- lib/spatial/geoserver/data/styles/data_bounds_style.sld	(revision 3117)
+++ lib/spatial/geoserver/data/styles/data_bounds_style.sld	(revision 3118)
@@ -4,6 +4,8 @@
 	xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" 
 	xmlns:xlink="http://www.w3.org/1999/xlink" 
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <UserLayer>
+    <Name>metacat:data_bounds</Name>
     <UserStyle>
         <Name>Default Styler</Name>
         <Title>Default Styler</Title>
@@ -47,4 +49,5 @@
             </Rule>
         </FeatureTypeStyle>
     </UserStyle>
+    </UserLayer>
 </StyledLayerDescriptor>
Index: lib/spatial/geoserver/data/styles/data_points_style.sld
===================================================================
--- lib/spatial/geoserver/data/styles/data_points_style.sld	(revision 3117)
+++ lib/spatial/geoserver/data/styles/data_points_style.sld	(revision 3118)
@@ -5,6 +5,8 @@
 	xmlns:ogc="http://www.opengis.net/ogc"
 	xmlns:xlink="http://www.w3.org/1999/xlink"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+        <UserLayer>
+        <Name>metacat:data_points</Name>
 	<UserStyle>
 		<Name>Default Styler</Name>
 		<Title>Default Styler</Title>
@@ -58,4 +60,5 @@
 			</Rule>
 		</FeatureTypeStyle>
 	</UserStyle>
+        </UserLayer>
 </StyledLayerDescriptor>
Index: src/edu/ucsb/nceas/metacat/spatial/SldFactory.java
===================================================================
--- src/edu/ucsb/nceas/metacat/spatial/SldFactory.java	(revision 3117)
+++ src/edu/ucsb/nceas/metacat/spatial/SldFactory.java	(revision 3118)
@@ -1,12 +1,44 @@
-/*
- * Styled Layer Descriptor Factory
- * Author: Matt Perry
- * Status: testing
- * MPTODO: Use a spatial access constraints class to generate the appropriate SLD filter
+/**
+ *  '$RCSfile$'
+ *  Copyright: 2000 Regents of the University of California and the
+ *  National Center for Ecological Analysis and Synthesis
+ *
+ *  Author: Matthew Perry
+ *  '$Date$'
+ *  '$Revision$'
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ *  Purpose: Servlet to generate a styled layer descriptor (SLD)
+ *           with a filter to restrict features on
+ *           a WMS map to given docids
+ *
+ *  Status: Currently this is just a working stub
+ *          with some hardcoded values. Since this needs to be
+ *          fired off on every map redraw, we'll need a way to make 
+ *          the generation of docid list very efficient. 
+ *
+ *  Usage: Append the URL as an "SLD" to any WMS GetMap request
+ *    ex: http://server/context/wms?...&SLD=http://server/context/sldfactory?originalSld=data_points_style
  */
+
+
 package edu.ucsb.nceas.metacat.spatial;
 
 import edu.ucsb.nceas.utilities.XMLUtilities;
+import edu.ucsb.nceas.metacat.MetaCatUtil;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
@@ -29,7 +61,10 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.FileNotFoundException;
 
+import java.util.Vector;
+
 import org.w3c.dom.*;
 
 /**
@@ -73,20 +108,23 @@
    *
    * @param request Incoming servlet request.
    * @param response Servlet response.
-   * @todo Determine filename from variables in metacat.properties.
    */
   private void handleGetOrPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException
   {
-    //String dataset = request.getParameter("dataset"); 
-    // MPTODO : Eventually use dataset to determine filename
-    String filename = "/var/lib/tomcat5/webapps/knb/style/skins/ebm/spatial/data_bounds_style.sld";
-    String sld = getSld(filename);
+    String dataset = request.getParameter("originalSld"); 
+    String filename = MetaCatUtil.getOption("certPath") + "data/styles/" + dataset;
+    try {
+	String sld = getSld(filename);
+        System.out.println(sld);
+	response.setContentType("text/xml");
+	response.getWriter().write(sld);
+    } catch (FileNotFoundException fnf) {
+	fnf.printStackTrace();
+    } catch (Exception e) {
+        e.printStackTrace();
+    }
     
-    response.setContentType("text/xml");
-    response.getWriter().write(sld);
-    
-    System.out.println("\n*** SldFactory request handled ***\n");
   }
   
   /**
@@ -93,6 +131,8 @@
    * Given a filename of an existing SLD document,
    * reads the sld and adds an ogc:Filter to exclude/include
    * certain docids based on user's permissions. 
+   * The sld file is specified without path and 
+   * must exist within geoserver's styles folder (context/data/styles/*)
    * 
    * returns SLD document as a String.
    * 
@@ -99,13 +139,50 @@
    * @param filename	Filename of the base sld.
    * @todo Implement the doc id list queries for contraints.
    */
-  private String getSld(String filename)
+  private String getSld(String filename) throws FileNotFoundException
   {
 	    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+	    Vector allowedDocids = new Vector();
 
+	    /*
+	     * TODO : 
+	     *  Get the list of allowable docids due to 
+	     *    access contraints (based on current logged-in user)
+	     *    skin filtering (eg organization name) 
+	     *    existing non-spatial query (eg taxonomic query)
+	     *
+	     *  These could ideally be cached as session variables to improve
+	     *  speed over running expensive SQL queries on 
+	     *  each map redraw.
+	     *
+	     * Combined, these will be a vector of allowed docids that
+	     * are to be displayed on the map
+	     *
+	     * Below is just a hardcoded example of the above...
+	     *
+	     */
+	    allowedDocids.add("nceas.288");
+	    allowedDocids.add("nrs.720");
+
+	    String rulesString = "";
+
 	    try {
-	       DocumentBuilder builder = factory.newDocumentBuilder();
-	       document = builder.parse( new File(filename) );	       
+		    DocumentBuilder builder = factory.newDocumentBuilder();
+		    document = builder.parse( new File(filename) );	       
+		    Element root = document.getDocumentElement();
+
+		    NodeList elemList = document.getElementsByTagName("Rule");
+		    Node ruleNode = elemList.item(0);
+
+		    // Get the Element/node comprising the ogc:Filter for all of the above
+		    Element filterElement = getFilterElement(document,allowedDocids);
+		    
+		    // Append the Filter to the ruleNode
+		    ruleNode.appendChild(filterElement);
+		    
+		    // Write new DOM as a string
+		    rulesString = XMLUtilities.getDOMTreeAsString((Node) root, true);
+
 	    } catch (SAXException sxe) {
 	       sxe.printStackTrace();
 	    } catch (ParserConfigurationException pce) {
@@ -112,27 +189,7 @@
 	       pce.printStackTrace();
 	    } catch (IOException ioe) {
 	       ioe.printStackTrace();
-	    }
-	    
-	    Element root = document.getDocumentElement();
-	    NodeList elemList = document.getElementsByTagName("Rule");
-	    Node ruleNode = elemList.item(0);
-	    
-	    // Get the list of docids  due to access contrainsts
-	    
-	    // Get the list of docids  due to skin filtering of org names
-	    
-	    // Get the list of docids  due to existing query (eg taxonomic)
-	    
-	    // Get the Element/node comprising the ogc:Filter for all of the above
-	    Element filterElement = getFilterElement(document);
-	    
-	    // Append the Filter to the ruleNode
-	    ruleNode.appendChild(filterElement);
-	    
-	    // Write new DOM as a string
-	    String rulesString = XMLUtilities.getDOMTreeAsString((Node) root, true);
-
+	    } 
 	    return rulesString;
   }
 
@@ -141,28 +198,36 @@
    * Creates an OGC Filter node
    * 
    * @param inDoc	DOM document.
-   * 
+   * @param docids 	Vector of documents allowed in the map.
    */
-  private Element getFilterElement(Document inDoc) 
+  private Element getFilterElement(Document inDoc, Vector docids) 
   {
 	  Element filterElem = inDoc.createElement("ogc:Filter");
+	  Element orElem = inDoc.createElement("ogc:Or");
+	  String docid = "";
 	  
-	  // MPTODO : BEGIN LOOP thru vector of docids
-	  Element opElem = inDoc.createElement("ogc:PropertyIsEqualTo");
+	  // Begin loop thru vector of allowed docids
+	  for (int i = 0; i < docids.size(); i++) {
+		  Element opElem = inDoc.createElement("ogc:PropertyIsEqualTo");
+
+		  Element propertyElem = inDoc.createElement("ogc:PropertyName");
+		  Text propertyText = inDoc.createTextNode("docid");
+		  propertyElem.appendChild(propertyText);
+		  
+		  Element literalElem = inDoc.createElement("ogc:Literal");	  
+
+		  docid = (String)docids.elementAt(i);
+		  Text literalText = inDoc.createTextNode(docid); 
+		  literalElem.appendChild(literalText);
+		  
+		  opElem.appendChild(propertyElem);
+		  opElem.appendChild(literalElem);
+
+		  orElem.appendChild(opElem);
+		  // END LOOP
+	  }
 	  
-	  Element propertyElem = inDoc.createElement("ogc:PropertyName");
-	  Text propertyText = inDoc.createTextNode("docid");
-	  propertyElem.appendChild(propertyText);
-	  
-	  Element literalElem = inDoc.createElement("ogc:Literal");	  
-	  Text literalText = inDoc.createTextNode("perry.1"); // i
-	  literalElem.appendChild(literalText);
-	  
-	  opElem.appendChild(propertyElem);
-	  opElem.appendChild(literalElem);
-	  filterElem.appendChild(opElem);
-	  // END LOOP
-	  
+	  filterElem.appendChild(orElem);
 	  return filterElem;	  
   }
   
Index: docs/user/spatial_option.html
===================================================================
--- docs/user/spatial_option.html	(revision 3117)
+++ docs/user/spatial_option.html	(revision 3118)
@@ -264,8 +264,25 @@
    <p style="margin-bottom:12pt"> Filter which spatial cache features are displayed by access contraints, skin constraints and the current non-spatial query set. This would involve intercepting incoming WMS requests and appending a styled layer descriptor (SLD) with an OGC filter to prevent/allow certain docids. </p>
 
    <h5>SLD factory</h5>
-   <p style="margin-bottom:12pt">Closely related to the WMS bypass implemetation, the SLD factory would be in charge of constructing the filter based on on the contraints mentioned above. Because it would have to generate this list of docids on every wms request, performance is a big concern. Likely we'll need to cache docid lists as session variables.</p>
+   <p style="margin-bottom:12pt">Closely related to the WMS bypass implemetation, the SLD factory would be in charge of constructing the filter based on on the contraints mentioned above. In other words, it would construct a document specifying which docids were to appear in the map. Because it would have to generate this list of docids on every wms request, performance is a big concern. Likely we'll need to cache docid lists as session variables.</p>
 
+  <p> There is currently a stub implementation of the SLD Factory servlet in <em>src/edu/ucsb/nceas/metacat/spatial/SldFactory.java</em>. It is functional except that it doesn't generate a dynamic list of allowable docids.  Assuming we can modify the SldFactory servlet to quickly generate a list of allowable docids based on stored session variables, applying this SLD to a WMS request is fairly easy and simply requires appending the URL of the sldfactory as an "SLD" parameter to the WMS GetMap request: </p>
+
+   <pre> http://indus/knb/wms?REQUEST=GetMap&SERVICE=WMS....&SLD=http://indus.msi.ucsb.edu/knb/sldfactory?originalSld=data_points_style.sld</pre>
+
+<p> where data_points_style.sld is the original style document existing in <em>{context}/data/styles/</em>. The sldfactory servlet will construct a list of allowable docids, append those to the original sld as an ogc filter, an return a (modified) SLD document. There are two possibilities for implementing this:</p>
+
+   <ol>
+   <li>
+     Mapbuilder (the WMS client in charge of constructing WMS request) can be told to append this SLD parameter through the use of the WMC config document. This would work for the skins but, alone, would not ensure that every WMS request were filtered since other clients could simply ommit the SLD parameter.
+   </li>
+   <li> 
+     An alternative, one that would ensure that EVERY wms request was filtered, would be to handle it all server side with a WMS bypass.
+   </li>
+   </ol>
+   
+   
+
    <h5>Map configuration interface </h5>
    <p style="margin-bottom:12pt">Geoserver currently offers a nice web-based configuration but it is lacking a few key features and may be difficult for a novice GIS user. We may want to reinvent a custom geoserver configuration interface to</p>
    <ul>
