TranslationBaseObject.java
7.96 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Value
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceWrapper
* org.slf4j.Logger
*/
package com.adobe.cq.wcm.translation.impl;
import com.adobe.cq.wcm.translation.impl.TranslationUtils;
import com.adobe.cq.wcm.translation.impl.scheduler.SyncTranslationState;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceWrapper;
import org.slf4j.Logger;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class TranslationBaseObject
extends ResourceWrapper {
private static int MILLISEC_IN_MINUTE = 60000;
protected javax.jcr.Node node;
Session userSession;
public TranslationBaseObject(javax.jcr.Node node, Resource resource, Session userSession) {
super(resource);
this.userSession = userSession;
this.node = node;
}
public javax.jcr.Node getNode() {
return this.node;
}
protected Logger getLogger() {
return null;
}
protected int getIntAttribute(String strAttributeName) {
return (int)this.getLongAttribute(strAttributeName);
}
protected long getLongAttribute(String strAttributeName) {
try {
Property property;
if (this.node.hasProperty(strAttributeName) && (property = this.node.getProperty(strAttributeName)) != null && property.getType() == 3) {
return property.getLong();
}
}
catch (RepositoryException ex) {
this.getLogger().error("Error while fetching int attribute " + strAttributeName, (Throwable)ex);
}
return 0;
}
protected boolean getBooleanAttribute(String strAttributeName, boolean bDefault) {
try {
Property property;
if (this.node.hasProperty(strAttributeName) && (property = this.node.getProperty(strAttributeName)) != null && property.getType() == 6) {
bDefault = property.getBoolean();
}
}
catch (RepositoryException ex) {
this.getLogger().error("Error while fetching boolean attribute " + strAttributeName, (Throwable)ex);
}
return bDefault;
}
protected Calendar getCalendarAttribute(String strAttributeName) {
return TranslationUtils.getCalendarAttribute(this.getLogger(), (Resource)this, strAttributeName);
}
protected String getStringAttribute(String strAttributeName) {
return TranslationUtils.getStringAttribute(this.getLogger(), this.node, strAttributeName, null);
}
protected ArrayList<String> getStringListAttribute(String strAttributeName) {
ArrayList<String> retVal = new ArrayList<String>();
try {
Value[] values;
Property property;
if (this.node.hasProperty(strAttributeName) && (property = this.node.getProperty(strAttributeName)) != null && property.isMultiple() && (values = property.getValues()) != null) {
for (Value val : values) {
retVal.add(val.getString());
}
}
}
catch (RepositoryException ex) {
this.getLogger().error("Error while fetching string attribute " + strAttributeName, (Throwable)ex);
}
return retVal;
}
protected void setAttribute(String strAttributeName, Calendar attributeValue) {
try {
this.node.setProperty(strAttributeName, attributeValue);
}
catch (RepositoryException ex) {
this.getLogger().error("Error while setting string attribute " + strAttributeName + " with value " + attributeValue.toString(), (Throwable)ex);
}
}
protected void setAttribute(String strAttributeName, ArrayList<String> attributeValueList) {
try {
Property prop = null;
if (this.node.hasProperty(strAttributeName)) {
prop = this.node.getProperty(strAttributeName);
}
if (prop == null) {
prop = this.node.setProperty(strAttributeName, new String[0]);
}
if (attributeValueList == null) {
prop.setValue((String[])null);
} else {
String[] newValArray = TranslationUtils.getStringArray(attributeValueList);
prop.setValue(newValArray);
}
}
catch (RepositoryException ex) {
this.getLogger().error("Error while setting StringList attribute " + strAttributeName + " with value " + attributeValueList.toString(), (Throwable)ex);
}
}
private void setAttribute(String strAttributeName, long longVal) {
try {
this.node.setProperty(strAttributeName, longVal);
}
catch (RepositoryException ex) {
this.getLogger().error("Error while setting long attribute " + strAttributeName + " with value " + longVal, (Throwable)ex);
}
}
protected void setAttribute(String strAttributeName, int iValue) {
try {
this.node.setProperty(strAttributeName, (long)iValue);
}
catch (RepositoryException ex) {
this.getLogger().error("Error while setting int attribute " + strAttributeName + " with value " + iValue, (Throwable)ex);
}
}
protected void setAttribute(String strAttributeName, String strAttributeValue) {
try {
this.node.setProperty(strAttributeName, strAttributeValue);
}
catch (RepositoryException ex) {
this.getLogger().error("Error while setting string attribute " + strAttributeName + " with value " + strAttributeValue, (Throwable)ex);
}
}
protected void setAttribute(String strAttributeName, boolean bValue) {
try {
this.node.setProperty(strAttributeName, bValue);
}
catch (RepositoryException ex) {
this.getLogger().error("Error while setting string attribute " + strAttributeName + " with value " + bValue, (Throwable)ex);
}
}
protected String getXMLNodeProperty(Node node, String attributeName) {
Element element = (Element)node;
if (element != null) {
return element.getAttribute(attributeName);
}
return null;
}
protected void setXMLNodePropertyValue(Node node, String attributeName, String strValue) {
((Element)node).setAttribute(attributeName, strValue);
}
public void save() throws RepositoryException {
if (this.userSession != null) {
this.userSession.save();
}
}
public void setTranslationObjectID(String strID) {
this.setAttribute("translationObjectID", strID);
}
public String getTranslationObjectID() {
return this.getStringAttribute("translationObjectID");
}
protected boolean isSyncTranslationStateInProgress() {
long iStartSince;
boolean bRetVal = false;
if (this.getBooleanAttribute("syncTranslationStateInProgress", false) && (iStartSince = this.getLongAttribute("syncTranslationStartSince")) > 0) {
long currentTime = new Date().getTime();
long waitTime = (long)MILLISEC_IN_MINUTE * SyncTranslationState.getSyncLockTimeout();
if (iStartSince + waitTime > currentTime) {
bRetVal = true;
}
}
return bRetVal;
}
protected void setSyncTranslationStateInProgress(boolean bState, Logger logger) {
this.setAttribute("syncTranslationStateInProgress", bState);
this.setAttribute("syncTranslationStartSince", new Date().getTime());
try {
this.save();
}
catch (RepositoryException e) {
logger.error("Error while saving ", (Throwable)e);
}
}
}