createview.java

来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 178 行

JAVA
178
字号
package Jt.wizard.struts.view;

import java.io.InputStream;
import java.util.Collection;
import java.util.LinkedList;

import Jt.JtContext;
import Jt.JtMessage;
import Jt.JtObject;
//import Jt.struts.JspGenerator;
import Jt.wizard.struts.ActionForm3;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.upload.FormFile;
/**
 * Create a View (JSP) for the Struts framework
 */
public class CreateView extends JtObject {
    private static final long serialVersionUID = 1L;

    private void handleUIError (String error) {
        Collection col;

        if (error == null)
            return;
        col = (Collection) this.getObjErrors();

        if (col == null) {
            col = new LinkedList ();
            setObjErrors (col);
        }
        col.add(error);


    }

/*
    public Object generateView (DynaActionForm form) {
        String className;
        JspGenerator jspGenerator = new JspGenerator ();
        String action;
        
        Object jtReply;
                  
        if (form == null) {
            return (null);            
        }

        className = (String) form.get ("className");


        if (className == null || className.equals ("")) {
            handleUIError ("Please enter a class name.");
            return (null);
        }    
        jspGenerator.setClassName(className);
        
        action = (String) form.get ("action");
        
        if (action != null && !action.equals(""))
            jspGenerator.setAction (action);
        

        jtReply = jspGenerator.processMessage(new JtMessage (JtObject.JtACTIVATE));

        // Propagate the exception
        if (jspGenerator.getObjException() != null)
            this.setObjException(jspGenerator.getObjException());
        
        return (jtReply);
    }
*/    
    
    private boolean checkExtension (String name) 
    {
        if (name == null)
            return false;
        
        return (name.endsWith(".java"));
       
    }
    
    public Object generateView (ActionForm3 form) {
        //String className;
        JspGenerator jspGenerator = new JspGenerator ();
        String action;
        FormFile theFile;
        InputStream inputStream = null;
        
        Object jtReply;
                  
        if (form == null) {
            return (null);            
        }
                       
        theFile = form.getTheFile();
        
        if (theFile == null || !checkExtension (theFile.getFileName())) {
            handleUIError ("File must be a java class file (.java)");
            return null;
        }
        
        try {
            inputStream = theFile.getInputStream();
        } catch (Exception e) {
            handleException (e);
        }
        
        if (inputStream == null) {
            return null;
        }   
        
/*
        className = (String) form.get ("className");


        if (className == null || className.equals ("")) {
            handleUIError ("Please enter a class name.");
            return (null);
        }
           
        jspGenerator.setClassName(className);
*/ 
        
        jspGenerator.setInputStream(inputStream);
        //action = (String) form.get ("action");
        action = form.getAction();
        
        if (action != null && !action.equals(""))
            jspGenerator.setAction (action);
        

        jtReply = jspGenerator.processMessage(new JtMessage (JtObject.JtACTIVATE));

        // Propagate the exception
        if (jspGenerator.getObjException() != null)
            this.setObjException(jspGenerator.getObjException());
        
        return (jtReply);
    }


    /**
     * Process object messages.
     * <ul>
     * <li> JtACTIVATE
     * </ul>
     * @param message message
     */

    public Object processMessage (Object message) {
        Object data;

        JtMessage e = (JtMessage) message;
        JtContext context;
        ActionForm form = null;

        if (e == null ||  (e.getMsgId() == null))
            return (null);
        
        context = (JtContext) e.getMsgContext();
        if (context != null)
            form = (ActionForm) context.getActionForm();  


        if (e.getMsgId().equals(JtObject.JtACTIVATE)) {

            // pass the form information   
            data = e.getMsgData ();
            return ( generateView ((ActionForm3) data));
        }

        return (super.processMessage(message));

    }
}

⌨️ 快捷键说明

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