Skip to content

Commit 6e40e48

Browse files
committed
Merge remote-tracking branch 'origin/master' into
refactor_add_support_for_other_rest_clients
2 parents dfb5449 + 89842aa commit 6e40e48

28 files changed

Lines changed: 1217 additions & 82 deletions

File tree

fluentforms/core/src/main/java/com/_4point/aem/fluentforms/api/DocumentFactory.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,62 @@
77

88
import com._4point.aem.fluentforms.impl.AdobeDocumentFactoryImpl;
99

10+
/**
11+
* Factory class for creating Document objects. In AEM server-side code, this is usually an AdobeDocumentFactoryImpl class
12+
* and in client code this is usually a SimpleDocumentFactoryImpl.
13+
*/
1014
public interface DocumentFactory {
1115

16+
/**
17+
* Creates a Document from a byte-array.
18+
*
19+
* @param data - The byte-array serving as the content-source for the Document.
20+
* @return
21+
*/
1222
public Document create(byte[] data);
1323

24+
/**
25+
* Creates a Document from a file.
26+
*
27+
* @deprecated Use create(Path) instead.
28+
*
29+
* @param file - The file serving as the content-source for the Document.
30+
* @param ownFile - Whether the file is henceforth to be managed by the Document.
31+
* @return
32+
*/
33+
@Deprecated
1434
public Document create(File file, boolean ownFile);
1535

36+
/**
37+
* Creates a Document from a file. Equivalent to create(file, false). See create(java.io.File, boolean) for more details.
38+
*
39+
* @deprecated Use create(Path) instead.
40+
*
41+
* @param file - The file serving as the content-source for the Document.
42+
* @return
43+
*/
44+
@Deprecated
1645
public Document create(File file);
1746

47+
/**
48+
* Creates a Document from a file path. Equivalent to create(file, false). See create(java.io.File, boolean) for more details.
49+
*
50+
* @param file - The file path serving as the content-source for the Document.
51+
* @return
52+
*/
1853
public Document create(Path file);
1954

55+
/**
56+
* Creates a Document from an input-stream.
57+
*
58+
* Note that the Document at no point in its life-cycle ever closes the input-stream itself,
59+
* in keeping with the practice of not managing resources passed in externally unless explicitly instructed to do so.
60+
* Hence, it is the responsibility of the application creating the Document to also close the input-stream properly
61+
* when the time comes.
62+
*
63+
* @param is - The input-stream serving as the content-source for the Document.
64+
* @return
65+
*/
2066
public Document create(InputStream is);
2167

2268
// Removed because this won't work with the client version of this library. This may be re-instated later
@@ -26,12 +72,38 @@ public interface DocumentFactory {
2672
//
2773
// public Document create(String jcrPath, ResourceResolver resolver);
2874
//
75+
/**
76+
* For internal use only.
77+
*
78+
* @param jcrPath
79+
* @return
80+
*/
2981
public Document create(String jcrPath);
3082

83+
/**
84+
* For internal use only.
85+
*
86+
* @param url
87+
* @return
88+
*/
3189
public Document create(URL url);
3290

91+
/**
92+
* For internal use only.
93+
*
94+
* @param document
95+
* @return
96+
*/
3397
public Document create(com.adobe.aemfd.docmanager.Document document);
3498

99+
/**
100+
* Intended as a convenience method however it returns an AdobeDocumentFactoryImpl which is not useful
101+
* for client side code, so it's best to avoid using this unless you know what you are doing.
102+
*
103+
* It may be deprecated and removed in the future version of FluentForms.
104+
*
105+
* @return
106+
*/
35107
public static DocumentFactory getDefault() {
36108
return AdobeDocumentFactoryImpl.getFactory();
37109
}

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import java.io.ByteArrayInputStream;
44
import java.io.ByteArrayOutputStream;
55
import java.io.File;
6-
import java.io.FileInputStream;
7-
import java.io.FileNotFoundException;
86
import java.io.IOException;
97
import java.io.InputStream;
108
import java.io.OutputStream;
9+
import java.io.UncheckedIOException;
1110
import java.net.URL;
11+
import java.nio.file.Files;
1212
import java.nio.file.Path;
1313
import java.util.Arrays;
1414
import java.util.Map;
@@ -26,12 +26,19 @@ public enum SimpleDocumentFactoryImpl implements DocumentFactory {
2626

2727
private static final Document EMPTY_DOCUMENT = new EmptyDocumentImpl();
2828

29+
/**
30+
* Returns a singleton instance of this SimpleDocumentFactoryImpl.
31+
*
32+
* @return - singleton instance of SimpleDocumentFactoryImpl
33+
*/
2934
public static DocumentFactory getFactory() {
3035
return INSTANCE;
3136
}
3237

3338
/* (non-Javadoc)
3439
* @see com._4point.aem.fluentforms.api.DocumentFactory#create(byte[])
40+
*
41+
* It holds a defensive copy of the array in memory.
3542
*/
3643
@Override
3744
public Document create(byte[] data) {
@@ -42,6 +49,7 @@ public Document create(byte[] data) {
4249
* @see com._4point.aem.fluentforms.api.DocumentFactory#create(java.io.File, boolean)
4350
*/
4451
@Override
52+
@Deprecated
4553
public Document create(File file, boolean ownFile) {
4654
return new SimpleDocumentImpl(file, ownFile);
4755
}
@@ -50,6 +58,7 @@ public Document create(File file, boolean ownFile) {
5058
* @see com._4point.aem.fluentforms.api.DocumentFactory#create(java.io.File)
5159
*/
5260
@Override
61+
@Deprecated
5362
public Document create(File file) {
5463
return new SimpleDocumentImpl(file);
5564
}
@@ -127,20 +136,19 @@ private SimpleDocumentImpl(byte[] data) {
127136

128137
private SimpleDocumentImpl(File file, boolean ownFile) {
129138
// We ignore the ownFile parameter because we don't care. We are going to just read it in anyway.
130-
try {
131-
this.inlineData = readToByteArray(new FileInputStream(file));
132-
} catch (FileNotFoundException e) {
133-
// Convert to runtime exception.
134-
throw new IllegalArgumentException("File not found. (" + file.toString() + ").", e);
135-
}
139+
this(file.toPath());
136140
}
137141

138142
private SimpleDocumentImpl(File file) {
143+
this(file.toPath());
144+
}
145+
146+
private SimpleDocumentImpl(Path path) {
139147
try {
140-
this.inlineData = readToByteArray(new FileInputStream(file));
141-
} catch (FileNotFoundException e) {
148+
this.inlineData = Files.readAllBytes(path);
149+
} catch (IOException e) {
142150
// Convert to runtime exception.
143-
throw new IllegalArgumentException("File not found. (" + file.toString() + ").", e);
151+
throw new UncheckedIOException("Error reading file (" + path.toString() + ").", e);
144152
}
145153
}
146154

fluentforms/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
<pitest.junit5.maven.plugin.version>1.2.1</pitest.junit5.maven.plugin.version>
8686

8787
<!-- Testing dependencies -->
88-
<mockito.version>5.8.0</mockito.version>
88+
<mockito.version>4.11.0</mockito.version> <!-- Last version that supports Java 8 -->
8989
<junit.version>5.10.1</junit.version>
9090
<wcm.mocks.version>5.4.0</wcm.mocks.version>
9191
<slf4j-test.version>1.2.0</slf4j-test.version>

0 commit comments

Comments
 (0)