001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.components.query;
019:
020: import java.io.IOException;
021: import java.io.Writer;
022: import java.util.Collection;
023: import java.util.Iterator;
024: import java.util.Map;
025:
026: import de.finix.contelligent.CallData;
027: import de.finix.contelligent.action.AbstractAction;
028: import de.finix.contelligent.action.Action;
029: import de.finix.contelligent.action.ActionException;
030: import de.finix.contelligent.exception.ContelligentException;
031: import de.finix.contelligent.logging.LoggingService;
032: import de.finix.contelligent.render.MissingParameterException;
033: import de.finix.contelligent.render.PageRenderer;
034: import de.finix.contelligent.render.ParameterDescription;
035: import de.finix.contelligent.render.Renderable;
036: import de.finix.contelligent.render.Renderer;
037:
038: public class PagingAction extends AbstractAction implements Renderer,
039: Renderable {
040: private final static org.apache.log4j.Logger log = LoggingService
041: .getLogger(PagingAction.class);
042:
043: final static String TARGET_POSITION = "targetPosition";
044:
045: final static String SESSION_STORE = "sessionStore";
046:
047: protected String doPerform(CallData callData)
048: throws ActionException {
049: String sessionStore = getStringParameter(SESSION_STORE,
050: callData).trim();
051: String targetPosition = getStringParameter(TARGET_POSITION,
052: callData).trim();
053: callData.setRequestAttribute(
054: QueryResultRenderer.CURRENT_POSITION, new Integer(
055: targetPosition), sessionStore);
056: return AbstractAction.ROUTING_OK;
057: }
058:
059: public Renderer getRenderer() {
060: return this ;
061: }
062:
063: public ParameterDescription[] getParameterDescription() {
064: return new ParameterDescription[0];
065: }
066:
067: public void render(Writer writer, Map parameterMap,
068: CallData callData) throws IOException,
069: MissingParameterException, ContelligentException {
070: if (parameterMap != null
071: && parameterMap.containsKey(PageRenderer.MODE)
072: && ((String[]) parameterMap.get(PageRenderer.MODE))[0]
073: .equals(PageRenderer.MODE_MARKUP)) {
074: super .getRenderer().render(writer, parameterMap, callData);
075: } else {
076: StringBuffer url = new StringBuffer(256);
077: url.append(callData.getCurrentBaseURL()).append(
078: getComponentContext().getPath()).append(
079: Action.TYPE_SUFFIX).append('?');
080: writer.write(callData.encodeURL(url.toString()));
081: String sessionStore = (String) callData
082: .getRequestAttribute(SESSION_STORE);
083: writer.write(SESSION_STORE);
084: writer.write("=");
085: writer.write(sessionStore);
086: writer.write('&');
087: writer.write(TARGET_POSITION);
088: writer.write("=");
089: String targetPosition = (String) callData
090: .getRequestAttribute(TARGET_POSITION);
091: writer.write(targetPosition);
092:
093: Iterator i = callData.getParameters().entrySet().iterator();
094:
095: while (i.hasNext()) {
096: Map.Entry e = (Map.Entry) i.next();
097: if (e.getKey().equals(TARGET_POSITION)
098: || e.getKey().equals(SESSION_STORE))
099: continue;
100:
101: Object o = e.getValue();
102: if (o instanceof String[]) {
103: String[] values = (String[]) o;
104:
105: for (int a = 0; a < values.length; a++) {
106: writer.write('&');
107: writer.write(e.getKey().toString());
108: writer.write('=');
109: writer.write(values[a]);
110: }
111: } else if (o instanceof String) {
112: String value = (String) o;
113: writer.write('&');
114: writer.write(e.getKey().toString());
115: writer.write('=');
116: writer.write(value);
117: }
118: }
119: }
120: }
121:
122: public Collection getSensitiveCategories() {
123: return null;
124: }
125: }
|