01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.wsrp;
23:
24: import org.jboss.portal.wsrp.core.LocalizedString;
25: import org.jboss.portal.wsrp.core.PortletDescription;
26: import org.jboss.portal.wsrp.core.ServiceDescription;
27:
28: /**
29: * Helper class to extract information from WSRP objects in readable manner
30: *
31: * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
32: * @version $Revision: 9360 $
33: */
34: public class ResponseDebugFactory {
35: private ResponseDebugFactory() {
36: }
37:
38: /**
39: * Extracts information from ServiceDescription and puts into StringBuffer object
40: *
41: * @param sd
42: * @return StringBuffer containing ServiceDescription content
43: */
44: public static StringBuffer extractServiceDescription(
45: final ServiceDescription sd) {
46: StringBuffer buffer = new StringBuffer();
47: if (sd == null) {
48: buffer.append("Empty service description");
49: return buffer;
50: }
51:
52: buffer.append("# ServiceDescription content:\n");
53:
54: //TODO: for now only simple property + offered portlets - extend this when needed
55:
56: buffer.append("isRequiresRegistration : ").append(
57: sd.isRequiresRegistration()).append("\n");
58:
59: buffer.append("### List of offered portlets: \n");
60: PortletDescription[] portlets = sd.getOfferedPortlets();
61: if (portlets != null) {
62: for (int i = 0; i < portlets.length; i++) {
63: PortletDescription portlet = portlets[i];
64: String index = "[" + i + "]";
65: buffer.append(index).append("portletHandle : ").append(
66: portlet.getPortletHandle()).append("\n");
67: buffer.append(index).append("description : ").append(
68: toString(portlet.getDescription()))
69: .append("\n");
70: buffer.append(index).append("shortTitle : ").append(
71: toString(portlet.getShortTitle())).append("\n");
72: buffer.append(index).append("title : ").append(
73: toString(portlet.getTitle())).append("\n");
74: buffer.append(index).append("displayName : ").append(
75: toString(portlet.getDisplayName()))
76: .append("\n");
77: }
78: } else {
79: buffer.append("no offered portlets");
80: }
81:
82: return buffer;
83: }
84:
85: public static String toString(LocalizedString ls) {
86: if (ls != null) {
87: return ls.getLang() + "; " + ls.getResourceName() + "; "
88: + ls.getValue();
89: } else {
90: return "";
91: }
92:
93: }
94:
95: }
|