Skip to content
This repository has been archived by the owner on May 24, 2019. It is now read-only.

Commit

Permalink
Remove dep on internal JDK class
Browse files Browse the repository at this point in the history
  • Loading branch information
n1hility committed Apr 6, 2011
1 parent 05eca9e commit 9f75d93
Showing 1 changed file with 74 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@

package org.apache.taglibs.standard.tag.common.xml;

import com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
import javax.xml.xpath.XPathFunctionResolver;
import javax.xml.xpath.XPathVariableResolver;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
* This factory class is added to provide access to our own implementation
Expand All @@ -67,9 +72,74 @@
*
* @author dhirup
*/
public class JSTLXPathFactory extends XPathFactoryImpl {

public class JSTLXPathFactory extends XPathFactory {

private XPathFactory actual;

public JSTLXPathFactory() {

ClassLoader old = getContextClassLoader();
try {
// Use the defining class loader
setContextClassLoader(JSTLXPathFactory.class.getClassLoader());
actual = XPathFactory.newInstance();
} finally {
setContextClassLoader(old);
}

if (actual == null)
throw new IllegalStateException("Could not load default XPathFactory");
}

private static ClassLoader getContextClassLoader() {
return (ClassLoader)
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
cl = Thread.currentThread().getContextClassLoader();
} catch (SecurityException eat) {
}
return cl;
}
});
}

private static void setContextClassLoader(ClassLoader cl) {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
ClassLoader cl = null;
try {
Thread.currentThread().setContextClassLoader(cl);
} catch (SecurityException eat) {
}

return null;
}
});
}

public javax.xml.xpath.XPath newXPath() {
return new org.apache.taglibs.standard.tag.common.xml.JSTLXPathImpl(null, null);
}
}

public boolean isObjectModelSupported(String objectModel) {
return actual.isObjectModelSupported(objectModel);
}

public void setFeature(String name, boolean value) throws XPathFactoryConfigurationException {
actual.setFeature(name, value);
}

public boolean getFeature(String name) throws XPathFactoryConfigurationException {
return actual.getFeature(name);
}

public void setXPathVariableResolver(XPathVariableResolver resolver) {
actual.setXPathVariableResolver(resolver);
}

public void setXPathFunctionResolver(XPathFunctionResolver resolver) {
actual.setXPathFunctionResolver(resolver);
}
}

0 comments on commit 9f75d93

Please sign in to comment.