aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/mammoth/internal/styles/StyleMapBuilder.java
blob: 2d66f2a179d4e7feadd906d5b0e34a1aa933c936 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package org.zwobble.mammoth.internal.styles;

import org.zwobble.mammoth.internal.documents.Break;
import org.zwobble.mammoth.internal.documents.Paragraph;
import org.zwobble.mammoth.internal.documents.Run;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class StyleMapBuilder {
    private Optional<HtmlPath> underline;
    private Optional<HtmlPath> strikethrough;
    private Optional<HtmlPath> bold;
    private Optional<HtmlPath> italic;
    private Optional<HtmlPath> commentReference;
    private final List<StyleMapping<Paragraph>> paragraphStyles = new ArrayList<>();
    private final List<StyleMapping<Run>> runStyles = new ArrayList<>();
    private final List<StyleMapping<Break>> breakStyles = new ArrayList<>();

    public StyleMapBuilder() {
        this.bold = Optional.empty();
        this.underline = Optional.empty();
        this.strikethrough = Optional.empty();
        this.italic = Optional.empty();
        this.commentReference = Optional.empty();
    }

    public StyleMapBuilder bold(HtmlPath path) {
        this.bold = Optional.of(path);
        return this;
    }

    public StyleMapBuilder italic(HtmlPath path) {
        this.italic = Optional.of(path);
        return this;
    }

    public StyleMapBuilder underline(HtmlPath path) {
        this.underline = Optional.of(path);
        return this;
    }

    public StyleMapBuilder strikethrough(HtmlPath path) {
        this.strikethrough = Optional.of(path);
        return this;
    }

    public StyleMapBuilder commentReference(HtmlPath path) {
        this.commentReference = Optional.of(path);
        return this;
    }

    public StyleMapBuilder mapParagraph(ParagraphMatcher matcher, HtmlPath path) {
        paragraphStyles.add(new StyleMapping<>(matcher, path));
        return this;
    }

    public StyleMapBuilder mapRun(RunMatcher matcher, HtmlPath path) {
        runStyles.add(new StyleMapping<>(matcher, path));
        return this;
    }

    public StyleMap build() {
        return new StyleMap(bold, italic, underline, strikethrough, commentReference, paragraphStyles, runStyles, breakStyles);
    }
}