⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 requestcycle.java

📁 Wicket一个开发Java Web应用程序框架。它使得开发web应用程序变得容易而轻松。 Wicket利用一个POJO data beans组件使得它可以与任何持久层技术相结合。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		// set start step		currentStep = PREPARE_REQUEST;		// loop through steps		steps();	}	/**	 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.	 * <p>	 * Responds to a request to re-render a single component.	 * </p>	 * <p>	 * NOTE: This method is typically only used for testing purposes.	 * </p>	 * 	 * @param component	 *            to be re-rendered	 */	public final void request(final Component component)	{		checkReuse();		if (component.isAuto())		{			throw new WicketRuntimeException("Auto-added components can not be re-rendered");		}		request(new ComponentRequestTarget(component));	}	/**	 * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.	 * <p>	 * Responds to a request with the request target.	 * 	 * @param target	 *            request target	 */	public final void request(IRequestTarget target)	{		checkReuse();		// set it as the current target, on the top of the stack		requestTargets.push(target);		// set start step		currentStep = PROCESS_EVENTS;		// loop through steps		steps();	}	/**	 * Permit clients like testers to examine feedback messages after processing.	 * 	 * @param automaticallyClearFeedbackMessages	 *            True to automatically detach request cycle at end of processing	 */	public void setAutomaticallyClearFeedbackMessages(boolean automaticallyClearFeedbackMessages)	{		// FIXME This method is a quick fix for a unit testing problem that		// should not exist		this.automaticallyClearFeedbackMessages = automaticallyClearFeedbackMessages;	}	/**	 * Sets whether the page for this request should be redirected.	 * 	 * @param redirect	 *            True if the page for this request cycle should be redirected to rather than	 *            directly rendered.	 */	public final void setRedirect(final boolean redirect)	{		this.redirect = redirect;	}	/**	 * @param request	 *            The request to set.	 */	public final void setRequest(Request request)	{		this.request = request;	}	/**	 * Sets the request target as the current.	 * 	 * @param requestTarget	 *            the request target to set as current	 */	public final void setRequestTarget(IRequestTarget requestTarget)	{		if (log.isDebugEnabled())		{			if (!requestTargets.isEmpty())			{				IRequestTarget former = (IRequestTarget)requestTargets.peek();				log.debug("replacing request target " + former + " with " + requestTarget);			}			else			{				log.debug("setting request target to " + requestTarget);			}		}		// change the current step to a step that will handle the		// new target if need be		if (currentStep >= RESPOND)		{			if (log.isDebugEnabled())			{				log.debug("rewinding request processing to PROCESS_EVENTS");			}			// we are not actually doing event processing again,			// but since we are still in the loop here, the next			// actual value will be RESPOND again			currentStep = PROCESS_EVENTS;		}		// NOTE: if we are at PROCESS_EVENTS, leave it as we don't		// want to re-execute that step again		requestTargets.push(requestTarget);	}	/**	 * Sets response.	 * 	 * @param response	 *            The response	 * @return the original response	 */	public final Response setResponse(final Response response)	{		final Response orig = this.response;		this.response = response;		return orig;	}	/**	 * Attempts to return name of current page map	 * 	 * @return	 */	private String getCurrentPageMap()	{		IRequestTarget target = RequestCycle.get().getRequestTarget();		if (target instanceof IPageRequestTarget)		{			Page page = ((IPageRequestTarget)target).getPage();			return page != null ? page.getPageMapName() : null;		}		else if (target instanceof IBookmarkablePageRequestTarget)		{			return ((IBookmarkablePageRequestTarget)target).getPageMapName();		}		else		{			return null;		}	}	/**	 * Convenience method that sets page class as the response. This will generate a redirect to the	 * page with a bookmarkable url	 * 	 * @param pageClass	 *            The page class to render as a response	 */	public final void setResponsePage(final Class pageClass)	{		setResponsePage(pageClass, null);	}	/**	 * Sets the page class with optionally the page parameters as the render target of this request.	 * 	 * @param pageClass	 *            The page class to render as a response	 * @param pageParameters	 *            The page parameters that gets appended to the bookmarkable url,	 */	public final void setResponsePage(final Class pageClass, final PageParameters pageParameters)	{		setResponsePage(pageClass, pageParameters, getCurrentPageMap());	}	/**	 * Sets the page class with optionally the page parameters and page map name as the render	 * target of this request.	 * 	 * @param pageClass	 *            The page class to render as a response	 * @param pageParameters	 *            The page parameters that gets appended to the bookmarkable url,	 * @param pageMapName	 *            The pagemap in which the response page should be created	 */	public final void setResponsePage(final Class pageClass, final PageParameters pageParameters,		final String pageMapName)	{		IRequestTarget target = new BookmarkablePageRequestTarget(pageMapName, pageClass,			pageParameters);		setRequestTarget(target);	}	/**	 * Sets the page as the render target of this request.	 * 	 * @param page	 *            The page to render as a response	 */	public final void setResponsePage(final Page page)	{		IRequestTarget target = new PageRequestTarget(page);		setRequestTarget(target);	}	/**	 * @see java.lang.Object#toString()	 */	public String toString()	{		return "[RequestCycle" + "@" + Integer.toHexString(hashCode()) + " thread=" +			Thread.currentThread().getName() + "]";	}	/**	 * @return true if the next to be encoded url is targeting a new window (ModalWindow, popup,	 *         tab).	 */	public final boolean isUrlForNewWindowEncoding()	{		return urlForNewWindowEncoding;	}	/**	 * Indicate if the next to be encoded url is targeting a new window (ModalWindow, popup, tab).	 * This temporary flag is specifically needed for portlet-support as then such a page needs a	 * special target (Resource) url. After each urlFor call, this flag is reset to false.	 */	public final void setUrlForNewWindowEncoding()	{		urlForNewWindowEncoding = true;	}	/**	 * Returns an encoded URL that references the given request target and clears the	 * urlForNewWindowEncoding flag.	 * 	 * @param requestTarget	 *            the request target to reference	 * @return a URL that references the given request target	 */	private final CharSequence encodeUrlFor(final IRequestTarget requestTarget)	{		CharSequence url = getProcessor().getRequestCodingStrategy().encode(this, requestTarget);		urlForNewWindowEncoding = false;		return url;	}	/**	 * Returns a bookmarkable URL that references a given page class using a given set of page	 * parameters. Since the URL which is returned contains all information necessary to instantiate	 * and render the page, it can be stored in a user's browser as a stable bookmark.	 * 	 * @param pageClass	 *            Class of page	 * @param parameters	 *            Parameters to page	 * @return Bookmarkable URL to page	 */	public final CharSequence urlFor(final Class pageClass, final PageParameters parameters)	{		return urlFor(null, pageClass, parameters);	}	/**	 * Returns a URL that references a given interface on a given behavior of a component. When the	 * URL is requested from the server at a later time, the interface on the behavior will be	 * called. A URL returned by this method will not be stable across sessions and cannot be	 * bookmarked by a user.	 * 	 * @param component	 *            The component to reference	 * @param behaviour	 *            The behavior to reference	 * @param listener	 *            The listener interface on the component	 * @return A URL that encodes a page, component, behavior and interface to call	 */	public final CharSequence urlFor(final Component component, final IBehavior behaviour,		final RequestListenerInterface listener)	{		int index = component.getBehaviors().indexOf(behaviour);		if (index == -1)		{			throw new IllegalArgumentException("Behavior " + this +				" was not registered with this component: " + component.toString());		}		RequestParameters params = new RequestParameters();		params.setBehaviorId(String.valueOf(index));		if (request instanceof ServletWebRequest)		{			ServletWebRequest swr = (ServletWebRequest)request;			// If we're coming in with an existing depth, use it. Otherwise,			// compute from the URL. This provides correct behavior for repeated			// AJAX requests: If we need to generate a URL within an AJAX			// request for another one, it needs to be at the same depth as the			// original AJAX request.			int urlDepth = swr.getRequestParameters().getUrlDepth();			params.setUrlDepth(urlDepth > -1 ? urlDepth : swr.getDepthRelativeToWicketHandler());		}		final IRequestTarget target = new BehaviorRequestTarget(component.getPage(), component,			listener, params);		return encodeUrlFor(target);	}	/**	 * Returns a URL that references a given interface on a component. When the URL is requested	 * from the server at a later time, the interface will be called. A URL returned by this method	 * will not be stable across sessions and cannot be bookmarked by a user.	 * 	 * @param component	 *            The component to reference	 * @param listener	 *            The listener interface on the component	 * @param params	 *            Additional parameters to pass to the page	 * @return A URL that encodes a page, component and interface to call	 */	public final CharSequence urlFor(final Component component,		final RequestListenerInterface listener, ValueMap params)	{		// Get Page holding component and mark it as stateful.		final Page page = component.getPage();		final IRequestTarget target;		if (listener != IRedirectListener.INTERFACE && component.isStateless() &&			page.isBookmarkable())		{			PageParameters pageParameters = page.getPageParameters();			if (pageParameters == null)			{				pageParameters = new PageParameters();			}			if (params != null)			{				Iterator it = params.entrySet().iterator();				while (it.hasNext())				{					final Map.Entry entry = (Entry)it.next();					final String key = entry.getKey().toString();					final String value = entry.getValue().toString();					pageParameters.add(encode(key), encode(value));				}			}			target = new BookmarkableListenerInterfaceRequestTarget(page.getPageMapName(),				page.getClass(), pageParameters, component, listener);			return encodeUrlFor(target);		}		else		{			page.setPageStateless(Boolean.FALSE);			// make session non-volatile if not already so			final Session session = getSession();			if (session.isTemporary())			{				session.bind();			}			// Get the listener interface name			target = new ListenerInterfaceRequestTarget(page, component, listener);			CharSequence url = encodeUrlFor(target);			if (params != null)			{				AppendingStringBuffer buff = new AppendingStringBuffer(url);				Iterator it = params.entrySet().iterator();				while (it.hasNext())				{					final Map.Entry entry = (Entry)it.next();					final String key = entry.getKey().toString();					final String value = entry.getValue().toString();					buff.append("&");					buff.append(encode(key));					buff.append("=");					buff.append(encode(value));				}				url = buff;			}			return url;		}	}	/**	 * Url encodes value using UTF-8	 * 	 * @param value	 *            value to encode	 * @return encoded value	 */	private static String encode(String value)	{		return RequestUtils.encode(value);	}	/**	 * Returns a URL that references a given interface on a component. When the URL is requested	 * from the server at a later time, the interface will be called. A URL returned by this method	 * will not be stable across sessions and cannot be bookmarked by a user.	 * 	 * @param component	 *            The component to reference	 * @param listener	 *            The listener interface on the component	 * @return A URL that encodes a page, component and interface to call	 */	public final CharSequence urlFor(final Component component,		final RequestListenerInterface listener)	{		return urlFor(component, listener, null);	}	/**	 * Returns a bookmarkable URL that references a given page class using a given set of page	 * parameters. Since the URL which is returned contains all information necessary to instantiate	 * and render the page, it can be stored in a user's browser as a stable bookmark.	 * 	 * @param pageMap	 *            Pagemap to use. If null is passed the default page map will be used	 * @param pageClass	 *            Class of page	 * @param parameters	 *            Parameters to page	 * @return Bookmarkable URL to page	 */	public final CharSequence urlFor(final IPageMap pageMap, final Class pageClass,		final PageParameters parameters)	{		final IRequestTarget target = new BookmarkablePageRequestTarget(pageMap == null			? PageMap.DEFAULT_NAME : pageMap.getName(), pageClass, parameters);		return encodeUrlFor(target);	}	/**	 * Returns a URL that references the given request target.	 * 	 * @param requestTarget	 *            the request target to reference	 * @return a URL that references the given request target	 */	public final CharSequence urlFor(final IRequestTarget requestTarget)	{		return encodeUrlFor(requestTarget);	}	/**	 * Returns a URL that references the given page. It also {@link Session#touch(Page) touches} the	 * page in the session so that it is put in the front of the page stack. Use this method only if	 * you plan to use it the next request.	 * 	 * @param page	 *            The page	 * @return The url pointing to the provided page	 */	public final CharSequence urlFor(final Page page)	{		IRequestTarget target = new PageRequestTarget(page);		getSession().touch(((IPageRequestTarget)target).getPage());		return encodeUrlFor(target);	}	/**	 * Returns a URL that references a shared resource through the provided resource reference.	 * 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -