1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2005 University of New Mexico and the
|
4
|
* Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* '$Author: costa $'
|
7
|
* '$Date: 2005-11-16 09:57:33 -0800 (Wed, 16 Nov 2005) $'
|
8
|
* '$Revision: 2741 $'
|
9
|
*
|
10
|
* This program is free software; you can redistribute it and/or modify
|
11
|
* it under the terms of the GNU General Public License as published by
|
12
|
* the Free Software Foundation; either version 2 of the License, or
|
13
|
* (at your option) any later version.
|
14
|
*
|
15
|
* This program is distributed in the hope that it will be useful,
|
16
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
* GNU General Public License for more details.
|
19
|
*
|
20
|
* You should have received a copy of the GNU General Public License
|
21
|
* along with this program; if not, write to the Free Software
|
22
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23
|
*/
|
24
|
|
25
|
package edu.ucsb.nceas.metacat.advancedsearch;
|
26
|
|
27
|
import java.util.ArrayList;
|
28
|
|
29
|
/**
|
30
|
* @author dcosta
|
31
|
*
|
32
|
* The AdvancedSearchPathQuery class holds the data needed to produce a
|
33
|
* valid PathQuery XML string.
|
34
|
*/
|
35
|
public class AdvancedSearchPathQuery {
|
36
|
|
37
|
// Object variables
|
38
|
private String indent; // String of spaces
|
39
|
private final int initialLength = 500; // Initial length of stringBuffer
|
40
|
private StringBuffer stringBuffer; // Holds the pathquery xml
|
41
|
private ArrayList returnFieldList = new ArrayList(); // List of returnfields
|
42
|
private AdvancedSearchQueryGroup queryGroup; // The outer query group
|
43
|
private String title; // The pathquery title
|
44
|
|
45
|
|
46
|
/**
|
47
|
* Constructor. Initializes the pathquery title, the main query group, and the
|
48
|
* indent string.
|
49
|
*
|
50
|
* @param title the title of the pathquery
|
51
|
* @param queryGroup the main query group
|
52
|
* @param indent a string of spaces used for indenting output
|
53
|
*/
|
54
|
public AdvancedSearchPathQuery(final String title,
|
55
|
final AdvancedSearchQueryGroup queryGroup,
|
56
|
final String indent) {
|
57
|
this.title = title;
|
58
|
this.queryGroup = queryGroup;
|
59
|
this.indent = indent;
|
60
|
addReturnField("dataset/title");
|
61
|
addReturnField("originator/individualName/surName");
|
62
|
addReturnField("dataset/creator/individualName/surName");
|
63
|
addReturnField("originator/organizationName");
|
64
|
addReturnField("creator/organizationName");
|
65
|
addReturnField("keyword");
|
66
|
}
|
67
|
|
68
|
|
69
|
/**
|
70
|
* Adds a returnfield to the pathquery xml.
|
71
|
*
|
72
|
* @param s the name of the returnfield to add
|
73
|
*/
|
74
|
public void addReturnField(final String s) {
|
75
|
returnFieldList.add(s);
|
76
|
}
|
77
|
|
78
|
|
79
|
/**
|
80
|
* Creates the pathquery xml string.
|
81
|
*
|
82
|
* @return a string holding the PathQuery XML.
|
83
|
*/
|
84
|
public String toString() {
|
85
|
String returnField;
|
86
|
|
87
|
stringBuffer = new StringBuffer(initialLength);
|
88
|
stringBuffer.append("<?xml version=\"1.0\"?>\n");
|
89
|
stringBuffer.append("<pathquery version=\"1.2\">\n");
|
90
|
stringBuffer.append(indent + "<querytitle>" +
|
91
|
title + "</querytitle>\n");
|
92
|
|
93
|
for (int i = 0; i < returnFieldList.size(); i++) {
|
94
|
returnField = (String) returnFieldList.get(i);
|
95
|
stringBuffer.append(indent + "<returnfield>" +
|
96
|
returnField + "</returnfield>\n");
|
97
|
}
|
98
|
|
99
|
stringBuffer.append(queryGroup.toString());
|
100
|
stringBuffer.append("</pathquery>\n");
|
101
|
|
102
|
return stringBuffer.toString();
|
103
|
}
|
104
|
|
105
|
}
|