将树输出到XML文件

/**
     * put out the tree information to XML file <br>
     * 
@return  if wrong return 0,else return 1
     * 
@throws  N/A
     * 
@author  tianrenliang
     * 
@since  V0.1(2007/12/06)
     
*/
    
public   int  saveTreeToXmlFile(ViewMsgTree viewMsgTree, String strName)
    {
        
if (viewMsgTree == null )
        {
            
return   0 ;
        }
        ViewMsgTreeItem rootItem 
=  viewMsgTree.getRootItem();
        ITreeNode treenode 
=  rootItem.getRefNode(); // get the root node
//         strFileName =  ViewTreeList.getInstance().getCurrentSelPduName();
         /* create a save dialog,create a xml file by using this dialog : Start */
        Shell sMain 
=  MainWindow.getInstance().openMainWindow();
        
if  ( null   ==  sMain) 
        {
            
return   0 ;
        }
        FileDialog fileDlg 
=   new  FileDialog(sMain, SWT.SAVE);
        
if  ( null   !=  strName)
        {
            fileDlg.setFileName(strName);
        }
        fileDlg.setFilterExtensions(
new  String[] {  " *.xml " });
        
// set first time dialog save path
        String def  =  getDefaultPath();
        
if (xmlFilePath == null )
        {
            fileDlg.setFilterPath(def);
        }
        xmlFilePath 
=  fileDlg.open();
        
// set next open dialog's save path
         if  ( null   !=  xmlFilePath) 
        {
            fileDlg.setFilterPath(xmlFilePath);
        }
        
else
        {
            
return   0 ;
        }
        File file 
=   new  File(xmlFilePath);
        
try  {
            file.createNewFile();
// create a new file to save the out put
        }  catch  (IOException e1) {
            OutPutIOException.getInstance().logException(e1);
        }
        
/* create a save dialog,create a xml file by using this dialog : End */
        
// out put the the tree to the xml file
        FileOutputStream fileOut  =   null ;
        
// control and manage progressBar
        createProgressThred();
        
        
if (xmlFilePath != null )
        {
            XMLOutputter XMLOut 
=   new  XMLOutputter(Format.getPrettyFormat());
            
try  {
                fileOut 
=   new  FileOutputStream(xmlFilePath);
            } 
catch  (FileNotFoundException e1) {
                
//  TODO Auto-generated catch block
                OutPutIOException.getInstance().logException(e1);
            }
            
try  { // out put a tree based on root treenode
                XMLOut.output(treenode.parseToXml(),fileOut);
            } 
catch  (FileNotFoundException e) {
                OutPutIOException.getInstance().logException(e);
            } 
catch  (IOException e) {
                OutPutIOException.getInstance().logException(e);
            }
            
try  {
                fileOut.close();
// close the stream
            }  catch  (IOException e) {
                OutPutIOException.getInstance().logException(e);
            }
        }
        mainInstance.setStopFlag(
true );
        
return   1 ;
    }
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值