Skip to content

Commit 5a84e35

Browse files
committed
✨ Created OutputService.generatePrintedOutput(PrintConfig pc) method
Deprecated the old method. Closes #53
1 parent 60edd90 commit 5a84e35

6 files changed

Lines changed: 352 additions & 21 deletions

File tree

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

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ public interface OutputService {
4242

4343
Document generatePrintedOutput(PathOrUrl urlOrFileName, Document data, PrintedOutputOptions printedOutputOptions) throws OutputServiceException, FileNotFoundException;
4444

45+
/**
46+
* @deprecated Use {@link #generatePrintedOutput(PrintConfig)} instead.
47+
*
48+
* @return
49+
*/
50+
@Deprecated
4551
GeneratePrintedOutputArgumentBuilder generatePrintedOutput();
4652

53+
GeneratePrintedOutputArgumentBuilder2 generatePrintedOutput(PrintConfig printConfig);
54+
4755
// TODO: Generate overloaded methods
4856
BatchResult generatePrintedOutputBatch(Map<String, PathOrUrl> templates, Map<String, Document> data, PrintedOutputOptions printedOutputOptions, BatchOptions batchOptions) throws OutputServiceException;
4957

@@ -365,6 +373,167 @@ public interface XciArgumentBuilder {
365373
}
366374
}
367375

