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:
@@ -20,6 +20,7 @@ package org.alfresco.repo.web.scripts.calendar;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.StringWriter;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@@ -42,13 +43,15 @@ import org.alfresco.util.ISO8601DateFormat;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.JSONTokener;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.json.JSONWriter;
|
||||
|
||||
/**
|
||||
* @author Nick Burch
|
||||
@@ -150,18 +153,18 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
{
|
||||
boolean isAllDay = false;
|
||||
|
||||
if(json.has("startAt") && json.has("endAt"))
|
||||
if(json.containsKey("startAt") && json.containsKey("endAt"))
|
||||
{
|
||||
// New style ISO8601 dates
|
||||
entry.setStart(parseDate(json.getString("startAt")));
|
||||
entry.setEnd(parseDate(json.getString("endAt")));
|
||||
if(json.has("allday"))
|
||||
entry.setStart(parseDate((String)json.get("startAt")));
|
||||
entry.setEnd(parseDate((String)json.get("endAt")));
|
||||
if(json.containsKey("allday"))
|
||||
{
|
||||
// TODO Handle All Day events properly, including timezones
|
||||
isAllDay = true;
|
||||
}
|
||||
}
|
||||
else if(json.has("allday"))
|
||||
else if(json.containsKey("allday"))
|
||||
{
|
||||
// Old style all-day event
|
||||
entry.setStart(parseDate(getOrNull(json, "from")));
|
||||
@@ -171,8 +174,8 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
else
|
||||
{
|
||||
// Old style regular event
|
||||
entry.setStart(parseDate(json.getString("from") + " " + json.getString("start")));
|
||||
entry.setEnd(parseDate(json.getString("to") + " " + json.getString("end")));
|
||||
entry.setStart(parseDate((String)json.get("from") + " " + (String)json.get("start")));
|
||||
entry.setEnd(parseDate((String)json.get("to") + " " + (String)json.get("end")));
|
||||
}
|
||||
|
||||
return isAllDay;
|
||||
@@ -180,9 +183,9 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
|
||||
protected String getOrNull(JSONObject json, String key) throws JSONException
|
||||
{
|
||||
if(json.has(key))
|
||||
if(json.containsKey(key))
|
||||
{
|
||||
return json.getString(key);
|
||||
return (String)json.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -237,13 +240,9 @@ public abstract class AbstractCalendarWebScript 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)
|
||||
@@ -254,15 +253,18 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
|
||||
try
|
||||
{
|
||||
JSONObject activity = new JSONObject();
|
||||
activity.put("title", entry.getTitle());
|
||||
activity.put("page", page + dateOpt);
|
||||
StringWriter activityJson = new StringWriter();
|
||||
JSONWriter activity = new JSONWriter(activityJson);
|
||||
activity.startObject();
|
||||
activity.writeValue("title", entry.getTitle());
|
||||
activity.writeValue("page", page + dateOpt);
|
||||
activity.endObject();
|
||||
|
||||
activityService.postActivity(
|
||||
"org.alfresco.calendar.event-" + event,
|
||||
site.getShortName(),
|
||||
CALENDAR_SERVICE_ACTIVITY_APP_NAME,
|
||||
activity.toString()
|
||||
activityJson.toString()
|
||||
);
|
||||
}
|
||||
catch(Exception e)
|
||||
@@ -324,15 +326,16 @@ public abstract class AbstractCalendarWebScript 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)
|
||||
{
|
||||
return buildError("Invalid JSON: " + io.getMessage());
|
||||
}
|
||||
catch(JSONException je)
|
||||
catch(org.json.simple.parser.ParseException je)
|
||||
{
|
||||
return buildError("Invalid JSON: " + je.getMessage());
|
||||
}
|
||||
@@ -351,18 +354,14 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
}
|
||||
if(siteName == null && json != null)
|
||||
{
|
||||
try
|
||||
if(json.containsKey("siteid"))
|
||||
{
|
||||
if(json.has("siteid"))
|
||||
siteName = (String)json.get("siteid");
|
||||
}
|
||||
else if(json.containsKey("site"))
|
||||
{
|
||||
siteName = json.getString("siteid");
|
||||
siteName = (String)json.get("site");
|
||||
}
|
||||
else if(json.has("site"))
|
||||
{
|
||||
siteName = json.getString("site");
|
||||
}
|
||||
}
|
||||
catch(JSONException e) {}
|
||||
}
|
||||
if(siteName == null)
|
||||
{
|
||||
|
@@ -32,7 +32,7 @@ import org.alfresco.repo.calendar.CalendarModel;
|
||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
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.WebScriptRequest;
|
||||
|
@@ -22,7 +22,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||
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.WebScriptRequest;
|
||||
|
@@ -29,7 +29,7 @@ import org.alfresco.service.cmr.calendar.CalendarRecurrenceHelper;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
|
@@ -26,7 +26,7 @@ import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||
import org.alfresco.service.cmr.calendar.CalendarEntryDTO;
|
||||
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.WebScriptRequest;
|
||||
@@ -59,9 +59,9 @@ public class CalendarEntryPost extends AbstractCalendarWebScript
|
||||
isAllDay = extractDates(entry, json);
|
||||
|
||||
// Handle tags
|
||||
if(json.has("tags"))
|
||||
if(json.containsKey("tags"))
|
||||
{
|
||||
StringTokenizer st = new StringTokenizer(json.getString("tags"), " ");
|
||||
StringTokenizer st = new StringTokenizer((String)json.get("tags"), " ");
|
||||
while(st.hasMoreTokens())
|
||||
{
|
||||
entry.getTags().add(st.nextToken());
|
||||
|
@@ -26,7 +26,7 @@ import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||
import org.alfresco.service.cmr.calendar.CalendarEntryDTO;
|
||||
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.WebScriptRequest;
|
||||
@@ -57,10 +57,10 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||
try
|
||||
{
|
||||
// Doc folder is a bit special
|
||||
String docFolder = json.getString("docfolder");
|
||||
String docFolder = (String)json.get("docfolder");
|
||||
|
||||
// Editing recurring events is special and a little bit odd...
|
||||
if(entry.getRecurrenceRule() != null && !json.has("recurrenceRule"))
|
||||
if(entry.getRecurrenceRule() != null && !json.containsKey("recurrenceRule"))
|
||||
{
|
||||
// Have an ignored event generated
|
||||
// Will allow us to override this one instance
|
||||
@@ -99,37 +99,37 @@ public class CalendarEntryPut extends AbstractCalendarWebScript
|
||||
isAllDay = extractDates(entry, json);
|
||||
|
||||
// Recurring properties, only changed if keys present
|
||||
if (json.has("recurrenceRule"))
|
||||
if (json.containsKey("recurrenceRule"))
|
||||
{
|
||||
if (json.isNull("recurrenceRule"))
|
||||
if (json.get("recurrenceRule") == null)
|
||||
{
|
||||
entry.setRecurrenceRule(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.setRecurrenceRule(json.getString("recurrenceRule"));
|
||||
entry.setRecurrenceRule((String)json.get("recurrenceRule"));
|
||||
}
|
||||
}
|
||||
if (json.has("recurrenceLastMeeting"))
|
||||
if (json.containsKey("recurrenceLastMeeting"))
|
||||
{
|
||||
if (json.isNull("recurrenceLastMeeting"))
|
||||
if (json.get("recurrenceLastMeeting") == null)
|
||||
{
|
||||
entry.setLastRecurrence(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.setLastRecurrence(
|
||||
parseDate(json.getString("recurrenceLastMeeting"))
|
||||
parseDate((String)json.get("recurrenceLastMeeting"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle tags
|
||||
if(json.has("tags"))
|
||||
if(json.containsKey("tags"))
|
||||
{
|
||||
entry.getTags().clear();
|
||||
|
||||
StringTokenizer st = new StringTokenizer(json.getString("tags"), " ");
|
||||
StringTokenizer st = new StringTokenizer((String)json.get("tags"), " ");
|
||||
while(st.hasMoreTokens())
|
||||
{
|
||||
entry.getTags().add(st.nextToken());
|
||||
|
@@ -37,7 +37,7 @@ import org.alfresco.service.cmr.calendar.CalendarEntryDTO;
|
||||
import org.alfresco.service.cmr.calendar.CalendarRecurrenceHelper;
|
||||
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.WebScriptRequest;
|
||||
|
@@ -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,12 +90,11 @@ 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.has("title"))
|
||||
if(json.containsKey("title"))
|
||||
{
|
||||
String title = json.getString("title");
|
||||
String title = (String)json.get("title");
|
||||
post.setTitle(title);
|
||||
if(title.length() > 0)
|
||||
{
|
||||
@@ -106,13 +103,13 @@ public class ForumPostPut extends AbstractDiscussionWebScript
|
||||
}
|
||||
|
||||
// Contents is on the post
|
||||
if(json.has("content"))
|
||||
if(json.containsKey("content"))
|
||||
{
|
||||
post.setContents(json.getString("content"));
|
||||
post.setContents((String)json.get("content"));
|
||||
}
|
||||
|
||||
// Tags are on the topic
|
||||
if(json.has("tags"))
|
||||
if(json.containsKey("tags"))
|
||||
{
|
||||
topic.getTags().clear();
|
||||
|
||||
@@ -122,11 +119,6 @@ public class ForumPostPut extends AbstractDiscussionWebScript
|
||||
topic.getTags().addAll(tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(JSONException e)
|
||||
{
|
||||
throw new WebScriptException("Invalid JSON: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Save the topic and the post
|
||||
discussionService.updateTopic(topic);
|
||||
|
@@ -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;
|
||||
if(json.containsKey("title"))
|
||||
{
|
||||
title = (String)json.get("title");
|
||||
}
|
||||
|
||||
String contents = null;
|
||||
|
||||
try
|
||||
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 = (String)json.get("title");
|
||||
}
|
||||
if(json.containsKey("content"))
|
||||
{
|
||||
title = json.getString("title");
|
||||
}
|
||||
if(json.has("content"))
|
||||
{
|
||||
contents = json.getString("content");
|
||||
}
|
||||
tags = getTags(json);
|
||||
}
|
||||
catch(JSONException e)
|
||||
{
|
||||
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;
|
||||
|
@@ -19,6 +19,7 @@
|
||||
package org.alfresco.repo.web.scripts.links;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -36,15 +37,16 @@ import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
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;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.json.JSONWriter;
|
||||
|
||||
/**
|
||||
* @author Nick Burch
|
||||
@@ -92,25 +94,25 @@ public abstract class AbstractLinksWebScript 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;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -127,10 +129,10 @@ public abstract class AbstractLinksWebScript 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) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -177,13 +179,9 @@ public abstract class AbstractLinksWebScript 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)
|
||||
@@ -194,15 +192,18 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
|
||||
|
||||
try
|
||||
{
|
||||
JSONObject activity = new JSONObject();
|
||||
activity.put("title", link.getTitle());
|
||||
activity.put("page", page + "?linkId=" + link.getSystemName());
|
||||
StringWriter activityJson = new StringWriter();
|
||||
JSONWriter activity = new JSONWriter(activityJson);
|
||||
activity.startObject();
|
||||
activity.writeValue("title", link.getTitle());
|
||||
activity.writeValue("page", page + "?linkId=" + link.getSystemName());
|
||||
activity.endObject();
|
||||
|
||||
activityService.postActivity(
|
||||
"org.alfresco.links.link-" + event,
|
||||
site.getShortName(),
|
||||
LINKS_SERVICE_ACTIVITY_APP_NAME,
|
||||
activity.toString()
|
||||
activityJson.toString()
|
||||
);
|
||||
}
|
||||
catch(Exception e)
|
||||
@@ -272,17 +273,18 @@ public abstract class AbstractLinksWebScript 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,18 +297,14 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
|
||||
}
|
||||
if(siteName == null && json != null)
|
||||
{
|
||||
try
|
||||
if(json.containsKey("siteid"))
|
||||
{
|
||||
if(json.has("siteid"))
|
||||
siteName = (String)json.get("siteid");
|
||||
}
|
||||
else if(json.containsKey("site"))
|
||||
{
|
||||
siteName = json.getString("siteid");
|
||||
siteName = (String)json.get("site");
|
||||
}
|
||||
else if(json.has("site"))
|
||||
{
|
||||
siteName = json.getString("site");
|
||||
}
|
||||
}
|
||||
catch(JSONException e) {}
|
||||
}
|
||||
if(siteName == null)
|
||||
{
|
||||
|
@@ -24,7 +24,7 @@ import java.util.Map;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.service.cmr.links.LinkInfo;
|
||||
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;
|
||||
|
@@ -23,7 +23,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.links.LinkInfo;
|
||||
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,11 +25,9 @@ import java.util.Map;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.service.cmr.links.LinkInfo;
|
||||
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;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -59,15 +57,13 @@ public class LinkPut extends AbstractLinksWebScript
|
||||
|
||||
|
||||
// Get the new link details from the JSON
|
||||
try
|
||||
{
|
||||
// Update the main properties
|
||||
link.setTitle(getOrNull(json, "title"));
|
||||
link.setDescription(getOrNull(json, "description"));
|
||||
link.setURL(getOrNull(json, "url"));
|
||||
|
||||
// Handle internal / not internal
|
||||
if(json.has("internal"))
|
||||
if(json.containsKey("internal"))
|
||||
{
|
||||
link.setInternal(true);
|
||||
}
|
||||
@@ -83,11 +79,6 @@ public class LinkPut extends AbstractLinksWebScript
|
||||
{
|
||||
link.getTags().addAll(tags);
|
||||
}
|
||||
}
|
||||
catch(JSONException je)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + je.getMessage());
|
||||
}
|
||||
|
||||
|
||||
// Update the link
|
||||
|
@@ -26,12 +26,10 @@ import java.util.Map;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.service.cmr.links.LinkInfo;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -53,14 +51,12 @@ public class LinksDeletePost extends AbstractLinksWebScript
|
||||
// Get the requested nodes from the JSON
|
||||
// Silently skips over any invalid ones specified
|
||||
List<LinkInfo> links = new ArrayList<LinkInfo>();
|
||||
try
|
||||
if(json.containsKey("items"))
|
||||
{
|
||||
if(json.has("items"))
|
||||
JSONArray items = (JSONArray)json.get("items");
|
||||
for(int i=0; i<items.size(); i++)
|
||||
{
|
||||
JSONArray items = json.getJSONArray("items");
|
||||
for(int i=0; i<items.length(); i++)
|
||||
{
|
||||
String name = items.getString(i);
|
||||
String name = (String)items.get(i);
|
||||
LinkInfo link = linksService.getLink(site.getShortName(), name);
|
||||
if(link != null)
|
||||
{
|
||||
@@ -68,11 +64,6 @@ public class LinksDeletePost extends AbstractLinksWebScript
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(JSONException je)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + je.getMessage());
|
||||
}
|
||||
|
||||
|
||||
// Check we got at least one link, and bail if not
|
||||
|
@@ -31,7 +31,7 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.links.LinkInfo;
|
||||
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.WebScriptRequest;
|
||||
|
@@ -25,11 +25,9 @@ import java.util.Map;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.service.cmr.links.LinkInfo;
|
||||
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;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
|
||||
/**
|
||||
@@ -51,23 +49,17 @@ public class LinksPost extends AbstractLinksWebScript
|
||||
String url;
|
||||
boolean internal;
|
||||
List<String> tags;
|
||||
try
|
||||
{
|
||||
|
||||
// Fetch the main properties
|
||||
title = getOrNull(json, "title");
|
||||
description = getOrNull(json, "description");
|
||||
url = getOrNull(json, "url");
|
||||
|
||||
// Handle internal / not internal
|
||||
internal = json.has("internal");
|
||||
internal = json.containsKey("internal");
|
||||
|
||||
// Do the tags
|
||||
tags = getTags(json);
|
||||
}
|
||||
catch(JSONException je)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + je.getMessage());
|
||||
}
|
||||
|
||||
|
||||
// Create the link
|
||||
|
@@ -19,6 +19,7 @@
|
||||
package org.alfresco.repo.web.scripts.wiki;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -34,14 +35,15 @@ import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
import org.alfresco.service.cmr.wiki.WikiService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
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;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.json.JSONWriter;
|
||||
|
||||
/**
|
||||
* @author Nick Burch
|
||||
@@ -91,11 +93,11 @@ public abstract class AbstractWikiWebScript 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;
|
||||
}
|
||||
@@ -150,13 +152,9 @@ public abstract class AbstractWikiWebScript 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)
|
||||
@@ -167,15 +165,18 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
||||
|
||||
try
|
||||
{
|
||||
JSONObject activity = new JSONObject();
|
||||
activity.put("title", wikiPage.getTitle());
|
||||
activity.put("page", page + "?title=" + wikiPage.getSystemName());
|
||||
StringWriter activityJson = new StringWriter();
|
||||
JSONWriter activity = new JSONWriter(activityJson);
|
||||
activity.startObject();
|
||||
activity.writeValue("title", wikiPage.getTitle());
|
||||
activity.writeValue("page", page + "?title=" + wikiPage.getSystemName());
|
||||
activity.endObject();
|
||||
|
||||
activityService.postActivity(
|
||||
"org.alfresco.wiki.page-" + event,
|
||||
site.getShortName(),
|
||||
WIKI_SERVICE_ACTIVITY_APP_NAME,
|
||||
activity.toString()
|
||||
activityJson.toString()
|
||||
);
|
||||
}
|
||||
catch(Exception e)
|
||||
@@ -251,17 +252,18 @@ public abstract class AbstractWikiWebScript 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,22 +276,18 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
||||
}
|
||||
if(siteName == null && json != null)
|
||||
{
|
||||
try
|
||||
if(json.containsKey("siteid"))
|
||||
{
|
||||
if(json.has("siteid"))
|
||||
siteName = (String)json.get("siteid");
|
||||
}
|
||||
else if(json.containsKey("siteId"))
|
||||
{
|
||||
siteName = json.getString("siteid");
|
||||
siteName = (String)json.get("siteId");
|
||||
}
|
||||
else if(json.has("siteId"))
|
||||
else if(json.containsKey("site"))
|
||||
{
|
||||
siteName = json.getString("siteId");
|
||||
siteName = (String)json.get("site");
|
||||
}
|
||||
else if(json.has("site"))
|
||||
{
|
||||
siteName = json.getString("site");
|
||||
}
|
||||
}
|
||||
catch(JSONException e) {}
|
||||
}
|
||||
if(siteName == null)
|
||||
{
|
||||
|
@@ -23,7 +23,7 @@ import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
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;
|
||||
|
@@ -31,7 +31,7 @@ import org.alfresco.repo.wiki.WikiServiceImpl;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
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.WebScriptRequest;
|
||||
|
@@ -31,7 +31,7 @@ import org.alfresco.repo.wiki.WikiServiceImpl;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
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.WebScriptRequest;
|
||||
|
@@ -26,7 +26,7 @@ import org.alfresco.service.cmr.model.FileExistsException;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
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;
|
||||
@@ -69,16 +69,8 @@ public class WikiPageMovePost extends AbstractWikiWebScript
|
||||
|
||||
|
||||
// Grab the new Title
|
||||
String newTitle;
|
||||
try
|
||||
{
|
||||
// The "name" in the JSON is actually the title!
|
||||
newTitle = json.getString("name");
|
||||
}
|
||||
catch(JSONException e)
|
||||
{
|
||||
throw new WebScriptException("Invalid JSON: " + e.getMessage());
|
||||
}
|
||||
String newTitle = (String)json.get("name");
|
||||
|
||||
|
||||
// Have the page re-named, if possible
|
||||
|
@@ -30,9 +30,8 @@ import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.cmr.version.VersionService;
|
||||
import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
@@ -60,20 +59,14 @@ public class WikiPagePut extends AbstractWikiWebScript
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
|
||||
// Grab the details of the change
|
||||
List<String> tags = null;
|
||||
String currentVersion = null;
|
||||
boolean forceSave;
|
||||
String contents;
|
||||
String title;
|
||||
try
|
||||
{
|
||||
// Fetch the contents
|
||||
contents = json.getString("pagecontent");
|
||||
String contents = (String)json.get("pagecontent");
|
||||
|
||||
// Fetch the title, used only when creating
|
||||
if(json.has("title"))
|
||||
String title;
|
||||
if(json.containsKey("title"))
|
||||
{
|
||||
title = json.getString("title");
|
||||
title = (String)json.get("title");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -81,14 +74,16 @@ public class WikiPagePut extends AbstractWikiWebScript
|
||||
}
|
||||
|
||||
// Fetch the versioning details
|
||||
forceSave = json.has("forceSave");
|
||||
if(json.has("currentVersion"))
|
||||
boolean forceSave = json.containsKey("forceSave");
|
||||
String currentVersion = null;
|
||||
if(json.containsKey("currentVersion"))
|
||||
{
|
||||
currentVersion = json.getString("currentVersion");
|
||||
currentVersion = (String)json.get("currentVersion");
|
||||
}
|
||||
|
||||
// Fetch the tags, if given
|
||||
if(json.has("tags"))
|
||||
List<String> tags = null;
|
||||
if(json.containsKey("tags"))
|
||||
{
|
||||
tags = new ArrayList<String>();
|
||||
if(json.get("tags").equals(""))
|
||||
@@ -98,18 +93,13 @@ public class WikiPagePut extends AbstractWikiWebScript
|
||||
else
|
||||
{
|
||||
// Array of tags
|
||||
JSONArray tagsA = json.getJSONArray("tags");
|
||||
for(int i=0; i<tagsA.length(); i++)
|
||||
JSONArray tagsA = (JSONArray)json.get("tags");
|
||||
for(int i=0; i<tagsA.size(); i++)
|
||||
{
|
||||
tags.add(tagsA.getString(i));
|
||||
tags.add((String)tagsA.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(JSONException e)
|
||||
{
|
||||
throw new WebScriptException("Invalid JSON: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Are we creating or editing?
|
||||
WikiPageInfo page = wikiService.getWikiPage(site.getShortName(), pageName);
|
||||
|
@@ -33,7 +33,7 @@ import org.alfresco.service.cmr.version.VersionDoesNotExistException;
|
||||
import org.alfresco.service.cmr.version.VersionHistory;
|
||||
import org.alfresco.service.cmr.version.VersionService;
|
||||
import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
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