📄 ixmlutil.java
字号:
package net.sf.oxmled.xml.util.dom4j;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import net.sf.oxmled.model.INode;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
/**
*
* @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
* Aug 6, 2007 4:25:18 PM
*这个接口提供了读写xml文件到Dom4j对象的方法
*/
/**
* @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
* 2007-8-7 下午04:52:07
*
*/
/**
* @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
* 2007-8-7 下午04:52:10
*
*/
/**
* @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
* 2007-8-7 下午04:52:14
*
*/
/**
* @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
* 2007-8-7 下午04:52:19
*
*/
/**
* @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
* 2007-8-7 下午04:55:52
*
*/
/**
* @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
* 2007-8-7 下午04:55:55
*
*/
/**
* @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
* 2007-8-7 下午04:56:17
*
*/
/**
* @author 沈东良 Edward Shen<a href="mailto:shendl_s@hotmail.com">shendl_s@hotmail.com</a>
* 2007-8-7 下午04:56:25
*
*/
public interface IXmlUtil {
public abstract INode getINode(Document document);
/**
* 使用Dom4j解析一个xml文件为Document对象
*
* @param url
* @return
* @throws DocumentException
*/
public abstract Document parse(URL url) throws DocumentException;
/**
* 把document对象写到指定的位置,生成xml文件。
*
* @param document
* @param fileName
* D:/java/eclipse32/workspace/BPMEditor1/bin/document/c.xml
* 如果是相对路径,就是相对于软件的目录的路径
* @throws IOException
*/
public abstract void write(Document document, String fileName)
throws IOException;
/**
* 把document对象写到指定的位置,生成xml文件。 生成优美格式的xml文件
*
* @param document
* @param fileName
* @throws IOException
* @throws URISyntaxException
*/
public abstract void writeToPrettyPrint(Document document, String fileName)
throws IOException, URISyntaxException;
/**
* 已修改好 这个方法有问题 由于Dom4j有BUG,只有使用JDOM
*
* 把document对象 生成优美格式的xml 格式的String
*
* @param document
* @param fileName
* @throws IOException
*/
public abstract String writeToPrettyPrint(Document document)
throws IOException;
// CompactFormat
/**
* 把document对象写到指定的位置,生成xml文件。 生成优美格式的xml文件
*
* @param document
* @param fileName
* @throws IOException
*/
public abstract void writeToCompactFormat(Document document, String fileName)
throws IOException;
/**
* 把document对象写到指定的位置,生成xml文件。
*
* @param document
* @param uri
* 使用getResource可以得到URL,URI,String可以互相转换
* @throws IOException
* @throws URISyntaxException
*
* public void write(Document document,URL url) throws IOException,
* URISyntaxException{ XmlUtil.getLog().info("url="+url);
* XmlUtil.getLog().info("uri="+url.toURI()); // lets write to a file
*
* //File file=new File(url.toURI()); //file.mkdirs();
* //file.createNewFile(); FileOutputStream fout=new FileOutputStream(new
* File(url.toURI())); XMLWriter writer = new Dom4jXMLWriter(fout);
*
* writer.write( document ); // fout.flush();
*
* writer.close();
*
* }
*/
/**
* 把document对象写到指定的位置,生成xml文件。
*
* @param document
* @param uri
* 使用getResource可以得到URL,URI,String可以互相转换
* @throws IOException
*/
public abstract void writeToCompactFormat(Document document, URI uri)
throws IOException;
/**
* 把document对象写到指定的位置,生成xml文件。
*
* @param document
* @param uri
* 使用getResource可以得到URL,URI,String可以互相转换
* @throws IOException
*/
public abstract void writeToPrettyPrint(Document document, URI uri)
throws IOException;
/**
*
* @param assembledElement
* 已装配好的元素。就是xml的所有元素已经组装完毕
* @return
*/
public abstract Document createDocument(Element assembledElement);
/**
*
* @param assembledElement
* 已装配好的元素。就是xml的所有元素已经组装完毕
* @param encoding
* xml文件的编码格式
* @return
*/
public abstract Document createDocument(Element assembledElement,
String encoding);
/**
* 把整个树,全部转换成element,并且链接好
* @param node
* @return
*/
public abstract Element convertToAssembledRootElement(INode node);
/**
* 根据元素,生成INode树
* @param element
* @return
*/
public abstract INode convertToAssembledRootINode(Element element);
/**
* 转换NodeModel节点为 Dom4j的Element
* @param node 节点
* @return 对应的Dom4j的Element对象
*/
public abstract Element convertToElement(INode node);
/**
*
* @param node 节点
* @return Dom4j的 Document对象
*/
public abstract Document getDocument(INode node);
/**
* 用于循环元素
* @param parentElement Dom4j格式的父亲元素
* @param parentNode 父节点,这个方法会把它的所有子节点转换成Element,加到它上面
*
* @return
*/
public abstract Element loopElement(Element parentElement,INode parentNode);
/**
* 用于循环元素,获取一个父节点,它包含了所有的子节点
* @param parentElement
* @param parentNode
* @return
*/
public abstract INode loopINode(Element parentElement, INode parentNode);
/**
* 转换Dom4j的Element节点为 INode
* @param element
* @return
*/
public abstract INode convertToINode(Element element);
/**
*
* @param url
* @return
* @throws Exception
*/
public abstract INode loadXmlFile(URL url) throws Exception;
/**
*
* @param node
* @param url
* @throws URISyntaxException
* @throws IOException
*/
public abstract void write(INode node, URL url) throws IOException, URISyntaxException;
/**
*
* @param node
* @param fileName
* @throws URISyntaxException
* @throws IOException
*/
public abstract void write(INode node, String fileName) throws IOException, URISyntaxException;
/**
*
* @param node
* @param fileName
* @throws IOException
*/
public abstract void writeToCompactFormat(INode node, String fileName) throws IOException;
/**
*
* @param node
* @param url
* @throws URISyntaxException
* @throws IOException
*/
public abstract void writeToCompactFormat(INode node, URL url) throws IOException, URISyntaxException;
/**
*
* @param node
* @param url
* @throws URISyntaxException
* @throws IOException
*/
public abstract void writeToPrettyPrint(INode node, URL url) throws IOException, URISyntaxException;
/**
*
* @param node
* @param fileName
* @throws IOException
* @throws URISyntaxException
*/
public abstract void writeToPrettyPrint(INode node, String fileName) throws IOException, URISyntaxException;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -