AnyURIDVpublic class AnyURIDV extends TypeValidator Represent the schema type "anyURI" |
Fields Summary |
---|
private static final org.apache.xerces.util.URI | BASE_URI | private static boolean[] | gNeedEscaping | private static char[] | gAfterEscaping1 | private static char[] | gAfterEscaping2 | private static char[] | gHexChs |
Methods Summary |
---|
private static java.lang.String | encode(java.lang.String anyURI)
// initialize the above 3 arrays
for (int i = 0; i <= 0x1f; i++) {
gNeedEscaping[i] = true;
gAfterEscaping1[i] = gHexChs[i >> 4];
gAfterEscaping2[i] = gHexChs[i & 0xf];
}
gNeedEscaping[0x7f] = true;
gAfterEscaping1[0x7f] = '7";
gAfterEscaping2[0x7f] = 'F";
char[] escChs = {' ", '<", '>", '"", '{", '}",
'|", '\\", '^", '~", '`"};
int len = escChs.length;
char ch;
for (int i = 0; i < len; i++) {
ch = escChs[i];
gNeedEscaping[ch] = true;
gAfterEscaping1[ch] = gHexChs[ch >> 4];
gAfterEscaping2[ch] = gHexChs[ch & 0xf];
}
int len = anyURI.length(), ch;
StringBuffer buffer = new StringBuffer(len*3);
// for each character in the anyURI
int i = 0;
for (; i < len; i++) {
ch = anyURI.charAt(i);
// if it's not an ASCII character, break here, and use UTF-8 encoding
if (ch >= 128)
break;
if (gNeedEscaping[ch]) {
buffer.append('%");
buffer.append(gAfterEscaping1[ch]);
buffer.append(gAfterEscaping2[ch]);
}
else {
buffer.append((char)ch);
}
}
// we saw some non-ascii character
if (i < len) {
// get UTF-8 bytes for the remaining sub-string
byte[] bytes = null;
byte b;
try {
bytes = anyURI.substring(i).getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
// should never happen
return anyURI;
}
len = bytes.length;
// for each byte
for (i = 0; i < len; i++) {
b = bytes[i];
// for non-ascii character: make it positive, then escape
if (b < 0) {
ch = b + 256;
buffer.append('%");
buffer.append(gHexChs[ch >> 4]);
buffer.append(gHexChs[ch & 0xf]);
}
else if (gNeedEscaping[b]) {
buffer.append('%");
buffer.append(gAfterEscaping1[b]);
buffer.append(gAfterEscaping2[b]);
}
else {
buffer.append((char)b);
}
}
}
// If encoding happened, create a new string;
// otherwise, return the orginal one.
if (buffer.length() != len) {
return buffer.toString();
}
else {
return anyURI;
}
| public java.lang.Object | getActualValue(java.lang.String content, org.apache.xerces.impl.dv.ValidationContext context)
// check 3.2.17.c0 must: URI (rfc 2396/2723)
try {
if( content.length() != 0 ) {
// encode special characters using XLink 5.4 algorithm
final String encoded = encode(content);
// Support for relative URLs
// According to Java 1.1: URLs may also be specified with a
// String and the URL object that it is related to.
new URI(BASE_URI, encoded );
}
} catch (URI.MalformedURIException ex) {
throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "anyURI"});
}
// REVISIT: do we need to return the new URI object?
return content;
| public short | getAllowedFacets()
URI uri = null;
try {
uri = new URI("abc://def.ghi.jkl");
} catch (URI.MalformedURIException ex) {
}
BASE_URI = uri;
return (XSSimpleTypeDecl.FACET_LENGTH | XSSimpleTypeDecl.FACET_MINLENGTH | XSSimpleTypeDecl.FACET_MAXLENGTH | XSSimpleTypeDecl.FACET_PATTERN | XSSimpleTypeDecl.FACET_ENUMERATION | XSSimpleTypeDecl.FACET_WHITESPACE );
|
|