001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE 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 Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: */
019:
020: package de.schlund.pfixcore.workflow.app;
021:
022: import java.util.HashMap;
023: import java.util.Iterator;
024:
025: import de.schlund.pfixcore.generator.RequestData;
026: import de.schlund.pfixcore.workflow.Context;
027: import de.schlund.pfixxml.PfixServletRequest;
028: import de.schlund.pfixxml.RequestParam;
029:
030: /**
031: * Implementation of the RequestData interface.
032: *
033: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
034: *
035: */
036:
037: public class RequestDataImpl implements RequestData {
038:
039: private HashMap<String, RequestParam[]> data = new HashMap<String, RequestParam[]>();
040: private HashMap<String, String[]> cmds = new HashMap<String, String[]>();
041: private String page;
042:
043: private static final String CMDS_PREFIX = "__CMD";
044: private static final String SBMT_PREFIX = "__SBMT:";
045: private static final String SYNT_PREFIX = "__SYNT:";
046:
047: public RequestDataImpl(Context context, PfixServletRequest preq) {
048: page = context.getCurrentPageRequest().getRootName();
049: initData(preq);
050: }
051:
052: /**
053: * @see de.schlund.pfixcore.generator.RequestData#getParameterNames()
054: */
055: public Iterator<String> getParameterNames() {
056: return data.keySet().iterator();
057: }
058:
059: /**
060: * @see de.schlund.pfixcore.generator.RequestData#getCommandNames()
061: */
062: public Iterator<String> getCommandNames() {
063: return cmds.keySet().iterator();
064: }
065:
066: /**
067: * @see de.schlund.pfixcore.generator.RequestData#getParameters(String)
068: */
069: public RequestParam[] getParameters(String key) {
070: return (RequestParam[]) data.get(key);
071: }
072:
073: /**
074: * @see de.schlund.pfixcore.generator.RequestData#getCommands(String)
075: */
076: public String[] getCommands(String key) {
077: return (String[]) cmds.get(key);
078: }
079:
080: private void initData(PfixServletRequest preq) {
081: String cmds_prefix = CMDS_PREFIX + "[" + page + "]:";
082:
083: String[] paramnames = preq.getRequestParamNames();
084: for (int i = 0; i < paramnames.length; i++) {
085: String name = paramnames[i];
086:
087: if (name.startsWith(cmds_prefix)) {
088: String key = name.substring(cmds_prefix.length());
089: RequestParam[] cmdvals = preq.getAllRequestParams(name);
090: if (cmdvals != null && cmdvals.length > 0) {
091: String[] cmdstrs = new String[cmdvals.length];
092: for (int j = 0; j < cmdvals.length; j++) {
093: cmdstrs[j] = cmdvals[j].getValue();
094: }
095: cmds.put(key, cmdstrs);
096: }
097: } else if (name.startsWith(SYNT_PREFIX)
098: || name.startsWith(SBMT_PREFIX)
099: || name.startsWith(CMDS_PREFIX)) {
100: // these are parameters that are no valid cmd and no "real" data
101: } else {
102: RequestParam[] datavals = preq
103: .getAllRequestParams(name);
104: if (datavals != null) {
105: data.put(name, datavals);
106: }
107: }
108: }
109: }
110: }
|