com.action.FileuploadAction.java Source code

Java tutorial

Introduction

Here is the source code for com.action.FileuploadAction.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.action;

import static com.opensymphony.xwork2.Action.ERROR;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionContext;
import com.util.Dom4jIUFOXML;
import com.util.Dom4jJQXML;
import java.io.File;
import org.apache.commons.io.FileUtils;
import com.util.ReadProperties;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

/**
 *
 * @author yishan_zhuang
 */
@Repository("fileuploadAction")
@Scope("prototype")
public class FileuploadAction {

    private File filename;
    private String filenameContentType;//
    private String filenameFileName;//??
    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public File getFilename() {
        return filename;
    }

    public void setFilename(File filename) {
        this.filename = filename;
    }

    public String getFilenameContentType() {
        return filenameContentType;
    }

    public void setFilenameContentType(String filenameContentType) {
        this.filenameContentType = filenameContentType;
    }

    public String getFilenameFileName() {
        return filenameFileName;
    }

    public void setFilenameFileName(String filenameFileName) {
        this.filenameFileName = filenameFileName;
    }

    //
    public String jqXmlupload() {
        String realPath = ReadProperties.getProperties("path");
        System.out.println(realPath);
        try {
            System.out.println("==============" + filenameFileName.substring(filenameFileName.indexOf('.') + 1));
            if ("xml".equals(filenameFileName.substring(filenameFileName.indexOf('.') + 1))) {
                if (filename != null) {
                    File savaFile = new File(new File(realPath), filenameFileName);
                    if (!savaFile.getParentFile().exists()) {
                        savaFile.getParentFile().mkdirs();
                    }
                    FileUtils.copyFile(filename, savaFile);
                    ActionContext.getContext().put("message", "?????");
                }
                File file = new File(realPath + filenameFileName);
                //xml??
                Dom4jJQXML djqxml = new Dom4jJQXML();
                djqxml.XMLDom4j(file);
                return SUCCESS;
            } else {
                ActionContext.getContext().put("message", "???xml??");
                return ERROR;
            }
        } catch (Exception e) {
            ActionContext.getContext().put("message", "?" + e);
            return ERROR;
        }
    }

    public String iufoXmlupload() {
        String realPath = ReadProperties.getProperties("path");
        System.out.println(realPath);
        try {
            System.out.println("==============" + filenameFileName.substring(filenameFileName.indexOf('.') + 1));
            if ("xml".equals(filenameFileName.substring(filenameFileName.indexOf('.') + 1))) {
                if (filename != null) {
                    File savaFile = new File(new File(realPath), filenameFileName);
                    if (!savaFile.getParentFile().exists()) {
                        savaFile.getParentFile().mkdirs();
                    }
                    FileUtils.copyFile(filename, savaFile);
                    ActionContext.getContext().put("message", "?????");

                }
                File file = new File(realPath + filenameFileName);
                //xml??
                Dom4jIUFOXML djqxml = new Dom4jIUFOXML();
                djqxml.XMLDom4j(file);
                return SUCCESS;
            } else {
                ActionContext.getContext().put("message", "???xml??");
                return ERROR;
            }
        } catch (Exception e) {
            ActionContext.getContext().put("message", "?" + e);
            return ERROR;
        }
    }
}