import org.cybergarage.xml.Node; //導入方法依賴的package包/類
/**
* @throws I2PParserException if any node not in whitelist (depends on mode)
* @return true if node was removed from parent (only for REMOVE_ELEMENT mode)
*/
private boolean validate(Node node) throws I2PParserException {
String name = node.getName();
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Validating element: " + name);
if (!xhtmlWhitelist.contains(name.toLowerCase(Locale.US))) {
switch (_mode) {
case ABORT:
case SKIP_ENTRY:
throw new I2PParserException("Invalid XHTML element \"" + name + '"');
case REMOVE_ATTRIBUTE:
case REMOVE_ELEMENT:
if (_log.shouldLog(Log.WARN))
_log.warn("Removing element: " + node);
node.getParentNode().removeNode(node);
return true;
case ALLOW_ALL:
if (_log.shouldLog(Log.WARN))
_log.warn("Allowing non-whitelisted element by configuration: " + node);
break;
}
}
for (int i = 0; i Attribute attr = node.getAttribute(i);
String aname = attr.getName();
if (attributeBlacklist.contains(aname.toLowerCase(Locale.US))) {
switch (_mode) {
case ABORT:
case SKIP_ENTRY:
throw new I2PParserException("Invalid XHTML element \"" + name + "\" due to attribute " + aname);
case REMOVE_ELEMENT:
if (_log.shouldLog(Log.WARN))
_log.warn("Removing element: " + node + " due to attribute " + aname);
node.getParentNode().removeNode(node);
return true;
case REMOVE_ATTRIBUTE:
if (_log.shouldLog(Log.WARN))
_log.warn("Removing attribute: " + aname + " from " + node);
// sadly, no removeAttribute(int)
if (node.removeAttribute(attr))
i--;
break;
case ALLOW_ALL:
if (_log.shouldLog(Log.WARN))
_log.warn("Allowing blacklisted attribute by configuration: " + node);
break;
}
}
}
int count = node.getNNodes();
for (int i = 0; i boolean removed = validate(node.getNode(i));
if (removed)
i--;
}
return false;
}