Class RemovalHandler

java.lang.Object
org.docx4j.model.datastorage.RemovalHandler

public class RemovalHandler extends Object
Tool to remove content controls (Structured Document Tags) from an OpenXML document part.

This tool removes SDTs tagged with a certain quantifier from the document part.

Restrictions:

  • As it does text processing and no real namespace qualification exist, the quantifiers must be prefixed exactly be "od", not any other prefix.
  • In case of qualified removal (in effect not RemovalHandler.Quantifier.ALL), bindings containing more than one qualifier are not supported, that is, when you tag od:repeat=/this&od:xpath=/that, the SDT is removed whenever you specify to remove either repeat or bind tags. (multiple qualifiers are not recommended in any case!)
Version:
$Revision: $ $Date: $
Author:
Karsten Tinnefeld
  • Constructor Details

    • RemovalHandler

      public RemovalHandler()
      Initializes the removal handler. This tool is thread safe and should be reused, as initialization is relatively expensive.
  • Method Details

    • removeSDTs

      public void removeSDTs(WordprocessingMLPackage wordMLPackage) throws Docx4JException
      Removes Structured Document Tags from the main document part, headers, and footer, preserving their contents.
      Parameters:
      wordMLPackage - The docx package to modify (in situ).
      Throws:
      Docx4JException - In case any transformation error occurs.
      Since:
      6.1.0
    • removeSDTs

      public void removeSDTs(WordprocessingMLPackage wordMLPackage, RemovalHandler.Quantifier quantifier, String... keys) throws Docx4JException
      Removes Structured Document Tags from the main document part, headers, and footer, preserving their contents. In case key "empty" is specified, value bindings (xpath) are removed only if they have void contents (e.g. the XML points nowhere).
      Parameters:
      wordMLPackage - The docx package to modify (in situ).
      quantifier - The quantifier regarding which kinds of parts are to be removed.
      keys - In case of RemovalHandler.Quantifier.NAMED, quantifier names. All strings except "xpath", "condition", "repeat", "empty" are ignored.
      Throws:
      Docx4JException - In case any transformation error occurs.
    • removeSDTs

      public void removeSDTs(JaxbXmlPart<? extends Object> part) throws Docx4JException
      Removes Structured Document Tags from a document part, preserving their contents. In case key "empty" is specified, value bindings (xpath) are removed only if they have void contents (e.g. the XML points nowhere).
      Parameters:
      part - The document part to modify (in situ).
      quantifier - The quantifier regarding which kinds of parts are to be removed.
      keys - In case of RemovalHandler.Quantifier.NAMED, quantifier names. All strings except "xpath", "condition", "repeat", "empty" are ignored.
      Throws:
      Docx4JException - In case any transformation error occurs.
    • removeSDTs

      public void removeSDTs(JaxbXmlPart<? extends Object> part, RemovalHandler.Quantifier quantifier, String... keys) throws Docx4JException
      Removes Structured Document Tags from a document part, preserving their contents. In case key "empty" is specified, value bindings (xpath) are removed only if they have void contents (e.g. the XML points nowhere).
      Parameters:
      part - The document part to modify (in situ).
      quantifier - The quantifier regarding which kinds of parts are to be removed.
      keys - In case of RemovalHandler.Quantifier.NAMED, quantifier names. All strings except "xpath", "condition", "repeat", "empty" are ignored.
      Throws:
      Docx4JException - In case any transformation error occurs.