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 = json.getString("siteid");
|
||||
}
|
||||
else if(json.has("site"))
|
||||
{
|
||||
siteName = json.getString("site");
|
||||
}
|
||||
siteName = (String)json.get("siteid");
|
||||
}
|
||||
else if(json.containsKey("site"))
|
||||
{
|
||||
siteName = (String)json.get("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;
|
||||
|
Reference in New Issue
Block a user