Skip to content

Commit acf5d45

Browse files
committed
✨ Added xci() to fluent interfaces for FormsService and OutputService
You can now embed fonts (by creating an XCI on the fly) from the fluent interface without the need for an external XCI.
1 parent b97eaca commit acf5d45

15 files changed

Lines changed: 254 additions & 36 deletions

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/api/forms/FormsService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com._4point.aem.fluentforms.api.DocumentFactory;
1515
import com._4point.aem.fluentforms.api.PathOrUrl;
1616
import com._4point.aem.fluentforms.api.Transformable;
17+
import com._4point.aem.fluentforms.api.Xci;
1718
import com._4point.aem.fluentforms.impl.SimpleDocumentFactoryImpl;
1819
import com.adobe.fd.forms.api.AcrobatVersion;
1920
import com.adobe.fd.forms.api.CacheStrategy;
@@ -136,6 +137,14 @@ public default RenderPDFFormArgumentBuilder setSubmitUrlString(String url) throw
136137
@Override
137138
public RenderPDFFormArgumentBuilder setXci(Document xci);
138139

140+
@Override
141+
public default RenderPDFFormArgumentBuilder setXci(Xci xci) {
142+
PDFFormRenderOptionsSetter.super.setXci(xci);
143+
return this;
144+
}
145+
146+
public XciArgumentBuilder xci();
147+
139148
public Document executeOn(PathOrUrl template, Document data) throws FormsServiceException, FileNotFoundException;
140149

141150
public Document executeOn(Path template, Document data) throws FormsServiceException, FileNotFoundException;
@@ -211,6 +220,11 @@ default public Document executeOn(URL template) throws FormsServiceException {
211220
default public Document executeOn(Document template) throws FormsServiceException {
212221
return executeOn(template, (Document)null);
213222
};
223+
224+
public interface XciArgumentBuilder {
225+
XciArgumentBuilder embedFonts(boolean embedFonts);
226+
RenderPDFFormArgumentBuilder done();
227+
}
214228
}
215229

