filezilla sitemanager.xml은
C:\Documents and Settings\netisinfinite\Application Data\FileZilla\sitemanager.xml
에 있다.

import java.io.IOException; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import org.apache.commons.net.ftp.FTPClient; import filezilla.FzSite; import filezilla.FzSiteManager; public class ZbPkgUploader { public static void main(String[] args){ String TITLEBAR_PRE = "제로보드 업로더"; //1. 안내 메시지 int next = JOptionPane.showConfirmDialog(null, "이 프로그램은 파일질라의 경로를 사용해 제로보드의 압축을 풀고 FTP에 업로드합니다.", TITLEBAR_PRE, JOptionPane.YES_NO_OPTION); if(next == JOptionPane.NO_OPTION) System.exit(0); //TODO 1-1 파일질라 파일 존재 확인 //fzsm.isExist(); FzSiteManager fzsm = new FzSiteManager(); Object[] arr = fzsm.getFzSites().keySet().toArray(); //2. 호스트 선택 FzSite site = fzsm.getFzSite(JOptionPane.showInputDialog(null, "연결할 호스트를 선택해주세요.", TITLEBAR_PRE + ": 서버 설정", JOptionPane.QUESTION_MESSAGE, null, arr, null)); //2-1,2 id/pass 필요시 요청 if(site.getUser() == null) site.setUser(JOptionPane.showInputDialog(null, "ID를 적어주세요.", TITLEBAR_PRE + ": ID 설정", JOptionPane.QUESTION_MESSAGE)); if(site.getPass() == null) site.setPass(JOptionPane.showInputDialog(null, "비밀번호를 적어주세요.", TITLEBAR_PRE + ": 비밀번호 설정", JOptionPane.QUESTION_MESSAGE)); //2-3 연결 확인 FTPClient ftp = new FTPClient(); try { ftp.connect(site.getHost()); if(!ftp.login(site.getUser(), site.getPass())) throw new IOException("아이디 혹은 비밀번호가 잘못되었습니다."); } catch (IOException e) { e.printStackTrace(); System.exit(0); } //3. 경로 설정 String path = JOptionPane.showInputDialog(null, "설치할 경로를 적어주세요.", TITLEBAR_PRE + ": 경로 지정", JOptionPane.QUESTION_MESSAGE); //3-1. 경로 확인 try { if(!ftp.changeWorkingDirectory(path)) throw new IOException("경로가 잘못되었습니다."); } catch (IOException e) { e.printStackTrace(); System.exit(0); } //4. 제로보드 zbxe.zip 설정 JFileChooser fc = new JFileChooser(); fc.showDialog(null, "파일을 선택해주세요."); //5. 압축 풀기 - 업로드 //압축을 풀고 있습니다. //6. 퍼미션 설정 (제로보드 설치 디렉터리의 퍼미션을 변경하는 대신 files 디렉터리를 생성하시겠습니까?) //7. 임시파일 제거 //8. 완료 메시지 JOptionPane.showMessageDialog(null, "업로드가 완료되었습니다! 이제 브라우저를 열고 업로드된 디렉터리를 열어 제로보드XE 설치를 진행하시기 바랍니다.", TITLEBAR_PRE + ": 완료", JOptionPane.PLAIN_MESSAGE); } }

package filezilla; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; public class FzSiteManager{ private Map<String, FzSite> fzSites = new HashMap<String, FzSite>(); public FzSiteManager(){ File fsXml = getFile(); if(fsXml.isFile()){ parse(fsXml); }else{ throw new NullPointerException("파일을 찾을 수 없습니다."); } } public void printAll(){ for(Map.Entry<String, FzSite> e : fzSites.entrySet()){ System.out.println(e.getKey() + " : \n" + e.getValue().toString()); } } private void parse(File file){ try { Document doc = getDocumentFrom(file); List<FzSite> sites = new ArrayList<FzSite>(); XPath xpath = createXPath(); /** * XPath 식을 단 한번만 사용하려고 한다면 컴파일 단계를 건너 뛰고 대신 XPath 객체에 evaluate() 메소드를 호출한다. * 하지만 같은 식을 여러 번 재사용 하면 컴파일이 더 빠르다. * http://www.ibm.com/developerworks/kr/library/x-javaxpathapi.html */ //XPathExpression expr = xpath.compile("//server"); //Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) xpath.evaluate("//Server", doc, XPathConstants.NODESET); for (int i=0; i < nodes.getLength(); i++) { FzSite fs = new FzSite(); sites.add(fs); NodeList innerNodes = nodes.item(i).getChildNodes(); for(int ii=0;ii<innerNodes.getLength();ii++){ String nodeName = innerNodes.item(ii).getNodeName(); String nodeContent = innerNodes.item(ii).getTextContent(); if(nodeName.equals("Host")){ fs.setHost(nodeContent); }else if(nodeName.equals("Port")){ fs.setPort(Integer.parseInt(nodeContent)); }else if(nodeName.equals("Protocol")){ fs.setProtocol(Integer.parseInt(nodeContent)); }else if(nodeName.equals("Type")){ fs.setType(Integer.parseInt(nodeContent)); }else if(nodeName.equals("Logontype")){ fs.setLogontype(Integer.parseInt(nodeContent)); }else if(nodeName.equals("User")){ fs.setUser(nodeContent); }else if(nodeName.equals("Pass")){ fs.setPass(nodeContent); }else if(nodeName.equals("TimezoneOffset")){ fs.setTimezoneOffset(Integer.parseInt(nodeContent)); }else if(nodeName.equals("PasvMode")){ if(nodeContent.equals("MODE_DEFAULT")) fs.setPasvMode(FzSite.PasvMode.MODE_DEFAULT); }else if(nodeName.equals("MaximumMultipleConnections")){ fs.setMaximumMultipleConnections(Integer.parseInt(nodeContent)); }else if(nodeName.equals("EncodingType")){ if(nodeContent.equals("Auto")) fs.setEncodingType(FzSite.EncodingType.Auto); }else if(nodeName.equals("Comments")){ fs.setComments(nodeContent); }else if(nodeName.equals("LocalDir")){ fs.setLocalDir(nodeContent); }else if(nodeName.equals("RemoteDir")){ fs.setRemoteDir(nodeContent); } fzSites.put(fs.getName() != null ? fs.getName() : fs.getHost(), fs); } } } catch (XPathExpressionException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public File getFile(){ return new File(System.getProperty("user.home") + "/Application Data/FileZilla/sitemanager.xml"); } private Document getDocumentFrom(File file) throws ParserConfigurationException, SAXException, IOException{ DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); // never forget this! DocumentBuilder builder = domFactory.newDocumentBuilder(); return builder.parse(file); } public XPath createXPath(){ return XPathFactory.newInstance().newXPath(); } public Map<String, FzSite> getFzSites() { return fzSites; } public FzSite getFzSite(Object key){ return fzSites.get(key); } }

package filezilla; import java.lang.reflect.Field; public class FzSite { public enum PasvMode{ MODE_DEFAULT } public enum EncodingType{ Auto } private String host; private int port; private int protocol; private int type; private int logontype; private String user; private String pass; private int timezoneOffset; private PasvMode pasvMode; private int maximumMultipleConnections; private EncodingType encodingType; private int bypassProxy; private String comments; private String localDir; private String name; private String remoteDir; public String getHost() { return host; } public void setHost(String host) { this.host = host; } public int getPort() { return port; } public void setPort(int port) { this.port = port; } public int getProtocol() { return protocol; } public void setProtocol(int protocol) { this.protocol = protocol; } public int getType() { return type; } public void setType(int type) { this.type = type; } public int getLogontype() { return logontype; } public void setLogontype(int logontype) { this.logontype = logontype; } public String getUser() { return user; } public void setUser(String user) { this.user = user; } public int getTimezoneOffset() { return timezoneOffset; } public void setTimezoneOffset(int timezoneOffset) { this.timezoneOffset = timezoneOffset; } public PasvMode getPasvMode() { return pasvMode; } public void setPasvMode(PasvMode pasvMode) { this.pasvMode = pasvMode; } public int getMaximumMultipleConnections() { return maximumMultipleConnections; } public void setMaximumMultipleConnections(int maximumMultipleConnections) { this.maximumMultipleConnections = maximumMultipleConnections; } public EncodingType getEncodingType() { return encodingType; } public void setEncodingType(EncodingType encodingType) { this.encodingType = encodingType; } public int getBypassProxy() { return bypassProxy; } public void setBypassProxy(int bypassProxy) { this.bypassProxy = bypassProxy; } public String getComments() { return comments; } public void setComments(String comments) { this.comments = comments; } public String getLocalDir() { return localDir; } public void setLocalDir(String localDir) { this.localDir = localDir; } public String getRemoteDir() { return remoteDir; } public void setRemoteDir(String remoteDir) { this.remoteDir = remoteDir; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPass() { return pass; } public void setPass(String pass) { this.pass = pass; } public String toString(){ StringBuilder result = new StringBuilder(); Class<FzSite> c = FzSite.class; for(Field f : c.getDeclaredFields()){ try { Object v = f.get(this); if(v != null && !v.equals("")){ result.append(f.getName()); result.append(" : "); result.append(v); result.append("\n"); } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } return result.toString(); } }
powered by Moniwiki | themed by clockoon
last modified 2008-12-30 10:44:14
Processing time 0.7245 sec