001: /*
002: * (C) Copyright 2000 - 2005 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portlet.wsadmin;
020:
021: import java.util.Vector;
022:
023: import javax.portlet.ActionRequest;
024: import javax.portlet.ActionResponse;
025:
026: import com.nabhinc.ws.core.PropertyInfo;
027: import com.nabhinc.ws.core.WebServiceException;
028:
029: /**
030: * Helper class for Web Service admin portlet.
031: *
032: * @author Padmanabh Dabke
033: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
034: */
035: public class WebServicePortletUtil {
036:
037: public static final String PROPERTY_NAME_PARAM_PREFIX = "property_name_";
038: public static final String PROPERTY_DESCR_PARAM_PREFIX = "property_descr_";
039: public static final String PROPERTY_PROMPT_PARAM_PREFIX = "property_prompt_";
040: public static final String PROPERTY_VALUE_PARAM_PREFIX = "property_value_";
041: public static final String PROPERTY_SPEC_TYPE_PARAM_PREFIX = "property_spec_type_";
042: public static final String PROPERTY_IS_MEMO_PARAM_PREFIX = "property_is_memo_";
043:
044: public static PropertyInfo[] constructPropertiesInfo(
045: ActionRequest req) throws WebServiceException {
046: int i = 0;
047: String propertyName = req
048: .getParameter(PROPERTY_NAME_PARAM_PREFIX + i);
049: Vector propList = new Vector();
050: while (propertyName != null
051: && (!propertyName.trim().equals(""))) {
052: PropertyInfo prop = new PropertyInfo();
053: prop.name = propertyName;
054: prop.description = req
055: .getParameter(PROPERTY_DESCR_PARAM_PREFIX + i);
056: String isMemoStr = req
057: .getParameter(PROPERTY_IS_MEMO_PARAM_PREFIX + i);
058: if (isMemoStr != null && (!isMemoStr.equals("")))
059: prop.isMemo = true;
060: prop.prompt = req.getParameter(PROPERTY_PROMPT_PARAM_PREFIX
061: + i);
062: prop.value = req.getParameter(PROPERTY_VALUE_PARAM_PREFIX
063: + i);
064: String specTypeStr = req
065: .getParameter(PROPERTY_SPEC_TYPE_PARAM_PREFIX + i);
066: if (specTypeStr != null && (!specTypeStr.equals("")))
067: prop.specType = PropertyInfo.SPEC_TYPE_COIL;
068: // if (prop.prompt == null) throw new WebServiceException("You must specify property display name.");
069: i++;
070: propertyName = req.getParameter(PROPERTY_NAME_PARAM_PREFIX
071: + i);
072: propList.addElement(prop);
073: }
074: PropertyInfo[] propArray = new PropertyInfo[propList.size()];
075: propList.copyInto(propArray);
076: return propArray;
077: }
078:
079: public static void setPropertyParams(ActionResponse response,
080: PropertyInfo[] props) {
081: if (props == null || props.length == 0)
082: return;
083: for (int i = 0; i < props.length; i++) {
084: PropertyInfo prop = props[i];
085: response.setRenderParameter(PROPERTY_NAME_PARAM_PREFIX + i,
086: prop.name);
087: if (prop.description != null)
088: response.setRenderParameter(PROPERTY_DESCR_PARAM_PREFIX
089: + i, prop.description);
090: if (prop.isMemo)
091: response.setRenderParameter(
092: PROPERTY_IS_MEMO_PARAM_PREFIX + i, "true");
093: if (prop.prompt != null)
094: response.setRenderParameter(
095: PROPERTY_PROMPT_PARAM_PREFIX + i, prop.prompt);
096: if (prop.value != null)
097: response.setRenderParameter(PROPERTY_VALUE_PARAM_PREFIX
098: + i, prop.value);
099: if (prop.specType == PropertyInfo.SPEC_TYPE_COIL)
100: response.setRenderParameter(
101: PROPERTY_SPEC_TYPE_PARAM_PREFIX + i, "true");
102: }
103: }
104:
105: }
|