216230
public static interface ValidateArgumentBuilder extends ValidationOptionsSetter, Transformable<ValidateArgumentBuilder> {

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/api/forms/PDFFormRenderOptionsSetter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com._4point.aem.fluentforms.api.AbsoluteOrRelativeUrl;
1313
import com._4point.aem.fluentforms.api.Document;
1414
import com._4point.aem.fluentforms.api.PathOrUrl;
15+
import com._4point.aem.fluentforms.api.Xci;
1516
import com.adobe.fd.forms.api.AcrobatVersion;
1617
import com.adobe.fd.forms.api.CacheStrategy;
1718
import com.adobe.fd.forms.api.RenderAtClient;
@@ -80,5 +81,9 @@ default PDFFormRenderOptionsSetter setSubmitUrl(URL url) {
8081
PDFFormRenderOptionsSetter setTaggedPDF(boolean isTagged);
8182

8283
PDFFormRenderOptionsSetter setXci(Document xci);
84+
85+
default PDFFormRenderOptionsSetter setXci(Xci xci) {
86+
return setXci(xci.toDocument());
87+
}
8388

8489
}

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/api/output/OutputService.java

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com._4point.aem.fluentforms.api.DocumentFactory;
1515
import com._4point.aem.fluentforms.api.PathOrUrl;
1616
import com._4point.aem.fluentforms.api.Transformable;
17+
import com._4point.aem.fluentforms.api.Xci;
1718
import com._4point.aem.fluentforms.impl.SimpleDocumentFactoryImpl;
1819
import com.adobe.fd.output.api.AcrobatVersion;
1920
import com.adobe.fd.output.api.PaginationOverride;
@@ -110,6 +111,14 @@ default GeneratePdfOutputArgumentBuilder setContentRoot(URL contentRoot) {
110111
@Override
111112
GeneratePdfOutputArgumentBuilder setXci(Document xci);
112113

114+
@Override
115+
default GeneratePdfOutputArgumentBuilder setXci(Xci xci) {
116+
PDFOutputOptionsSetter.super.setXci(xci);
117+
return this;
118+
}
119+
120+
public XciArgumentBuilder xci();
121+
113122
public Document executeOn(PathOrUrl template, Document data) throws OutputServiceException, FileNotFoundException;
114123

115124
public Document executeOn(Path template, Document data) throws OutputServiceException, FileNotFoundException;
@@ -185,6 +194,11 @@ default public Document executeOn(URL template) throws OutputServiceException {
185194
default public Document executeOn(Document template) throws OutputServiceException {
186195
return executeOn(template, (Document)null);
187196
};
197+
198+
public interface XciArgumentBuilder {
199+
XciArgumentBuilder embedFonts(boolean embedFonts);
200+
GeneratePdfOutputArgumentBuilder done();
201+
}
188202
}
189203

190204
public static interface GeneratePrintedOutputArgumentBuilder extends PrintedOutputOptionsSetter, Transformable<GeneratePrintedOutputArgumentBuilder> {
@@ -221,13 +235,59 @@ default GeneratePrintedOutputArgumentBuilder setContentRoot(URL url) {
221235

222236
@Override
223237
GeneratePrintedOutputArgumentBuilder setXci(Document xci);
238+
239+
@Override
240+
default GeneratePrintedOutputArgumentBuilder setXci(Xci xci) {
241+
PrintedOutputOptionsSetter.super.setXci(xci);
242+
return this;
243+
}
224244

245+
public XciArgumentBuilder xci();
246+
247+
/**
248+
* Merges the provided template with the provided data and returns the generated
249+
* output.
250+
*
251+
* @param template The template to merge data into.
252+
* @param data The data to merge with the template.
253+
* @return The generated output document.
254+
* @throws OutputServiceException If an error occurs during processing.
255+
* @throws FileNotFoundException If the template file is not found.
256+
*/
225257
public Document executeOn(PathOrUrl template, Document data) throws OutputServiceException, FileNotFoundException;
226258

259+
/**
260+
* Merges the provided template with the provided data and returns the generated
261+
* output.
262+
*
263+
* @param template The template to merge data into.
264+
* @param data The data to merge with the template.
265+
* @return The generated output document.
266+
* @throws OutputServiceException If an error occurs during processing.
267+
* @throws FileNotFoundException If the template file is not found.
268+
*/
227269
public Document executeOn(Path template, Document data) throws OutputServiceException, FileNotFoundException;
228270

271+
/**
272+
* Merges the provided template with the provided data and returns the generated
273+
* output.
274+
*
275+
* @param template The template to merge data into.
276+
* @param data The data to merge with the template.
277+
* @return The generated output document.
278+
* @throws OutputServiceException If an error occurs during processing.
279+
*/
229280
public Document executeOn(URL template, Document data) throws OutputServiceException;
230281

282+
/**
283+
* Merges the provided template with the provided data and returns the generated
284+
* output.
285+
*
286+
* @param template The template to merge data into.
287+
* @param data The data to merge with the template.
288+
* @return The generated output document.
289+
* @throws FileNotFoundException If the template file is not found.
290+
*/
231291
public Document executeOn(Document template, Document data) throws OutputServiceException;
232292

233293
default public Document executeOn(PathOrUrl template, byte[] data) throws OutputServiceException, FileNotFoundException {
@@ -298,6 +358,11 @@ default public Document executeOn(Document template) throws OutputServiceExcepti
298358
return executeOn(template, (Document)null);
299359
};
300360

361+
public interface XciArgumentBuilder {
362+
XciArgumentBuilder embedPclFonts(boolean embedFonts);
363+
XciArgumentBuilder embedPsFonts(boolean embedFonts);
364+
GeneratePrintedOutputArgumentBuilder done();
365+
}
301366
}
302367

303368
public static interface GeneratePdfOutputBatchArgumentBuilder extends PDFOutputOptionsSetter, BatchArgumentBuilder, Transformable<GeneratePdfOutputArgumentBuilder> {
@@ -344,7 +409,15 @@ default GeneratePdfOutputBatchArgumentBuilder setContentRoot(URL contentRoot) {
344409
@Override
345410
GeneratePdfOutputBatchArgumentBuilder setXci(Document xci);
346411

347-
// TODO: Fix up the executeOns to overload the options.
412+
@Override
413+
default GeneratePdfOutputBatchArgumentBuilder setXci(Xci xci) {
414+
PDFOutputOptionsSetter.super.setXci(xci);
415+
return this;
416+
}
417+
418+
public XciArgumentBuilder xci();
419+
420+
// TODO: Fix up the executeOns to overload the options.
348421
public BatchResult executeOn(PathOrUrl template, Document data) throws OutputServiceException, FileNotFoundException;
349422

350423
public BatchResult executeOn(Path template, Document data) throws OutputServiceException, FileNotFoundException;
@@ -387,6 +460,10 @@ default public BatchResult executeOn(URL template) throws OutputServiceException
387460
return executeOn(template, (Document) null);
388461
};
389462

463+
public interface XciArgumentBuilder {
464+
XciArgumentBuilder embedFonts(boolean embedFonts);
465+
GeneratePdfOutputBatchArgumentBuilder done();
466+
}
390467
}
391468

392469
public static interface GeneratePrintedOutputBatchArgumentBuilder extends PrintedOutputOptionsSetter, BatchArgumentBuilder, Transformable<GeneratePrintedOutputArgumentBuilder> {
@@ -424,7 +501,15 @@ default GeneratePrintedOutputBatchArgumentBuilder setContentRoot(URL url) {
424501
@Override
425502
GeneratePrintedOutputBatchArgumentBuilder setXci(Document xci);
426503

427-
// TODO: Fix up the executeOns to overload the options.
504+
@Override
505+
default GeneratePrintedOutputBatchArgumentBuilder setXci(Xci xci) {
506+
PrintedOutputOptionsSetter.super.setXci(xci);
507+
return this;
508+
}
509+
510+
public XciArgumentBuilder xci();
511+
512+
// TODO: Fix up the executeOns to overload the options.
428513
public BatchResult executeOn(PathOrUrl template, Document data) throws OutputServiceException, FileNotFoundException;
429514

430515
public BatchResult executeOn(Path template, Document data) throws OutputServiceException, FileNotFoundException;
@@ -466,7 +551,12 @@ default public BatchResult executeOn(Path template) throws OutputServiceExceptio
466551
default public BatchResult executeOn(URL template) throws OutputServiceException {
467552
return executeOn(template, (Document)null);
468553
};
469-
554+
555+
public interface XciArgumentBuilder {
556+
XciArgumentBuilder embedPclFonts(boolean embedFonts);
557+
XciArgumentBuilder embedPsFonts(boolean embedFonts);
558+
GeneratePrintedOutputBatchArgumentBuilder done();
559+
}
470560
}
471561

472562
public static interface BatchArgumentBuilder {

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/api/output/PDFOutputOptionsSetter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com._4point.aem.fluentforms.api.Document;
88
import com._4point.aem.fluentforms.api.PathOrUrl;
9+
import com._4point.aem.fluentforms.api.Xci;
910
import com.adobe.fd.output.api.AcrobatVersion;
1011

1112
public interface PDFOutputOptionsSetter {
@@ -38,4 +39,8 @@ default PDFOutputOptionsSetter setContentRoot(URL contentRoot) {
3839

3940
PDFOutputOptionsSetter setXci(Document xci);
4041

42+
default PDFOutputOptionsSetter setXci(Xci xci) {
43+
return setXci(xci.toDocument());
44+
}
45+
4146
}

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/api/output/PrintedOutputOptionsSetter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com._4point.aem.fluentforms.api.Document;
88
import com._4point.aem.fluentforms.api.PathOrUrl;
9+
import com._4point.aem.fluentforms.api.Xci;
910
import com.adobe.fd.output.api.PaginationOverride;
1011

1112
public interface PrintedOutputOptionsSetter {
@@ -32,4 +33,7 @@ default PrintedOutputOptionsSetter setContentRoot(URL url) {
3233

3334
PrintedOutputOptionsSetter setXci(Document xci);
3435

36+
default PrintedOutputOptionsSetter setXci(Xci xci) {
37+
return setXci(xci.toDocument());
38+
}
3539
}

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/impl/XciImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Document toDocument(DocumentFactory factory) {
7373
return factory.create(result.getBytes());
7474
}
7575

76-
public static class JavaxXciBuilder implements Xci.XciBuilder {
76+
public static class XciBuilderImpl implements Xci.XciBuilder {
7777
private DestinationBuilderImpl pdfBuilder = null;
7878
private DestinationBuilderImpl pclBuilder = null;
7979
private DestinationBuilderImpl psBuilder = null;
@@ -120,7 +120,7 @@ public DestinationBuilder embedFonts(Boolean embedFonts) {
120120

121121
@Override
122122
public XciBuilder buildDestination() {
123-
return JavaxXciBuilder.this;
123+
return XciBuilderImpl.this;
124124
}
125125
}
126126
}

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/impl/forms/FormsServiceImpl.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
import com._4point.aem.fluentforms.api.AbsoluteOrRelativeUrl;
1313
import com._4point.aem.fluentforms.api.Document;
1414
import com._4point.aem.fluentforms.api.PathOrUrl;
15+
import com._4point.aem.fluentforms.api.Xci;
1516
import com._4point.aem.fluentforms.api.forms.FormsService;
1617
import com._4point.aem.fluentforms.api.forms.PDFFormRenderOptions;
1718
import com._4point.aem.fluentforms.api.forms.ValidationOptions;
1819
import com._4point.aem.fluentforms.api.forms.ValidationResult;
1920
import com._4point.aem.fluentforms.impl.TemplateValues;
2021
import com._4point.aem.fluentforms.impl.UsageContext;
22+
import com._4point.aem.fluentforms.impl.XciImpl;
2123
import com.adobe.fd.forms.api.AcrobatVersion;
2224
import com.adobe.fd.forms.api.CacheStrategy;
2325
import com.adobe.fd.forms.api.DataFormat;
@@ -239,6 +241,27 @@ public Document executeOn(URL template, Document data) throws FormsServiceExcept
239241
public Document executeOn(Document template, Document data) throws FormsServiceException {
240242
return renderPDFForm(template, data, options);
241243
}
244+
245+
@Override
246+
public XciArgumentBuilder xci() {
247+
return new XciArgumentBuilderImpl();
248+
}
249+
250+
private class XciArgumentBuilderImpl implements XciArgumentBuilder {
251+
private final Xci.XciBuilder xciBuilder = new XciImpl.XciBuilderImpl();
252+
253+
@Override
254+
public XciArgumentBuilder embedFonts(boolean embedFonts) {
255+
xciBuilder.pdf().embedFonts(embedFonts);
256+
return this;
257+
}
258+
259+
@Override
260+
public RenderPDFFormArgumentBuilder done() {
261+
RenderPDFFormArgumentBuilderImpl.this.setXci(xciBuilder.build());
262+
return RenderPDFFormArgumentBuilderImpl.this;
263+
}
264+
}
242265
}
243266

244267
protected TraditionalFormsService getAdobeFormsService() {

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/impl/output/AdobeOutputServiceAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static com._4point.aem.fluentforms.impl.BuilderUtils.setIfNotNull;
44

5-
import java.io.IOException;
65
import java.util.Map;
76
import java.util.Objects;
87
import java.util.Optional;

0 commit comments

Comments
 (0)