mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-10122 Switch the new Wiki, Links, Calendar and Discussions webscripts to using org.json.simple instead of org.json
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30182 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -45,10 +45,10 @@ import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
@@ -116,11 +116,11 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
|
||||
}
|
||||
|
||||
|
||||
protected String getOrNull(JSONObject json, String key) throws JSONException
|
||||
protected String getOrNull(JSONObject json, String key)
|
||||
{
|
||||
if(json.has(key))
|
||||
if(json.containsKey(key))
|
||||
{
|
||||
return json.getString(key);
|
||||
return (String)json.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -165,16 +165,16 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
|
||||
return paging;
|
||||
}
|
||||
|
||||
protected List<String> getTags(JSONObject json) throws JSONException
|
||||
protected List<String> getTags(JSONObject json)
|
||||
{
|
||||
List<String> tags = null;
|
||||
if(json.has("tags"))
|
||||
if(json.containsKey("tags"))
|
||||
{
|
||||
// Is it "tags":"" or "tags":[...] ?
|
||||
if(json.get("tags") instanceof String)
|
||||
{
|
||||
// This is normally an empty string, skip
|
||||
String tagsS = json.getString("tags");
|
||||
String tagsS = (String)json.get("tags");
|
||||
if("".equals(tagsS))
|
||||
{
|
||||
// No tags were given
|
||||
@@ -190,10 +190,10 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
|
||||
else
|
||||
{
|
||||
tags = new ArrayList<String>();
|
||||
JSONArray jsTags = json.getJSONArray("tags");
|
||||
for(int i=0; i<jsTags.length(); i++)
|
||||
JSONArray jsTags = (JSONArray)json.get("tags");
|
||||
for(int i=0; i<jsTags.size(); i++)
|
||||
{
|
||||
tags.add( jsTags.getString(i) );
|
||||
tags.add( (String)jsTags.get(i) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,13 +213,9 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
|
||||
String page = req.getParameter("page");
|
||||
if(page == null && json != null)
|
||||
{
|
||||
if(json.has("page"))
|
||||
if(json.containsKey("page"))
|
||||
{
|
||||
try
|
||||
{
|
||||
page = json.getString("page");
|
||||
}
|
||||
catch(JSONException e) {}
|
||||
page = (String)json.get("page");
|
||||
}
|
||||
}
|
||||
if(page == null)
|
||||
@@ -481,17 +477,18 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
|
||||
}
|
||||
if(MimetypeMap.MIMETYPE_JSON.equals(contentType))
|
||||
{
|
||||
JSONParser parser = new JSONParser();
|
||||
try
|
||||
{
|
||||
json = new JSONObject(new JSONTokener(req.getContent().getContent()));
|
||||
json = (JSONObject)parser.parse(req.getContent().getContent());
|
||||
}
|
||||
catch(IOException io)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + io.getMessage());
|
||||
}
|
||||
catch(JSONException je)
|
||||
catch(ParseException pe)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + je.getMessage());
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + pe.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -24,7 +24,7 @@ import org.alfresco.service.cmr.discussion.PostInfo;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
@@ -24,7 +24,7 @@ import org.alfresco.service.cmr.discussion.PostInfo;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
@@ -25,9 +25,7 @@ import org.alfresco.service.cmr.discussion.PostInfo;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
@@ -92,40 +90,34 @@ public class ForumPostPut extends AbstractDiscussionWebScript
|
||||
JSONObject json)
|
||||
{
|
||||
// Fetch the details from the JSON
|
||||
try
|
||||
|
||||
// Update the titles on the post and it's topic
|
||||
if(json.containsKey("title"))
|
||||
{
|
||||
// Update the titles on the post and it's topic
|
||||
if(json.has("title"))
|
||||
String title = (String)json.get("title");
|
||||
post.setTitle(title);
|
||||
if(title.length() > 0)
|
||||
{
|
||||
String title = json.getString("title");
|
||||
post.setTitle(title);
|
||||
if(title.length() > 0)
|
||||
{
|
||||
topic.setTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
// Contents is on the post
|
||||
if(json.has("content"))
|
||||
{
|
||||
post.setContents(json.getString("content"));
|
||||
}
|
||||
|
||||
// Tags are on the topic
|
||||
if(json.has("tags"))
|
||||
{
|
||||
topic.getTags().clear();
|
||||
|
||||
List<String> tags = getTags(json);
|
||||
if(tags != null)
|
||||
{
|
||||
topic.getTags().addAll(tags);
|
||||
}
|
||||
topic.setTitle(title);
|
||||
}
|
||||
}
|
||||
catch(JSONException e)
|
||||
|
||||
// Contents is on the post
|
||||
if(json.containsKey("content"))
|
||||
{
|
||||
throw new WebScriptException("Invalid JSON: " + e.getMessage());
|
||||
post.setContents((String)json.get("content"));
|
||||
}
|
||||
|
||||
// Tags are on the topic
|
||||
if(json.containsKey("tags"))
|
||||
{
|
||||
topic.getTags().clear();
|
||||
|
||||
List<String> tags = getTags(json);
|
||||
if(tags != null)
|
||||
{
|
||||
topic.getTags().addAll(tags);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the topic and the post
|
||||
|
@@ -19,7 +19,6 @@
|
||||
package org.alfresco.repo.web.scripts.discussion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -28,7 +27,7 @@ import org.alfresco.service.cmr.discussion.PostWithReplies;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
@@ -25,8 +25,7 @@ import org.alfresco.service.cmr.discussion.PostInfo;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
@@ -83,25 +82,17 @@ public class ForumPostRepliesPost extends AbstractDiscussionWebScript
|
||||
{
|
||||
// Fetch the details from the JSON
|
||||
String title = null;
|
||||
String contents = null;
|
||||
if(json.containsKey("title"))
|
||||
{
|
||||
title = (String)json.get("title");
|
||||
}
|
||||
|
||||
try
|
||||
String contents = null;
|
||||
if(json.containsKey("content"))
|
||||
{
|
||||
// Grab the data
|
||||
if(json.has("title"))
|
||||
{
|
||||
title = json.getString("title");
|
||||
}
|
||||
if(json.has("content"))
|
||||
{
|
||||
contents = json.getString("content");
|
||||
}
|
||||
contents = (String)json.get("content");
|
||||
}
|
||||
|
||||
}
|
||||
catch(JSONException e)
|
||||
{
|
||||
throw new WebScriptException("Invalid JSON: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Create the reply
|
||||
PostInfo reply = discussionService.createReply(post, contents);
|
||||
|
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.discussion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -26,9 +25,7 @@ import org.alfresco.service.cmr.discussion.PostInfo;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
@@ -58,23 +55,15 @@ public class ForumTopicPost extends AbstractDiscussionWebScript
|
||||
// Grab the details of the new Topic and Post
|
||||
String title = "";
|
||||
String contents = "";
|
||||
List<String> tags = null;
|
||||
try
|
||||
if(json.containsKey("title"))
|
||||
{
|
||||
if(json.has("title"))
|
||||
{
|
||||
title = json.getString("title");
|
||||
}
|
||||
if(json.has("content"))
|
||||
{
|
||||
contents = json.getString("content");
|
||||
}
|
||||
tags = getTags(json);
|
||||
title = (String)json.get("title");
|
||||
}
|
||||
catch(JSONException e)
|
||||
if(json.containsKey("content"))
|
||||
{
|
||||
throw new WebScriptException("Invalid JSON: " + e.getMessage());
|
||||
contents = (String)json.get("content");
|
||||
}
|
||||
List<String> tags = getTags(json);
|
||||
|
||||
|
||||
// Have the topic created
|
||||
|
@@ -26,7 +26,7 @@ import org.alfresco.service.cmr.discussion.PostInfo;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
@@ -30,7 +30,7 @@ import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
@@ -27,7 +27,7 @@ import org.alfresco.service.cmr.discussion.PostInfo;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
@@ -27,7 +27,7 @@ import org.alfresco.service.cmr.discussion.PostInfo;
|
||||
import org.alfresco.service.cmr.discussion.TopicInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
Reference in New Issue
Block a user