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

📄 downloadtemplate_engine.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////  DownloadTemplate_Engine//  EV      30.11.2000////  getInstance()//  authoriseRender()//  renderLink()//  needsJahiaData()//  handleActions()//package org.jahia.engines.downloadtemplate;import java.io.*;                       // PrintWriterimport org.jahia.utils.*;           // JahiaConsoleimport org.jahia.data.*;            // JahiaDataimport org.jahia.services.pages.JahiaPage;import org.jahia.services.pages.JahiaPageDefinition;import org.jahia.params.*;          // ParamBeanimport org.jahia.engines.*;         // JahiaEngine interfaceimport org.jahia.gui.*;             // FieldFormsimport org.jahia.registries.*;      // ServicesRegistryimport org.jahia.exceptions.JahiaException;public class DownloadTemplate_Engine implements JahiaEngine {    private static  DownloadTemplate_Engine theObject   = null;    private         String                  engineName  = "downloadtemplate";    /***        * constructor        * EV    30.11.2000        *        */    private DownloadTemplate_Engine()    {        // JahiaConsole.println( "Engine", "***** Starting DownloadTemplate Engine *****" );    } // end constructor    /***        * getInstance        * EV    30.11.2000        *        */    public static synchronized DownloadTemplate_Engine getInstance()    {        if (theObject == null) {            theObject = new DownloadTemplate_Engine();        }        return theObject;    } // end getInstance    /***        * authoriseRender        * EV    30.11.2000        *        */    public boolean authoriseRender( ParamBean jParams )    {        return (jParams.getOperationMode() == jParams.EDIT);    } // end authoriseRender    /***        * renderLink        * EV    30.11.2000        *        */    public String renderLink( ParamBean jParams, Object theObj )    throws JahiaException    {        String params = "";//        params += "&mode=displaywindow";        params += "?mode=displaywindow";        return jParams.composeEngineUrl( engineName, params );    } // end renderLink    /***        * needsJahiaData        * EV    30.11.2000        *        */    public boolean needsJahiaData( ParamBean jParams )    {        return false;    } // end needsJahiaData    /***        * handleActions        * EV    30.11.2000        *        */    public void handleActions( ParamBean jParams, JahiaData jData )    throws JahiaException    {        String mode     = jParams.getRequest().getParameter( "mode" );        String ipAddr   = jParams.getRequest().getRemoteAddr();        if (mode != null) {            if (mode.equals("displaywindow")) {                JahiaConsole.println( "DownloadTemplate_Engine", ipAddr + " is displaying DownloadTemplate Window"  );                displayFormWindow( jParams );            } else if (mode.equals("processform")) {                JahiaConsole.println( "DownloadTemplate_Engine", ipAddr + " is processing DownloadATemplate Form"  );                processForm( jParams );            }        }    } // end handleAction    /***        * displayFormWindow()        * EV    30.11.2000        *        */    public void displayFormWindow( ParamBean jParams )    throws JahiaException    {        String  html        = "";        String urlParams    = "";        urlParams           += "&mode=processform";        String theUrl       = jParams.composeEngineUrl( engineName, urlParams );        html += "<center><table border=\"0\" width=\"90%\"><tr>\n";        html += "<td width=\"100%\" colspan=\"2\" bgcolor=\"#333333\">\n";        html += "<font face=\"arial\" size=\"2\">Please choose template to download :</font>\n";        html += "</td></tr>\n";        html += "<tr><td width\"20%\" valign=\"top\">&nbsp;</td>\n";        html += "<td width=\"80%\">";        html += "<form method=\"POST\" action=\"" + theUrl + "\">\n";        // ONLY FOR DEBUG PURPOSES        // should be performed by browsing through a LDAP server        html += "<select name=\"templateid\" size=\"5\">\n";        html += "<option value=\"1\" selected> Compas Template </option>\n";        html += "</select>\n";        html += "</form>\n";        html += "</td></tr></table>\n";        EngineRenderer.getInstance().render( jParams, engineName, html );    }    // end displayFormWindow    /***        * processForm()        * EV    29.11.2000        *        */    public void processForm( ParamBean jParams )        throws JahiaException    {        String templateIDStr = "";        try {            PrintWriter out = jParams.getResponse().getWriter();            jParams.getResponse().setContentType( "text/html" );            out.println( "<center> Computing values... </center>" );            templateIDStr = jParams.getRequest().getParameter( "templateid" );            if (templateIDStr != null)            {                int templateID = Integer.parseInt( templateIDStr );                // ONLY FOR DEBUG PURPOSES                // should be performed by parsing an XML file                String urlPath = "";                String diskPath = "";                String fileName = "";                String tempTitle = "";                //////////////////////////////////////////////////////////////////////////////                //  FIXME -Fulco-                //                //      Oops .. this is real dirty code !!!!!!!                //        1. A unique case should not be in a switch statement                //           but only in an if statement.                //        2. NOTHING should be hardcoded in the source code.                //                //      I'm looking forward the author of this will change it                //      as soon as possible !                //                //////////////////////////////////////////////////////////////////////////////                switch (templateID) {                    case (1) :  tempTitle   = "Compas Template";                                fileName    = "compas.jsp";                                urlPath     = "http://www.jahia.org/jahia/templates/";                                diskPath    = "compas";                                break;                }                if ((!urlPath.equals("")) && (!diskPath.equals("")) &&                    (!fileName.equals("")) && (!tempTitle.equals("")))                {                    if (ServicesRegistry.getInstance().getJahiaFileTransferService().downloadTemplate( fileName, urlPath, diskPath ))                    {                        String tempPath = jParams.settings().getTemplatesContext() + diskPath + "/" + fileName;                        //////////////////////////////////////////////////////////////////////                        // FIXME -Fulco-                        //                        //      The person who coded this class should check if the default                        //      parameters (I inserted) are correct in the page template                        //      creation below.                        //                        //      Thanks.                        //                        //////////////////////////////////////////////////////////////////////                        JahiaPageDefinition theTemplate = ServicesRegistry.                                getInstance().getJahiaPageTemplateService().                                createPageTemplate (jParams.getPage().getJahiaID(),                                tempTitle, tempPath,                                true,   	// is visible                                "",  		// no image                                jParams.getSiteID() );                    }                }                                                                                                                                                    }            out.println( "<script language=\"javascript\" src=\"" + jParams.settings().getJsHttpPath() + "\">" );            out.println( "</script>" );            out.println( "<script language=\"javascript\">" );            out.println( "  CloseJahiaWindow();" );            out.println( "</script>" );        } catch (NullPointerException npe) {            String errorMsg = "Cannot retrieve POST templateID (" + templateIDStr + ") : " + npe.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "DownloadTemplate_Engine", errorMsg );            throw new JahiaException(   "Error in Jahia parameters",                                        errorMsg, JahiaException.PARAMETER_ERROR, JahiaException.CRITICAL );        } catch (NumberFormatException nfe) {            String errorMsg = "Template id parameter is not a number (" + templateIDStr + ") : " + nfe.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "DownloadTemplate_Engine", errorMsg );            throw new JahiaException(   "Error in Jahia parameters",                                        errorMsg, JahiaException.PARAMETER_ERROR, JahiaException.CRITICAL );        } catch (IOException ie) {            String errorMsg = "Error while handling the DownloadTemplate Window : " + ie.getMessage() + " -> BAILING OUT";            JahiaConsole.println( "DownTemplate_Engine", errorMsg );            throw new JahiaException(   "Error while handling a Jahia window's content",                                        errorMsg, JahiaException.DATA_ERROR, JahiaException.CRITICAL );        }    }    // end processForm} // end DownloadTemplate_Engine

⌨️ 快捷键说明

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