/** * I think in the basic framework this method is never called explicitely, because processing is * done implicitly by the render */ @Override public void process( Processor processor, Parameters blockParameters, Parameters frameworkParameters) throws FrameworkException { HttpServletRequest request = frameworkParameters.get(Parameter.REQUEST); State state = State.getState(request); state.startBlock(frameworkParameters, null); setBlockParametersForProcess(state, blockParameters); processor.process(blockParameters); }
@Override public Block getRenderingBlock(Parameters frameworkParameters) { HttpServletRequest request = frameworkParameters.get(Parameter.REQUEST); State state = State.getState(request); if (state.isRendering()) { return state.getBlock(); } else { return null; } }
@Override public String getProcessUrl( String path, Map<String, ?> parameters, Parameters frameworkParameters, boolean escapeAmps) throws FrameworkException { HttpServletRequest request = BasicUrlConverter.getUserRequest(frameworkParameters.get(Parameter.REQUEST)); State state = State.getState(request); frameworkParameters.set(ACTION, state.getId()); Url url = urlConverter.getProcessUrl(path, parameters, frameworkParameters, escapeAmps); if (url == Url.NOT) { log.debug("Fall back url"); return fallbackConverter .getProcessUrl(path, parameters, frameworkParameters, escapeAmps) .getUrl(); } else { log.debug("Url converter url " + url); return url.getUrl(); } }
@SuppressWarnings("unchecked") protected void setBlockParametersForRender(State state, Parameters blockParameters) { ServletRequest request = state.getRequest(); String prefix = getPrefix(state); log.debug("prefix " + prefix); blockParameters.setAutoCasting(true); for (Map.Entry<String, String[]> entry : ((Map<String, String[]>) request.getParameterMap()).entrySet()) { String key = entry.getKey(); if (key.startsWith(prefix)) { log.trace("setting" + entry); blockParameters.setIfDefined(key.substring(prefix.length()), entry.getValue()); } } if (log.isDebugEnabled()) { log.debug("Set " + blockParameters); } }
protected String getPrefix(final State state) { // return "_" + renderer.getBlock().getComponent().getName() + "_" + // renderer.getBlock().getName() + "_" + count + "_"; return state.getId() + ":"; }
/** * Basic Framework implicitely also processes, i'm not sure if we should require any framework to * do that (perhaps we could say, that the render method must process, if that is necessary, and * not yet done). */ @Override public void render( Renderer renderer, Parameters blockParameters, Parameters frameworkParameters, Writer w, WindowState windowState) throws FrameworkException { ServletRequest request = frameworkParameters.get(Parameter.REQUEST); if (request == null) { throw new IllegalArgumentException("No request object given"); } State state = State.getState(request); if (state .isRendering()) { // mm:component used during rending of a component, that's fine, but use a // new State. state = new State(request); log.debug("Alreadying rendering, taking a new state for sub-block-rendering: " + state); } log.debug("Rendering " + renderer.getBlock() + " " + renderer); Object prevHints = request.getAttribute(RenderHints.KEY); try { request.setAttribute(COMPONENT_CLASS_KEY, getComponentClass()); request.setAttribute(COMPONENT_CURRENTUSER_KEY, getUserNode(frameworkParameters)); Renderer actualRenderer = state.startBlock(frameworkParameters, renderer); if (!actualRenderer.equals(renderer)) { Parameters newBlockParameters = actualRenderer.getBlock().createParameters(); newBlockParameters.setAllIfDefined(blockParameters); blockParameters = newBlockParameters; } state.setAction(request.getParameter(ACTION.getName())); if (state.needsProcess()) { log.service("Performing action on " + actualRenderer.getBlock()); Processor processor = actualRenderer.getBlock().getProcessor(); state.process(processor); log.service("Processing " + actualRenderer.getBlock() + " " + processor); setBlockParametersForProcess(state, blockParameters); processor.process(blockParameters); state.endProcess(); } state.render(actualRenderer); setBlockParametersForRender(state, blockParameters); RenderHints hints = new RenderHints( actualRenderer, windowState, state.getId(), getComponentClass(), RenderHints.Mode.NORMAL); request.setAttribute(RenderHints.KEY, hints); actualRenderer.render(blockParameters, w, hints); request.setAttribute("org.mmbase.framework.hints", hints); } catch (FrameworkException fe) { log.debug(fe); URI uri = renderer.getUri(); Renderer error = new ErrorRenderer( renderer.getType(), renderer.getBlock(), (uri != null) ? uri.toString() : null, 500, fe); RenderHints hints = new RenderHints( error, windowState, state.getId(), getComponentClass(), RenderHints.Mode.NORMAL); error.render(blockParameters, w, hints); } finally { request.setAttribute(RenderHints.KEY, prevHints); state.endBlock(); } }
/** @todo */ protected void setBlockParametersForProcess(State state, Parameters blockParameters) { ServletRequest request = state.getRequest(); for (Map.Entry<String, ?> entry : blockParameters.toMap().entrySet()) { request.setAttribute(entry.getKey(), entry.getValue()); } }