/*
 * Copyright  1999-2004 The Apache Software Foundation.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package org.apache.xml.security.utils;

import org.apache.xpath.CachedXPathAPI;
import org.w3c.dom.Document;


/**
 * @author Raul Benito
 */
public class CachedXPathAPIHolder {
	 static org.apache.commons.logging.Log log = 
	        org.apache.commons.logging.LogFactory.getLog(CachedXPathAPIHolder.class.getName());

    static ThreadLocal  local=new ThreadLocal();
    static ThreadLocal localDoc=new ThreadLocal();
  
	/**
	 * Sets the doc for the xpath transformation. Resets the cache if needed
	 * @param doc
	 */
	public static void setDoc(Document doc) {                    
       if (localDoc.get()!=doc) {
            CachedXPathAPI cx=(CachedXPathAPI)local.get();
            if (cx==null) {
               cx=new CachedXPathAPI();
               local.set(cx);
               localDoc.set(doc);
               return;
            }
            //Different docs reset.
            cx.getXPathContext().reset();
            localDoc.set(doc);                     
        }		
	}
    /**
     * @return the cachexpathapi for this thread
     */
    public static CachedXPathAPI getCachedXPathAPI() {        
        CachedXPathAPI cx=(CachedXPathAPI)local.get();        
        if (cx==null) {
            cx=new CachedXPathAPI();
            local.set(cx);
            localDoc.set(null);            
        }
    	return cx;
    }
}

@@ -736,17 +736,16 @@
 ument;%0A%0A
-%0A
 /**%0A * @
@@ -806,148 +806,8 @@
 er %7B
-%0A%09 static org.apache.commons.logging.Log log = %0A%09        org.apache.commons.logging.LogFactory.getLog(CachedXPathAPIHolder.class.getName());
 %0A%0A  
@@ -911,14 +911,20 @@
 %0A  %0A
-%09/**%0A%09
+    /**%0A    
  * S
@@ -992,17 +992,20 @@
  needed%0A
-%09
+    
  * @para
@@ -1014,14 +1014,20 @@
 doc%0A
-%09 */%0A%09
+     */%0A    
 publ
@@ -1087,24 +1087,25 @@
     %0A       
+ 
 if (localDoc
@@ -1213,32 +1213,33 @@
 %0A               
+ 
 cx=new CachedXPa
@@ -1239,32 +1239,33 @@
 chedXPathAPI();%0A
+ 
                l
@@ -1285,32 +1285,33 @@
 %0A               
+ 
 localDoc.set(doc
@@ -1313,16 +1313,17 @@
 t(doc);%0A
+ 
         
@@ -1497,10 +1497,14 @@
 %7D%09%09%0A
-%09%7D
+    %7D%0A
 %0A   

Fix findbugs bug: Unread field: CachedXPathAPIHolder.log