001
014
015 package com.liferay.portlet.dynamicdatamapping.action;
016
017 import com.liferay.portal.kernel.json.JSONArray;
018 import com.liferay.portal.kernel.json.JSONFactoryUtil;
019 import com.liferay.portal.kernel.json.JSONObject;
020 import com.liferay.portal.kernel.servlet.ServletResponseUtil;
021 import com.liferay.portal.kernel.util.ContentTypes;
022 import com.liferay.portal.kernel.util.ParamUtil;
023 import com.liferay.portlet.dynamicdatamapping.model.DDMStructure;
024 import com.liferay.portlet.dynamicdatamapping.service.DDMStructureServiceUtil;
025 import com.liferay.portlet.dynamicdatamapping.util.DDMXSDUtil;
026
027 import javax.servlet.http.HttpServletRequest;
028 import javax.servlet.http.HttpServletResponse;
029
030 import org.apache.struts.action.Action;
031 import org.apache.struts.action.ActionForm;
032 import org.apache.struts.action.ActionForward;
033 import org.apache.struts.action.ActionMapping;
034
035
038 public class GetStructureJSONAction extends Action {
039
040 @Override
041 public ActionForward execute(
042 ActionMapping actionMapping, ActionForm actionForm,
043 HttpServletRequest request, HttpServletResponse response)
044 throws Exception {
045
046 try {
047 long structureId = ParamUtil.getLong(request, "structureId");
048
049 String xsd = ParamUtil.getString(request, "xsd");
050
051 DDMStructure structure = null;
052
053 if (structureId > 0) {
054 structure = DDMStructureServiceUtil.getStructure(structureId);
055 }
056
057 JSONArray jsonArray = DDMXSDUtil.getJSONArray(structure, xsd);
058
059 response.setContentType(ContentTypes.APPLICATION_JSON);
060
061 ServletResponseUtil.write(response, jsonArray.toString());
062 }
063 catch (Exception e) {
064 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
065
066 jsonObject.putException(e);
067
068 ServletResponseUtil.write(response, jsonObject.toString());
069 }
070
071 return null;
072 }
073
074 }