Package com.xmlmind.w2x.processor

## Class SplitStep

- java.lang.Object
- - com.xmlmind.w2x.processor.ProcessStep
  - - com.xmlmind.w2x.processor.SplitStep

- Direct Known Subclasses:
    `EpubStep`, `WebHelpStep`

      public class SplitStep
      extends ProcessStep

  This processing step is used to split input XHTML+CSS document (typically created using a `ConvertStep`) or input semantic XHTML document (typically created using a `EditStep` running "`w2x:xed/main.xed`") into several parts and to save to disk the corresponding frameset.

  The outline level used to split the input XHTML+CSS document is specified by parameter `step_name.split-before-level`. This outline level is an integer between 0 and 8 inclusive.

  For an input semantic XHTML document, this outline level is an integer between 0 (`h1`) and 5 (`h6`) inclusive.

  Default outline level is 0.

  The save file of the frameset is specified by parameter `step_name.out-file`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `protected static class` | `SplitStep.Part` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected static Name` | `COLS_ATTR` |
    `protected static Name` | `FRAME_ELEM` |
    `protected static Name` | `FRAMESET_ELEM` |
    `protected static Name` | `SCROLLING_ATTR` |
    `protected static String` | `TOC_CSS` |

    - ### Fields inherited from class com.xmlmind.w2x.processor.ProcessStep

      `stepName`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `SplitStep​(String stepName)` | Constructs a SplitStep having specified name.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected SplitStep.Part` | `addPart​(int level, int splitBeforeLevel, Set<String> idUsedAsFilename, boolean allowLonelyHeading, Element p, Element dstBody, File outFile, Document partTemplate, List<SplitStep.Part> parts)` |
    `protected static void` | `collectCounters​(Element tree, Map<String,​Integer> counterMap, Map<String,​Integer> resetCounterMap)` |
    `protected static void` | `collectIds​(Element tree, String docHref, Map<String,​String[]> idMap)` |
    `protected void` | `collectNotes​(Element tree, Map<String,​Element> idToNote)` |
    `protected void` | `copyNotes​(String role, Element tree, Element srcNotes, Element dstNotes)` |
    `protected void` | `copyNotes2​(Element tree, Map<String,​Element> idToNote, int[] noteCount, Element dstBody)` |
    `protected static Element` | `createCharsetMeta​(String charset)` |
    `protected Document` | `createFrameset​(Document xhtmlDoc, String charset, String tocHref, String contentHref)` |
    `protected Document` | `createPartTemplate​(Document xhtmlDoc)` |
    `protected Element` | `createTOCStyle​(List<SplitStep.Part> parts)` |
    `protected static void` | `creatingFile​(File file, ProgressMonitor monitor)` |
    `protected void` | `deleteNotes​(Element tree)` |
    `protected static Element` | `findById​(Element tree, String id)` |
    `protected static String` | `findCharset​(Document doc)` |
    `protected static Element` | `findCharsetMeta​(Element head, String[] foundCharset)` |
    `protected static Element` | `findNotes​(String role, Element body)` |
    `protected static SplitStep.Part` | `findParentPart​(List<SplitStep.Part> parts)` |
    `protected static Element` | `findTitle​(Document doc)` |
    `protected static void` | `fixLinks​(Element tree, String docHref, Map<String,​String[]> idMap)` |
    `protected static String` | `getAllText​(Element tree, boolean collapseWhiteSpace)` |
    `protected static Element` | `getBoxFirstChildElement​(Element element)` |
    `protected static int` | `getOutlineLevel​(Element element)` |
    `protected static boolean` | `isNote​(Element element)` |
    `protected static boolean` | `isNoteRef​(Element element)` |
    `protected static boolean` | `isNoteSeparator​(Element element)` |
    `protected File` | `newOutFile​(File file, int partNum)` |
    `protected static File` | `newOutFile​(File file, String suffix)` |
    `protected static Object[]` | `parseCounterPI​(Element p, ProcessingInstruction[] counterPI)` |
    `protected static void` | `parseCounterReset​(String prop, Map<String,​Integer> counterMap)` |
    `void` | `process​(Object[] state, Map<String,​String> parameters, int[] stepCounter, ProgressMonitor monitor)` | Execute this processing step.
    `protected void` | `processCounters​(List<SplitStep.Part> parts)` |
    `protected void` | `processLinks​(List<SplitStep.Part> parts)` |
    `protected void` | `processNotes​(List<SplitStep.Part> parts, Document htmlDoc)` |
    `protected void` | `processNotes2​(Element srcBody, List<SplitStep.Part> parts, Document htmlDoc)` |
    `protected void` | `processParts​(List<SplitStep.Part> parts, Document htmlDoc)` |
    `protected static String` | `resetCounters​(Map<String,​Integer> counterMap, Map<String,​Integer> resetCounterMap)` |
    `protected void` | `saveDocument​(Document doc, boolean indent, String encoding, File file, ProgressMonitor monitor)` |
    `protected void` | `saveParts​(List<SplitStep.Part> parts, boolean indent, String encoding, File outFile, ProgressMonitor monitor)` |
    `protected static void` | `setNotes​(String role, Element newNotes, Element body)` |
    `protected void` | `splitDocument​(Document xhtmlDoc, int splitBeforeLevel, Set<String> idUsedAsFilename, boolean allowLonelyHeading, File outFile, List<SplitStep.Part> parts, ProgressMonitor monitor)` |
    `protected Document` | `toTOC​(List<SplitStep.Part> parts, String charset)` |
    `protected boolean` | `useSameChunk​(boolean allowLonelyHeading, Element dstBody)` |

    - ### Methods inherited from class com.xmlmind.w2x.processor.ProcessStep

      `debugParameters, equals, getAllParameters, getBooleanParameter, getFileParameter, getIntParameter, getParameter, getURLParameter, hashCode, illegalState, joinAllParameters, missingParameter, parameterName, progress, toString, urlOrFile`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### FRAMESET_ELEM

          protected static final Name FRAMESET_ELEM

    - #### FRAME_ELEM

          protected static final Name FRAME_ELEM

    - #### COLS_ATTR

          protected static final Name COLS_ATTR

    - #### SCROLLING_ATTR

          protected static final Name SCROLLING_ATTR

    - #### TOC_CSS

          protected static final String TOC_CSS

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SplitStep

          public SplitStep​(String stepName)

      Constructs a SplitStep having specified name.

  - ### Method Detail

    - #### process

          public void process​(Object[] state,
                              Map<String,​String> parameters,
                              int[] stepCounter,
                              ProgressMonitor monitor)
                       throws Exception

      Execute this processing step.

      `state[0]` contains:

      - Before this method is executed: an XHTML+CSS document (typically created using a `ConvertStep`).
      - After this method is executed: the save file containing the frameset.
      Specified by:
        `process` in class `ProcessStep`
      Parameters:
        `state` - contains the current state of processing: a `Document` or a `File`.

        This object is used as the input of this step and thus, is processed by this step.

        After its execution, this method generally updates the `state` array with a new `Document` or `File` to pass the result/output of this step to the next step.

        `parameters` - all the parameters passed to the `Processor` owning and thus executing this process step.

        Parameters which are relevant to this processing step are prefixed with "``ProcessStep.stepName`.`".

        `stepCounter` - contains the rank of previously executed processing step. Must be incremented by this method.
        `monitor` - used to monitor the progress of the processing steps

        Invoking convenience method `ProcessStep.progress(java.lang.String, int[], com.xmlmind.util.ProgressMonitor)` suffices to make good use of both `monitor` and `stepCounter`.

      Throws:
        `Exception` - if for any reason, this method fails

    - #### findCharset

          protected static final String findCharset​(Document doc)

    - #### findCharsetMeta

          protected static final Element findCharsetMeta​(Element head,
                                                         String[] foundCharset)

    - #### newOutFile

          protected File newOutFile​(File file,
                                    int partNum)

    - #### newOutFile

          protected static final File newOutFile​(File file,
                                                 String suffix)

    - #### splitDocument

          protected void splitDocument​(Document xhtmlDoc,
                                       int splitBeforeLevel,
                                       Set<String> idUsedAsFilename,
                                       boolean allowLonelyHeading,
                                       File outFile,
                                       List<SplitStep.Part> parts,
                                       ProgressMonitor monitor)
                                throws Exception

      Throws:
        `Exception`

    - #### getOutlineLevel

          protected static final int getOutlineLevel​(Element element)

    - #### getBoxFirstChildElement

          protected static final Element getBoxFirstChildElement​(Element element)

    - #### createPartTemplate

          protected Document createPartTemplate​(Document xhtmlDoc)
                                         throws Exception

      Throws:
        `Exception`

    - #### addPart

          protected SplitStep.Part addPart​(int level,
                                           int splitBeforeLevel,
                                           Set<String> idUsedAsFilename,
                                           boolean allowLonelyHeading,
                                           Element p,
                                           Element dstBody,
                                           File outFile,
                                           Document partTemplate,
                                           List<SplitStep.Part> parts)

    - #### parseCounterPI

          protected static final Object[] parseCounterPI​(Element p,
                                                         ProcessingInstruction[] counterPI)

    - #### findTitle

          protected static final Element findTitle​(Document doc)

    - #### findParentPart

          protected static final SplitStep.Part findParentPart​(List<SplitStep.Part> parts)

    - #### useSameChunk

          protected boolean useSameChunk​(boolean allowLonelyHeading,
                                         Element dstBody)

    - #### processParts

          protected void processParts​(List<SplitStep.Part> parts,
                                      Document htmlDoc)

    - #### processCounters

          protected void processCounters​(List<SplitStep.Part> parts)

    - #### parseCounterReset

          protected static final void parseCounterReset​(String prop,
                                                        Map<String,​Integer> counterMap)

    - #### collectCounters

          protected static final void collectCounters​(Element tree,
                                                      Map<String,​Integer> counterMap,
                                                      Map<String,​Integer> resetCounterMap)

    - #### resetCounters

          protected static final String resetCounters​(Map<String,​Integer> counterMap,
                                                      Map<String,​Integer> resetCounterMap)

    - #### processNotes

          protected void processNotes​(List<SplitStep.Part> parts,
                                      Document htmlDoc)

    - #### findNotes

          protected static final Element findNotes​(String role,
                                                   Element body)

    - #### copyNotes

          protected void copyNotes​(String role,
                                   Element tree,
                                   Element srcNotes,
                                   Element dstNotes)

    - #### findById

          protected static final Element findById​(Element tree,
                                                  String id)

    - #### setNotes

          protected static final void setNotes​(String role,
                                               Element newNotes,
                                               Element body)

    - #### processNotes2

          protected void processNotes2​(Element srcBody,
                                       List<SplitStep.Part> parts,
                                       Document htmlDoc)

    - #### deleteNotes

          protected void deleteNotes​(Element tree)

    - #### isNote

          protected static final boolean isNote​(Element element)

    - #### isNoteSeparator

          protected static final boolean isNoteSeparator​(Element element)

    - #### collectNotes

          protected void collectNotes​(Element tree,
                                      Map<String,​Element> idToNote)

    - #### copyNotes2

          protected void copyNotes2​(Element tree,
                                    Map<String,​Element> idToNote,
                                    int[] noteCount,
                                    Element dstBody)

    - #### isNoteRef

          protected static final boolean isNoteRef​(Element element)

    - #### processLinks

          protected void processLinks​(List<SplitStep.Part> parts)

    - #### collectIds

          protected static final void collectIds​(Element tree,
                                                 String docHref,
                                                 Map<String,​String[]> idMap)

    - #### fixLinks

          protected static final void fixLinks​(Element tree,
                                               String docHref,
                                               Map<String,​String[]> idMap)

    - #### saveParts

          protected void saveParts​(List<SplitStep.Part> parts,
                                   boolean indent,
                                   String encoding,
                                   File outFile,
                                   ProgressMonitor monitor)
                            throws Exception

      Throws:
        `Exception`

    - #### saveDocument

          protected void saveDocument​(Document doc,
                                      boolean indent,
                                      String encoding,
                                      File file,
                                      ProgressMonitor monitor)
                               throws CanceledException,
                                      IOException

      Throws:
        `CanceledException`
        `IOException`

    - #### creatingFile

          protected static final void creatingFile​(File file,
                                                   ProgressMonitor monitor)
                                            throws CanceledException,
                                                   IOException

      Throws:
        `CanceledException`
        `IOException`

    - #### toTOC

          protected Document toTOC​(List<SplitStep.Part> parts,
                                   String charset)

    - #### createTOCStyle

          protected Element createTOCStyle​(List<SplitStep.Part> parts)

    - #### createCharsetMeta

          protected static final Element createCharsetMeta​(String charset)

    - #### createFrameset

          protected Document createFrameset​(Document xhtmlDoc,
                                            String charset,
                                            String tocHref,
                                            String contentHref)

    - #### getAllText

          protected static final String getAllText​(Element tree,
                                                   boolean collapseWhiteSpace)