本文整理汇总了Java中org.directwebremoting.WebContext类的典型用法代码示例。如果您正苦于以下问题:Java WebContext类的具体用法?Java WebContext怎么用?Java WebContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebContext类属于org.directwebremoting包,在下文中一共展示了WebContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUsersToAffect
import org.directwebremoting.WebContext; //导入依赖的package包/类
/**
* @return The collection of people to affect
*/
private Collection getUsersToAffect()
{
WebContext wctx = WebContextFactory.get();
String currentPage = wctx.getCurrentPage();
// For all the browsers on the current page:
Collection sessions = wctx.getScriptSessionsByPage(currentPage);
// But not the current user!
sessions.remove(wctx.getScriptSession());
log.debug("Affecting " + sessions.size() + " users");
return sessions;
}
示例2: generateId
import org.directwebremoting.WebContext; //导入依赖的package包/类
/**
* Generates and returns a new unique id suitable to use for the
* CSRF session cookie. This method is itself exempted from CSRF checking.
*/
public String generateId()
{
WebContext webContext = WebContextFactory.get();
// If the current session already has a set DWRSESSIONID then we return that
HttpServletRequest request = webContext.getHttpServletRequest();
HttpSession sess = request.getSession(false);
if (sess != null && sess.getAttribute(ATTRIBUTE_DWRSESSIONID) != null)
{
return (String) sess.getAttribute(ATTRIBUTE_DWRSESSIONID);
}
// Otherwise generate a fresh ID
IdGenerator idGenerator = webContext.getContainer().getBean(IdGenerator.class);
return idGenerator.generate();
}
示例3: getNowPlayingForCurrentPlayer
import org.directwebremoting.WebContext; //导入依赖的package包/类
/**
* Returns details about what the current player is playing.
*
* @return Details about what the current player is playing, or <code>null</code> if not playing anything.
*/
public NowPlayingInfo getNowPlayingForCurrentPlayer() throws Exception {
WebContext webContext = WebContextFactory.get();
Player player = playerService.getPlayer(webContext.getHttpServletRequest(), webContext.getHttpServletResponse());
for (NowPlayingInfo info : getNowPlaying()) {
if (player.getId().equals(info.getPlayerId())) {
return info;
}
}
return null;
}
示例4: storeParsedRequest
import org.directwebremoting.WebContext; //导入依赖的package包/类
/**
* Build a Batch and put it in the request
* @param request Where we store the parsed data
* @param webContext We need to notify others of some of the data we find
* @param batch The parsed data to store
*/
private void storeParsedRequest(HttpServletRequest request, WebContext webContext, Batch batch)
{
String normalizedPage = pageNormalizer.normalizePage(batch.getPage());
webContext.setCurrentPageInformation(normalizedPage, batch.getScriptSessionId());
// Remaining parameters get put into the request for later consumption
Map paramMap = batch.getSpareParameters();
if (paramMap.size() != 0)
{
for (Iterator it = paramMap.entrySet().iterator(); it.hasNext();)
{
Map.Entry entry = (Map.Entry) it.next();
String key = (String) entry.getKey();
String value = (String) entry.getValue();
request.setAttribute(key, value);
log.debug("Moved param to request: " + key + "=" + value);
}
}
}
示例5: convertInbound
import org.directwebremoting.WebContext; //导入依赖的package包/类
public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx)
{
WebContext webcx = WebContextFactory.get();
if (HttpServletRequest.class.isAssignableFrom(paramType))
{
return webcx.getHttpServletRequest();
}
if (HttpServletResponse.class.isAssignableFrom(paramType))
{
return webcx.getHttpServletResponse();
}
if (ServletConfig.class.isAssignableFrom(paramType))
{
return webcx.getServletConfig();
}
if (ServletContext.class.isAssignableFrom(paramType))
{
return webcx.getServletContext();
}
if (HttpSession.class.isAssignableFrom(paramType))
{
return webcx.getSession(true);
}
return null;
}
示例6: forwardToString
import org.directwebremoting.WebContext; //导入依赖的package包/类
public String forwardToString(String url) throws ServletException, IOException
{
StringWriter sout = new StringWriter();
StringBuffer buffer = sout.getBuffer();
HttpServletResponse realResponse = getHttpServletResponse();
HttpServletResponse fakeResponse = new SwallowingHttpServletResponse(realResponse, sout, realResponse.getCharacterEncoding());
HttpServletRequest realRequest = getHttpServletRequest();
realRequest.setAttribute(WebContext.ATTRIBUTE_DWR, Boolean.TRUE);
getServletContext().getRequestDispatcher(url).forward(realRequest, fakeResponse);
return buffer.toString();
}
示例7: Publisher
import org.directwebremoting.WebContext; //导入依赖的package包/类
/**
* Create a new publish thread and start it
*/
public Publisher()
{
WebContext webContext = WebContextFactory.get();
ServletContext servletContext = webContext.getServletContext();
serverContext = ServerContextFactory.get(servletContext);
// A bit nasty: the call to serverContext.getScriptSessionsByPage()
// below could fail because the system might need to read web.xml which
// means it needs a ServletContext, which is only available using
// WebContext, which in turn requires a DWR thread. We can cache the
// results simply by calling this in a DWR thread, as we are now.
webContext.getScriptSessionsByPage("");
synchronized (Publisher.class)
{
if (worker == null)
{
worker = new Thread(this, "Publisher");
worker.start();
}
}
}
示例8: disengageThread
import org.directwebremoting.WebContext; //导入依赖的package包/类
public void disengageThread()
{
// null check for DWR-426 - DefaultWebContextBuilder disengageThread throws null pointer exception.
if (contextStack != null)
{
ArrayList<WebContext> stack = contextStack.get();
if (stack != null)
{
if (stack.size() > 0)
{
stack.remove(stack.size() - 1);
}
if (stack.size() == 0)
{
contextStack.set(null);
}
}
}
}
示例9: subscribe
import org.directwebremoting.WebContext; //导入依赖的package包/类
/**
* Ensure that the clients know about server publishes
* @param topic The topic being subscribed to
* @param subscriptionId The ID to pass back to link to client side data
*/
@SuppressWarnings("unchecked")
public void subscribe(String topic, String subscriptionId)
{
WebContext webContext = WebContextFactory.get();
Hub hub = HubFactory.get();
final ScriptSession session = webContext.getScriptSession();
// Create a subscription block
BrowserMessageListener subscription = new BrowserMessageListener(session, topic, subscriptionId);
Map<String, BrowserMessageListener> subscriptions = (Map<String, BrowserMessageListener>) session.getAttribute(ATTRIBUTE_SUBSCRIPTIONS);
if (subscriptions == null)
{
subscriptions = new HashMap<String, BrowserMessageListener>();
}
subscriptions.put(subscriptionId, subscription);
session.setAttribute(ATTRIBUTE_SUBSCRIPTIONS, subscriptions);
hub.subscribe(subscription.topic, subscription);
}
示例10: execute
import org.directwebremoting.WebContext; //导入依赖的package包/类
@Override
public Replies execute(Calls calls) {
WebContext webContext=WebContextFactory.get();
String uri = webContext.getHttpServletRequest().getRequestURI();
if(uri.indexOf("__System.pageLoaded")>-1||uri.indexOf("LoginService.adminLogin")>-1
||uri.indexOf("LoginService.merUserLogin")>-1){
return super.execute(calls);
}
HttpSession session = webContext.getSession(false);
// String page=webContext.getCurrentPage();
if (session == null) {
logOut();
return super.execute(new Calls());
}
return super.execute(calls);
}
示例11: renderAsync
import org.directwebremoting.WebContext; //导入依赖的package包/类
/**
* {@inheritDoc}
* @throws Exception sometimes things just don't work out
*/
public String renderAsync() throws Exception {
WebContext ctx = WebContextFactory.get();
HttpServletRequest req = ctx.getHttpServletRequest();
RequestContext rhnCtx = new RequestContext(req);
User user = rhnCtx.getCurrentUser();
PageControl pc = new PageControl();
pc.setStart(1);
pc.setPageSize(PAGE_SIZE);
render(user, pc, req);
HttpServletResponse resp = ctx.getHttpServletResponse();
return RendererHelper.renderRequest(
getPageUrl(),
req,
resp);
}
示例12: renderAsync
import org.directwebremoting.WebContext; //导入依赖的package包/类
/**
* Renders Action Chain entries from an Action Chain having a certain sort
* order number.
* @param actionChainId Action Chain identifier
* @param sortOrder sort order number
* @return a response string
* @throws ServletException if something goes wrong
* @throws IOException if something goes wrong
*/
public String renderAsync(Long actionChainId, Integer sortOrder)
throws ServletException, IOException {
WebContext webContext = WebContextFactory.get();
HttpServletRequest request = webContext.getHttpServletRequest();
User u = new RequestContext(request).getCurrentUser();
ActionChain actionChain = ActionChainFactory.getActionChain(u, actionChainId);
request.setAttribute("sortOrder", sortOrder);
request.setAttribute("entries",
ActionChainFactory.getActionChainEntries(actionChain, sortOrder));
HttpServletResponse response = webContext.getHttpServletResponse();
return RendererHelper.renderRequest(
"/WEB-INF/pages/common/fragments/schedule/actionchainentries.jsp", request,
response);
}
示例13: getProtocolTypes
import org.directwebremoting.WebContext; //导入依赖的package包/类
public String[] getProtocolTypes()
{
WebContext webContext = WebContextFactory.get();
HttpServletRequest request = webContext.getHttpServletRequest();
try {
SortedSet<String> types = null;
types = InitSetup.getInstance().getDefaultAndOtherTypesByLookup(
request, "protocolTypes", "protocol", "type", "otherType", true);
types.add("");
String[] eleArray = new String[types.size()];
return types.toArray(eleArray);
} catch (Exception e) {
logger.error("Problem setting protocol types: \n", e);
e.printStackTrace();
}
return new String[] { "" };
}
示例14: getPublicationCategories
import org.directwebremoting.WebContext; //导入依赖的package包/类
public String[] getPublicationCategories(String searchLocations) {
WebContext wctx = WebContextFactory.get();
HttpServletRequest request = wctx.getHttpServletRequest();
try {
SortedSet<String> types = InitSetup.getInstance()
.getDefaultAndOtherTypesByLookup(request,
"publicationCategories", "publication", "category",
"otherCategory", true);
types.add("");
String[] eleArray = new String[types.size()];
return types.toArray(eleArray);
} catch (Exception e) {
logger.error("Problem getting publication types: \n", e);
e.printStackTrace();
}
return new String[] { "" };
}
示例15: getPublicationStatuses
import org.directwebremoting.WebContext; //导入依赖的package包/类
public String[] getPublicationStatuses() {
WebContext wctx = WebContextFactory.get();
HttpServletRequest request = wctx.getHttpServletRequest();
try {
SortedSet<String> types = InitSetup.getInstance()
.getDefaultAndOtherTypesByLookup(request,
"publicationStatuses", "publication", "status", "otherStatus", true);
types.add("");
String[] eleArray = new String[types.size()];
return types.toArray(eleArray);
} catch (Exception e) {
logger.error("Problem getting publication statuses: \n", e);
e.printStackTrace();
}
return new String[] { "" };
}