ResolverFragment.java revision 0
0N/A/*
0N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/A/*
0N/A * Copyright 1999-2004 The Apache Software Foundation.
0N/A *
0N/A * Licensed under the Apache License, Version 2.0 (the "License");
0N/A * you may not use this file except in compliance with the License.
0N/A * You may obtain a copy of the License at
0N/A *
0N/A * http://www.apache.org/licenses/LICENSE-2.0
0N/A *
0N/A * Unless required by applicable law or agreed to in writing, software
0N/A * distributed under the License is distributed on an "AS IS" BASIS,
0N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A * See the License for the specific language governing permissions and
0N/A * limitations under the License.
0N/A *
0N/A */
0N/Apackage com.sun.org.apache.xml.internal.security.utils.resolver.implementations;
0N/A
0N/A
0N/A
0N/Aimport com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.IdResolver;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverException;
0N/Aimport com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverSpi;
0N/Aimport org.w3c.dom.Attr;
0N/Aimport org.w3c.dom.Document;
0N/Aimport org.w3c.dom.Node;
0N/A
0N/A
0N/A/**
0N/A * This resolver is used for resolving same-document URIs like URI="" of URI="#id".
0N/A *
0N/A * @author $Author: dims $
0N/A * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#sec-ReferenceProcessingModel">The Reference processing model in the XML Signature spec</A>
0N/A * @see <A HREF="http://www.w3.org/TR/xmldsig-core/#sec-Same-Document">Same-Document URI-References in the XML Signature spec</A>
0N/A * @see <A HREF="http://www.ietf.org/rfc/rfc2396.txt">Section 4.2 of RFC 2396</A>
0N/A */
0N/Apublic class ResolverFragment extends ResourceResolverSpi {
0N/A
0N/A /** {@link java.util.logging} logging facility */
0N/A static java.util.logging.Logger log =
0N/A java.util.logging.Logger.getLogger(
0N/A ResolverFragment.class.getName());
0N/A
0N/A /**
0N/A * Method engineResolve
0N/A *
0N/A * Wird das gleiche Dokument referenziert?
0N/A * Wird ein anderes Dokument referenziert?
0N/A * @inheritDoc
0N/A * @param uri
0N/A * @param BaseURI
0N/A *
0N/A */
0N/A public XMLSignatureInput engineResolve(Attr uri, String BaseURI)
0N/A throws ResourceResolverException
0N/A {
0N/A
0N/A String uriNodeValue = uri.getNodeValue();
0N/A Document doc = uri.getOwnerElement().getOwnerDocument();
0N/A
0N/A
0N/A Node selectedElem = null;
0N/A if (uriNodeValue.equals("")) {
0N/A
0N/A /*
0N/A * Identifies the node-set (minus any comment nodes) of the XML
0N/A * resource containing the signature
0N/A */
0N/A
0N/A if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "ResolverFragment with empty URI (means complete document)");
0N/A selectedElem = doc;
0N/A } else {
0N/A
0N/A /*
0N/A * URI="#chapter1"
0N/A * Identifies a node-set containing the element with ID attribute
0N/A * value 'chapter1' of the XML resource containing the signature.
0N/A * XML Signature (and its applications) modify this node-set to
0N/A * include the element plus all descendents including namespaces and
0N/A * attributes -- but not comments.
0N/A */
0N/A String id = uriNodeValue.substring(1);
0N/A
0N/A // Element selectedElem = doc.getElementById(id);
0N/A selectedElem = IdResolver.getElementById(doc, id);
0N/A if (selectedElem==null) {
0N/A Object exArgs[] = { id };
0N/A throw new ResourceResolverException(
0N/A "signature.Verification.MissingID", exArgs, uri, BaseURI);
0N/A }
0N/A if (true)
0N/A if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Try to catch an Element with ID " + id + " and Element was " + selectedElem);
0N/A }
0N/A
0N/A XMLSignatureInput result = new XMLSignatureInput(selectedElem);
0N/A result.setExcludeComments(true);
0N/A
0N/A //if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "We return a nodeset with " + resultSet.size() + " nodes");
0N/A result.setMIMEType("text/xml");
0N/A result.setSourceURI((BaseURI != null) ? BaseURI.concat(uri.getNodeValue()) :
0N/A uri.getNodeValue());
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * Method engineCanResolve
0N/A * @inheritDoc
0N/A * @param uri
0N/A * @param BaseURI
0N/A *
0N/A */
0N/A public boolean engineCanResolve(Attr uri, String BaseURI) {
0N/A
0N/A if (uri == null) {
0N/A if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Quick fail for null uri");
0N/A return false;
0N/A }
0N/A
0N/A String uriNodeValue = uri.getNodeValue();
0N/A
0N/A if (uriNodeValue.equals("")
0N/A || ((uriNodeValue.charAt(0)=='#')
0N/A &&!uriNodeValue.startsWith("#xpointer("))) {
0N/A if (true)
0N/A if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "State I can resolve reference: \"" + uriNodeValue + "\"");
0N/A return true;
0N/A }
0N/A if (true)
0N/A if (log.isLoggable(java.util.logging.Level.FINE)) log.log(java.util.logging.Level.FINE, "Do not seem to be able to resolve reference: \"" + uriNodeValue + "\"");
0N/A return false;
0N/A }
0N/A
0N/A}