more..
package hufs.File;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.OutputKeys;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.OutputKeys;
import java.io.*;
import java.util.Date;
import java.util.Date;
public class XmlManager {
private Document doc;
private Element fileList;
private Element file;
private Element name;
private Element size;
private Element update;
private Element path;
private Element format;
private String str = "";
private StreamResult result;
private Writer writer;
private DocumentBuilderFactory docFactory;
private DocumentBuilder builder;
private String xmlRoot = "./Server/Xml/";
private String type;
private Element fileList;
private Element file;
private Element name;
private Element size;
private Element update;
private Element path;
private Element format;
private String str = "";
private StreamResult result;
private Writer writer;
private DocumentBuilderFactory docFactory;
private DocumentBuilder builder;
private String xmlRoot = "./Server/Xml/";
private String type;
FileListManager fileListManager;
public XmlManager(String name) {
this.type = name;
writer = new StringWriter();
result = new StreamResult(writer);
result = new StreamResult(writer);
}
public boolean exist() { // xml 존재유무
File file = new File(xmlRoot + type + ".xml");
if (file.isFile())
return true;
else
return false;
return true;
else
return false;
}
public void update() { // xml 생성
initial();
getXml();
}
getXml();
}
public void initial() { // 초기화
try {
docFactory = DocumentBuilderFactory.newInstance();
builder = docFactory.newDocumentBuilder();
doc = builder.newDocument();
builder = docFactory.newDocumentBuilder();
doc = builder.newDocument();
fileList = doc.createElement("fileList");
fileList.setAttribute("file", "root");
fileList.setAttribute("file", "root");
} catch (Exception ex) {
System.out.println(ex);
}
System.out.println(ex);
}
}
public void getXml() { // xml element 생성
String name = null;
long size;
Date update;
String path = null;
String format = null;
long size;
Date update;
String path = null;
String format = null;
fileListManager = new FileListManager();
fileListManager.search(); // 파일 검색
while (true) { // Node 생성
fileListManager.search(); // 파일 검색
while (true) { // Node 생성
if (!fileListManager.exist()) // boolean
break;
break;
name = fileListManager.getname();
size = fileListManager.getsize();
update = fileListManager.getdate();
path = fileListManager.getpath();
format = fileListManager.getformat();
size = fileListManager.getsize();
update = fileListManager.getdate();
path = fileListManager.getpath();
format = fileListManager.getformat();
setElement(name, size, update, path, format);
}
saveXml(); // save
}
public void setElement(String ename, long esize, Date eupdate,
String epath, String eformat) {
String epath, String eformat) {
file = doc.createElement("file");
name = doc.createElement("name");
name.appendChild(doc.createTextNode(ename));
file.appendChild(name);
name.appendChild(doc.createTextNode(ename));
file.appendChild(name);
size = doc.createElement("size");
size.appendChild(doc.createTextNode("" + esize));
file.appendChild(size);
size.appendChild(doc.createTextNode("" + esize));
file.appendChild(size);
update = doc.createElement("update");
update.appendChild(doc.createTextNode("" + eupdate));
file.appendChild(update);
update.appendChild(doc.createTextNode("" + eupdate));
file.appendChild(update);
path = doc.createElement("path");
path.appendChild(doc.createTextNode(epath));
file.appendChild(path);
path.appendChild(doc.createTextNode(epath));
file.appendChild(path);
format = doc.createElement("format");
format.appendChild(doc.createTextNode(eformat));
file.appendChild(format);
format.appendChild(doc.createTextNode(eformat));
file.appendChild(format);
fileList.appendChild(file);
}
public void saveXml() { // xml 파일로 저장
try {
doc.appendChild(fileList);
StringWriter sw = new StringWriter();
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer trans = tFactory.newTransformer();
Transformer trans = tFactory.newTransformer();
trans.setOutputProperty(OutputKeys.INDENT, "yes");
trans.setOutputProperty(OutputKeys.METHOD, "xml");
trans.setOutputProperty(OutputKeys.ENCODING, "euc-kr");
trans.setOutputProperty(OutputKeys.METHOD, "xml");
trans.setOutputProperty(OutputKeys.ENCODING, "euc-kr");
trans.transform(new DOMSource(doc), new StreamResult(System.out));
trans.transform(new DOMSource(doc), result);
trans.transform(new DOMSource(doc), new StreamResult(
new FileWriter(xmlRoot + type + ".xml")));
trans.transform(new DOMSource(doc), result);
trans.transform(new DOMSource(doc), new StreamResult(
new FileWriter(xmlRoot + type + ".xml")));
str = writer.toString();
} catch (Exception ex) {
} catch (Exception ex) {
System.out.println(ex);
}
}
}
}
댓글 없음:
댓글 쓰기