Class AttributeCleaner

  • Direct Known Subclasses:
    InlineStyleCleaner

    public class AttributeCleaner
    extends Cleaner
    Clean any HTML attribute value using a Cleaner settings.

    Since:
    jcms-10.0.0 / JCMS-6170
    • Constructor Detail

      • AttributeCleaner

        public AttributeCleaner​(java.lang.String attributeKey)
        Builds a new cleaner for the specified attribute.
        Parameters:
        attributeKey - the name of the HTML attribute whose value is to be cleaned. (eg "id")
      • AttributeCleaner

        public AttributeCleaner​(java.lang.String attributeKey,
                                java.lang.String splitRegex,
                                java.lang.String delimiter)
        Builds a new cleaner for the specified attribute, which may contains multiple value seperated with the specified pattern.
        Parameters:
        attributeKey - the name of the HTML attribute whose value is to be cleaned. (eg "class")
        splitRegex - a regular expression used to split multiple values of the attribute (eg "\s").
        delimiter - a string used to seperate multiple values once they have been cleaned (eg " ").
    • Method Detail

      • configureFromProperties

        public void configureFromProperties​(JProperties prop)
        Description copied from class: Cleaner
        Configure the current cleaner with the specified properties.
        Overrides:
        configureFromProperties in class Cleaner
        Parameters:
        prop - a instance of JProperties, must not be null
      • clean

        public java.lang.String clean​(java.lang.String unsafeValue)
        Clean the specified attribute value.
        Parameters:
        unsafeValue - value of the HTML attribute
        Returns:
        a cleaned version of the value attribute, where only currently allowed css properties have been kept
      • cleanSingleValue

        protected java.lang.String cleanSingleValue​(java.lang.String unsafeValue)
        Clean individual value of the attribute.

        When attributes accept several values (such as "class" attribute), this method is invoked for each of this value.
        When attributes accept only one value (such as "id" attribute), this method is invoked one for the whole attribute value.

        Override to provide custom cleaning behavior.

        Parameters:
        unsafeValue - the unsafe attribute value (or "split" value in case multiple values)
        Returns:
        a safe sanitized value (or empty string if no value was kept, never return null)
      • clean

        public void clean​(org.jsoup.nodes.Node node)
        Clean style attribute in the specified node and its descendant.
        Parameters:
        node - the node to clean, must not be null