// Do an initial processing to validate that the external
// stylesheet causes a SecurityException
//
UserAgent userAgent = buildUserAgent();
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(userAgent);
ctx.setDynamic(true);
// We expect either a SecurityException or a BridgeException
// with ERR_URI_UNSECURE.
try {
builder.build(ctx, doc);
if (secure) {
failures.addElement(EXTERNAL_STYLESHEET_ID);
}
} catch (BridgeException e){
if (!secure
||
(secure && !ErrorConstants.ERR_URI_UNSECURE.equals(e.getCode()))) {
report.setErrorCode(ERROR_WHILE_PROCESSING_SVG_DOCUMENT);
report.addDescriptionEntry(ENTRY_KEY_ERROR_DESCRIPTION,
e.getMessage());
report.setPassed(false);
return report;
}
} catch (SecurityException e) {
if (!secure) {
failures.addElement(EXTERNAL_STYLESHEET_ID);
}
}
//
// Remove the stylesheet from the document
//
Node child = doc.getFirstChild();
Node next = null;
while (child != null) {
next = child.getNextSibling();
if (child.getNodeType() == child.PROCESSING_INSTRUCTION_NODE) {
doc.removeChild(child);
}
child = next;
}
//
// Now, get the list of ids to be checked
//
Element root = doc.getDocumentElement();
String idList = root.getAttributeNS(testNS, "targetids");
if (idList == null || "".equals(idList)) {
report.setErrorCode(ERROR_NO_ID_LIST);
report.setPassed(false);
return report;
}
StringTokenizer st = new StringTokenizer(idList, ",");
String[] ids = new String[st.countTokens()];
for (int i=0; i<ids.length; i++) {
ids[i] = st.nextToken().toString().trim();
}
for (int i=0; i<ids.length; i++) {
String id = ids[i];
userAgent = buildUserAgent();
builder = new GVTBuilder();
ctx = new BridgeContext(userAgent);
ctx.setDynamic(true);
Document cloneDoc = (Document)doc.cloneNode(true);
Element insertionPoint = cloneDoc.getElementById(INSERTION_POINT_ID);
if (insertionPoint == null) {