generatejsp.java

来自「Java Pattern Oriented Framework (Jt) 是为了」· Java 代码 · 共 609 行 · 第 1/2 页

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

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;

import Jt.JtContext;
import Jt.JtDirectory;
import Jt.JtFactory;
import Jt.JtMessage;
import Jt.JtObject;
import Jt.DAO.DAODefinition;
//import Jt.struts.JspGenerator;
import Jt.wizard.WizardConfig;
import Jt.wizard.struts.CrudForm;
import Jt.wizard.struts.DAODefinitionForm;
import Jt.wizard.struts.FileForm;
import Jt.xml.JDOMAdapter;

/**
 * Struts Configuration File (Internal JtWizard Class).
 */

public class GenerateJSP extends JtObject {
    private static final long serialVersionUID = 1L;
    public static final String JtCLASS_NAME = GenerateJSP.class.getName(); 
    private JtFactory factory = new JtFactory ();
    private WizardConfig config;
    public static final String CRUD_PREFIX = "CRUD";

    
    private boolean init = false;
    private String prefix;    
    //private String path;
    private InputStream resourceStream;
    private String classname;
    private String key0;    
    private List keys = null;
    //private String templatesPath = "/home/projects/Jt1/webapps/JtWizard/CRUDtemplates";   
    //private String webAppPath;
    //private String crudPath;
    private String jspDirectoryPath;
    



    public String getClassname() {
        return classname;
    }

    public void setClassname(String classname) {
        this.classname = classname;
    }



    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }



    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);


    }
    

    
    
    private String capFirstLetter (String str) {
        if (str == null)
            return (null);

        if (str.equals(""))
            return (str);

        if (str.length() == 1)
            return str.toUpperCase();
        
        return (str.substring(0, 1).toUpperCase() + str.substring(1));
    }
    

 
    
    private String concatenatePath (String path, String subpath) {
        char separator = File.separatorChar;
        File file;


        if (path == null)
            return null;
        if (subpath == null)
            return path;

        file = new File (path);


        return (file.getAbsolutePath() + separator + subpath);

    }
    
/*    
    private void renameFiles () {
        JtMessage msg = new JtMessage (JtDirectory.JtDIR);
        JtMessage msg1 = new JtMessage (JtFile.JtRENAME);
        List fileList;
        JtDirectory webAppDir = new JtDirectory ();
        Iterator iterator;
        String fileName;
        String tmp;
        JtFile jfile = new JtFile ();
        String jspAbsolutePath;
        File file;
        
        if (jspDirectoryPath == null)
            return;
        
        webAppDir.setName(jspDirectoryPath);
        
        fileList = (List) factory.sendMessage (webAppDir, msg);
        
        if (fileList == null)
            return;
        
        iterator = fileList.iterator();
        
        file = new File (jspDirectoryPath);
        
        while (iterator.hasNext()) {
            fileName = (String) iterator.next();
            
            if (fileName.indexOf("Member") < 0)
                continue;
            
            tmp = fileName.replaceAll("Member", capFirstLetter (prefix));
            
            jfile.setName(file.getAbsolutePath() +  
                    File.separatorChar + fileName);
            
            msg1.setMsgContent (file.getAbsolutePath() + File.separatorChar
                    + tmp);
            factory.sendMessage (jfile, msg1);
        }
        
    }
*/

    /*
    private void copyTemplateDirectory () {
        JtMessage msg = new JtMessage (JtDirectory.JtCOPY_DIRECTORY);
        JtDirectory templateDir = new JtDirectory ();
        
        templateDir.setName(templatesPath);
        
        msg.setMsgContent(jspDirectoryPath);
        
        factory.sendMessage (templateDir, msg);       
        
    }
    */
    
    private void propagateException (JtObject obj) {
        if (obj.getObjException() != null) {
            this.setObjException(obj.getObjException());           
        }

    }
    
    private boolean copyTemplate (String templateName, String filename) {
        JDOMAdapter templateAdapter = new JDOMAdapter ();
        String fpath;
        
        
        resourceStream = this.getClass().getClassLoader().getResourceAsStream (templateName);
        
        if (resourceStream == null) {
            handleError ("Resource not found:" + templateName);
            return (false);
        }
        
        
        templateAdapter.setInputStream(resourceStream);
        factory.sendMessage (templateAdapter, new JtMessage (JDOMAdapter.READ_STREAM));
        
        if (templateAdapter.getObjException() != null) {
            propagateException (templateAdapter);
            return (false);
        }
        
        fpath = concatenatePath (jspDirectoryPath , filename);
        
        templateAdapter.setPath(fpath);
        
        factory.sendMessage (templateAdapter, new JtMessage (JDOMAdapter.SAVE_FILE));
        

        if (templateAdapter.getObjException() != null) {
            propagateException (templateAdapter);
            return (false);
        }
        
        return (true);
    }
    
    private void createJSPDirectory () {
        String path, tmp;
        JtDirectory jdir = new JtDirectory ();
        JtMessage msg = new JtMessage (JtDirectory.JtCREATE_DIRECTORY);
        
              
        if (config == null)
            return;
        
        path = config.getWebAppPath();
                
        tmp = concatenatePath (path, GenerateJSP.CRUD_PREFIX + capFirstLetter (prefix));
        jdir.setName(tmp);
        jspDirectoryPath = tmp;
        factory.sendMessage (jdir, msg);        
        
        propagateException (jdir);
        
    }
 
 
    private void updateQueryJsp (String fileName, String formName) {
        String fpath;
        
        JspGenerator jspGenerator = new JspGenerator ();
        
        //fpath = webAppPath + "/" + fileName;
        fpath = concatenatePath (jspDirectoryPath , fileName);
        
        jspGenerator.setPath(fpath);
        jspGenerator.setPrefix(prefix);    
        
        //jspGenerator.setClassName(classname); // check   
        jspGenerator.setFormName(formName);
        
        if (key0 != null)
            jspGenerator.setKey(key0);
        
        if (keys != null && (keys.size() > 0)) {
            jspGenerator.setKeys(keys);
        }
        
        factory.sendMessage(jspGenerator, new JtMessage (JspGenerator.UPDATE_DISPLAY_TAG));
        
        propagateException (jspGenerator);
        
    }
    
    private void updateIndexJsp (String fileName) {
        String fpath;
        
        JspGenerator jspGenerator = new JspGenerator ();
        
        fpath = concatenatePath (jspDirectoryPath , fileName);
        
        jspGenerator.setPath(fpath);
        jspGenerator.setPrefix(prefix);    
        
        //jspGenerator.setClassName(classname); // check   
        
        //if (key != null)
        //    jspGenerator.setKey(key);
        
        factory.sendMessage(jspGenerator, new JtMessage (JspGenerator.UPDATE_LINKS));
        
        propagateException (jspGenerator);
        
    }
    
    
    private void updateJsp (String fileName, String formName, String operation) {
        String fpath;
        JtMessage msg = new JtMessage (JspGenerator.UPDATE_FORM);
        
        if (operation == null)
            return;
        
        JspGenerator jspGenerator = new JspGenerator ();
        

⌨️ 快捷键说明

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