-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_dita2splash.xml
238 lines (217 loc) · 7.97 KB
/
build_dita2splash.xml
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?xml version="1.0" encoding="UTF-8"?>
<!--ant-->
<!--
This file is part of the DITA-OT Splash Screen Plug-in project.
See the accompanying LICENSE file for applicable licenses.
-->
<project
xmlns:if="ant:if"
xmlns:unless="ant:unless"
xmlns:splash="antlib:fox.jason.splash"
name="fox.jason.splash"
>
<!--
Set default values for the parameters passed into this plugin.
-->
<target depends="build-init" name="splash.init">
<path id="splash.classpath">
<fileset dir="${dita.plugin.fox.jason.splash.dir}/lib">
<include name="*.jar"/>
</fileset>
<pathelement location="${dita.dir}/lib/ant-launcher.jar"/>
<pathelement location="${dita.dir}/lib/ant.jar"/>
</path>
<mkdir dir="${dita.temp.dir}"/>
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="splash.info.file"
/>
</target>
<!--
Make an HTTP request to the Cats API - check we are online and can obtain an image.
For more information see: http://thecatapi.com/docs.html
-->
<target
name="cats.init"
description="Requesting image from the Cats API.">
<local name="cats.url"/>
<local name="cats.url.base"/>
<property name="cats.url.base" if:set="cats.api_key" value="https://api.thecatapi.com/v1/images/search?api_key=${cats.api_key}"/>
<property name="cats.url.base" unless:set="cats.api_key" value="https://api.thecatapi.com/v1/images/search"/>
<property name="cats.url" if:set="cats.api.extend" value="${cats.url.base}&${cats.api.extend}"/>
<property name="cats.url" unless:set="cats.api.extend" value="${cats.url.base}"/>
<get
dest="${splash.info.file}"
ignoreerrors="true"
retries="1"
src="${cats.url}"
/>
<condition property="splash.exists" value="true">
<and>
<available file="${splash.info.file}"/>
<length file="${splash.info.file}" length="0" when="gt"/>
</and>
</condition>
</target>
<!--
Make an HTTP request to the Dogs API - check we are online and can obtain an image.
For more information see: http://thedogapi.com/docs.html
-->
<target
name="dogs.init"
description="Requesting image from the Dogs API.">
<local name="dogs.url"/>
<local name="dogs.url.base"/>
<property name="dogs.url.base" if:set="dogs.api_key" value="https://api.thedogapi.com/v1/images/search?api_key=${dogs.api_key}"/>
<property name="dogs.url.base" unless:set="dogs.api_key" value="https://api.thedogapi.com/v1/images/search"/>
<property name="dogs.url" if:set="dogs.api.extend" value="${dogs.url.base}&${dogs.api.extend}"/>
<property name="dogs.url" unless:set="dogs.api.extend" value="${dogs.url.base}"/>
<get
dest="${splash.info.file}"
ignoreerrors="true"
retries="1"
src="${dogs.url}"
/>
<condition property="splash.exists" value="true">
<and>
<available file="${splash.info.file}"/>
<length file="${splash.info.file}" length="0" when="gt"/>
</and>
</condition>
</target>
<!--
Extracts the image URL and attribution from the Cat API response. The parsing has been done
using simple string manipulation instead of loading the data as XML.
Important: To protect yourself from Copyright issues, when you show an Image you MUST have it linked to; or clearly show the 'source_url' the value of the XML, or leave the link in-place with HTML format. This then links back to the image on thecatapi.com, where we then link to where we do the same to the last known Copyright holder.
-->
<target if="splash.exists" name="cats.parse">
<loadfile
failonerror="true"
property="cats.info"
srcfile="${splash.info.file}"
/>
<splash:cats-parse/>
<echo level="verbose" message="Cats image URL: ${splash.image.url}"/>
</target>
<target if="splash.exists" name="dogs.parse">
<loadfile
failonerror="true"
property="dogs.info"
srcfile="${splash.info.file}"
/>
<splash:dogs-parse/>
<echo level="verbose" message="Dogs image URL: ${splash.image.url}"/>
</target>
<!--
Make an HTTP request to the XKCD API - check we are online and can obtain an image.
For more information see: https://xkcd.com/json.html
-->
<target
name="xkcd.init"
description="Requesting image from XKCD API.">
<get
dest="${splash.info.file}"
ignoreerrors="true"
retries="1"
src="https://xkcd.com/info.0.json"
/>
<condition property="splash.exists" value="true">
<and>
<available file="${splash.info.file}"/>
<length file="${splash.info.file}" length="0" when="gt"/>
</and>
</condition>
</target>
<!--
Select a random image using the repsonse received previously and requests a
random comic. Extracts the image URL and title
XKCD comics are written by Randall Munroe, and his work is licensed under a
Creative Commons Attribution-NonCommercial 2.5 License.
This means you're free to copy and share these comics (but not to sell them)
Since some early versions of Rhino do not expose the NativeJSON class as public,
simple string manipulation has been used to extract the necessary JSON elements.
-->
<target if="splash.exists" name="xkcd.parse">
<loadfile
failonerror="true"
property="xkcd.latest"
srcfile="${splash.info.file}"
/>
<splash:xkcd-select/>
<tempfile
deleteonexit="true"
destdir="${dita.temp.dir}"
property="xkcd.json.file"
/>
<get
dest="${xkcd.json.file}"
ignoreerrors="true"
retries="1"
src="https://xkcd.com/${num}/info.0.json"
/>
<loadfile failonerror="true" property="xkcd.info" srcfile="${xkcd.json.file}"/>
<splash:xkcd-parse/>
<echo level="verbose" message="XKCD image URL: ${splash.image.url}"/>
</target>
<!--
Invoke the splash screen with the given parameters.
-->
<target if="splash.exists" name="splash">
<property name="splash.resizer.url" value=""/>
<java
classname="org.apache.tools.ant.launch.Launcher"
classpathref="splash.classpath"
fork="true"
spawn="true"
>
<arg value="-buildfile"/>
<arg value="${dita.plugin.fox.jason.splash.dir}/run-splash.xml"/>
<arg value="-Dsplash.image=${splash.resizer.url}${splash.image.url}"/>
<arg value="-Dsplash.title=${splash.title}"/>
<arg value="-Dsplash.duration=20000"/>
</java>
</target>
<!--
Extracts the image URL from thisanimedoesnotexist.
-->
<target
name="anime.init"
description="Requesting image from thisanimedoesnotexist.ai.">
<splash:anime-select/>
<property name="splash.title" value="This Anime does not exist"/>
<property name="splash.exists" value="true"/>
<property name="splash.image.url" value="https://thisanimedoesnotexist.ai/results/psi-${anime.psi}/seed3${anime.seed}.png"/>
<echo level="verbose" message="Anime image URL: ${splash.image.url}"/>
</target>
<!--
Fixed URL from Lorem Picsum
-->
<target name="picsum.init"
description="Requesting image from Lorem Picsum.">
<property name="splash.exists" value="true"/>
<property name="splash.title" value="Lorem Picsum Image"/>
<property name="splash.image.url" value="https://picsum.photos/600/400"/>
<echo level="verbose" message="https://picsum.photos/600/400"/>
</target>
<!--
Targets to be used when chaining the splash plugin from DITA-OT.
-->
<target depends="splash.init,xkcd.init,xkcd.parse,splash" name="xkcd.splash"/>
<target depends="splash.init,cats.init,cats.parse,splash" name="cats.splash"/>
<target depends="splash.init,dogs.init,dogs.parse,splash" name="dogs.splash"/>
<target depends="splash.init,anime.init,splash" name="anime.splash"/>
<target depends="splash.init,picsum.init,splash" name="picsum.splash"/>
<target name="random.splash">
<property file="${dita.plugin.fox.jason.splash.dir}/cfg/configuration.properties"/>
<dita-ot-echo id="SPLSH01I" unless:set="splash.source">
<param name="1" value="Requesting a random image."/>
</dita-ot-echo>
<splash:random-select unless:set="splash.source"/>
<antcall target="${splash.source}.splash"/>
</target>
<!--
Main targets executed if you directly call this plugin from Ant or Java
-->
<target depends="random.splash" name="dita2splash"/>
</project>