/** * Override to add additional conditions. * @param tagNode * @param attName * @param value * @return true if the attribute should not be outputed. */ protected boolean isForbiddenAttribute(TagNode tagNode, String attName, String value) { return !props.isNamespacesAware() && (XMLNS_NAMESPACE.equals(attName) || attName.startsWith(XMLNS_NAMESPACE +":")); }
/** * Override to add additional conditions. * * @param tagNode * @param attName * @param value * @return true if the attribute should not be outputed. */ protected boolean isForbiddenAttribute(TagNode tagNode, String attName, String value) { return !props.isNamespacesAware() && (XMLNS_NAMESPACE.equals(attName) || attName.startsWith(XMLNS_NAMESPACE + ":")); }
/** * Checks whether we can allow a tag as "foreign markup". * This means we must have namespace aware set to true, and we must * either have a current xmlns declaration within scope that isn't for * HTML, or we have a namespace prefix on the tag * * @param cleanTimeValues * @return */ private boolean isAllowedAsForeignMarkup(String tagname, CleanTimeValues cleanTimeValues) { if (!properties.isNamespacesAware()) return false; if (tagname == null) return false; if (tagname.contains(":")) return true; if (cleanTimeValues.namespace == null || cleanTimeValues.namespace.size() == 0) return false; String ns = cleanTimeValues.namespace.peek(); if (ns == null) return false; if (ns.equals("http://www.w3.org/1999/xhtml")) return false; return true; }
protected void serializeEndTag(TagNode tagNode, Writer writer, boolean newLine) throws IOException { String tagName = tagNode.getName(); if (Utils.isEmptyString(tagName)) { return; } if (Utils.getXmlNSPrefix(tagName) != null && !props.isNamespacesAware()) { tagName = Utils.getXmlName(tagName); } writer.write( "</" + tagName + ">" ); if (newLine) { writer.write("\n"); } }
protected void serializeEndTag(TagNode tagNode, Writer writer, boolean newLine) throws IOException { String tagName = tagNode.getName(); if (Utils.isEmptyString(tagName)) { return; } if (Utils.getXmlNSPrefix(tagName) != null && !props.isNamespacesAware()) { tagName = Utils.getXmlName(tagName); } writer.write("</" + tagName + ">"); if (newLine) { writer.write("\n"); } }
suffix = suffix.substring(0, nextColumnIndex); if (props.isNamespacesAware()) { id = prefix + ":" + suffix; if ( !"xmlns".equalsIgnoreCase(prefix) ) {
suffix = suffix.substring(0, nextColumnIndex); if (props.isNamespacesAware()) { id = prefix + ":" + suffix; if (!"xmlns".equalsIgnoreCase(prefix)) {
boolean nsAware = props.isNamespacesAware();
if (properties.isNamespacesAware() && namespacePrefixes != null) { Iterator<String> iterator = namespacePrefixes.iterator(); while (iterator.hasNext()) {
boolean nsAware = props.isNamespacesAware();
if (attPrefix != null) { attrName = Utils.getXmlName(attrName); if (props.isNamespacesAware()) { String nsURI = node.getNamespaceURIOnPath(attPrefix); if (nsURI == null) {
private void setAttributes(TagNode node, Element element) { for (Map.Entry<String, String> entry : node.getAttributes().entrySet()) { String attrName = entry.getKey(); String attrValue = entry.getValue(); if (escapeXml) { attrValue = Utils.escapeXml(attrValue, props, true); } String attPrefix = Utils.getXmlNSPrefix(attrName); Namespace ns = null; if (attPrefix != null) { attrName = Utils.getXmlName(attrName); if (props.isNamespacesAware()) { String nsURI = node.getNamespaceURIOnPath(attPrefix); if (nsURI == null) { nsURI = attPrefix; } if (!attPrefix.startsWith("xml")) { ns = Namespace.getNamespace(attPrefix, nsURI); } } } if (ns == null) { element.setAttribute(attrName, attrValue); } else { element.setAttribute(attrName, attrValue, ns); } } }
if (properties.isNamespacesAware() && namespacePrefixes != null) { Iterator<String> iterator = namespacePrefixes.iterator(); while (iterator.hasNext()) {
/** * @param configuration the configuration to use for the cleaning * @return the default {@link CleanerProperties} to be used for cleaning. */ private CleanerProperties getDefaultCleanerProperties(HTMLCleanerConfiguration configuration) { CleanerProperties defaultProperties = new CleanerProperties(); defaultProperties.setOmitUnknownTags(true); defaultProperties.setNamespacesAware(true); // HTML Cleaner uses the compact notation by default but we don't want that since: // - it's more work and not required since not compact notation is valid XHTML // - expanded elements can also be rendered fine in browsers that only support HTML. defaultProperties.setUseEmptyElementTags(false); // Wrap script and style content in CDATA blocks defaultProperties.setUseCdataForScriptAndStyle(true); // Handle the NAMESPACE_AWARE configuration property String param = configuration.getParameters().get(HTMLCleanerConfiguration.NAMESPACES_AWARE); boolean namespacesAware = (param != null) ? Boolean.parseBoolean(param) : defaultProperties.isNamespacesAware(); defaultProperties.setNamespacesAware(namespacesAware); return defaultProperties; }
private Element createElement(TagNode node) { String name = node.getName(); boolean nsAware = props.isNamespacesAware(); String prefix = Utils.getXmlNSPrefix(name); Map<String, String> nsDeclarations = node.getNamespaceDeclarations();
private Element createElement(TagNode node) { String name = node.getName(); boolean nsAware = props.isNamespacesAware(); String prefix = Utils.getXmlNSPrefix(name); Map<String, String> nsDeclarations = node.getNamespaceDeclarations();
ITagInfoProvider tagInfoProvider = cleaner.getTagInfoProvider(); TagInfo tagInfo = tagInfoProvider.getTagInfo(tagName); if ((tagInfo == null && !props.isOmitUnknownTags() && props.isTreatUnknownTagsAsContent() && !isReservedTag(tagName) && !props.isNamespacesAware()) || (tagInfo != null && tagInfo.isDeprecated() && !props.isOmitDeprecatedTags() && props.isTreatDeprecatedTagsAsContent())) { content();
ITagInfoProvider tagInfoProvider = cleaner.getTagInfoProvider(); TagInfo tagInfo = tagInfoProvider.getTagInfo(tagName); if ((tagInfo == null && !props.isOmitUnknownTags() && props.isTreatUnknownTagsAsContent() && !isReservedTag(tagName) && !props.isNamespacesAware()) || (tagInfo != null && tagInfo.isDeprecated() && !props.isOmitDeprecatedTags() && props.isTreatDeprecatedTagsAsContent())) { content();