Example #1
0
 private void initCT() {
   ct = new CleanerTransformations();
   TagTransformation tt = new TagTransformation("div", "div", true);
   tt.addAttributeTransformation("xmlns:saxon");
   tt.addAttributeTransformation("xmlns:xs");
   ct.addTransformation(tt);
 }
  /**
   * @param configuration The cleaner configuration.
   * @return the default cleaning transformations to perform on tags, in addition to the base
   *     transformations done by HTML Cleaner
   */
  private CleanerTransformations getDefaultCleanerTransformations(
      HTMLCleanerConfiguration configuration) {
    CleanerTransformations defaultTransformations = new CleanerTransformations();

    TagTransformation tt =
        new TagTransformation(HTMLConstants.TAG_B, HTMLConstants.TAG_STRONG, false);
    defaultTransformations.addTransformation(tt);

    tt = new TagTransformation(HTMLConstants.TAG_I, HTMLConstants.TAG_EM, false);
    defaultTransformations.addTransformation(tt);

    tt = new TagTransformation(HTMLConstants.TAG_U, HTMLConstants.TAG_INS, false);
    defaultTransformations.addTransformation(tt);

    tt = new TagTransformation(HTMLConstants.TAG_S, HTMLConstants.TAG_DEL, false);
    defaultTransformations.addTransformation(tt);

    tt = new TagTransformation(HTMLConstants.TAG_STRIKE, HTMLConstants.TAG_DEL, false);
    defaultTransformations.addTransformation(tt);

    tt = new TagTransformation(HTMLConstants.TAG_CENTER, HTMLConstants.TAG_P, false);
    tt.addAttributeTransformation(HTMLConstants.ATTRIBUTE_STYLE, "text-align:center");
    defaultTransformations.addTransformation(tt);

    String restricted = configuration.getParameters().get(HTMLCleanerConfiguration.RESTRICTED);
    if ("true".equalsIgnoreCase(restricted)) {

      tt = new TagTransformation(HTMLConstants.TAG_SCRIPT, HTMLConstants.TAG_PRE, false);
      defaultTransformations.addTransformation(tt);

      tt = new TagTransformation(HTMLConstants.TAG_STYLE, HTMLConstants.TAG_PRE, false);
      defaultTransformations.addTransformation(tt);
    }

    return defaultTransformations;
  }