📄 rollerrequest.java
字号:
{ mPage = userMgr.retrievePage(pageId); // We can use page to find the user, if we don't have one yet if ( mWebsite == null ) { mWebsite = mPage.getWebsite(); } } else if (mWebsite != null) { mPage = userMgr.retrievePage( mWebsite.getDefaultPageId() ); } // Look for day in request params String daystr = mRequest.getParameter(WEBLOGDAY_KEY); if ( daystr != null ) { mDate = parseDate(daystr); if ( mDate != null ) { // we have the /username/datestring form of URL mDateString = daystr; mIsDateSpecified = true; } } } catch ( Exception ignored ) { mLogger.debug("Exception parsing request params",ignored); } } //------------------------------------------------------------------------ /** Get HttpServletmRequest that is wrapped by this RollerRequest */ public PageContext getPageContext() { return mPageContext; } public void setPageContext(PageContext p) { mPageContext = p; } //------------------------------------------------------------------------ /** Get HttpServletmRequest that is wrapped by this RollerRequest */ public HttpServletRequest getRequest() { return mRequest; } //------------------------------------------------------------------------ /** * Get the RollerRequest object that is stored in the request. Creates * RollerRequest if one not found in mRequest. */ public static RollerRequest getRollerRequest( HttpServletRequest r, ServletContext ctx ) throws RollerException { RollerRequest ret= (RollerRequest)r.getAttribute(ROLLER_REQUEST); if ( ret == null ) { ret = new RollerRequest(r,ctx); r.setAttribute( ROLLER_REQUEST, ret ); } return ret; } //------------------------------------------------------------------------ /** * Get the RollerRequest object that is stored in the request. Creates * RollerRequest if one not found in mRequest. */ public static RollerRequest getRollerRequest( HttpServletRequest r ) { try { return getRollerRequest(r, RollerContext.getServletContext()); } catch (Exception e) { mLogger.debug("Unable to create a RollerRequest", e); } return null; } //------------------------------------------------------------------------ /** * Get the RollerRequest object that is stored in the request. Creates * RollerRequest if one not found in mRequest. */ public static RollerRequest getRollerRequest( PageContext p ) { HttpServletRequest r = (HttpServletRequest)p.getRequest(); RollerRequest ret = (RollerRequest)r.getAttribute(ROLLER_REQUEST); if (ret == null) { try { ret = new RollerRequest( p ); r.setAttribute( ROLLER_REQUEST, ret ); } catch (Exception e) { mLogger.debug("Unable to create a RollerRequest", e); } } else { ret.setPageContext( p ); } return ret; } //------------------------------------------------------------------------ /** * Get RollerRequest object for the current thread using EVIL MAGIC, * do not use unless you absolutely, positively, cannot use on of the * getRollerRequest() methods. */ public static RollerRequest getRollerRequest() { return (RollerRequest)mRollerRequestTLS.get(); } //------------------------------------------------------------------------ /** * Get the RollerRequest object that is stored in the requeset. * Creates RollerRequest if one not found in mRequest. */ public ServletContext getServletContext() { return mContext; } //------------------------------------------------------------------------ /** Get Roller instance from */ public Roller getRoller() { return RollerContext.getRoller( mRequest ); } //------------------------------------------------------------------------ /** Is mRequest's user the admin user? */ public boolean isAdminUser() throws RollerException { UserData user = getUser(); if (user != null && user.hasRole("admin")) { return true; } else { return false; } } //------------------------------------------------------------------------ /** Is mRequest's user authorized to edit the mRequested resource */ public boolean isUserAuthorizedToEdit() throws RollerException { // Make sure authenticated user is the owner of this item // Session's principal's name must match user name in mRequest RollerContext rctx = RollerContext.getRollerContext(mContext); Authenticator auth = rctx.getAuthenticator(); String userName = auth.getAuthenticatedUserName(mRequest); // TODO: A hack to be replaced by Object.canEdit() UserData owningUser = null; if (mRequest.getAttribute(OWNING_USER) != null) { owningUser = (UserData)mRequest.getAttribute(OWNING_USER); } else { owningUser = getUser(); } if ( userName != null && owningUser != null && userName.equalsIgnoreCase( owningUser.getUserName() ) && auth.isAuthenticatedUserInRole(mRequest,"editor")) { return true; } else { return false; } } //------------------------------------------------------------------------ /** * Get user by name. */ public UserData getUser( String userName ) throws Exception { return getRoller().getUserManager().getUser(userName); } //------------------------------------------------------------------------ public boolean isDateSpecified() { return mIsDateSpecified; } //------------------------------------------------------------------------ public int getWeblogEntryCount() { // Get count of entries to return, or 20 if null int count = 20; if ( mRequest.getParameter("count") != null ) { count= Utilities.stringToInt(mRequest.getParameter("count")); if ( count==0 || count>50 ) { count = 20; } } return count; } //------------------------------------------------------------------------ /** * Gets the date specified by the request, or null. * @return Date */ public Date getDate() { return getDate(false); } //------------------------------------------------------------------------ /** * Gets the date specified by the request * @param orToday If no date specified, then use today's date. * @return Date */ public Date getDate( boolean orToday ) { Date ret = null; if ( mDate != null ) { ret = mDate; } else if ( orToday ) { ret = getToday(); } return ret; } /** * Gets the current date based on Website's Locale & Timezone. * @return */ private Date getToday() { Calendar todayCal = Calendar.getInstance(); if (this.getWebsite() != null) { todayCal = Calendar.getInstance( this.getWebsite().getTimeZoneInstance(), this.getWebsite().getLocaleInstance()); } todayCal.setTime( new Date() ); return todayCal.getTime(); } //------------------------------------------------------------------------ /** * Gets the YYYYMMDD date string specified by the request, or null. * @return String */ public String getDateString() { return getDateString(false); } //------------------------------------------------------------------------ /** * Gets the date specified by the request * @param orToday If no date specified, then use today's date. * @return Date */ public String getDateString( boolean orToday ) { String ret = null; if ( mDateString != null ) { ret = mDateString; } else if ( orToday ) { Calendar todayCal = Calendar.getInstance(); if (this.getWebsite() != null) { todayCal = Calendar.getInstance( this.getWebsite().getTimeZoneInstance(), this.getWebsite().getLocaleInstance()); } todayCal.setTime( new Date() ); ret = mFmt.format(todayCal.getTime()); } return ret; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -