DocumentVsDataBuffer.java
4.97 KB
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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.service.DataBuffer
* com.adobe.service.DataManager
* com.adobe.service.FileDataBuffer
* com.adobe.service.FileDataBufferHelper
* com.adobe.service.InlinedDataBuffer
* com.adobe.service.InvalidSourceException
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemfd.docmanager;
import com.adobe.aemfd.docmanager.Document;
import com.adobe.aemfd.docmanager.internal.passivation.DataBufferPassivationHandler;
import com.adobe.aemfd.docmanager.io.IOUtils;
import com.adobe.aemfd.docmanager.passivation.DocumentPassivationHandler;
import com.adobe.aemfd.docmanager.source.DocumentSourceHandler;
import com.adobe.aemfd.docmanager.source.FileBasedDocumentSourceHandler;
import com.adobe.service.DataBuffer;
import com.adobe.service.DataManager;
import com.adobe.service.FileDataBuffer;
import com.adobe.service.FileDataBufferHelper;
import com.adobe.service.InlinedDataBuffer;
import com.adobe.service.InvalidSourceException;
import java.io.File;
import java.io.IOException;
import org.omg.CORBA.Object;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class DocumentVsDataBuffer {
private static final Logger logger = LoggerFactory.getLogger(DocumentVsDataBuffer.class);
private static boolean isNotEmpty(String str) {
return str != null && str.trim().length() != 0;
}
public static Document toDocument(DataBuffer db) {
Document res;
if (db._is_a(FileDataBufferHelper.id())) {
FileDataBuffer fdb = FileDataBufferHelper.narrow((Object)db);
File f = new File(fdb.getFilePath());
res = new Document(f);
} else {
res = new Document(new DataBufferPassivationHandler(db));
}
String type = db.getContentType();
if (DocumentVsDataBuffer.isNotEmpty(type)) {
res.setContentType(type);
}
return res;
}
public static Document toDocument(InlinedDataBuffer idb) {
if (idb.isInlined) {
Document res = new Document(idb.inlinedData);
if (DocumentVsDataBuffer.isNotEmpty(idb.inlinedContentType)) {
res.setContentType(idb.inlinedContentType);
}
return res;
}
return DocumentVsDataBuffer.toDocument(idb.remoteDataBuffer);
}
private static DataBuffer toDataBuffer(Document doc, boolean passivate) throws IOException {
DocumentSourceHandler dsh;
FileDataBuffer res;
File f;
if (passivate) {
doc.passivate();
}
if ((dsh = doc.getSourceHandler()) == null) {
throw new IllegalStateException("Document source handler is null even after passivation!");
}
if (dsh instanceof FileBasedDocumentSourceHandler) {
f = ((FileBasedDocumentSourceHandler)dsh).getSourceFile();
} else {
f = IOUtils.getTempFileManager().getTransactionBoundTempFile();
doc.copyToFile(f);
}
DataManager dm = IOUtils.getTempFileManager().getDataManager();
try {
res = dm.createFileDataBuffer(f.getPath());
}
catch (InvalidSourceException e) {
throw new IOException("Error creating FileDataBuffer from file " + f.getPath(), (Throwable)e);
}
try {
String type = doc.getContentType();
if (DocumentVsDataBuffer.isNotEmpty(type)) {
res.setContentType(type);
}
}
catch (UnsupportedOperationException e) {
logger.warn("UnsupportedOperationException encountered on calling getContentType() on document of type " + doc.getClass().getName() + ". This warning can be ignored for SharedPdfDocument instances", (Throwable)e);
}
return res;
}
public static DataBuffer toDataBuffer(Document doc) throws IOException {
return DocumentVsDataBuffer.toDataBuffer(doc, true);
}
public static InlinedDataBuffer toInlinedDataBuffer(Document doc) throws IOException {
InlinedDataBuffer res = new InlinedDataBuffer();
res.inlinedContentType = "";
res.inlinedData = new byte[0];
byte[] inlined = doc.getInlineData();
if (inlined != null) {
res.isInlined = true;
try {
String type = doc.getContentType();
if (DocumentVsDataBuffer.isNotEmpty(type)) {
res.inlinedContentType = type;
}
}
catch (UnsupportedOperationException e) {
logger.warn("UnsupportedOperationException encountered on calling getContentType() on document of type " + doc.getClass().getName() + ". This warning can be ignored for SharedPdfDocument instances", (Throwable)e);
}
res.inlinedData = inlined;
} else {
res.isInlined = false;
res.remoteDataBuffer = DocumentVsDataBuffer.toDataBuffer(doc, false);
}
return res;
}
}