001
014
015 package com.liferay.portal.action;
016
017 import com.liferay.documentlibrary.service.DLLocalServiceUtil;
018 import com.liferay.documentlibrary.service.DLServiceUtil;
019 import com.liferay.mail.service.MailServiceUtil;
020 import com.liferay.portal.kernel.json.JSONArray;
021 import com.liferay.portal.kernel.json.JSONException;
022 import com.liferay.portal.kernel.json.JSONFactoryUtil;
023 import com.liferay.portal.kernel.json.JSONObject;
024 import com.liferay.portal.kernel.log.Log;
025 import com.liferay.portal.kernel.log.LogFactoryUtil;
026 import com.liferay.portal.kernel.util.ArrayUtil;
027 import com.liferay.portal.kernel.util.GetterUtil;
028 import com.liferay.portal.kernel.util.LocalizationUtil;
029 import com.liferay.portal.kernel.util.MethodInvoker;
030 import com.liferay.portal.kernel.util.MethodWrapper;
031 import com.liferay.portal.kernel.util.ParamUtil;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.Validator;
035 import com.liferay.portal.model.BaseModel;
036 import com.liferay.portal.service.ServiceContext;
037 import com.liferay.portal.service.ServiceContextUtil;
038 import com.liferay.portal.struts.JSONAction;
039 import com.liferay.portlet.asset.model.AssetEntryDisplay;
040 import com.liferay.portlet.asset.model.AssetEntryType;
041
042 import java.lang.reflect.InvocationTargetException;
043 import java.lang.reflect.Method;
044 import java.lang.reflect.Type;
045
046 import java.util.Arrays;
047 import java.util.Date;
048 import java.util.HashMap;
049 import java.util.HashSet;
050 import java.util.List;
051 import java.util.Map;
052 import java.util.Set;
053 import java.util.regex.Matcher;
054 import java.util.regex.Pattern;
055
056 import javax.servlet.http.HttpServletRequest;
057 import javax.servlet.http.HttpServletResponse;
058
059 import org.apache.struts.action.ActionForm;
060 import org.apache.struts.action.ActionMapping;
061
062
068 public class JSONServiceAction extends JSONAction {
069
070 public JSONServiceAction() {
071 _invalidClassNames.add(DLLocalServiceUtil.class.getName());
072 _invalidClassNames.add(DLServiceUtil.class.getName());
073 _invalidClassNames.add(MailServiceUtil.class.getName());
074 }
075
076 public String getJSON(
077 ActionMapping mapping, ActionForm form, HttpServletRequest request,
078 HttpServletResponse response)
079 throws Exception {
080
081 String className = ParamUtil.getString(request, "serviceClassName");
082 String methodName = ParamUtil.getString(request, "serviceMethodName");
083 String[] serviceParameters = getStringArrayFromJSON(
084 request, "serviceParameters");
085 String[] serviceParameterTypes = getStringArrayFromJSON(
086 request, "serviceParameterTypes");
087
088 if (!isValidRequest(request)) {
089 return null;
090 }
091
092 Thread currentThread = Thread.currentThread();
093
094 ClassLoader contextClassLoader = currentThread.getContextClassLoader();
095
096 Class<?> classObj = contextClassLoader.loadClass(className);
097
098 Object[] methodAndParameterTypes = getMethodAndParameterTypes(
099 classObj, methodName, serviceParameters, serviceParameterTypes);
100
101 if (methodAndParameterTypes != null) {
102 Method method = (Method)methodAndParameterTypes[0];
103 Type[] parameterTypes = (Type[])methodAndParameterTypes[1];
104 Object[] args = new Object[serviceParameters.length];
105
106 for (int i = 0; i < serviceParameters.length; i++) {
107 args[i] = getArgValue(
108 request, classObj, methodName, serviceParameters[i],
109 parameterTypes[i]);
110 }
111
112 try {
113 if (_log.isDebugEnabled()) {
114 _log.debug(
115 "Invoking " + classObj + " on method " +
116 method.getName() + " with args " +
117 Arrays.toString(args));
118 }
119
120 Object returnObj = method.invoke(classObj, args);
121
122 if (returnObj != null) {
123 return getReturnValue(returnObj);
124 }
125 else {
126 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
127
128 return jsonObject.toString();
129 }
130 }
131 catch (Exception e) {
132 if (_log.isDebugEnabled()) {
133 _log.debug(
134 "Invoked " + classObj + " on method " +
135 method.getName() + " with args " +
136 Arrays.toString(args),
137 e);
138 }
139
140 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
141
142 if (e instanceof InvocationTargetException) {
143 jsonObject.put("exception", e.getCause().toString());
144 }
145 else {
146 jsonObject.put("exception", e.getMessage());
147 }
148
149 return jsonObject.toString();
150 }
151 }
152
153 return null;
154 }
155
156 protected Object getArgValue(
157 HttpServletRequest request, Class<?> classObj, String methodName,
158 String parameter, Type parameterType)
159 throws Exception {
160
161 String typeNameOrClassDescriptor = getTypeNameOrClassDescriptor(
162 parameterType);
163
164 String value = ParamUtil.getString(request, parameter);
165
166 if (Validator.isNull(value) &&
167 !typeNameOrClassDescriptor.equals("[Ljava.lang.String;")) {
168
169 return null;
170 }
171 else if (typeNameOrClassDescriptor.equals("boolean") ||
172 typeNameOrClassDescriptor.equals(Boolean.class.getName())) {
173
174 return Boolean.valueOf(ParamUtil.getBoolean(request, parameter));
175 }
176 else if (typeNameOrClassDescriptor.equals("double") ||
177 typeNameOrClassDescriptor.equals(Double.class.getName())) {
178
179 return new Double(ParamUtil.getDouble(request, parameter));
180 }
181 else if (typeNameOrClassDescriptor.equals("int") ||
182 typeNameOrClassDescriptor.equals(Integer.class.getName())) {
183
184 return new Integer(ParamUtil.getInteger(request, parameter));
185 }
186 else if (typeNameOrClassDescriptor.equals("long") ||
187 typeNameOrClassDescriptor.equals(Long.class.getName())) {
188
189 return new Long(ParamUtil.getLong(request, parameter));
190 }
191 else if (typeNameOrClassDescriptor.equals("short") ||
192 typeNameOrClassDescriptor.equals(Short.class.getName())) {
193
194 return new Short(ParamUtil.getShort(request, parameter));
195 }
196 else if (typeNameOrClassDescriptor.equals(Date.class.getName())) {
197 return new Date(ParamUtil.getLong(request, parameter));
198 }
199 else if (typeNameOrClassDescriptor.equals(
200 ServiceContext.class.getName())) {
201
202 JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);
203
204 jsonObject.put("javaClass", ServiceContext.class.getName());
205
206 return ServiceContextUtil.deserialize(jsonObject);
207 }
208 else if (typeNameOrClassDescriptor.equals(String.class.getName())) {
209 return value;
210 }
211 else if (typeNameOrClassDescriptor.equals("[Z")) {
212 return ParamUtil.getBooleanValues(request, parameter);
213 }
214 else if (typeNameOrClassDescriptor.equals("[D")) {
215 return ParamUtil.getDoubleValues(request, parameter);
216 }
217 else if (typeNameOrClassDescriptor.equals("[F")) {
218 return ParamUtil.getFloatValues(request, parameter);
219 }
220 else if (typeNameOrClassDescriptor.equals("[I")) {
221 return ParamUtil.getIntegerValues(request, parameter);
222 }
223 else if (typeNameOrClassDescriptor.equals("[J")) {
224 return ParamUtil.getLongValues(request, parameter);
225 }
226 else if (typeNameOrClassDescriptor.equals("[S")) {
227 return ParamUtil.getShortValues(request, parameter);
228 }
229 else if (typeNameOrClassDescriptor.equals("[Ljava.lang.String;")) {
230 return StringUtil.split(value);
231 }
232 else if (typeNameOrClassDescriptor.equals("[[Z")) {
233 String[] values = request.getParameterValues(parameter);
234
235 if ((values != null) && (values.length > 0)) {
236 String[] values0 = StringUtil.split(values[0]);
237
238 boolean[][] doubleArray =
239 new boolean[values.length][values0.length];
240
241 for (int i = 0; i < values.length; i++) {
242 String[] curValues = StringUtil.split(values[i]);
243
244 for (int j = 0; j < curValues.length; j++) {
245 doubleArray[i][j] = GetterUtil.getBoolean(curValues[j]);
246 }
247 }
248
249 return doubleArray;
250 }
251 else {
252 return new boolean[0][0];
253 }
254 }
255 else if (typeNameOrClassDescriptor.equals("[[D")) {
256 String[] values = request.getParameterValues(parameter);
257
258 if ((values != null) && (values.length > 0)) {
259 String[] values0 = StringUtil.split(values[0]);
260
261 double[][] doubleArray =
262 new double[values.length][values0.length];
263
264 for (int i = 0; i < values.length; i++) {
265 String[] curValues = StringUtil.split(values[i]);
266
267 for (int j = 0; j < curValues.length; j++) {
268 doubleArray[i][j] = GetterUtil.getDouble(curValues[j]);
269 }
270 }
271
272 return doubleArray;
273 }
274 else {
275 return new double[0][0];
276 }
277 }
278 else if (typeNameOrClassDescriptor.equals("[[F")) {
279 String[] values = request.getParameterValues(parameter);
280
281 if ((values != null) && (values.length > 0)) {
282 String[] values0 = StringUtil.split(values[0]);
283
284 float[][] doubleArray =
285 new float[values.length][values0.length];
286
287 for (int i = 0; i < values.length; i++) {
288 String[] curValues = StringUtil.split(values[i]);
289
290 for (int j = 0; j < curValues.length; j++) {
291 doubleArray[i][j] = GetterUtil.getFloat(curValues[j]);
292 }
293 }
294
295 return doubleArray;
296 }
297 else {
298 return new float[0][0];
299 }
300 }
301 else if (typeNameOrClassDescriptor.equals("[[I")) {
302 String[] values = request.getParameterValues(parameter);
303
304 if ((values != null) && (values.length > 0)) {
305 String[] values0 = StringUtil.split(values[0]);
306
307 int[][] doubleArray =
308 new int[values.length][values0.length];
309
310 for (int i = 0; i < values.length; i++) {
311 String[] curValues = StringUtil.split(values[i]);
312
313 for (int j = 0; j < curValues.length; j++) {
314 doubleArray[i][j] = GetterUtil.getInteger(curValues[j]);
315 }
316 }
317
318 return doubleArray;
319 }
320 else {
321 return new int[0][0];
322 }
323 }
324 else if (typeNameOrClassDescriptor.equals("[[J")) {
325 String[] values = request.getParameterValues(parameter);
326
327 if ((values != null) && (values.length > 0)) {
328 String[] values0 = StringUtil.split(values[0]);
329
330 long[][] doubleArray =
331 new long[values.length][values0.length];
332
333 for (int i = 0; i < values.length; i++) {
334 String[] curValues = StringUtil.split(values[i]);
335
336 for (int j = 0; j < curValues.length; j++) {
337 doubleArray[i][j] = GetterUtil.getLong(curValues[j]);
338 }
339 }
340
341 return doubleArray;
342 }
343 else {
344 return new long[0][0];
345 }
346 }
347 else if (typeNameOrClassDescriptor.equals("[[S")) {
348 String[] values = request.getParameterValues(parameter);
349
350 if ((values != null) && (values.length > 0)) {
351 String[] values0 = StringUtil.split(values[0]);
352
353 short[][] doubleArray =
354 new short[values.length][values0.length];
355
356 for (int i = 0; i < values.length; i++) {
357 String[] curValues = StringUtil.split(values[i]);
358
359 for (int j = 0; j < curValues.length; j++) {
360 doubleArray[i][j] = GetterUtil.getShort(curValues[j]);
361 }
362 }
363
364 return doubleArray;
365 }
366 else {
367 return new short[0][0];
368 }
369 }
370 else if (typeNameOrClassDescriptor.equals("[[Ljava.lang.String")) {
371 String[] values = request.getParameterValues(parameter);
372
373 if ((values != null) && (values.length > 0)) {
374 String[] values0 = StringUtil.split(values[0]);
375
376 String[][] doubleArray =
377 new String[values.length][values0.length];
378
379 for (int i = 0; i < values.length; i++) {
380 doubleArray[i] = StringUtil.split(values[i]);
381 }
382
383 return doubleArray;
384 }
385 else {
386 return new String[0][0];
387 }
388 }
389 else if (typeNameOrClassDescriptor.equals(
390 "java.util.Map<java.util.Locale, java.lang.String>")) {
391
392 JSONObject jsonObject = JSONFactoryUtil.createJSONObject(value);
393
394 return LocalizationUtil.deserialize(jsonObject);
395 }
396 else {
397 _log.error(
398 "Unsupported parameter type for class " + classObj +
399 ", method " + methodName + ", parameter " + parameter +
400 ", and type " + typeNameOrClassDescriptor);
401
402 return null;
403 }
404 }
405
406 protected Object[] getMethodAndParameterTypes(
407 Class<?> classObj, String methodName, String[] parameters,
408 String[] parameterTypes)
409 throws Exception {
410
411 String parameterNames = StringUtil.merge(parameters);
412
413 String key =
414 classObj.getName() + "_METHOD_NAME_" + methodName +
415 "_PARAMETERS_" + parameterNames;
416
417 Object[] methodAndParameterTypes = _methodCache.get(key);
418
419 if (methodAndParameterTypes != null) {
420 return methodAndParameterTypes;
421 }
422
423 Method method = null;
424 Type[] methodParameterTypes = null;
425
426 Method[] methods = classObj.getMethods();
427
428 for (int i = 0; i < methods.length; i++) {
429 Method curMethod = methods[i];
430
431 if (curMethod.getName().equals(methodName)) {
432 Type[] curParameterTypes = curMethod.getGenericParameterTypes();
433
434 if (curParameterTypes.length == parameters.length) {
435 if ((parameterTypes.length > 0) &&
436 (parameterTypes.length == curParameterTypes.length)) {
437
438 boolean match = true;
439
440 for (int j = 0; j < parameterTypes.length; j++) {
441 String t1 = parameterTypes[j];
442 String t2 = getTypeNameOrClassDescriptor(
443 curParameterTypes[j]);
444
445 if (!t1.equals(t2)) {
446 match = false;
447 }
448 }
449
450 if (match) {
451 method = curMethod;
452 methodParameterTypes = curParameterTypes;
453
454 break;
455 }
456 }
457 else if (method != null) {
458 _log.error(
459 "Obscure method name for class " + classObj +
460 ", method " + methodName + ", and parameters " +
461 parameterNames);
462
463 return null;
464 }
465 else {
466 method = curMethod;
467 methodParameterTypes = curParameterTypes;
468 }
469 }
470 }
471 }
472
473 if (method != null) {
474 methodAndParameterTypes = new Object[] {
475 method, methodParameterTypes
476 };
477
478 _methodCache.put(key, methodAndParameterTypes);
479
480 return methodAndParameterTypes;
481 }
482 else {
483 _log.error(
484 "No method found for class " + classObj + ", method " +
485 methodName + ", and parameters " + parameterNames);
486
487 return null;
488 }
489 }
490
491 protected String getReturnValue(AssetEntryDisplay assetEntryDisplay)
492 throws Exception {
493
494 JSONObject jsonObject = toJSONObject(assetEntryDisplay);
495
496 return jsonObject.toString();
497 }
498
499 protected String getReturnValue(AssetEntryDisplay[] assetEntryDisplays)
500 throws Exception {
501
502 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
503
504 for (int i = 0; i < assetEntryDisplays.length; i++) {
505 AssetEntryDisplay assetEntryDisplay = assetEntryDisplays[i];
506
507 jsonArray.put(toJSONObject(assetEntryDisplay));
508 }
509
510 return jsonArray.toString();
511 }
512
513 protected String getReturnValue(AssetEntryType assetEntryType)
514 throws Exception {
515
516 JSONObject jsonObject = toJSONObject(assetEntryType);
517
518 return jsonObject.toString();
519 }
520
521 protected String getReturnValue(AssetEntryType[] assetEntryTypes)
522 throws Exception {
523
524 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
525
526 for (int i = 0; i < assetEntryTypes.length; i++) {
527 AssetEntryType assetEntryType = assetEntryTypes[i];
528
529 jsonArray.put(toJSONObject(assetEntryType));
530 }
531
532 return jsonArray.toString();
533 }
534
535 protected String getReturnValue(Object returnObj) throws Exception {
536 if ((returnObj instanceof Boolean) || (returnObj instanceof Double) ||
537 (returnObj instanceof Integer) || (returnObj instanceof Long) ||
538 (returnObj instanceof Short) || (returnObj instanceof String)) {
539
540 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
541
542 jsonObject.put("returnValue", returnObj.toString());
543
544 return jsonObject.toString();
545 }
546 else if (returnObj instanceof BaseModel<?>) {
547 String serlializerClassName = getSerializerClassName(returnObj);
548
549 MethodWrapper methodWrapper = new MethodWrapper(
550 serlializerClassName, "toJSONObject", returnObj);
551
552 JSONObject jsonObject = (JSONObject)MethodInvoker.invoke(
553 methodWrapper, false);
554
555 return jsonObject.toString();
556 }
557 else if (returnObj instanceof BaseModel<?>[]) {
558 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
559
560 BaseModel<?>[] returnArray = (BaseModel[])returnObj;
561
562 if (returnArray.length > 0) {
563 BaseModel<?> returnItem0 = returnArray[0];
564
565 String serializerClassName = getSerializerClassName(
566 returnItem0);
567
568 MethodWrapper methodWrapper = new MethodWrapper(
569 serializerClassName, "toJSONArray", returnObj);
570
571 jsonArray = (JSONArray)MethodInvoker.invoke(
572 methodWrapper, false);
573 }
574
575 return jsonArray.toString();
576 }
577 else if (returnObj instanceof BaseModel<?>[][]) {
578 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
579
580 BaseModel<?>[][] returnArray = (BaseModel<?>[][])returnObj;
581
582 if ((returnArray.length > 0) &&
583 (returnArray[0].length > 0)) {
584
585 BaseModel<?> returnItem0 = returnArray[0][0];
586
587 String serializerClassName = getSerializerClassName(
588 returnItem0);
589
590 MethodWrapper methodWrapper = new MethodWrapper(
591 serializerClassName, "toJSONArray", returnObj);
592
593 jsonArray = (JSONArray)MethodInvoker.invoke(
594 methodWrapper, false);
595 }
596
597 return jsonArray.toString();
598 }
599 else if (returnObj instanceof List<?>) {
600 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
601
602 List<Object> returnList = (List<Object>)returnObj;
603
604 if (!returnList.isEmpty()) {
605 Object returnItem0 = returnList.get(0);
606
607 String serlializerClassName = getSerializerClassName(
608 returnItem0);
609
610 MethodWrapper methodWrapper = new MethodWrapper(
611 serlializerClassName, "toJSONArray", returnObj);
612
613 jsonArray = (JSONArray)MethodInvoker.invoke(
614 methodWrapper, false);
615 }
616
617 return jsonArray.toString();
618 }
619 else if (returnObj instanceof JSONArray) {
620 JSONArray jsonArray = (JSONArray)returnObj;
621
622 return jsonArray.toString();
623 }
624 else if (returnObj instanceof JSONObject) {
625 JSONObject jsonObject = (JSONObject)returnObj;
626
627 return jsonObject.toString();
628 }
629 else if (returnObj instanceof AssetEntryDisplay) {
630 return getReturnValue((AssetEntryDisplay)returnObj);
631 }
632 else if (returnObj instanceof AssetEntryDisplay[]) {
633 return getReturnValue((AssetEntryDisplay[])returnObj);
634 }
635 else if (returnObj instanceof AssetEntryType) {
636 return getReturnValue((AssetEntryType)returnObj);
637 }
638 else if (returnObj instanceof AssetEntryType[]) {
639 return getReturnValue((AssetEntryType[])returnObj);
640 }
641 else {
642 return JSONFactoryUtil.serialize(returnObj);
643 }
644 }
645
646 protected String getSerializerClassName(Object obj) {
647 String serlializerClassName = StringUtil.replace(
648 obj.getClass().getName(),
649 new String[] {".model.impl.", "Impl"},
650 new String[] {".service.http.", "JSONSerializer"});
651
652 return serlializerClassName;
653 }
654
655 protected String[] getStringArrayFromJSON(
656 HttpServletRequest request, String param)
657 throws JSONException {
658
659 String json = ParamUtil.getString(request, param, "[]");
660
661 JSONArray jsonArray = JSONFactoryUtil.createJSONArray(json);
662
663 return ArrayUtil.toStringArray(jsonArray);
664 }
665
666 protected String getTypeNameOrClassDescriptor(Type type) {
667 String typeName = type.toString();
668
669 if (typeName.contains("class ")) {
670 return typeName.substring(6);
671 }
672
673 Matcher matcher = _fieldDescriptorPattern.matcher(typeName);
674
675 while (matcher.find()) {
676 String dimensions = matcher.group(2);
677 String fieldDescriptor = matcher.group(1);
678
679 if (Validator.isNull(dimensions)) {
680 return fieldDescriptor;
681 }
682
683 dimensions = dimensions.replace(
684 StringPool.CLOSE_BRACKET, StringPool.BLANK);
685
686 if (fieldDescriptor.equals("boolean")) {
687 fieldDescriptor = "Z";
688 }
689 else if (fieldDescriptor.equals("byte")) {
690 fieldDescriptor = "B";
691 }
692 else if (fieldDescriptor.equals("char")) {
693 fieldDescriptor = "C";
694 }
695 else if (fieldDescriptor.equals("double")) {
696 fieldDescriptor = "D";
697 }
698 else if (fieldDescriptor.equals("float")) {
699 fieldDescriptor = "F";
700 }
701 else if (fieldDescriptor.equals("int")) {
702 fieldDescriptor = "I";
703 }
704 else if (fieldDescriptor.equals("long")) {
705 fieldDescriptor = "J";
706 }
707 else if (fieldDescriptor.equals("short")) {
708 fieldDescriptor = "S";
709 }
710 else {
711 fieldDescriptor = "L".concat(fieldDescriptor).concat(
712 StringPool.SEMICOLON);
713 }
714
715 return dimensions.concat(fieldDescriptor);
716 }
717
718 throw new IllegalArgumentException(type.toString() + " is invalid");
719 }
720
721 protected boolean isValidRequest(HttpServletRequest request) {
722 String className = ParamUtil.getString(request, "serviceClassName");
723
724 if (className.contains(".service.") &&
725 className.endsWith("ServiceUtil") &&
726 !className.endsWith("LocalServiceUtil") &&
727 !_invalidClassNames.contains(className)) {
728
729 return true;
730 }
731 else {
732 return false;
733 }
734 }
735
736 protected JSONObject toJSONObject(AssetEntryDisplay assetEntryDisplay) {
737 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
738
739 jsonObject.put("entryId", assetEntryDisplay.getEntryId());
740 jsonObject.put("companyId", assetEntryDisplay.getCompanyId());
741 jsonObject.put("userId", assetEntryDisplay.getUserId());
742 jsonObject.put("userName", assetEntryDisplay.getUserName());
743 jsonObject.put("createDate", assetEntryDisplay.getCreateDate());
744 jsonObject.put("modifiedDate", assetEntryDisplay.getModifiedDate());
745 jsonObject.put("classNameId", assetEntryDisplay.getClassNameId());
746 jsonObject.put("className", assetEntryDisplay.getClassName());
747 jsonObject.put("classPK", assetEntryDisplay.getClassPK());
748 jsonObject.put("portletId", assetEntryDisplay.getPortletId());
749 jsonObject.put("portletTitle", assetEntryDisplay.getPortletTitle());
750 jsonObject.put("startDate", assetEntryDisplay.getStartDate());
751 jsonObject.put("endDate", assetEntryDisplay.getEndDate());
752 jsonObject.put("publishDate", assetEntryDisplay.getPublishDate());
753 jsonObject.put("expirationDate", assetEntryDisplay.getExpirationDate());
754 jsonObject.put("mimeType", assetEntryDisplay.getMimeType());
755 jsonObject.put("title", assetEntryDisplay.getTitle());
756 jsonObject.put("description", assetEntryDisplay.getDescription());
757 jsonObject.put("summary", assetEntryDisplay.getSummary());
758 jsonObject.put("url", assetEntryDisplay.getUrl());
759 jsonObject.put("height", assetEntryDisplay.getHeight());
760 jsonObject.put("width", assetEntryDisplay.getWidth());
761 jsonObject.put("priority", assetEntryDisplay.getPriority());
762 jsonObject.put("viewCount", assetEntryDisplay.getViewCount());
763 jsonObject.put(
764 "assetCategoryIds",
765 StringUtil.merge(assetEntryDisplay.getCategoryIds()));
766 jsonObject.put("assetTagNames", assetEntryDisplay.getTagNames());
767
768 return jsonObject;
769 }
770
771 protected JSONObject toJSONObject(AssetEntryType assetEntryType) {
772 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
773
774 jsonObject.put("classNameId", assetEntryType.getClassNameId());
775 jsonObject.put("className", assetEntryType.getClassName());
776 jsonObject.put("portletId", assetEntryType.getPortletId());
777 jsonObject.put("portletTitle", assetEntryType.getPortletTitle());
778
779 return jsonObject;
780 }
781
782 private static Log _log = LogFactoryUtil.getLog(JSONServiceAction.class);
783
784 private static Pattern _fieldDescriptorPattern = Pattern.compile(
785 "^(.*?)((\\[\\])*)$", Pattern.DOTALL);
786
787 private Set<String> _invalidClassNames = new HashSet<String>();
788 private Map<String, Object[]> _methodCache =
789 new HashMap<String, Object[]>();
790
791 }