import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.utils.resolver.ResourceResolverException;
import org.apache.xml.security.utils.resolver.ResourceResolverSpi;
*/
public class StdResourceResolver extends ResourceResolverSpi {
- static private ThreadLocal<SigningProcessDataHolder> signingProcessDataHolderThreadLocal = new ThreadLocal<SigningProcessDataHolder>();
-
- static void startSigningProcess(File baseDir) {
- signingProcessDataHolderThreadLocal.set(new SigningProcessDataHolder(baseDir));
- }
-
- static void endSigningProcess() {
- for (IsOpenInputStream is : signingProcessDataHolderThreadLocal.get().getUsedInputStreams()) {
- if (is.isOpen()) {
- try {
- is.close();
- } catch(IOException ioe) {
- throw new RuntimeException(ioe);
- }
- }
- }
- signingProcessDataHolderThreadLocal.set(null);
- }
-
- static private File getBaseDir() {
- return signingProcessDataHolderThreadLocal.get().getBaseDir();
- }
-
- @Override
- public XMLSignatureInput engineResolve(Attr uri, String BaseURI) throws ResourceResolverException {
- try {
- IsOpenInputStream iois = new IsOpenInputStream(new File(getBaseDir(), uri.getValue()));
- signingProcessDataHolderThreadLocal.get().usedInputStreams.add(iois);
- return new XMLSignatureInput(iois);
- } catch (FileNotFoundException fnfe) {
- throw new RuntimeException(fnfe);
- }
- }
-
- @Override
- public boolean engineCanResolve(Attr uri, String baseURI) {
- return (baseURI == null || baseURI.isEmpty()) && ! uri.getValue().startsWith("#") && new File(getBaseDir(), uri.getValue()).exists();
- }
-
- static private class IsOpenInputStream extends FileInputStream {
-
- private boolean open = true;
-
- private IsOpenInputStream(File file) throws FileNotFoundException {
- super(file);
- }
-
- @Override
- public void close() throws IOException {
- super.close();
- this.open = false;
- }
-
- public boolean isOpen() {
- return open;
- }
-
- }
-
- static private class SigningProcessDataHolder {
- private File baseDir;
- private List<IsOpenInputStream> usedInputStreams;
-
- private SigningProcessDataHolder(File baseDir) {
- this.baseDir = baseDir;
- usedInputStreams = new ArrayList<IsOpenInputStream>();
- }
-
- public File getBaseDir() {
- return baseDir;
- }
-
- public List<IsOpenInputStream> getUsedInputStreams() {
- return usedInputStreams;
- }
-
-
- }
+ static private ThreadLocal<SigningProcessDataHolder> signingProcessDataHolderThreadLocal = new ThreadLocal<SigningProcessDataHolder>();
+
+ static void startSigningProcess(final File baseDir) {
+ signingProcessDataHolderThreadLocal.set(new SigningProcessDataHolder(baseDir));
+ }
+
+ static void endSigningProcess() {
+ for (final IsOpenInputStream is : signingProcessDataHolderThreadLocal.get().getUsedInputStreams()) {
+ if (is.isOpen()) {
+ try {
+ is.close();
+ } catch (final IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+ }
+ signingProcessDataHolderThreadLocal.set(null);
+ }
+
+ static private File getBaseDir() {
+ return signingProcessDataHolderThreadLocal.get().getBaseDir();
+ }
+
+ @Override
+ public XMLSignatureInput engineResolve(final Attr uri, final String BaseURI) throws ResourceResolverException {
+ try {
+ final IsOpenInputStream iois = new IsOpenInputStream(new File(getBaseDir(), uri.getValue()));
+ signingProcessDataHolderThreadLocal.get().usedInputStreams.add(iois);
+ return new XMLSignatureInput(iois);
+ } catch (final FileNotFoundException fnfe) {
+ throw new RuntimeException(fnfe);
+ }
+ }
+
+ @Override
+ public boolean engineCanResolve(final Attr uri, final String baseURI) {
+ return (baseURI == null || baseURI.isEmpty()) && !uri.getValue().startsWith("#") && new File(getBaseDir(), uri.getValue()).exists();
+ }
+
+ static private class IsOpenInputStream extends FileInputStream {
+
+ private boolean open = true;
+
+ private IsOpenInputStream(final File file) throws FileNotFoundException {
+ super(file);
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+ this.open = false;
+ }
+
+ public boolean isOpen() {
+ return this.open;
+ }
+
+ }
+
+ static private class SigningProcessDataHolder {
+ private final File baseDir;
+ private final List<IsOpenInputStream> usedInputStreams;
+
+ private SigningProcessDataHolder(final File baseDir) {
+ this.baseDir = baseDir;
+ this.usedInputStreams = new ArrayList<IsOpenInputStream>();
+ }
+
+ public File getBaseDir() {
+ return this.baseDir;
+ }
+
+ public List<IsOpenInputStream> getUsedInputStreams() {
+ return this.usedInputStreams;
+ }
+
+ }
}