Skip to content

Commit f57f1c8

Browse files
committed
More swapping of strings
1 parent f11bcae commit f57f1c8

2 files changed

Lines changed: 69 additions & 36 deletions

File tree

src/main/java/org/buddycloud/channelserver/channel/validate/AtomEntry.java

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.buddycloud.channelserver.channel.ChannelManager;
1212
import org.buddycloud.channelserver.channel.Conf;
1313
import org.buddycloud.channelserver.db.exception.NodeStoreException;
14+
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.set.XMLConstants;
1415
import org.buddycloud.channelserver.pubsub.model.GlobalItemID;
1516
import org.buddycloud.channelserver.pubsub.model.NodeItem;
1617
import org.buddycloud.channelserver.pubsub.model.impl.GlobalItemIDImpl;
@@ -73,7 +74,9 @@ public class AtomEntry implements PayloadValidator {
7374
private Element geoloc;
7475
private String globalItemID;
7576

76-
public AtomEntry() {}
77+
public AtomEntry() {
78+
79+
}
7780

7881
public AtomEntry(Element item) {
7982
setPayload(item);
@@ -103,67 +106,67 @@ public boolean isValid() throws NodeStoreException {
103106
return false;
104107
}
105108

106-
Element id = this.entry.element("id");
107-
if ((id == null) || (true == id.getText().isEmpty())) {
109+
Element id = this.entry.element(XMLConstants.ID_ELEM);
110+
if ((id == null) || (id.getText().isEmpty())) {
108111
if (null != id) {
109112
id.detach();
110113
}
111114
LOGGER.debug("ID of the entry was missing. We add a default one to it: 1");
112115
this.entry.addElement("id").setText("1");
113116
}
114117

115-
Element title = this.entry.element("title");
118+
Element title = this.entry.element(XMLConstants.TITLE_ELEM);
116119
if (null == title) {
117120
LOGGER.debug("Title of the entry was missing. We add a default one to it: 'Post'.");
118-
title = this.entry.addElement("title");
121+
title = this.entry.addElement(XMLConstants.TITLE_ELEM);
119122
title.setText("Post");
120123
}
121-
this.params.put("title", title.getText());
124+
this.params.put(XMLConstants.TITLE_ELEM, title.getText());
122125

123126
Element content = this.entry.element("content");
124127
if (null == content) {
125128
this.errorMessage = MISSING_CONTENT_ELEMENT;
126129
return false;
127130
}
128-
String contentType = content.attributeValue("type");
131+
String contentType = content.attributeValue(XMLConstants.TYPE_ATTR);
129132
if (null == contentType) {
130133
contentType = CONTENT_TEXT;
131134
}
132-
if ((false == contentType.equals(CONTENT_TEXT)) && (false == contentType.equals(CONTENT_XHTML))) {
135+
if ((!contentType.equals(CONTENT_TEXT)) && (!contentType.equals(CONTENT_XHTML))) {
133136
this.errorMessage = UNSUPPORTED_CONTENT_TYPE;
134137
return false;
135138
}
136139
this.params.put("content", content.getText());
137140
this.params.put("content-type", contentType);
138141

139-
Element updated = this.entry.element("updated");
142+
Element updated = this.entry.element(XMLConstants.UPDATED_ELEM);
140143
if (null == updated) {
141144

142145
String updateTime = Conf.formatDate(new Date());
143146
LOGGER.debug("Update of the entry was missing. We add a default one to it: '" + updateTime + "'.");
144-
this.entry.addElement("updated").setText(updateTime);
147+
this.entry.addElement(XMLConstants.UPDATED_ELEM).setText(updateTime);
145148
}
146149

147-
this.geoloc = this.entry.element("geoloc");
150+
this.geoloc = this.entry.element(XMLConstants.GEOLOC_ELEM);
148151

149-
if (false == validateInReplyToElement(this.entry.element("in-reply-to"))) {
152+
if (!validateInReplyToElement(this.entry.element(XMLConstants.IN_REPLY_TO_ELEM))) {
150153
return false;
151154
}
152155

153-
if (false == validateTargetElement(this.entry.element("target"))) {
156+
if (!validateTargetElement(this.entry.element(XMLConstants.TARGET_ELEM))) {
154157
return false;
155158
}
156159

157-
if (false == validateRatingElement(this.entry.element("rating"))) {
160+
if (!validateRatingElement(this.entry.element(XMLConstants.RATING_ELEM))) {
158161
return false;
159162
}
160163

161-
Element meta = this.entry.element("meta");
164+
Element meta = this.entry.element(XMLConstants.META_ELEM);
162165
if (null != meta) {
163166
this.meta = meta;
164167
}
165168

166-
Element media = this.entry.element("media");
169+
Element media = this.entry.element(XMLConstants.MEDIA_ELEM);
167170
if (null != media) {
168171
this.media = media;
169172
}
@@ -174,36 +177,36 @@ public boolean isValid() throws NodeStoreException {
174177
@Override
175178
public Element getPayload() {
176179

177-
Element entry = new DOMElement("entry", new org.dom4j.Namespace("", Atom.NS));
180+
Element entry = new DOMElement(XMLConstants.ENTRY_ELEM, new org.dom4j.Namespace("", Atom.NS));
178181
entry.add(new org.dom4j.Namespace("activity", ActivityStreams.NS));
179182

180183
String postType = POST_TYPE_NOTE;
181184
String activityVerb = ACTIVITY_VERB_POST;
182185

183-
entry.addElement("id").setText(getGlobalItemId());
186+
entry.addElement(XMLConstants.ID_ELEM).setText(getGlobalItemId());
184187

185188
String title = this.params.get("title");
186189
String itemContent = this.params.get("content");
187190
String publishedDate = Conf.formatDate(new Date());
188191

189-
entry.addElement("published").setText(publishedDate);
192+
entry.addElement(XMLConstants.PUBLISHED_ELEM).setText(publishedDate);
190193

191-
entry.addElement("updated").setText(publishedDate);
194+
entry.addElement(XMLConstants.UPDATED_ELEM).setText(publishedDate);
192195

193-
Element author = entry.addElement("author");
196+
Element author = entry.addElement(XMLConstants.AUTHOR_ELEM);
194197

195-
author.addElement("name").setText(jid.toBareJID());
198+
author.addElement(XMLConstants.NAME_ELEM).setText(jid.toBareJID());
196199

197-
author.addElement("uri").setText(AUTHOR_URI_PREFIX + jid.toBareJID());
200+
author.addElement(XMLConstants.URI_ELEM).setText(AUTHOR_URI_PREFIX + jid.toBareJID());
198201

199-
author.addElement("activity:object-type").setText(AUTHOR_TYPE);
202+
author.addElement(XMLConstants.ACTIVITY_OBJECT_TYPE_ELEM).setText(AUTHOR_TYPE);
200203

201204
if (this.geoloc != null) {
202205
entry.add(this.geoloc.createCopy());
203206
}
204207

205208
if (this.inReplyTo != null) {
206-
Element reply = entry.addElement("in-reply-to");
209+
Element reply = entry.addElement(XMLConstants.IN_REPLY_TO_ELEM);
207210
reply.addNamespace("", Atom.NS_THREAD);
208211
reply.addAttribute("ref", inReplyTo);
209212
postType = POST_TYPE_COMMENT;
@@ -276,7 +279,7 @@ private boolean validateInReplyToElement(Element reply) throws NodeStoreExceptio
276279
}
277280

278281
inReplyTo = reply.attributeValue("ref");
279-
if (true == GlobalItemIDImpl.isGlobalId(inReplyTo)) {
282+
if (GlobalItemIDImpl.isGlobalId(inReplyTo)) {
280283
inReplyTo = GlobalItemIDImpl.toLocalId(inReplyTo);
281284
}
282285

@@ -297,7 +300,7 @@ private boolean validateTargetElement(Element target) throws NodeStoreException
297300
if (null == target) {
298301
return true;
299302
}
300-
targetId = target.elementText("id");
303+
targetId = target.elementText(XMLConstants.ID_ELEM);
301304
if ((null == targetId) || (0 == targetId.length())) {
302305
this.errorMessage = MISSING_TARGET_ID;
303306
return false;
@@ -306,10 +309,10 @@ private boolean validateTargetElement(Element target) throws NodeStoreException
306309
this.errorMessage = IN_REPLY_TO_MISSING;
307310
return false;
308311
}
309-
if (true == GlobalItemIDImpl.isGlobalId(targetId)) {
312+
if (GlobalItemIDImpl.isGlobalId(targetId)) {
310313
targetId = GlobalItemIDImpl.toLocalId(targetId);
311314
}
312-
if (true == targetId.equals(replyingToItem.getId())) {
315+
if (targetId.equals(replyingToItem.getId())) {
313316
targetItem = replyingToItem;
314317
} else {
315318
targetItem = channelManager.getNodeItem(node, targetId);
@@ -318,10 +321,10 @@ private boolean validateTargetElement(Element target) throws NodeStoreException
318321
this.errorMessage = TARGETED_ITEM_NOT_FOUND;
319322
return false;
320323
}
321-
if (true == targetItem.getId().equals(targetId)) {
324+
if (targetItem.getId().equals(targetId)) {
322325
return true;
323326
}
324-
if ((null == targetItem.getInReplyTo()) || (false == targetItem.getInReplyTo().equals(targetId))) {
327+
if ((null == targetItem.getInReplyTo()) || (!targetItem.getInReplyTo().equals(targetId))) {
325328
this.errorMessage = TARGET_MUST_BE_IN_SAME_THREAD;
326329
return false;
327330
}
@@ -360,7 +363,7 @@ private boolean validateRatingElement(Element rating) throws NodeStoreException
360363
}
361364

362365
GlobalItemID globalTargetId = new GlobalItemIDImpl(new JID(channelServerDomain), node, targetId);
363-
if (true == channelManager.userHasRatedPost(node, jid, globalTargetId)) {
366+
if (channelManager.userHasRatedPost(node, jid, globalTargetId)) {
364367
this.errorMessage = ITEM_ALREADY_RATED;
365368
return false;
366369
}
@@ -384,12 +387,12 @@ public String getGlobalItemId() {
384387

385388
@Override
386389
public String getInReplyTo() {
387-
String inReplyTo = null;
388-
Element inReplyToElement = this.entry.element("in-reply-to");
390+
String localReply = null;
391+
Element inReplyToElement = this.entry.element(XMLConstants.IN_REPLY_TO_ELEM);
389392
if (null != inReplyToElement) {
390-
inReplyTo = GlobalItemIDImpl.toLocalId(inReplyToElement.attributeValue("ref"));
393+
localReply = GlobalItemIDImpl.toLocalId(inReplyToElement.attributeValue("ref"));
391394
}
392-
return inReplyTo;
395+
return localReply;
393396
}
394397

395398
@Override

src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/XMLConstants.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,36 @@ public class XMLConstants {
9696

9797
public static final String ITEM_REQUIRED_ELEM = "item-required";
9898

99+
public static final String ID_ELEM = "id";
100+
101+
public static final String TITLE_ELEM = "title";
102+
103+
public static final String UPDATED_ELEM = "updated";
104+
105+
public static final String GEOLOC_ELEM = "geoloc";
106+
107+
public static final String IN_REPLY_TO_ELEM = "in-reply-to";
108+
109+
public static final String TARGET_ELEM = "target";
110+
111+
public static final String RATING_ELEM = "rating";
112+
113+
public static final String META_ELEM = "meta";
114+
115+
public static final String MEDIA_ELEM = "media";
116+
117+
public static final String ENTRY_ELEM = "entry";
118+
119+
public static final String PUBLISHED_ELEM = "published";
120+
121+
public static final String NAME_ELEM = "name";
122+
123+
public static final String URI_ELEM = "uri";
124+
125+
public static final String ACTIVITY_OBJECT_TYPE_ELEM = "activity:object-type";
126+
127+
public static final String AUTHOR_ELEM = "author";
128+
99129
// Private (hidden) constructor
100130
private XMLConstants() {
101131

0 commit comments

Comments
 (0)