376+
public static interface GeneratePrintedOutputArgumentBuilder2 extends PrintedOutputOptionsSetter2, Transformable<GeneratePrintedOutputArgumentBuilder> {
377+
378+
@Override
379+
GeneratePrintedOutputArgumentBuilder2 setContentRoot(PathOrUrl pathOrUrl);
380+
381+
@Override
382+
default GeneratePrintedOutputArgumentBuilder2 setContentRoot(Path path) {
383+
PrintedOutputOptionsSetter2.super.setContentRoot(path);
384+
return this;
385+
}
386+
387+
@Override
388+
default GeneratePrintedOutputArgumentBuilder2 setContentRoot(URL url) {
389+
PrintedOutputOptionsSetter2.super.setContentRoot(url);
390+
return this;
391+
}
392+
393+
@Override
394+
GeneratePrintedOutputArgumentBuilder2 setCopies(int copies);
395+
396+
@Override
397+
GeneratePrintedOutputArgumentBuilder2 setDebugDir(Path debugDir);
398+
399+
@Override
400+
GeneratePrintedOutputArgumentBuilder2 setLocale(Locale locale);
401+
402+
@Override
403+
GeneratePrintedOutputArgumentBuilder2 setPaginationOverride(PaginationOverride paginationOverride);
404+
405+
@Override
406+
GeneratePrintedOutputArgumentBuilder2 setXci(Document xci);
407+
408+
@Override
409+
default GeneratePrintedOutputArgumentBuilder2 setXci(Xci xci) {
410+
PrintedOutputOptionsSetter2.super.setXci(xci);
411+
return this;
412+
}
413+
414+
public XciArgumentBuilder xci();
415+
416+
/**
417+
* Merges the provided template with the provided data and returns the generated
418+
* output.
419+
*
420+
* @param template The template to merge data into.
421+
* @param data The data to merge with the template.
422+
* @return The generated output document.
423+
* @throws OutputServiceException If an error occurs during processing.
424+
* @throws FileNotFoundException If the template file is not found.
425+
*/
426+
public Document executeOn(PathOrUrl template, Document data) throws OutputServiceException, FileNotFoundException;
427+
428+
/**
429+
* Merges the provided template with the provided data and returns the generated
430+
* output.
431+
*
432+
* @param template The template to merge data into.
433+
* @param data The data to merge with the template.
434+
* @return The generated output document.
435+
* @throws OutputServiceException If an error occurs during processing.
436+
* @throws FileNotFoundException If the template file is not found.
437+
*/
438+
public Document executeOn(Path template, Document data) throws OutputServiceException, FileNotFoundException;
439+
440+
/**
441+
* Merges the provided template with the provided data and returns the generated
442+
* output.
443+
*
444+
* @param template The template to merge data into.
445+
* @param data The data to merge with the template.
446+
* @return The generated output document.
447+
* @throws OutputServiceException If an error occurs during processing.
448+
*/
449+
public Document executeOn(URL template, Document data) throws OutputServiceException;
450+
451+
/**
452+
* Merges the provided template with the provided data and returns the generated
453+
* output.
454+
*
455+
* @param template The template to merge data into.
456+
* @param data The data to merge with the template.
457+
* @return The generated output document.
458+
* @throws FileNotFoundException If the template file is not found.
459+
*/
460+
public Document executeOn(Document template, Document data) throws OutputServiceException;
461+
462+
default public Document executeOn(PathOrUrl template, byte[] data) throws OutputServiceException, FileNotFoundException {
463+
return executeOn(template, SimpleDocumentFactoryImpl.getFactory().create(data));
464+
};
465+
466+
default public Document executeOn(Path template, byte[] data) throws OutputServiceException, FileNotFoundException {
467+
return executeOn(template, SimpleDocumentFactoryImpl.getFactory().create(data));
468+
};
469+
470+
default public Document executeOn(URL template, byte[] data) throws OutputServiceException {
471+
return executeOn(template, SimpleDocumentFactoryImpl.getFactory().create(data));
472+
};
473+
474+
default public Document executeOn(Document template, byte[] data) throws OutputServiceException {
475+
return executeOn(template, SimpleDocumentFactoryImpl.getFactory().create(data));
476+
};
477+
478+
default public Document executeOn(byte[] template, byte[] data) throws OutputServiceException {
479+
DocumentFactory factory = SimpleDocumentFactoryImpl.getFactory();
480+
return executeOn(factory.create(template), factory.create(data));
481+
};
482+
483+
default public Document executeOn(InputStream template, byte[] data) throws OutputServiceException {
484+
DocumentFactory factory = SimpleDocumentFactoryImpl.getFactory();
485+
return executeOn(factory.create(template), factory.create(data));
486+
};
487+
488+
default public Document executeOn(PathOrUrl template, InputStream data) throws OutputServiceException, FileNotFoundException {
489+
return executeOn(template, SimpleDocumentFactoryImpl.getFactory().create(data));
490+
};
491+
492+
default public Document executeOn(Path template, InputStream data) throws OutputServiceException, FileNotFoundException {
493+
return executeOn(template, SimpleDocumentFactoryImpl.getFactory().create(data));
494+
};
495+
496+
default public Document executeOn(URL template, InputStream data) throws OutputServiceException {
497+
return executeOn(template, SimpleDocumentFactoryImpl.getFactory().create(data));
498+
};
499+
500+
default public Document executeOn(Document template, InputStream data) throws OutputServiceException {
501+
return executeOn(template, SimpleDocumentFactoryImpl.getFactory().create(data));
502+
};
503+
504+
default public Document executeOn(byte[] template, InputStream data) throws OutputServiceException {
505+
DocumentFactory factory = SimpleDocumentFactoryImpl.getFactory();
506+
return executeOn(factory.create(template), factory.create(data));
507+
};
508+
509+
default public Document executeOn(InputStream template, InputStream data) throws OutputServiceException {
510+
DocumentFactory factory = SimpleDocumentFactoryImpl.getFactory();
511+
return executeOn(factory.create(template), factory.create(data));
512+
};
513+
514+
default public Document executeOn(PathOrUrl template) throws OutputServiceException, FileNotFoundException {
515+
return executeOn(template, (Document)null);
516+
};
517+
518+
default public Document executeOn(Path template) throws OutputServiceException, FileNotFoundException {
519+
return executeOn(template, (Document)null);
520+
};
521+
522+
default public Document executeOn(URL template) throws OutputServiceException {
523+
return executeOn(template, (Document)null);
524+
};
525+
526+
default public Document executeOn(Document template) throws OutputServiceException {
527+
return executeOn(template, (Document)null);
528+
};
529+
530+
public interface XciArgumentBuilder {
531+
XciArgumentBuilder embedPclFonts(boolean embedFonts);
532+
XciArgumentBuilder embedPsFonts(boolean embedFonts);
533+
GeneratePrintedOutputArgumentBuilder2 done();
534+
}
535+
}
536+
368537
public static interface GeneratePdfOutputBatchArgumentBuilder extends PDFOutputOptionsSetter, BatchArgumentBuilder, Transformable<GeneratePdfOutputArgumentBuilder> {
369538

370539
@Override

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,39 @@
99
import com._4point.aem.fluentforms.api.Xci;
1010
import com.adobe.fd.output.api.PaginationOverride;
1111

12-
public interface PrintedOutputOptionsSetter {
12+
public interface PrintedOutputOptionsSetter extends PrintedOutputOptionsSetter2 {
1313

14+
@Override
1415
PrintedOutputOptionsSetter setContentRoot(PathOrUrl pathOrUrl);
1516

17+
@Override
1618
default PrintedOutputOptionsSetter setContentRoot(Path path) {
1719
return setContentRoot(PathOrUrl.from(path));
1820
}
1921

22+
@Override
2023
default PrintedOutputOptionsSetter setContentRoot(URL url) {
2124
return setContentRoot(PathOrUrl.from(url));
2225
}
2326

27+
@Override
2428
PrintedOutputOptionsSetter setCopies(int copies);
2529

30+
@Override
2631
PrintedOutputOptionsSetter setDebugDir(Path debugDir);
2732

33+
@Override
2834
PrintedOutputOptionsSetter setLocale(Locale locale);
2935

36+
@Override
3037
PrintedOutputOptionsSetter setPaginationOverride(PaginationOverride paginationOverride);
3138

3239
PrintedOutputOptionsSetter setPrintConfig(PrintConfig printConfig);
3340

41+
@Override
3442
PrintedOutputOptionsSetter setXci(Document xci);
3543

44+
@Override
3645
default PrintedOutputOptionsSetter setXci(Xci xci) {
3746
return setXci(xci.toDocument());
3847
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com._4point.aem.fluentforms.api.output;
2+
3+
import java.net.URL;
4+
import java.nio.file.Path;
5+
import java.util.Locale;
6+
7+
import com._4point.aem.fluentforms.api.Document;
8+
import com._4point.aem.fluentforms.api.PathOrUrl;
9+
import com._4point.aem.fluentforms.api.Xci;
10+
import com.adobe.fd.output.api.PaginationOverride;
11+
12+
public interface PrintedOutputOptionsSetter2 {
13+
14+
PrintedOutputOptionsSetter2 setContentRoot(PathOrUrl pathOrUrl);
15+
16+
default PrintedOutputOptionsSetter2 setContentRoot(Path path) {
17+
return setContentRoot(PathOrUrl.from(path));
18+
}
19+
20+
default PrintedOutputOptionsSetter2 setContentRoot(URL url) {
21+
return setContentRoot(PathOrUrl.from(url));
22+
}
23+
24+
PrintedOutputOptionsSetter2 setCopies(int copies);
25+
26+
PrintedOutputOptionsSetter2 setDebugDir(Path debugDir);
27+
28+
PrintedOutputOptionsSetter2 setLocale(Locale locale);
29+
30+
PrintedOutputOptionsSetter2 setPaginationOverride(PaginationOverride paginationOverride);
31+
32+
PrintedOutputOptionsSetter2 setXci(Document xci);
33+
34+
default PrintedOutputOptionsSetter2 setXci(Xci xci) {
35+
return setXci(xci.toDocument());
36+
}
37+
}

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public GeneratePrintedOutputArgumentBuilder generatePrintedOutput() {
140140
return new GeneratePrintedOutputArgumentBuilderImpl();
141141
}
142142

143+
@Override
144+
public GeneratePrintedOutputArgumentBuilder2 generatePrintedOutput(PrintConfig printConfig) {
145+
return new GeneratePrintedOutputArgumentBuilderImpl2(printConfig);
146+
}
147+
143148
@Override
144149
public BatchResult generatePrintedOutputBatch(Map<String, PathOrUrl> templates, Map<String, Document> data, PrintedOutputOptions printedOutputOptions,
145150
BatchOptions batchOptions) throws OutputServiceException {
@@ -354,6 +359,101 @@ public GeneratePrintedOutputArgumentBuilder done() {
354359

355360
}
356361

362+
private class GeneratePrintedOutputArgumentBuilderImpl2 implements GeneratePrintedOutputArgumentBuilder2 {
363+
364+
PrintedOutputOptions printedOutputOptions = new PrintedOutputOptionsImpl();
365+
366+
private GeneratePrintedOutputArgumentBuilderImpl2(PrintConfig printConfig) {
367+
this.printedOutputOptions.setPrintConfig(Objects.requireNonNull(printConfig, "printConfig cannot be null."));
368+
}
369+
370+
@Override
371+
public GeneratePrintedOutputArgumentBuilder2 setContentRoot(PathOrUrl pathOrUrl) {
372+
this.printedOutputOptions.setContentRoot(pathOrUrl);
373+
return this;
374+
}
375+
376+
@Override
377+
public GeneratePrintedOutputArgumentBuilder2 setCopies(int copies) {
378+
this.printedOutputOptions.setCopies(copies);
379+
return this;
380+
}
381+
382+
@Override
383+
public GeneratePrintedOutputArgumentBuilder2 setDebugDir(Path debugDir) {
384+
this.printedOutputOptions.setDebugDir(debugDir);
385+
return this;
386+
}
387+
388+
@Override
389+
public GeneratePrintedOutputArgumentBuilder2 setLocale(Locale locale) {
390+
this.printedOutputOptions.setLocale(locale);
391+
return this;
392+
}
393+
394+
@Override
395+
public GeneratePrintedOutputArgumentBuilder2 setPaginationOverride(PaginationOverride paginationOverride) {
396+
this.printedOutputOptions.setPaginationOverride(paginationOverride);
397+
return this;
398+
}
399+
400+
@Override
401+
public GeneratePrintedOutputArgumentBuilder2 setXci(Document xci) {
402+
this.printedOutputOptions.setXci(xci);
403+
return this;
404+
}
405+
406+
@Override
407+
public Document executeOn(PathOrUrl template, Document data)
408+
throws OutputServiceException, FileNotFoundException {
409+
return generatePrintedOutput(template, data, this.printedOutputOptions);
410+
}
411+
412+
@Override
413+
public Document executeOn(Path template, Document data) throws OutputServiceException, FileNotFoundException {
414+
return generatePrintedOutput(template, data, this.printedOutputOptions);
415+
}
416+
417+
@Override
418+
public Document executeOn(URL template, Document data) throws OutputServiceException {
419+
return generatePrintedOutput(template, data, this.printedOutputOptions);
420+
}
421+
422+
@Override
423+
public Document executeOn(Document template, Document data) throws OutputServiceException {
424+
return generatePrintedOutput(template, data, this.printedOutputOptions);
425+
}
426+
427+
@Override
428+
public XciArgumentBuilder xci() {
429+
return new XciArgumentBuilderImpl();
430+
}
431+
432+
private class XciArgumentBuilderImpl implements XciArgumentBuilder {
433+
private final Xci.XciBuilder xciBuilder = new XciImpl.XciBuilderImpl();
434+
435+
@Override
436+
public XciArgumentBuilder embedPclFonts(boolean embedFonts) {
437+
xciBuilder.pcl().embedFonts(embedFonts);
438+
return this;
439+
}
440+
441+
@Override
442+
public XciArgumentBuilder embedPsFonts(boolean embedFonts) {
443+
xciBuilder.ps().embedFonts(embedFonts);
444+
return this;
445+
}
446+
447+
@Override
448+
public GeneratePrintedOutputArgumentBuilder2 done() {
449+
GeneratePrintedOutputArgumentBuilderImpl2.this.setXci(xciBuilder.build());
450+
return GeneratePrintedOutputArgumentBuilderImpl2.this;
451+
}
452+
453+
}
454+
455+
}
456+
357457
/**
358458
* This class could (and should) be replaced by private methods in the OutputService.BatchArgumentBuilder interface
359459
* however that would require Java 11 and for now we're stuck in Java 8 land. Hopefully someone will move this class'

0 commit comments

Comments
 (0)