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

📄 displayresult.java

📁 使用模式映射方法
💻 JAVA
字号:
/*
 * DisplayResult.java
 *
 * Created on 2007年5月11日, 上午12:54
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package XRSystem.Process;

/**
 *
 * @author 王刚
 */
import java.lang.*;
import java.util.*;
import java.sql.*;

import org.jdom.*;
import org.jdom.output.*;

import XRSystem.Util.*;
import XRSystem.DataAccess.*;
import XRSystem.Process.*;

public class DisplayResult {
    
    private ArrayList<ResultElement> ResultList = new ArrayList<ResultElement>();
    private String XMLString;
    /** Creates a new instance of DisplayResult */
    public DisplayResult(ArrayList<ResultElement> ResultList) {
        this.ResultList = ResultList;
    }
    
    private int GetDocID() {
        int DocID = ResultList.get(0).GetDocumentID();
        return DocID;
    }
    
    private ArrayList<ElementNode> ProcessData(String SQL) {
        ResultSet rs = null;
        ArrayList<ElementNode> ElementList = new ArrayList<ElementNode>();
        String SQLString=SQL;
        try{
            rs = new SQLResultSet().ExecuteSQL(SQLString);
            while(rs.next()) {
                XRSystem.Util.ElementNode TempNode = new ElementNode(this.GetDocID(),rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getInt(4),rs.getInt(5));
                ElementList.add(TempNode);
            }
        }catch(SQLException e){e.printStackTrace();} catch(Exception e){e.printStackTrace();}
        return ElementList;
    }
    
    private ArrayList<TextNode> ProcessText(int TEPre) {
        ArrayList<TextNode> TextList =  new ArrayList<TextNode>();
        String TextSQL="SELECT TextID,ElementPre,ElementPost,TextContent FROM [Text] WHERE ElementPre="+TEPre+" AND DocumentID="+this.GetDocID();
        ResultSet rsT = null;
        try{
            rsT = new SQLResultSet().ExecuteSQL(TextSQL);
            while(rsT.next()){
                TextNode TempText = new TextNode(this.GetDocID(),rsT.getInt(1),rsT.getInt(2),rsT.getInt(3),rsT.getString(4));
                TextList.add(TempText);
            }
        }catch(SQLException e){e.printStackTrace();} catch(Exception e){e.printStackTrace();}
        return TextList;
    }
    
    private ArrayList<AttributeNode> ProcessAttribute(int AEPre) {
        ArrayList<AttributeNode> AttributeList =  new ArrayList<AttributeNode>();
        String AttributeSQL="SELECT AttributeID,ElementPre,ElementPost,AttributeName,AttributeValue FROM Attribute WHERE ElementPre="+AEPre+" AND DocumentID="+this.GetDocID();
        ResultSet rsA = null;
        try{
            rsA = new SQLResultSet().ExecuteSQL(AttributeSQL);
            while(rsA.next()) {
                AttributeNode TempAttribute = new AttributeNode(this.GetDocID(),rsA.getInt(1),rsA.getInt(2),rsA.getInt(3),rsA.getString(4),rsA.getString(5));
                AttributeList.add(TempAttribute);
            }
        }catch(SQLException e){e.printStackTrace();} catch(Exception e){e.printStackTrace();}
        return AttributeList;
    }
    
    private Element RecursiveConstruct(Element TempElem,ArrayList<ElementNode> TempList) {
        Element ThisElem=TempElem;
        ArrayList<AttributeNode> AList2 = new ArrayList<AttributeNode>();
        ArrayList<TextNode> TList2 = new ArrayList<TextNode>();
        for(int m=0;m<TempList.size();m++) {
            Element ChildElement = new Element(TempList.get(m).GetTagName());
            AList2 = ProcessAttribute(TempList.get(m).GetElementPre());
            TList2= ProcessText(TempList.get(m).GetElementPre());
            for(int A2=0;A2<AList2.size();A2++) {
                ChildElement.setAttribute(AList2.get(A2).GetAttributeName(),AList2.get(A2).GetAttributeValue());
            }
            for(int T2=0;T2<TList2.size();T2++){
                String TValue = TList2.get(T2).GetTextContent();
                ChildElement.setText(TValue);
            }
            String ChildSQL="SELECT ElementPre,ElementPost,ElementTag,ParentPre,ParentPost FROM Element WHERE ParentPre="+TempList.get(m).GetElementPre()+" AND DocumentID="+this.GetDocID();
            ArrayList<ElementNode> TNList = new ArrayList<ElementNode>();
            TNList = ProcessData(ChildSQL);
            ThisElem.addContent(RecursiveConstruct(ChildElement,TNList));
        }
        return ThisElem;
    }
    
    public void BuildResult() {
        Document ThisDoc = this.ConstructFrag(ResultList);
        this.PrintResult(ThisDoc);
    }
    
    private void PrintResult(Document XMLDocument) {
        XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat());
        try{
            XMLString = outp.outputString(XMLDocument);
        } catch(Exception e){e.printStackTrace();}
        XMLString = XMLString.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n","");
        XMLString = XMLString.replace("<结果XML文档片断>\r\n","");
        XMLString = XMLString.replace("</结果XML文档片断>\r\n\r\n","");
        System.out.println(XMLString);
        new XRSystem.GUI.QueryResult(XMLString).setVisible(true);
    }
    
    private Document ConstructFrag(ArrayList<ResultElement> TList) {
        Document ThisDocument;
        Element RootElement = new Element("结果XML文档片断");
        ThisDocument = new Document(RootElement);

        for(int i=0;i<TList.size();i++) {
            Element ParentElement = new Element(TList.get(i).GetTagName());
            ArrayList<AttributeNode> AList1 = new ArrayList<AttributeNode>();
            ArrayList<TextNode> TList1 = new ArrayList<TextNode>();
            AList1= ProcessAttribute(TList.get(i).GetElementPre());
            TList1= ProcessText(TList.get(i).GetElementPre());
            for(int A1=0;A1<AList1.size();A1++) {
                ParentElement.setAttribute(AList1.get(A1).GetAttributeName(),AList1.get(A1).GetAttributeValue());
            }
            for(int T1=0;T1<TList1.size();T1++){
                ParentElement.setText(TList1.get(T1).GetTextContent());
            }
            String LowSQL="SELECT ElementPre,ElementPost,ElementTag,ParentPre,ParentPost FROM Element WHERE ParentPre="+TList.get(i).GetElementPre()+" AND DocumentID="+this.GetDocID();
            ArrayList<ElementNode> ChildList = new ArrayList<ElementNode>();
            ChildList = ProcessData(LowSQL);
            Element SecondLevel = RecursiveConstruct(ParentElement,ChildList);
            ThisDocument.getRootElement().addContent(SecondLevel);
        }
        return ThisDocument;
    }   
   
}

⌨️ 快捷键说明

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