HrefService.java
5.49 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
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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.xfa.service.href;
import com.adobe.xfa.AppModel;
import com.adobe.xfa.Attribute;
import com.adobe.xfa.Element;
import com.adobe.xfa.HrefHandler;
import com.adobe.xfa.Model;
import com.adobe.xfa.Node;
import com.adobe.xfa.ProtoableNode;
import com.adobe.xfa.XFA;
import com.adobe.xfa.configuration.ConfigurationModel;
import com.adobe.xfa.protocol.ProtocolUtils;
import com.adobe.xfa.service.Service;
import com.adobe.xfa.service.href.HrefStore;
import com.adobe.xfa.template.TemplateModel;
import com.adobe.xfa.ut.ExFull;
import com.adobe.xfa.ut.MsgFormatPos;
import com.adobe.xfa.ut.ResId;
import com.adobe.xfa.ut.StringUtils;
public class HrefService
extends Service
implements HrefHandler {
private final HrefStore mHrefStore;
private Node mContextNode;
private final String msConfigSchemaName;
public static final int CACHE_SIZE = 51200;
public HrefService(Node contextNode, int nHrefCacheSize) {
String sBasePath = HrefService.getBaseUrl(contextNode);
String sUriPath = HrefService.getAlternativeUrl(contextNode);
if (nHrefCacheSize == 0) {
nHrefCacheSize = 51200;
}
this.mHrefStore = new HrefStore(this, sBasePath, sUriPath, nHrefCacheSize);
this.mContextNode = contextNode;
this.msConfigSchemaName = null;
}
public HrefService(String sConfigSchemaName, int nHrefCacheSize) {
if (nHrefCacheSize == 0) {
nHrefCacheSize = 51200;
}
this.mHrefStore = new HrefStore(this, null, null, nHrefCacheSize);
this.mContextNode = null;
this.msConfigSchemaName = sConfigSchemaName;
}
public final Node getContextNode() {
return this.mContextNode;
}
public final String getConfigSchemaName() {
return this.msConfigSchemaName;
}
public final void setContextNode(Node contextNode) {
this.mContextNode = contextNode;
}
public final boolean isTrusted() {
return this.mHrefStore.isTrusted();
}
public final void isTrusted(boolean bTrusted) {
this.mHrefStore.isTrusted(bTrusted);
}
public final int getCacheSize() {
return this.mHrefStore.getCacheSize();
}
final void setCacheSize(int nSize) {
this.mHrefStore.setCacheSize(nSize);
}
public final void clearCache() {
this.mHrefStore.clearCache();
}
public final int getCurrentCacheSize() {
return this.mHrefStore.getCurrentCacheSize();
}
private final HrefStore getHrefStore() {
return this.mHrefStore;
}
@Override
public AppModel loadFragment(ProtoableNode protoableNode) {
Attribute usehref = protoableNode.peekAttribute(XFA.USEHREFTAG);
if (usehref == null) {
throw new IllegalArgumentException();
}
return this.loadFragmentInternal(protoableNode.getAppModel(), usehref.toString(), protoableNode.getName());
}
@Override
public AppModel loadFragment(AppModel appModel, String sUrl) {
return this.loadFragmentInternal(appModel, sUrl, null);
}
private AppModel loadFragmentInternal(AppModel appModel, String sUrl, String sNodeName) {
int nSharp;
ConfigurationModel configModel;
if (StringUtils.isEmpty(sUrl)) {
throw new IllegalArgumentException();
}
Node context = this.getContextNode();
if (context == null && this.getConfigSchemaName() != null && (configModel = ConfigurationModel.getConfigurationModel(appModel, false)) != null && (context = configModel.getCommonNode(this.getConfigSchemaName())) != null) {
String sUriPath;
String sBasePath = HrefService.getBaseUrl(context);
if (!StringUtils.isEmpty(sBasePath)) {
this.setBaseUrl(sBasePath);
}
if (!StringUtils.isEmpty(sUriPath = HrefService.getAlternativeUrl(context))) {
this.setAlternativeUrl(sUriPath);
}
this.setContextNode(context);
}
if ((nSharp = sUrl.indexOf(35)) >= 0) {
sUrl = sUrl.substring(0, nSharp);
}
try {
this.getHrefStore().add(sUrl);
HrefStore.HrefData oHrefData = this.getHrefStore().getHrefData(sUrl);
return oHrefData.getAppModel();
}
catch (ExFull e) {
MsgFormatPos oMsg = null;
if (!StringUtils.isEmpty(sNodeName)) {
oMsg = new MsgFormatPos(ResId.XFAHrefServiceException);
oMsg.format(sNodeName);
ExFull oErr = new ExFull(oMsg);
oErr.insert(e, false);
throw oErr;
}
throw e;
}
}
@Override
public Model getDocument(AppModel appModel) {
return TemplateModel.getTemplateModel(appModel, false);
}
public final String getBaseUrl() {
return this.mHrefStore.getBaseUrl();
}
public final void setBaseUrl(String sBaseUrl) {
this.mHrefStore.setBaseUrl(sBaseUrl);
}
public final String getAlternativeUrl() {
return this.mHrefStore.getAlternativeUrl();
}
public final void setAlternativeUrl(String sAltUrl) {
this.mHrefStore.setAlternativeUrl(sAltUrl);
}
private static final String getBaseUrl(Node contextNode) {
return ProtocolUtils.getTemplateBasePathFromConfig(contextNode);
}
private static final String getAlternativeUrl(Node contextNode) {
return ProtocolUtils.getTemplateUriPathFromConfig(contextNode);
}
}