Source code: recoinx/clef/CLEFResultList.java
1 package recoinx.clef;
2
3 import java.util.Enumeration;
4
5 import org.apache.log4j.Logger;
6
7 import recoin.container.ResultList;
8
9 import recoinx.clef.CLEFQuery.CLEFTopic;
10
11 /**
12 * A CLEFResultList extends a simple ResultList. It provides special attributes and
13 * methods to store and access data about the topic that was used to create this
14 * CLEFResultList and the collection that was queried.
15 * @author Jan H. Scheufen
16 * @version 0.2.9
17 */
18 public class CLEFResultList extends ResultList
19 {
20 /**
21 * The logger for this class.
22 */
23 static Logger logger;
24 /**
25 * The collection of this CLEFResultList. Default is -1 for 'No Collection'.
26 */
27 private int collection = -1;
28 /**
29 * The topic.
30 */
31 private CLEFQuery.CLEFTopic topic;
32
33 /**
34 * Creates a new CLEFResultList.
35 * @param id the id of the Component that produced this CLEFResultList
36 */
37 public CLEFResultList()
38 {
39 super();
40 // Initialize the logger for this class.
41 logger = Logger.getLogger( CLEFResultList.class.getName() );
42 }
43
44 /**
45 * Creates a new CLEFResultList that copies the attributes and results of
46 * the specified CLEFResultList.
47 * @param listA
48 */
49 public CLEFResultList( CLEFResultList list )
50 {
51 super();
52 // Initialize the logger for this class.
53 logger = Logger.getLogger( CLEFResultList.class.getName() );
54 this.collection = list.getCollection();
55 setName( list.getName() );
56 setChainID( list.getChainID() );
57 setResults( list.getResults() );
58 }
59
60 /**
61 * Returns the language.
62 * @return the language
63 */
64 public int getLanguage()
65 {
66 return topic.getLanguage();
67 }
68
69 /**
70 * Returns the collection.
71 * @return the collection
72 */
73 public int getCollection()
74 {
75 return collection;
76 }
77
78 /**
79 * Returns a short name of the collection of the CLEFResultList. Actually this
80 * is the same as calling CLEFConstants.getCollectionTable(int) with this
81 * CLEFResultList's <code>collection</code> fiels as parameter.
82 * @return the collection code
83 */
84 public String getCollectionCode()
85 {
86 return CLEFConstants.getCollectionTable( this.collection );
87 }
88
89 /**
90 * Sets the collection of this CLEFResultList to the specified one.
91 * @param i the collection
92 */
93 public void setCollection(int i)
94 {
95 collection = i;
96 }
97
98 /**
99 * Returns a XML representation of this CLEFResultList. The returned
100 * String will be a valid XML file including a prolog.
101 * @return the XML representation
102 */
103 public String toXML()
104 {
105 String nl = System.getProperty("line.separator");
106 String xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"+nl+nl+
107 "<CLEFRESULTLIST>"+nl+
108 "<COLLECTIONNAME>"+getName()+"</COLLECTIONNAME>"+nl+
109 "<COLLECTIONCODE>"+getCollectionCode()+"</COLLECTIONCODE>"+nl+
110 "<TOPIC>"+getTopicNumber()+"</TOPIC>"+nl+
111 "<CHAINID>"+getChainID()+"</CHAINID>"+nl+nl;
112 for( Enumeration enum = getResults().elements(); enum.hasMoreElements(); )
113 {
114 xml += ((CLEFResult)enum.nextElement()).toXML()+nl;
115 }
116 xml += "</CLEFRESULTLIST>"+nl;
117 return xml;
118 }
119
120 /**
121 * Returns the topic number that is stored in this CLEFResultList's CLEFTopic.
122 * @return the topic number
123 */
124 public String getTopicNumber()
125 {
126 return this.topic.getTopicNumber();
127 }
128
129 /**
130 * Sets the CLEFTopic of this CLEFResultList.
131 * @param top the topic
132 */
133 public void setTopic( CLEFQuery.CLEFTopic top )
134 {
135 this.topic = top;
136 }
137
138 /**
139 * Returns this CLEFResultList's CLEFTopic.
140 * @return the topic
141 */
142 public CLEFTopic getTopic()
143 {
144 return this.topic;
145 }
146
147 }