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

📄 parambean.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                if (pageIDStr != null) {                    // try to get the page reference.                    try {                        int pid = Integer.parseInt (pageIDStr);                        thePage = ServicesRegistry.getInstance ()                                .getJahiaPageService ().lookupPage (pid, this);                        // if the page is not found, throw the associated exception                        if (thePage != null) {                            this.siteID = thePage.getJahiaID ();                            // Try to get the site by its sitekey                            this.site = ServicesRegistry.getInstance ()                                    .getJahiaSitesService ()                                    .getSite (this.siteID);                            if (this.site != null)                                this.siteKey = site.getSiteKey ();                        }                    } catch (NumberFormatException nfe) {                        JahiaConsole.println ("ParamBean.getSiteInfos", "Number format exception");                        throw new JahiaPageNotFoundException (pageIDStr);                    }                    // Ensure if the requested page is a page of the current site                    if (thePage.getJahiaID () != this.getSiteID ()) {                        thePage = this.site.getHomePage ();                    }                }            } else {                JahiaConsole.println ("ParamBean.getSiteInfos",                        "Site found with serverName");                if (!(theSettings.isSiteIDInURL ())) {                    JahiaConsole.println ("ParamBean.getSiteInfos",                            "Adding default parameter values to site found in serverName");                    // we have found the site in the server name, let's set it in                    // the default parameter values.                    this.defaultParameterValues.setProperty (this.SITE_KEY_PARAMETER, site.getSiteKey ());                }            }            if (this.site == null) {                JahiaConsole.println ("ParamBean.getSiteInfos()",                        "No site found in URL, serverName or via page ID, going to default site...");                // finally try to get the default site                this.site = getDefaultSite ();                if ((this.site != null) && !(theSettings.isSiteIDInURL ())) {                    // since we loaded the default site let's remove it from the URL                    this.defaultParameterValues.setProperty (this.SITE_KEY_PARAMETER, site.getSiteKey ());                }            }        }        if (site == null) {            throw new JahiaSiteNotFoundException ("400 Bad Request : No site specified or site not found",                    JahiaException.CRITICAL);        }        this.siteID = this.site.getID ();        this.siteKey = this.site.getSiteKey ();        JahiaSite oldSite = (JahiaSite)session.getAttribute (SESSION_SITE);        if (oldSite == null) {            this.siteHasChanged = true;        } else if (oldSite.getID () != site.getID ()) {            this.siteHasChanged = true;            // setUserGuest(this.getSiteID());        }        if (!(theSettings.isSiteIDInURL ())) {            JahiaSite defaultSite = getDefaultSite ();            if ((defaultSite != null) && (defaultSite.getID () == site.getID ())) {                // site in URL is the default site, let's remove it from the                // URL                this.defaultParameterValues.setProperty (this.SITE_KEY_PARAMETER, site.getSiteKey ());            }        }        session.setAttribute (SESSION_SITE, site);    }    /**     * Return the default site or null if not found or undefined     *     * @return JahiaSite the default site     */    private JahiaSite getDefaultSite () {        // JahiaConsole.println("ParamBean","getDefaultSite started");        JahiaSite site = null;        String siteKey = null;        // try to load from storage        PropertiesManager pm = new PropertiesManager (Jahia.getJahiaPropertiesFileName ());        if (pm != null) {            siteKey = pm.getProperty ("defautSite");            if (siteKey == null || siteKey.trim ().equals ("")) {                return null;            }        }        if (siteKey != null) {            try {                site = ServicesRegistry.getInstance ()                        .getJahiaSitesService ()                        .getSiteByKey (siteKey);            } catch (JahiaException je) {                return null;            }        }        return site;    }    /**     * Returns an URL only if the parameterValue for the parameterName is     * different from its defined default value, or if it has no default     * value.     * @param parameterName name of the parameter to add in the URL     * @param parameterValue value of the parameter to add in the URL     * @return an empty string if the value is equal to the default value,     * otherwise it returns a composition as follow : "/" + parameterName +     * "/" + parameterValue     */    private String condAppendURL (String parameterName, String parameterValue) {        String defaultValue = defaultParameterValues.getProperty (parameterName);        StringBuffer result = new StringBuffer ("/");        result.append (parameterName);        result.append ("/");        result.append (parameterValue);        if (defaultValue == null) {            return result.toString ();        } else {            if (defaultValue.equals (parameterValue)) {                return "";            } else {                return result.toString ();            }        }    }    //-------------------------------------------------------------------------    // EV   20 Nov. 2000 : Original implementation    // FH   22 Jan. 2001 : - Changed += operation on a String to a StringBuffer.    //                     - added error check.    // MJ   29 May. 2001 : get http path from request instead of settings,    /**     * Compose an URL by adding default parameters (like the page id, the session id, ...)     * to the passed in parameter string.     *     * @param   params  String of parameters.     *     * @return  Return a valid URL by adding default parameters. Return an non-null     *          empty string on any error.     */    public String composeUrl (String params)            throws JahiaException {        StringBuffer theUrl = new StringBuffer (this.getJahiaCoreHttpPath ());        theUrl.append (getEngineURLPart (CORE_ENGINE_NAME));        theUrl.append (getSiteURLPart (site.getSiteKey ()));        theUrl.append (getOpModeURLPart (opMode));        theUrl.append (getCacheModeURLPart (cacheStatus));        //theUrl.append (getLastRequestedPageURLPart (thePage.getID()));        if (thePage != null)            theUrl.append (getPageURLPart (thePage.getID ()));        appendParams (theUrl, params);        appendAnchor (theUrl);        return encodeURL (theUrl.toString ());    } // end composeUrl    //-------------------------------------------------------------------------    // EV   20 Nov. 2000 : Original implementation    // FH   22 Jan. 2001 : Changed += operation on a String to a StringBuffer.    // MJ   29 May. 2001 : get http path from request instead of settings,    // MJ   24 Jul. 2001 : dirty hack to hide catalina bug in HttpServletResponse    //                     .encodeURL(String URL)    //                     (bug description : reference to response object is    //                     sometimes lost after intensive calls to this method)    //                     Affected version : Tomcat 4.0 beta 1    /**     *     */    public String composePageUrl (int pageID)            throws JahiaException {        StringBuffer theUrl = new StringBuffer (this.getJahiaCoreHttpPath ());        theUrl.append (getEngineURLPart (CORE_ENGINE_NAME));        theUrl.append (getSiteURLPart (site.getSiteKey ()));        theUrl.append (getOpModeURLPart (opMode));        theUrl.append (getCacheModeURLPart (cacheStatus));        theUrl.append (getPageURLPart (pageID));        try {            return encodeURL (theUrl.toString ());        } catch (NullPointerException npe) {            return theUrl.toString ();        }    } // end composePageUrl    //-------------------------------------------------------------------------    // MJ   27 Feb. 2001 : Overloaded method without params besides engineName    // MJ   29 May. 2001 : get http path from request instead of settings,    /**     * composeEngineUrl     * MJ    27.02.2001     *     */    public String composeEngineUrl (String engineName)            throws JahiaException {        StringBuffer theUrl = new StringBuffer (this.getJahiaCoreHttpPath ());        if (engineName != null) {            theUrl.append (getEngineURLPart (engineName));        }        if (thePage != null)            theUrl.append (getPageURLPart (thePage.getID ()));        appendAnchor (theUrl);        return encodeURL (theUrl.toString ());    } // end composeEngineUrl    //-------------------------------------------------------------------------    // EV   20 Nov. 2000 : Original implementation    // FH   22 Jan. 2001 : Changed += operation on a String to a StringBuffer.    // MJ   29 May. 2001 : get http path from request instead of settings,    /**     * composeEngineUrl     * EV    20.11.2000     *     */    public String composeEngineUrl (String engineName, String params)            throws JahiaException {        //JahiaConsole.println("ParamBean.composeEngineUrl(engineName,params)","started");        StringBuffer theUrl = new StringBuffer (this.getJahiaCoreHttpPath ());        //JahiaConsole.println("ParamBean.composeEngineUrl(engineName,params) jahiaCoreHttpPath=",theUrl.toString());        if (engineName != null) {            theUrl.append (getEngineURLPart (engineName));        }        //JahiaConsole.println("ParamBean.composeEngineUrl(engineName,params) jahiaCoreHttpPath=",theUrl.toString());        theUrl.append (getSiteURLPart ());        theUrl.append (getOpModeURLPart (opMode));        if (thePage != null)            theUrl.append (getPageURLPart (thePage.getID ()));        appendParams (theUrl, params);        appendAnchor (theUrl);        return encodeURL (theUrl.toString ());    } // end composeEngineUrl    /**     * Supplementary version that allows us to add parameters in standard Jahia     * parameter form.     * @param engineName the name of the engine for which to generate the URL     * @param extraJahiaParams additional /name/value parameter to insert in     * the url     * @param params standard URL parameters in the form of a string that starts     * with ?     * @return String containing the generated URL.     * @throws JahiaException     */    public String composeEngineUrl (String engineName,                                    Properties extraJahiaParams,                                    String params)            throws JahiaException {        //JahiaConsole.println("ParamBean.composeEngineUrl(engineName,params)","started");        StringBuffer theUrl = new StringBuffer (this.getJahiaCoreHttpPath ());        //JahiaConsole.println("ParamBean.composeEngineUrl(engineName,params) jahiaCoreHttpPath=",theUrl.toString());        if (engineName != null) {            theUrl.append (getEngineURLPart (engineName));        }        //JahiaConsole.println("ParamBean.composeEngineUrl(engineName,params) jahiaCoreHttpPath=",theUrl.toString());        theUrl.append (getSiteURLPart ());        theUrl.append (getOpModeURLPart (opMode));        if (thePage != null)            theUrl.append (getPageURLPart (thePage.getID ()));        Enumeration propertyNames = extraJahiaParams.propertyNames ();        while (propertyNames.hasMoreElements ()) {            String propertyName = (String)propertyNames.nextElement ();            String propertyValue = extraJahiaParams.getProperty (propertyName);            theUrl.append (condAppendURL (propertyName, propertyValue));        }        appendParams (theUrl, params);        appendAnchor (theUrl);        return encodeURL (theUrl.toString ());    } // end composeEngineUrl    /**     * composeEngineUrl     * NK compose an engine url with the field id information     *     */    public String composeEngineUrl (String engineName, String params, int fieldID)     

⌨️ 快捷键说明

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