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

📄 webrequestcodingstrategy.java

📁 Wicket一个开发Java Web应用程序框架。它使得开发web应用程序变得容易而轻松。 Wicket利用一个POJO data beans组件使得它可以与任何持久层技术相结合。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * 	 * If you override this method to behave different then also	 * {@link #addResourceParameters(Request, RequestParameters)} should be overridden to be in sync	 * with that behavior.	 * 	 * @param requestCycle	 *            the current request cycle	 * @param requestTarget	 *            the target to encode	 * @return the encoded url	 */	protected CharSequence encode(RequestCycle requestCycle,			ISharedResourceRequestTarget requestTarget)	{		final String sharedResourceKey = requestTarget.getResourceKey();		if ((sharedResourceKey == null) || (sharedResourceKey.trim().length() == 0))		{			return "";		}		else		{			final AppendingStringBuffer buffer = new AppendingStringBuffer(sharedResourceKey					.length());			buffer.append(RESOURCES_PATH_PREFIX);			buffer.append(sharedResourceKey);			Map map = requestTarget.getRequestParameters().getParameters();			if (map != null && map.size() > 0)			{				buffer.append('?');				Iterator it = map.entrySet().iterator();				while (it.hasNext())				{					Map.Entry entry = (Entry)it.next();					buffer.append(entry.getKey());					buffer.append('=');					buffer.append(entry.getValue());					if (it.hasNext())					{						buffer.append('&');					}				}			}			return buffer;		}	}	/**	 * Encode a listener interface target.	 * 	 * If you override this method to behave different then also	 * {@link #addInterfaceParameters(Request, RequestParameters)} should be overridden to be in	 * sync with that behavior.	 * 	 * @param requestCycle	 *            the current request cycle	 * @param requestTarget	 *            the target to encode	 * @return the encoded url	 */	protected CharSequence encode(RequestCycle requestCycle,			IListenerInterfaceRequestTarget requestTarget)	{		final RequestListenerInterface rli = requestTarget.getRequestListenerInterface();		// Start string buffer for url		final AppendingStringBuffer url = new AppendingStringBuffer(64);		url.append('?');		url.append(INTERFACE_PARAMETER_NAME);		url.append('=');		// Get component and page for request target		final Component component = requestTarget.getTarget();		final Page page = component.getPage();		// Add pagemap		final IPageMap pageMap = page.getPageMap();		if (!pageMap.isDefault())		{			url.append(pageMap.getName());		}		url.append(Component.PATH_SEPARATOR);		// Add path to component		url.append(component.getPath());		url.append(Component.PATH_SEPARATOR);		// Add version		final int versionNumber = component.getPage().getCurrentVersionNumber();		if (!rli.getRecordsPageVersion())		{			url.append(Page.LATEST_VERSION);		}		else if (versionNumber > 0)		{			url.append(versionNumber);		}		url.append(Component.PATH_SEPARATOR);		// Add listener interface		final String listenerName = rli.getName();		if (!IRedirectListener.INTERFACE.getName().equals(listenerName))		{			url.append(listenerName);		}		url.append(Component.PATH_SEPARATOR);		// Add behaviourId		RequestParameters params = requestTarget.getRequestParameters();		if (params != null && params.getBehaviorId() != null)		{			url.append(params.getBehaviorId());		}		url.append(Component.PATH_SEPARATOR);		// Add URL depth		if (params != null && params.getUrlDepth() != 0)		{			url.append(params.getUrlDepth());		}		if (IActivePageBehaviorListener.INTERFACE.getName().equals(listenerName))		{			url.append(url.indexOf("?") > -1 ? "&amp;" : "?").append(					IGNORE_IF_NOT_ACTIVE_PARAMETER_NAME).append("=true");		}		return url;	}	/**	 * Encode a page target.	 * 	 * @param requestCycle	 *            the current request cycle	 * @param requestTarget	 *            the target to encode	 * @return the encoded url	 */	protected CharSequence encode(RequestCycle requestCycle, IPageRequestTarget requestTarget)	{		// Get the page we want a url from:		Page page = requestTarget.getPage();		// A url to a page is the IRedirectListener interface:		CharSequence urlRedirect = page.urlFor(IRedirectListener.INTERFACE);		// Touch the page once because it could be that it did go from stateless		// to stateful or it was a internally made page where just a url must		// be made for (frames)		Session.get().touch(page);		return urlRedirect;	}	/**	 * Gets the mount encoder for the given request target if any.	 * 	 * @param requestTarget	 *            the request target to match	 * @return the mount encoder if any	 */	protected IRequestTargetUrlCodingStrategy getMountEncoder(IRequestTarget requestTarget)	{		synchronized (mountsOnPath)		{			// TODO Post 1.2: Performance: Optimize algorithm if possible and/ or			// cache lookup results			for (Iterator i = mountsOnPath.strategies().iterator(); i.hasNext();)			{				IRequestTargetUrlCodingStrategy encoder = (IRequestTargetUrlCodingStrategy)i.next();				if (encoder.matches(requestTarget))				{					return encoder;				}			}		}		return null;	}	/**	 * Gets the request info path. This is an overridable method in order to provide users with a	 * means to implement e.g. a path encryption scheme. This method by default returns	 * {@link Request#getPath()}.	 * 	 * @param request	 *            the request	 * @return the path info object, possibly processed	 */	protected String getRequestPath(Request request)	{		return request.getPath();	}	/**	 * Map used to store mount paths and their corresponding url coding strategies.	 * 	 * @author ivaynberg	 */	private static class MountsMap	{		private static final long serialVersionUID = 1L;		/** case sensitive flag */		private final boolean caseSensitiveMounts;		/** backing map */		private final TreeMap map;		/**		 * Constructor		 * 		 * @param caseSensitiveMounts		 *            whether or not keys of this map are case-sensitive		 */		public MountsMap(boolean caseSensitiveMounts)		{			map = new TreeMap(LENGTH_COMPARATOR);			this.caseSensitiveMounts = caseSensitiveMounts;		}		/**		 * Checks if the specified path matches any mount, and if so returns the coding strategy for		 * that mount. Returns null if the path doesn't match any mounts.		 * 		 * NOTE: path here is not the mount - it is the full url path		 * 		 * @param path		 *            non-null url path		 * @return coding strategy or null		 */		public IRequestTargetUrlCodingStrategy strategyForPath(String path)		{			if (path == null)			{				throw new IllegalArgumentException("Argument [[path]] cannot be null");			}			if (caseSensitiveMounts == false)			{				path = path.toLowerCase();			}			for (final Iterator it = map.entrySet().iterator(); it.hasNext();)			{				final Map.Entry entry = (Entry)it.next();				final String key = (String)entry.getKey();				if (path.startsWith(key))				{					IRequestTargetUrlCodingStrategy strategy = (IRequestTargetUrlCodingStrategy)entry							.getValue();					if (strategy.matches(path))					{						return strategy;					}				}			}			return null;		}		/**		 * @return number of mounts in the map		 */		public int size()		{			return map.size();		}		/**		 * @return collection of coding strategies associated with every mount		 */		public Collection strategies()		{			return map.values();		}		/**		 * Removes mount from the map		 * 		 * @param mount		 */		public void unmount(String mount)		{			if (caseSensitiveMounts == false && mount != null)			{				mount = mount.toLowerCase();			}			map.remove(mount);		}		/**		 * Gets the coding strategy for the specified mount path		 * 		 * @param mount		 *            mount path		 * @return associated coding strategy or null if none		 */		public IRequestTargetUrlCodingStrategy strategyForMount(String mount)		{			if (caseSensitiveMounts == false && mount != null)			{				mount = mount.toLowerCase();			}			return (IRequestTargetUrlCodingStrategy)map.get(mount);		}		/**		 * Associates a mount with a coding strategy		 * 		 * @param mount		 * @param encoder		 * @return previous coding strategy associated with the mount, or null if none		 */		public IRequestTargetUrlCodingStrategy mount(String mount,				IRequestTargetUrlCodingStrategy encoder)		{			if (caseSensitiveMounts == false && mount != null)			{				mount = mount.toLowerCase();			}			return (IRequestTargetUrlCodingStrategy)map.put(mount, encoder);		}		/** Comparator implementation that sorts longest strings first */		private static final Comparator LENGTH_COMPARATOR = new Comparator()		{			public int compare(Object o1, Object o2)			{				// longer first				if (o1 == o2)				{					return 0;				}				else if (o1 == null)				{					return 1;				}				else if (o2 == null)				{					return -1;				}				else				{					final String lhs = (String)o1;					final String rhs = (String)o2;					return rhs.compareTo(lhs);				}			}		};	}	/**	 * Makes page map name url safe.	 * 	 * Since the default page map name in wicket is null and null does not encode well into urls	 * this method will substitute null for a known token. If the <code>pageMapName</code> passed	 * in is not null it is returned without modification.	 * 	 * @param pageMapName	 *            page map name	 * @return encoded pagemap name	 */	public static final String encodePageMapName(String pageMapName)	{		if (Strings.isEmpty(pageMapName))		{			return DEFAULT_PAGEMAP_NAME;		}		else		{			return pageMapName;		}	}	/**	 * Undoes the effect of {@link #encodePageMapName(String)}	 * 	 * @param pageMapName	 *            page map name	 * @return decoded page map name	 */	public static String decodePageMapName(String pageMapName)	{		if (DEFAULT_PAGEMAP_NAME.equals(pageMapName))		{			return null;		}		else		{			return pageMapName;		}	}}

⌨️ 快捷键说明

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