1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.forgerock.doc.maven.build;
18
19 import org.apache.maven.plugin.MojoExecutionException;
20 import org.forgerock.doc.maven.AbstractDocbkxMojo;
21 import org.forgerock.doc.maven.utils.ImageCopier;
22 import org.forgerock.doc.maven.utils.OLinkUtils;
23 import org.twdata.maven.mojoexecutor.MojoExecutor;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.util.ArrayList;
28
29
30
31
32 public class Xhtml5 {
33
34
35
36
37 private AbstractDocbkxMojo m;
38
39
40
41
42 private final Executor executor;
43
44
45
46
47
48
49 public Xhtml5(final AbstractDocbkxMojo mojo) {
50 m = mojo;
51 this.executor = new Executor();
52 }
53
54
55
56
57
58
59 public void execute() throws MojoExecutionException {
60 executor.prepareOlinkDB();
61 executor.build();
62 }
63
64
65
66
67
68
69
70
71
72 final String getTargetDB() throws MojoExecutionException {
73 File targetDB = new File(m.getBuildDirectory(), "olinkdb-xhtml.xml");
74
75 try {
76 OLinkUtils.createTargetDatabase(targetDB, "xhtml5", m);
77 } catch (Exception e) {
78 throw new MojoExecutionException(
79 "Failed to write link target database: " + targetDB.getPath(), e);
80 }
81
82 return targetDB.getPath();
83 }
84
85
86
87
88 class Executor extends MojoExecutor {
89
90
91
92
93
94
95 void prepareOlinkDB() throws MojoExecutionException {
96
97 for (String docName : m.getDocNames()) {
98 ArrayList<Element> cfg = new ArrayList<Element>();
99 cfg.add(element(name("chunkedOutput"), "false"));
100 cfg.add(element(name("collectXrefTargets"), "only"));
101 cfg.add(element(name("includes"), docName + "/" + m.getDocumentSrcName()));
102 cfg.add(element(name("sourceDirectory"), m.path(m.getDocbkxModifiableSourcesDirectory())));
103 cfg.add(element(name("xhtml5Customization"), m.path(m.getXhtml5Customization())));
104 cfg.add(element(name("xincludeSupported"), m.isXincludeSupported()));
105 cfg.add(element(name("targetDirectory"), m.path(m.getDocbkxOutputDirectory()) + "/xhtml"));
106 cfg.add(element(name("targetsFilename"), m.getDocumentSrcName() + ".xhtml.target.db"));
107
108 executeMojo(
109 plugin(
110 groupId("com.agilejava.docbkx"),
111 artifactId("docbkx-maven-plugin"),
112 version(m.getDocbkxVersion())),
113 goal("generate-xhtml5"),
114 configuration(cfg.toArray(new Element[cfg.size()])),
115 executionEnvironment(m.getProject(), m.getSession(), m.getPluginManager()));
116 }
117 }
118
119
120
121
122
123
124 void build() throws MojoExecutionException {
125
126 try {
127 ImageCopier.copyImages("xhtml", "", m);
128 } catch (IOException e) {
129 throw new MojoExecutionException("Failed to copy images", e);
130 }
131
132 ArrayList<Element> cfg = new ArrayList<Element>();
133 cfg.add(element(name("chunkedOutput"), "false"));
134 cfg.add(element(name("highlightSource"), m.useSyntaxHighlighting()));
135 cfg.add(element(name("includes"), "*/" + m.getDocumentSrcName()));
136 cfg.add(element(name("sectionAutolabel"), m.areSectionsAutolabeled()));
137 cfg.add(element(name("sectionLabelIncludesComponentLabel"), m.doesSectionLabelIncludeComponentLabel()));
138 cfg.add(element(name("sourceDirectory"), m.path(m.getDocbkxModifiableSourcesDirectory())));
139 cfg.add(element(name("targetDatabaseDocument"), getTargetDB()));
140 cfg.add(element(name("targetDirectory"), m.path(m.getDocbkxOutputDirectory()) + "/xhtml"));
141 cfg.add(element(name("xhtml5Customization"), m.path(m.getXhtml5Customization())));
142 cfg.add(element(name("xincludeSupported"), m.isXincludeSupported()));
143
144 executeMojo(
145 plugin(
146 groupId("com.agilejava.docbkx"),
147 artifactId("docbkx-maven-plugin"),
148 version(m.getDocbkxVersion())),
149 goal("generate-xhtml5"),
150 configuration(cfg.toArray(new Element[cfg.size()])),
151 executionEnvironment(m.getProject(), m.getSession(), m.getPluginManager()));
152 }
153 }
154 }