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

📄 parambean.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  ParamBean//  EV      03.11.2000//  EV      23.12.2000  SettingsBean now in ParamBean//  SH      24.01.2001  added getSession accessor//  SH      24.01.2001  added some debugging code and some comments about comportement under Orion//	DJ		30.01.2001  added an internal wrapper for FileUpload/HttpServletRequest getParameter.//  SH      04.02.2001  added some comments on InputStream, Parameters, WebApps problems + javadoc//  MJ      21.03.2001  replaced basic URL parameters with PathInfo elements//	NK		17.04.2001	added Multisite features//	NK		14.05.2001  Jump to requested site's home page when the actual requested page is not of this site//						instead of page not found Exception.//	NK		11.07.2001  Added last requested page parameter//  JB      25.10.2001  Added setOperationMode methode//  SH      01.02.2002  Added defaultParameterValues hashtable to reduce URL length//                      when using default values for engine names, operation//                      modes, etc...////  settings//  getRequest//  getResponse//  getContext//  getHttpMethod//  getEngine//  getOperationMode//  getPageID//  getPage//  getUser//  getFieldID//  getSession////	setUserGuest()		; sets the current user to guest////  composeUrl//  composePageUrl//  composeEngineUrl//  composeOperationUrl//// Development notes : for the moment this class does not handle the problematic// of reading an input stream multiple times. This can cause problems if for// example Jahia needs to read the InputStream object from the request before// forwarding it to a web application. Also, under some server implementations,// such as the Orion server, retrieving an InputStream object before reading the// parameters will cause an error when trying to call a getParameter method.// The main issue of all this is that we are very dependant on the implementation// of these methods right now. A solution that was studied involved writing// parsers for the content of the request and managing the body internally inside// Jahia. This is probably the most solid way to do it, but it involves a lot of// development, especially since there should be a significant performance hit// if not done fully.// Basically the solution would be something like this :// 1. Jahia retrieves the InputStream (or Reader) object// 2. Jahia retrieves the full content and stores it either in memory or on disk// depending on some criteria to be defined (size, type of request ?)// 3. Jahia parses the parameters included in the request body, making sure it// then uses only the result of that parsing internally// 4. Jahia's dispatching service can then emulate a full web container behaviour// without much problems, since it can intercept everything, include the request// body (which is the part of the emulation currently missing). So the application// could indeed retrieve an InputStream or a Reader that is passed the body only// of that application and that comes from memory or disk storage instead of the// socket.//// Advantages :// - Allows for a FULL implementation of a request object// - Allows Jahia and web applications to process the request multiple times// - Improved security because we could only pass the body that concerns the// web application.//// Disadvantages :// - Serious performance hit because the worst case is : Jahia processes the// request body, parses it, forwards it to the app, that reprocesses it again !// The current case is : Jahia forwards it directly to the webapp, not reading// it most of the time.// - Loss of security because in some cases an application can receive a GET// request that actually has the body of a POST request (this is because the// emulation replaces the URL but not the body currently, mostly for performance// reasons).// - More usage of resources, since request bodies should have to be stored// in memory and/or on disk, probably multiple times.// The current decision was not to go forward with this implementation since it// will involve a lot of work and that the benefits are dependant on the applications// that must run under it. If the applications do not undergo problems in the// meantime the current solution should be sufficient.///** * @todo Implement a default setting for URLs, so as to avoid generating URL's * with /engine/core, /cache/on etc when these are the actual defaults * * @todo Implement a system to store parameters either in the session or in * the URL, transparently, in order to generate short URLs * * @todo Implement static (or search engine) friendly URLs, such as .html ending * URLs */package org.jahia.params;import java.io.*;import java.util.*;import javax.servlet.*;					// ServletContextimport javax.servlet.http.*;            // HttpServletRequestimport org.jahia.tools.files.*;           // FileUploadimport org.jahia.bin.Jahia;import org.jahia.utils.*;           // JahiaConsoleimport org.jahia.settings.*;        // Settingsimport org.jahia.registries.*;      // ServicesRegistryimport org.jahia.services.sites.JahiaSite;import org.jahia.data.events.*;     // JahiaEventimport org.jahia.services.applications.*; // ServletInculdeRequestWrapperimport org.jahia.services.pages.JahiaPage;import org.jahia.utils.properties.*;            // PropertiesManagerimport org.jahia.services.usermanager.JahiaUser;import org.jahia.services.usermanager.JahiaUserManagerService;import org.jahia.services.applications.ServletIncludeResponseWrapper;import org.jahia.services.htmlcache.CacheServerService;import org.jahia.exceptions.JahiaException;import org.jahia.exceptions.JahiaPageNotFoundException;import org.jahia.exceptions.JahiaSessionExpirationException;import org.jahia.exceptions.JahiaSiteNotFoundException;/** * This object contains most of the request context, including object such as * the request and response objects, sessions, engines, contexts, ... It also * contains methods for generating URLs for output generation. * * @author Eric Vassalli * @author Khue NGuyen * @author Fulco Houkes * @author David Jilli * @author Serge Huber * @author Mikhael Janson */public class ParamBean {    private static final String CLASS_NAME = ParamBean.class.getName ();    public static final String ENGINE_NAME_PARAMETER = "engineName";    public static final String SITE_KEY_PARAMETER = "site";    public static final String PAGE_ID_PARAMETER = "pid";  // refers to the same as current page or new requested page    public static final String FIELD_ID_PARAMETER = "fid";    public static final String OPERATION_MODE_PARAMETER = "op";    public static final String CACHE_MODE_PARAMETER = "cache";    public static final String CONTAINER_SCROLL_PREFIX_PARAMETER = "ctnscroll_";    public static final String DEFAULT_SITE_PROPERTY = "defaultSite";    /** default page id */    public static final String DEFAULT_PAGE_ID = "1";    /** Engine core name */    public static final String CORE_ENGINE_NAME = "core";    // http modes    public static final int GET_METHOD = 1;    public static final int POST_METHOD = 2;    // navigation operations    public static final String NORMAL = "normal";         // normal navigation    public static final String EDIT = "edit";           // edit navigation    public static final String DEBUG = "debug";          // debug navigation    // cache modes    public static final String CACHE_ON = "on";    public static final String CACHE_ONLYUPDATE = "onlyupdate";     // means we only want to update the cache, not read from it    public static final String CACHE_OFFONCE = "offonce";        // off only for the current request, all the generated URLs will be wich cache    public static final String CACHE_BYPASS = "bypass";         // the request will be done completely ignoring cache, but all the URLs will have the cache activated    public static final String CACHE_OFF = "off";    // session names    public static final String SESSION_USER = "org.jahia.usermanager.jahiauser";    public static final String SESSION_SITE = "org.jahia.services.sites.jahiasite";    public static final String SESSION_DEFAULT_SITE = "org.jahia.services.sites.jahiadefaultsite";    public static final String SESSION_LAST_REQUESTED_PAGE_ID = "org.jahia.params.lastrequestedpageid";    public static final String SESSION_LAST_ENGINE_NAME = "org.jahia.engines.lastenginename";    public static final String SESSION_JAHIA_RUNNING_MODE = "org.jahia.bin.jahiarunningmode";    public static final String SESSION_JAHIA_ENGINEMAP = "jahia_session_engineMap";    private long startTime = 0;    private int httpMethod = 0;    private String engineName = "";    private int fieldID = 0;    private String opMode = "";    private HttpServletRequest mRequest;    private HttpServletResponse mRealResponse;    // The new mResponse format is used for content caching.    private ServletIncludeResponseWrapper mResponse;    private ServletContext context;    private SettingsBean theSettings;    private JahiaPage thePage;    private JahiaUser theUser = null;    private String userAgent = "";    private Locale currentLocale = null;    //private int 				jahiaID				= -1;		// FIXME_MULTISITE Hollis: jahiaID = siteID redondant info    // DaDa'S requested a Server key in the Datasourcing context    // So Sirdrake what is your opinion ? It's your baby so choose    // and let me know.    private String anchor = null;    private int siteID = -1;    private String siteKey = null;    private JahiaSite site;    private boolean siteHasChanged = false;    /**     * @associates String     */    private Map customParameters = new HashMap ();    private int lastRequestedPageID = 0;    private boolean newPageRequest = false; // true , if a new page is requested    private String lastEngineName = null;    private boolean engineHasChanged = false; // true , if the current engine differs with the previous engine    private String coreHttpPath = "";    private String cacheStatus = CACHE_ON;  // cache is activated by default.    private String originalCacheStatus = cacheStatus; // this represents the original request cache status.    private Date cacheExpirationDate;    private static Properties defaultParameterValues;         // stores the default values for parameters.    static {        /** @todo we might want to put this in a configuration file so the         *  administrator can change it.         */        // static constructor for defaultParameterValues;        defaultParameterValues = new Properties ();        defaultParameterValues.setProperty (ParamBean.ENGINE_NAME_PARAMETER, ParamBean.CORE_ENGINE_NAME);        defaultParameterValues.setProperty (ParamBean.OPERATION_MODE_PARAMETER, ParamBean.NORMAL);        defaultParameterValues.setProperty (ParamBean.SITE_KEY_PARAMETER, "");        defaultParameterValues.setProperty (ParamBean.CACHE_MODE_PARAMETER, ParamBean.CACHE_ON);        // defaultParameterValues.setProperty(ParamBean.PAGE_ID_PARAMETER, ParamBean.DEFAULT_PAGE_ID); // doesn't work yet because of logout engine URL mess    }    /**     * This constructor is used by AdminParamBean to create a ParamBean     * with the minimum data requirement needed to work within JahiaAdministration Servlet     * Do not use this constructor within Jahia Servlet     */    ParamBean (HttpServletRequest request,               HttpServletResponse response,               ServletContext context,               JahiaPrivateSettings jSettings,               long startTime,               int httpMethod,               JahiaSite site,               JahiaUser user,               JahiaPage page)            throws JahiaPageNotFoundException,            JahiaSessionExpirationException,            JahiaSiteNotFoundException,            JahiaException {        // default vars        this.engineName = CORE_ENGINE_NAME;        this.opMode = NORMAL;        // objects        theSettings = new SettingsBean (jSettings);        // main vars        mRequest = request;        mRealResponse = response;        mResponse = new ServletIncludeResponseWrapper (response, false, null);        this.context = context;        this.startTime = startTime;        this.httpMethod = httpMethod;        this.site = site;        this.siteID = site.getID ();        this.siteKey = site.getSiteKey ();        thePage = page;        theUser = user;        HttpSession session = mRequest.getSession ();        // last requested page        Integer lrpID = (Integer)session.getAttribute (SESSION_LAST_REQUESTED_PAGE_ID);        if ((lrpID == null)) {            lrpID = new Integer (-1);        }        this.newPageRequest = (lrpID.intValue () != this.getPageID ());        this.lastRequestedPageID = lrpID.intValue ();        // Get the current user out of the session. If there is no user        // present, then assign the guest user to this session.        theUser = (JahiaUser)session.getAttribute (SESSION_USER);        if (theUser == null) {            setUserGuest (this.getSiteID ());        }        Enumeration userAgentValues = mRequest.getHeaders ("user-agent");        if (userAgentValues.hasMoreElements ()) {            // we only take the first value.            userAgent = (String)userAgentValues.nextElement ();        }    }    /***     * constructor     * EV    03.11.2000     * EV    04.11.2000  now request object in parameters     * EV    05.11.2000  invalid page passed from critical to error     * EV    20.11.2000  okay, everything changed... old framework, get a life

⌨️ 快捷键说明

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