Ling Xiaohan wrote:
factory.newReference("My%20document/test.txt", ...);
However, apache XMLDsig could set Reference's URI with space by calling
XMLSignature.addDocument, ex.,
sig.addDocument("My document/test.txt", null,
Constants.ALGO_ID_DIGEST_SHA1);
Although method newReference could succeed with URI escaped space to
%20, the %20
would also appear in output file. I think it is not a proper readable
format for user to comprehend
it. So implementation of apache sounds better. Anyone approve?!
I disagree. The XML Signature specification specifically states that the
Reference URI attribute is an RFC 3986 URI, so putting the URI above into the
Signature as-is without escaping the space would be a non-compliant RFC 3986
URI, and other XML Signature implementations may not be able to parse it.
The API however, could provide a method to represent or parse the URI into a
more readable form. For example, the URI.getPath() method returns the URI and
decodes the escaped octets whereas getRawPath() does not:
import java.net.URI;
public class ParseURI {
public static void main(String[] args) throws Exception {
URI uri = URI.create(args[0]);
System.out.println(uri.getPath());
System.out.println(uri.getRawPath());
}
}
$ java ParseURI "foo%20foo"
foo foo
foo%20foo
--Sean