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

📄 getallfiletoresource.java

📁 替换jsp中的中文为sturts中的bundle
💻 JAVA
字号:
package com.pengjj.app;

import java.io.File;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.pengjj.util.FileUtil;
import com.pengjj.util.PengjjLog;

public class GetAllFileToResource extends PengjjLog{
	/**
	 * 资源文件的目录
	 */
	private Text textDiretoryResource;
	/**
	 * JSP文件目录
	 */
	private Text textDirectoryJsp;
	private static Label label ;
	protected Shell shell;
	private ProcessTask process = new ProcessTask(this);
	public String sFinish = "false";
	private String resourceProcess;
	private ReplaceWordsByResource replaceWordsByResource = new ReplaceWordsByResource(this);
	private File fileJsp;
	private File fileResource;
	/**
	 * jsp文件的总数
	 */
	private int iJspNum;
	private int iJspNumFinish;
	/**
	 * 资源文件的总数
	 */
	private int iResourceNum;
	private int iResourceNumFinish;
	
	private Thread thread;
	private Thread threadReplace; 
	/**
	 * Launch the application
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			//ReplaceWordsByResource replaceByWordsByResource = new ReplaceWordsByResource(this);
			GetAllFileToResource window = new GetAllFileToResource();
			window.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window
	 */
	public void open() {
		final Display display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	/**
	 * Create contents of the window
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(617, 311);
		shell.setText("JSP资源文件替换器");

		final Button button = new Button(shell, SWT.NONE);
		button.setText("请选择要替换的JSP文件目录");
		button.setBounds(11, 15, 193, 24);

		textDirectoryJsp = new Text(shell, SWT.BORDER);
		textDirectoryJsp.setBounds(11, 51, 591, 26);
		button.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				DirectoryDialog dlg = new DirectoryDialog(shell);
				dlg.setText("请选择要替换的JSP文件目录"); // 设置窗口标题
				dlg.setFilterPath("d:"); // 设置初始目录
				String dir = dlg.open(); // 打开对话框并返回一个包含所选目录路径的字符串
				// PENGJJ_TODO 需要检验生成的文件是否excel文件
				log.debug("you want to getFile,the file is--" + dir);
				if (dir != null) {
					textDirectoryJsp.setText(dir);
				}
			}
		});

		final Button buttonResource = new Button(shell, SWT.NONE);
		buttonResource.setText("请选择资源文件所在的目录");
		buttonResource.setBounds(12, 88, 193, 25);

		textDiretoryResource = new Text(shell, SWT.BORDER);
		textDiretoryResource.setBounds(9, 127, 591, 26);
		buttonResource.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				DirectoryDialog dlg = new DirectoryDialog(shell);
				dlg.setText("请选择资源文件所在的目录"); // 设置窗口标题
				dlg.setFilterPath("d:/"); // 设置初始目录
				String dir = dlg.open(); // 打开对话框并返回一个包含所选目录路径的字符串
				// PENGJJ_TODO 需要检验生成的文件是否excel文件
				log.debug("you want to getFile,the file is--" + dir);
				if (dir != null) {
					textDiretoryResource.setText(dir);
				}
			}
		});


		label = new Label(shell, SWT.NONE);
		label.setBounds(13, 205, 594, 38);
		//label.setText("替换正在进行中,这需要花费一些时间,请不要操作相关的文件,进行中......");
		final Button buttonConfirm = new Button(shell, SWT.NONE);
		buttonConfirm.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
//				textDirectoryJsp.setText("e:/flow");
//				textDiretoryResource.setText("e:/resources");
				String sJsp = textDirectoryJsp.getText();
				String sResource = textDiretoryResource.getText();
				if (sJsp == null || sJsp.trim().length() <= 0) {
					MessageDialog.openWarning(shell, "您没有选择Jsp所在的目录",
							"请选择Jsp所在的目录");
				} else if (sResource == null || sResource.trim().length() <= 0) {
					MessageDialog.openWarning(shell, "您没有选择资源文件所在的目录",
							"请选择资源文件所在的目录");
				} else {
					//替换反斜杠为斜杠
					sJsp = sJsp.replaceAll("\\","/");
					sResource = sResource.replaceAll("\\","/");
					//判断是否正在进行中
					if(sFinish.equals("begin")){
						MessageDialog.openWarning(shell, "正在替换中",
						"正在替换中,不能重复提交");						
					}
					if (!sFinish.equals("begin")&&!sFinish.equals("end")) {
						boolean flag = MessageDialog.openConfirm(shell,
								"进行确认目录提交", "确认Jsp目录和资源文件的目录都正确?");
						if (flag) {
							label
									.setText("替换正在进行中,这需要花费一些时间,请不要操作相关的文件,替换进行中......");
							// ReplaceWordsByResource replace = new
							// ReplaceWordsByResource();
							fileJsp = new File(sJsp);
							fileResource = new File(sResource);
							FileUtil fileUtil = new FileUtil();
							//PENGJJ_TODO 文件类型
							fileUtil.getFileNumber(fileJsp, "Root");
							iJspNum = fileUtil.getINumber();
							fileUtil.setINumber(0);
							fileUtil.getFileNumber(fileResource, ".properties");
							iResourceNum = fileUtil.getINumber();
							// System.out.println(iJspNum);
							// System.out.println(iResourceNum);
							sFinish = "false";
							thread = new Thread() {
								public void run() {
									resourceProcess = "begin";
									process.start();
								}
							};
							thread.start();
							threadReplace = new Thread() {
								public void run() {
									replaceWordsByResource.isFinish(fileJsp,
											fileResource, ".jsp");
								}
							};
							threadReplace.start();
							label.setText("替换的结果请查看log目录下的相关log文件,");
						}
					}
					
				}
			}
		});
		buttonConfirm.setText("确认");
		buttonConfirm.setBounds(11, 164, 193, 28);
		//
	}
	/**
	 * 设置label的text
	 * 
	 * @param str
	 */
	public void setText(String str) {
		label.setText(str);
	}
	public String getText() {
		return label.getText();
	}
	public void setResourceProcess(String sFileName) {
		this.resourceProcess = sFileName;
	}
	/**
	 * 得到处理文件的名称
	 * @return
	 */
	public String getResourceProcess() {
		return this.resourceProcess;
	}
	/**
	 * 是否完成
	 * @return
	 */
	public String getFinish() {
		return this.sFinish;
	}
	public void setFinish(String str){
		this.sFinish=str;
	}
	/**
	 * 完成的jsp数量
	 * @return 
	 */
	public int getJspNumFinish(){
		return this.iJspNumFinish;
	}
	/**
	 * 得到jsp的数量 
	 * @return
	 */
	public int getJspNum(){
		return this.iJspNum;
	}
	/**
	 * 设置完成的jsp数量
	 * @param jspNumFinish
	 */
	public void setJspNumFinish(int jspNumFinish){
		this.iJspNumFinish=jspNumFinish;
	}

	/**
	 * @return Returns the iResourceNum.
	 */
	public int getIResourceNum() {
		return this.iResourceNum;
	}

	/**
	 * @param resourceNum The iResourceNum to set.
	 */
	public void setIResourceNum(int resourceNum) {
		this.iResourceNum = resourceNum;
	}

	/**
	 * @return Returns the iResourceNumFinish.
	 */
	public int getIResourceNumFinish() {
		return this.iResourceNumFinish;
	}

	/**
	 * @param resourceNumFinish The iResourceNumFinish to set.
	 */
	public void setIResourceNumFinish(int resourceNumFinish) {
		this.iResourceNumFinish = resourceNumFinish;
	}
}

⌨️ 快捷键说明

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