Project

General

Profile

« Previous | Next » 

Revision 318

Added by berkley over 24 years ago

no message

View differences:

lib/marine/marine.xsl
21 21
  <xsl:template match="/">
22 22
    <html>
23 23
      <head>
24
	<link rel="stylesheet" type="text/css" href="/xmltodb/lib/rowcol.css" />
24
	<link rel="stylesheet" type="text/css" href="/xmltodb/lib/marine/rowcol.css" />
25 25
      </head>
26 26
      <body class="emlbody">
27
      <script language="JavaScript">
28
        function gotoNceas()
29
        {
30
          window.location="http://www.nceas.ucsb.edu";
31
        }
32
      </script>
27 33
        <a name="top" />
34
        <table width="100%">
35
        <tr>
36
          <td align="left" valign="top">
37
            <form action="http://alpha.nceas.ucsb.edu/servlets/marineServlet#browse"
38
                  method="POST">
39
               <input type="hidden" name="action" value="squery" />   
40
    	       <input type="hidden" name="query" value="" />
41
    	       <input type="hidden" name="qformat" value="html" />
42
               <input type="hidden" name="operator" value="UNION" />
43
               <input type="hidden" name="anyfield" value="%" />
44
               <input type="submit" value="Browse the Database" size="15" />
45
            </form>   
46
          </td>
47
          <td align="center" valign="bottom">
48
            <img src="/xmltodb/lib/marine/logo-line.gif" alt="NCEAS Logo" onClick="gotoNceas()" />
49
          </td>
50
          <td align="right" valign="top">
51
            <form action="http://alpha.nceas.ucsb.edu/servlets/marineServlet#browse"
52
                  method="POST">
53
               Quick Search: <input type="text" name="query" size="10" />
54
               <input type="hidden" name="action" value="query" />   
55
    	       <input type="hidden" name="qformat" value="html" />
56
    	       <input type="hidden" name="operator" value="UNION" />
57
    	     </form>
58
    	   </td>
59
    	 </tr>
60
        </table>
61
        
62
        <hr />
63
        
28 64
        <center><h1>MARINE Query Interface</h1></center>
65
        <font size="2">
66
        <p class="intro">
67
          This page is used to query information for 
68
          <a href="http://www.mms.gov/omm/pacific/enviro/mint.htm">MARINE</a> scientists from
69
          the NCEAS Ecological Metadata Database.  For more information on
70
          this project, please read the 
71
          <a href="https://www2.nceas.ucsb.edu/admin/db/web.ppage?projid_in=2841">
72
          proposal abstract</a>.
73
        </p>
29 74
        
30
        <p><h3>You can either <a href="#browse">browse the database</a> or start with 
31
           step 1 below.</h3></p>
75
        <p class="intro">
76
           Each step below contains several fields relating to a part of the dataset.  
77
           You may also browse
78
           the entire database by simply clicking the browse link at the top of the page.
79
           Clicking on the buttons next to each data line will give you more
80
           information about the dataset or allow you to download the entire dataset.  
81
           Please note some fields in the query forms will not be pertinent to your dataset.  
82
           If this is the case, simply leave any field blank to omit it from the searching.  
83
        </p>
32 84
        
33
        <table width="100%" border="1">
34
          <tr>
35
             <td valign="bottom">
36
        	<img src="http://alpha.nceas.ucsb.edu/xmltodb/lib/marine/step1.png" />
37
        	<p>Enter data about the owner of the dataset.  There may be more than one
38
        	   owner of any given dataset.  Any field(s) left blank will not be used
39
        	   in the search criteria.
40
        	</p>
41
              </td>
42
          </tr>
43
        </table>
44
             
45
      	<form action="http://alpha.nceas.ucsb.edu/servlets/marineServlet#browse" 
85
        <p class="intro">
86
           Note that the wildcard character is a percent sign (%).  It may be used in any
87
           field to denote "any" value.  For example, the query "do%" would return "document"
88
           or "dog" or "domino" or "dolphin", etc.  Placing a single percent sign in a field
89
           will return any document that contains that field.  Placing a percent sign in
90
           the "Any Field" field is equivalent to browsing the database (i.e. it will return
91
           every document).  
92
        </p>
93
        </font>
94
        
95
        <form action="http://alpha.nceas.ucsb.edu/servlets/marineServlet#browse" 
46 96
              method="POST"> 
47
           <table width="100%">
48
             <tr>
49
                <td>First Name:</td>
50
                <td><input type="text" name="given_name" /></td>
51
                <td>Last Name:</td>
52
                <td><input type="text" name="surname" /></td>
53
             </tr>
54
             <tr>
55
             	<td>Organization:</td>
56
             	<td><input type="text" name="organization" /></td>
57
             	<td>Address:</td>
58
             	<td><input type="text" name="deliveryPoint" /></td>
59
             </tr>
60
             <tr>
61
             	<td>City:</td>
62
             	<td><input type="text" name="city" /></td>
63
             	<td>Postal Code:</td>
64
             	<td><input type="text" name="postalCode" /></td>
65
             </tr>
66
             <tr>
67
             	<td>Email Address:</td>
68
             	<td><input type="text" name="electronicMailAddress" /></td>
69
             	<td>Phone:</td>
70
             	<td><input type="text" name="voice" /></td>
71
             </tr>
72
           </table>
73
        
97
           
74 98
        <table width="100%" border="1">
75 99
          <tr>
76
             <td valign="bottom">
77
        	<img src="http://alpha.nceas.ucsb.edu/xmltodb/lib/marine/step2.png" />
78
        	<p>Enter bibliographic data relevent to the dataset.  
79
        	   Any field(s) left blank will not be used in the search criteria.  
80
        	   Some fields might not be relevent to the dataset for which you are 
81
        	   searching.
82
        	</p>
100
             <td valign="bottom" width = "25">
101
        	<img src="http://alpha.nceas.ucsb.edu/xmltodb/lib/marine/step1.jpg" />
83 102
             </td>
103
             <td>
104
               <h4>Keywords and Title</h4>
105
               <p>
106
               <font size="2">
107
                 Enter any keywords that might partain to the dataset you are looking for.  
108
                 The "Any Field" text box will search for any field in any document for 
109
                 the text you provide.  The title and alternate title will search for text 
110
                 in the title or alternate title fields of a document only.  Fields left 
111
                 blank will not be used in the search criteria.
112
               </font></p>
113
             </td> 
84 114
          </tr>
85 115
        </table>
86
           
116
        
87 117
        <table width="100%">
88 118
             <tr>
89
             	<td>Publisher:</td>
90
                <td><input type="text" name="publisher" /></td>
91 119
                <td>Title:</td>
92
                <td><input type="text" name="title" /></td>
120
                <td>
121
                  <input type="text" name="title" size="15">
122
                  <xsl:attribute name="value">
123
                  <xsl:value-of select="resultset/query/title" />
124
                  </xsl:attribute>
125
                  </input>
126
                </td>
127
                <td>Any Field:</td>
128
                <td>
129
                  <input type="text" name="anyfield" size="15">
130
                  <xsl:attribute name="value">
131
                  <xsl:value-of select="resultset/query/anyfield" />
132
                  </xsl:attribute>
133
                  </input>
134
                </td>
93 135
             </tr>
94 136
             <tr>
95
             	<td>Publication Date:</td>
96
             	<td><input type="text" name="pubdate" /></td>
97
             	<td>Alternate Title:</td>
98
             	<td><input type="text" name="alttitle" /></td>
137
                <td>Alternate Title:</td>
138
             	<td>        
139
		  <input type="text" name="alttitle" size="15">
140
             	  <xsl:attribute name="value">
141
                  <xsl:value-of select="resultset/query/alttitle" />
142
                  </xsl:attribute>
143
                  </input>
144
                </td>
145
                <td>Keywords:</td>
146
                <td>
147
                  <input type="text" name="keyword" size="15">
148
                  <xsl:attribute name="value">
149
                  <xsl:value-of select="resultset/query/keyword" />
150
                  </xsl:attribute>
151
                  </input>
152
                </td>
99 153
             </tr>
100
             <tr>
101
             	<td>Publication Place:</td>
102
             	<td><input type="text" name="pubplace" /></td>
103
             	<td>URL:</td>
104
             	<td><input type="text" name="url" /></td>
105
             </tr>
106
             <tr>
107
             	<td>ISBN:</td>
108
             	<td><input type="text" name="isbn" /></td>
109
             	<td>Geospatial Representation Form:</td>
110
             	<!-- <td><input type="text" name="geoform" /></td> -->
111
             	<td>
112
             	<select name="geoform">
113
             	  <option value="" />
114
             	  <option value="atlas" />Atlas
115
             	  <option value="audio" />Audio
116
             	  <option value="diagram" />Diagram
117
             	  <option value="document" />Document
118
             	  <option value="globe" />Globe
119
             	  <option value="map" />Map
120
             	  <option value="model" />Model
121
             	  <option value="multimediaPresentation" />Multimedia Presentation
122
             	  <option value="profile" />Profiles
123
             	  <option value="rasterDigitalData" />Raster Digital Data
124
             	  <option value="remoteSensingImage" />Remote Sensing Image
125
             	  <option value="section" />Section
126
             	  <option value="spreadsheet" />Spreadsheet
127
             	  <option value="tabularDigialData" />Tabular Digial Data
128
             	  <option value="vectorDigitalData" />Vector Digital Data
129
             	  <option value="video" />Video
130
             	  <option value="view" />View
131
             	</select>
132
             	</td>
133
             </tr>
134
             <tr>
135
             	<td>ISSN:</td>
136
             	<td><input type="text" name="issn" /></td>
137
             	<td></td>
138
             	<td></td>
139
             </tr>
140
             <tr>
141
             	<td>Editor:</td>
142
             	<td><input type="text" name="editor" /></td>
143
             	<td></td>
144
             	<td></td>
145
             </tr>
146
             <tr>
147
             	<td>Edition:</td>
148
             	<td><input type="text" name="edition" /></td>
149
             	<td></td>
150
             	<td></td>
151
             </tr>
152
             <tr>
153
             	<td>Volume:</td>
154
             	<td><input type="text" name="volume" /></td>
155
             	<td></td>
156
             	<td></td>
157
             </tr>
158 154
        </table>
159

  
155
        
160 156
        <table width="100%" border="1">
161 157
          <tr>
162
             <td valign="bottom">
163
        	<img src="http://alpha.nceas.ucsb.edu/xmltodb/lib/marine/step3.png" />
164
        	<p>Enter any keywords that might partain to the dataset you are looking 
165
        	   for.  The "Any Field" text box will search any field in any document
166
        	   for the text you provide.
167
        	   Field(s) left blank will not be used in the search criteria.  
158
             <td valign="bottom" width="25">
159
        	<img src="http://alpha.nceas.ucsb.edu/xmltodb/lib/marine/step2.jpg" />
160
             </td>
161
             <td>
162
                <h4>Dataset Owner Information</h4>
163
        	<p>
164
        	   <font size="2">
165
        	   Enter data about the owner of the dataset.  There may be more than one
166
        	   owner of any given dataset.  Any field(s) left blank will not be used
167
        	   in the search criteria.
168
        	   </font>
168 169
        	</p>
169 170
             </td>
170 171
          </tr>
171 172
        </table>
172
           
173 173
        <table width="100%">
174 174
             <tr>
175
             	<td>Keywords:</td>
176
                <td><input type="text" name="keyword" /></td>
177
                <td>Any Field:</td>
178
                <td><input type="text" name="anyfield" /></td>
175
                <td>First Name:</td>
176
                <td> 
177
                  <input type="text" name="given_name" size="15">
178
             	  <xsl:attribute name="value">
179
                  <xsl:value-of select="resultset/query/given_name" />
180
                  </xsl:attribute>
181
                  </input>
182
                </td>
183
                <td>Last Name:</td>
184
                <td> <!-- <input type="text" name="surname" /> -->
185
                  <input type="text" name="surname" size="15">
186
             	  <xsl:attribute name="value">
187
                  <xsl:value-of select="resultset/query/surname" />
188
                  </xsl:attribute>
189
                  </input>
190
                </td>
179 191
             </tr>
180
        </table>
192
             <tr>
193
             	<td>Organization:</td>
194
             	<td> 
195
             	  <input type="text" name="organizationName" size="15">
196
             	  <xsl:attribute name="value">
197
                  <xsl:value-of select="resultset/query/organizationName" />
198
                  </xsl:attribute>
199
                  </input>
200
                </td>
201
             	<td>Email Address:</td>
202
             	<td> 
203
             	  <input type="text" name="electronicMailAddress" size="15">
204
             	  <xsl:attribute name="value">
205
                  <xsl:value-of select="resultset/query/electronicMailAddress" />
206
                  </xsl:attribute>
207
                  </input>
208
                </td>
209
             </tr>
210
           </table>
181 211
           
182 212
        <table width="100%" border="1">
183 213
          <tr>
184
             <td valign="bottom">
185
        	<img src="http://alpha.nceas.ucsb.edu/xmltodb/lib/marine/step4.png" />
186
        	<p>Click the Query button to submit your query.  The results will be
187
        	   displayed below under the heading "Query Results".
214
             <td valign="bottom" width="25">
215
        	<img src="http://alpha.nceas.ucsb.edu/xmltodb/lib/marine/step3.jpg" />
216
             </td>
217
             <td>
218
        	<h4>Query the Database</h4>
219
        	<p>
220
        	   <font size="2">
221
        	   Click the Query button to submit your query.  The results will be
222
        	   displayed below under the heading "Results".
223
        	   </font>
188 224
        	</p>
189 225
             </td>
190 226
          </tr>
......
194 230
    	<input type="hidden" name="qformat" value="html" />
195 231
    	<input type="hidden" name="operator" value="UNION" />
196 232
        
197
        <input type="submit" value="Query" /><input type="reset" value="Clear Form" />
233
        <input type="submit" value="Query" />
234
        <input type="reset" value="Clear Form" />
198 235
        
199 236
        </form>
200 237
             
201 238
        <a name="browse" />
239
	<font size="3"><xsl:number value="count(resultset/document)" /> documents found.</font>
240
	<!-- This tests to see if there are returned documents,
241
	     if there are not then don't show the query results
242
	-->
243
	<xsl:if test="count(resultset/document) &gt; 0">
202 244
	
203 245
	<center>
204 246
          <u><h2>Results</h2></u>
......
206 248
        
207 249
        <form action="/servlets/marineServlet" method="POST">
208 250
        <input type="hidden" name="action" value="getdocument"/>
209

  
251
                
210 252
        <table width="100%">
211 253
        <tr class="rowodd">
212 254
        <th>&nbsp;</th>
213 255
        <th><xsl:text>Title</xsl:text></th>
214
        <th><xsl:text>Resource Name</xsl:text></th>
256
        <th><xsl:text>Owner</xsl:text></th>
257
        <th><xsl:text>Organization</xsl:text></th>
258
        <th><xsl:text>Creation Date</xsl:text></th>
259
        <th><xsl:text>Last Updated</xsl:text></th>
215 260
        </tr>
216 261

  
262
	
263
	
217 264
        <xsl:for-each select="resultset/document">
265
          <xsl:sort select="doctitle"/>
218 266
          <tr valign="top">
219 267
            <xsl:attribute name="class">
220 268
              <xsl:choose>
......
228 276
                <xsl:attribute name="src">
229 277
                  <xsl:choose>
230 278
                    <xsl:when test="position() 
231
                         mod 2 = 1">/xmltodb/images/bttns-white.png</xsl:when>
279
                         mod 2 = 1">/xmltodb/lib/marine/whiteMenu.jpg</xsl:when>
232 280
                    <xsl:when test="position() 
233
                         mod 2 = 0">/xmltodb/images/bttns-blue.jpg</xsl:when>
281
                         mod 2 = 0">/xmltodb/lib/marine/blueMenu.jpg</xsl:when>
234 282
                  </xsl:choose>
235 283
                </xsl:attribute>
236 284
                <xsl:attribute name="name">
......
239 287
              </input>
240 288
          </td>
241 289
          <td><xsl:value-of select="./doctitle"/>
290
              
242 291
              <xsl:text>&nbsp;</xsl:text>
243
         </td>
292
          </td>
293
          <td><xsl:value-of select="./givenName" />
294
              <xsl:text>&nbsp;</xsl:text>
295
              <xsl:value-of select="./surName" />
296
              <xsl:text>&nbsp;</xsl:text>
297
          </td>
298
          <td><xsl:value-of select="./organizationName" />
299
              <xsl:text>&nbsp;</xsl:text>
300
          </td>
244 301
          <td>
245
              <xsl:value-of select="./docname"/> 
246
              <xsl:text> </xsl:text>
302
              <xsl:value-of select="./date_created" />
303
              <xsl:text>&nbsp;</xsl:text>
247 304
          </td>
305
          <td>
306
              <xsl:value-of select="./date_updated" /> 
307
              <xsl:text>&nbsp;</xsl:text>
308
          </td>
248 309
          </tr>
249 310
        </xsl:for-each>
250 311
        </table>
......
252 313

  
253 314
        <h3><a href="#top">New Query</a></h3>
254 315
        
316
        </xsl:if>
317
        
255 318
      </body>
256 319
    </html>
257 320
  </xsl:template>
lib/marine/rowcol.css
1
 .page    {font-family: Tahoma, sans-serif; background-color:white}
2
 .emlbody    {font-family: Tahoma, sans-serif; background-color:white}
3
 .rowodd  {background-color: #CCCCCC; color: black; vertical-align: top}
4
 .roweven {background-color: #F8F8F8; color: black; vertical-align: top}
5
 .rowlight {background-color: #0099C8; color: black;  vertical-align: top}
6
 .rowwhite {background-color: #FFFFFF; color: black; vertical-align: top}
7
 .stephead {background=color: #000000; color: white;}
8
 .coleven {}
9
 .colodd  {}
10
 .shaded  {background-color: #DDDDDD; color: black; font-size: -1}
0 11

  
lib/marine/marine.properties
8 8
defaultDB=jdbc:oracle:thin:@24.237.21.98:1521:test
9 9
dbDriver=oracle.jdbc.driver.OracleDriver
10 10
resultStyleURL=http://alpha.nceas.ucsb.edu/xmltodb/lib/marine/marine.xsl
11
docStyleURL=http://alpha.nceas.ucsb.edu/xmltodb/lib/marine/marineDoc.xsl
11 12
xmlcatalogfile=http://alpha.nceas.ucsb.edu/xmltodb/lib/catalog.txt
12 13
defaultdatapath=C:\Temp\
13 14
executescript=test.bat
lib/marine/marineDoc.xsl
1
<?xml version="1.0" ?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
  <xsl:output method="html"/>
4
  <xsl:template match="/">
5
  <!--
6
    List elements in the following order:
7
    - ID
8
    - Title
9
    - Alt title
10
    - URL
11
    - originator(s)
12
    - abstract
13
    - keyword info
14
      - keyword, keyword type
15
    - additionalInfo
16
  -->
17
  
18
  <html>
19
  <head>
20
  <title>
21
  <xsl:value-of select="title" />
22
  </title>
23
  </head>
24
  <body>
25
  <h1>
26
  <xsl:value-of select-"title" />
27
  </h1>
28
  <h2>
29
  <xsl:value-of select="alternateTitle" />
30
  </h2>
31
  <font size = 5>
32
  ID: <xsl:value-of select="identifier" />
33
  </font>
34
  <h3>URL:
35
  <xsl:value-of select="URL" />
36
  </h3>
37
  
38
  
39
  <xsl:for-each select="originator">
40
   <p>
41
    <xsl:value-of select="salutation" />
42
    <xsl:value-of select="givenName" />
43
    <xsl:value-of select="surName" />
44
    <br/>
45
    <xsl:value-of select="deliveryPoint" />
46
    <br/>
47
    <xsl:value-of select="city" />, 
48
    <xsl:value-of select="adminitrativeArea />
49
    <xsl:value-of select="postalCode" />
50
    <br/>
51
    <xsl:value-of select="electronicMailAddress" />
52
    <br/>
53
    <xsl:value-of select="onlineResource/URL" />
54
    <br/>
55
    <xsl:value-of select="hoursOfService" />
56
    <br/>
57
    <xsl:value-of select="contactInstructions" />
58
    <br/>
59
    voice:<xsl:value-of select="voice" />
60
    <br/>
61
    fax:<xsl:value-of select="facsimile" />
62
    <br/>
63
   </p> 
64
  </xsl:for-each>
65
  
66
  </body>
67
  </html>
0 68

  
lib/marine/index.html
3 3
<title>MARINE Database Query Engine: Enter...</title>
4 4
</head>
5 5
<body bgcolor="white">
6
  <center>
7
     <img src="nceas.gif">
8
     <img src="nsf.gif">
9
     <img src="mms.gif">
10
  </center>
11
  <center><h1>Welcome to the MARINE database query engine</h1></center>
12
  
13
  <p>
14
     This page is used to query information for 
15
     <a href="http://www.mms.gov/omm/pacific/enviro/mint.htm">MARINE</a> scientists from
16
     the NCEAS Ecological Metadata Database.  For more information on
17
     this project, please read the 
18
     <a href="https://www2.nceas.ucsb.edu/admin/db/web.ppage?projid_in=2841">
19
     proposal abstract</a>.
20
  </p>
21
  
22
  <p>
23
  Once you enter the query page, you will be asked to fill out a form in 4 steps.  Each
24
  step contains several fields relating to a part of the dataset.  You may also browse
25
  the entire database by simply clicking the browse link at the top of the query page
26
  or by clicking the browse button below.
27
  Clicking on the buttons next to each data line will give you more
28
  information about the dataset or allow you to download the entire dataset.  Please note 
29
  some fields in the query forms will not be pertinent to your dataset.  If this is the case,
30
  simply leave any field blank to omit it from the searching.  
31
  </p>
32
       
33
 <center>
34
  <form action="http://alpha.nceas.ucsb.edu/servlets/marineServlet" 
35
              method="POST"> 
36
    <input type="hidden" name="action" value="init">   
37
    <input type="hidden" name="query" value="">
38
    <input type="hidden" name="doctype" value="ANY">
39
    <input type="hidden" name="qformat" value="html">
40
    <input type="submit" value="Query the Database">
41
  </form>
42
  <form action="http://alpha.nceas.ucsb.edu/servlets/marineServlet#browse" 
43
              method="POST"> 
44
    <input type="hidden" name="action" value="init">   
45
    <input type="hidden" name="query" value="">
46
    <input type="hidden" name="doctype" value="ANY">
47
    <input type="hidden" name="qformat" value="html">
48
    <input type="submit" value="Browse the Database">
49
  </form>
50
 </center
6

  
7
<script language="JavaScript">
8
window.location="http://alpha.nceas.ucsb.edu/servlets/marineServlet?action=init&query=&doctype=any&qformat=html";
9
</script>
10

  
11

  
12
<center><img src="/xmltodb/lib/marine/logo-line.gif"></center>
13
<center><h4>Connecting to the MARINE Database...Please Wait</h4></center>
14

  
15
<noscript>
16
Please click 
17
<a href="http://alpha.nceas.ucsb.edu/servlets/marineServlet?action=init&query=&doctype=any&qformat=html"> 
18
 here</a> to enter the MARINE database.  To disable this message in the future please
19
 enable JavaScript on your browser.
20
</noscript>
21

  
51 22
</body>
52 23
</html>
src/edu/ucsb/nceas/metacat/marine/marineServlet.java
13 13
 
14 14
package edu.ucsb.nceas.metacat.marine;
15 15

  
16

  
16 17
import java.io.*;
17 18
import java.util.*;
18 19
import javax.servlet.*;
19 20
import javax.servlet.http.*;
20 21
import java.net.*;
21 22
import java.sql.*;
22
import oracle.xml.parser.v2.*;
23 23
import org.xml.sax.*;
24 24
import org.xml.sax.helpers.*;
25 25
import edu.ucsb.nceas.metacat.*;
......
31 31
{
32 32
	private marineUtil util;
33 33
	private String resultStyleURL;
34
	private String docStyleURL;
34 35
	private String xmlcatalogfile;
35 36
	private String saxparser;
36 37
	private String defaultdatapath;
......
40 41
	private DBTransform dbt;
41 42
	private Connection conn;
42 43
	private PropertyResourceBundle options;
43
	private String msg;
44
	private String msg=null;
44 45
	private String queryname;
46
	private ServletConfig		config = null;
47
        private ServletContext	context = null;
45 48
	
49
	/**
50
	  Initializes the servlet and creates a connection to 
51
	  the database
52
 	**/
53

  
46 54
	public void init(PrintWriter out) 
47 55
	{
48 56
		util = new marineUtil();
57
		docStyleURL = util.getOption("docStyleURL");
49 58
		resultStyleURL = util.getOption("resultStyleURL");
50 59
		xmlcatalogfile = util.getOption("xmlcatalogfile");
51 60
      		saxparser = util.getOption("saxparser");
52 61
      		defaultdatapath = util.getOption("defaultdatapath");
53 62
      		executescript = util.getOption("executescript");
54
      		
55
      	
63

  
56 64
      		try
57 65
      		{
58
      			conn = util.openDBConnection();
66
      		    conn = util.openDBConnection();  
59 67
      			queryobj = new DBQuery(conn,saxparser);
60 68
        		docreader = new DBReader(conn);
61 69
        		dbt = new DBTransform(conn);
62
        	
63
        		//msg += new String(conn.toString());
64
      			//msg += "\n" + saxparser;
65
      			//msg += "\n" + queryobj;
66
      			//msg += "\n" + docreader;
67
      			//msg += "\n" + dbt;
68
      			
69 70
      		}
70 71
      		catch(Exception e)
71 72
      		{
72
      			msg += new String("Error in init\n " 
73
      			      + e.fillInStackTrace().toString() );
73
      		    e.printStackTrace(System.err);
74 74
      		}
75 75
	}
76 76

  
77
	/**
78
	  Handles any GET requests 
79
	**/
77 80
	public void doGet (HttpServletRequest request, 
78 81
	                   HttpServletResponse response)
79 82
    			throws ServletException, IOException 
......
81 84
    		handleGetOrPost(request, response);
82 85
    	}
83 86
    	
87
    	/**
88
    	  Handles and POST requests
89
    	**/
84 90
    	public void doPost (HttpServletRequest request, 
85 91
    	                    HttpServletResponse response)
86 92
    			throws ServletException, IOException 
......
88 94
    		handleGetOrPost(request, response);
89 95
    	}
90 96
    	
97
    	/**
98
    	  This method is called from doGet and doPost.  It handles
99
    	  each request and sends back the response. It also handles
100
    	  the XSL tranformations
101
    	**/
91 102
    	private void handleGetOrPost(HttpServletRequest request, 
92 103
    			HttpServletResponse response) 
93 104
    			throws ServletException, IOException 
......
102 113
		}
103 114
    		catch(Exception e)
104 115
      		{
105
      			System.err.println("marineServlet: Exception in handleGetOrPost: ");
106
      			System.err.println(e.toString());
116
      			System.err.println("marineServlet: Exception in init in handleGetOrPost: ");
117
      			e.printStackTrace(System.err);
107 118
      		}
108 119
    		
109 120
    		String name = null;
......
145 156
      			((String[])params.get("ypos"))[0]).longValue());
146 157
      			
147 158
      			//out.println("<P>YPOS IS " + ypos);
148
      			if (ypos <= 13) 
159
      			if (ypos <= 20) 
149 160
      			{
150
        			action = "getdocument";
161
        			action = "viewabstract";
151 162
      			} 
152
      			else if (ypos > 13 && ypos <= 27) 
163
      			else if (ypos > 20 && ypos <= 45) 
153 164
      			{
154
        			action = "validate";
165
        			action = "viewdocumentation";
155 166
      			} 
156
      			else if (ypos > 27) 
167
      			else if (ypos > 45) 
157 168
      			{
158
        			action = "transform";
169
        			action = "download";
159 170
      			}
160 171
    		} 
161 172
    		catch (Exception npe) 
162 173
    		{
163
      			//out.println("<P>Caught exception looking for Y value.");
174
      			npe.printStackTrace(System.err);
164 175
    		}
165 176
    		
166 177
    		//Jivka's login code should go here!
167 178
    		
168 179
    		try{
169
    		if (action.equals("query") || action.equals("squery")
180
    		if(action.equals("query") || action.equals("squery")
170 181
    		    || action.equals("init")) 
171 182
    		{
183
    		    //send any type of query action to handleQueryAction
172 184
      			handleQueryAction(out, params, response);
173
    		} 
185
    		}
186
    		else if(action.equals("viewabstract"))
187
    		{
188
    		    //when the user clicks the view abstract graphic
189
    			handleViewAbstractAction(out, params, response);
190
    		}
191
    		else if(action.equals("viewdocumentation"))
192
    		{
193
    		    //when the user clicks the view documentation graphic
194
    		 	handleViewDocumentationAction(out, params, response);
195
    		}
196
    		else if(action.equals("download"))
197
    		{
198
    		    //when the user clicks the download graphic
199
    			handleDownloadAction(out, params, response);
200
    		}
174 201
    		else 
175 202
    		{
176
      			out.println("Error: action not registered" +
203
      			out.println("Error: action " + action + " not registered" +
177 204
      			  "Please report this error.");
178 205
    		}
179 206
    		}
180 207
		catch(Exception e)
181 208
		{
182
			out.print("msg:<br> ");
183
			//System.err.println("\n\n\n");
184
			System.err.println(e.fillInStackTrace().toString());
185
			System.err.println(msg);
186
			//out.println(msg);
187
			out.println("<br><br>marineServlet says: ok");
188
			out.close();
209
			//out.print("There was an exception, check the log file for details.<br>");
210
			//out.print("msg:<br> ");
211
			e.printStackTrace(System.err);
212
			//out.println("<br><br>marineServlet says: ok");
213
			//out.close();
189 214
		}
190
		System.err.println(msg);
215
		System.err.println("msg: " + msg);
216
		out.close();
191 217
    	}
192

  
218
	
219
        /**
220
          Handles when the user clicks the View Abstract graphic.
221
        **/
222
	private void handleViewAbstractAction(PrintWriter out, Hashtable params, 
223
               HttpServletResponse response)
224
        {
225
         	PreparedStatement pstatement;
226
         	ResultSet rs = null;
227
        	String markup = null;
228
        	String docid = ((String[])params.get("docid"))[0];
229
        	
230
        	//this query is based on the eml-resource datatype
231
        	//it will NOT work with eml-dataset documents because
232
        	//eml-dataset removes the abstract data an extra level
233
        	//from the <abstract> tag.
234
        	String querysql = "select nodedata from xml_nodes" +
235
                             " where parentnodeid in" +
236
                             " (select nodeid from xml_nodes where" +
237
                             " nodename like 'abstract') and docid like '" +
238
                             docid + "'";
239
                try{
240
                   //create the query, execute it, get the result
241
                   pstatement = conn.prepareStatement(querysql);
242
                   pstatement.execute();
243
                   rs = pstatement.getResultSet();
244
                
245
                   boolean moreRows = rs.next();
246
                   //print out the html.  This does not use any XSL
247
                   markup = "<html><body bgcolor=\"white\"><h1>Abstract</h1>";
248
                   while(moreRows)
249
                   {
250
                	   markup += "<p>" + rs.getString(1) + "</p>";
251
                	   moreRows = rs.next();
252
                   }
253
                   markup += "</body></html>";
254
                   }
255
                catch(SQLException sqle)
256
                {
257
                	System.err.println("Error returning abstract");
258
                } 
259
                catch(Exception e)
260
                {
261
                	System.err.println("error in handleviewabstract " +
262
                	    e.fillInStackTrace().toString());
263
                }
264
                out.println(markup); //send the output to the browser
265
        }
266
        
267
        /**
268
          Handles when the user clicks the View Documentation graphic.
269
        **/
270
        private void handleViewDocumentationAction(PrintWriter out, Hashtable params, 
271
               HttpServletResponse response)
272
        {
273
        	String doc = null;
274
        	String docid = ((String[])params.get("docid"))[0];
275
        	//out.println("view documentation not yet implemented");
276
		try{        	
277
        	    doc = docreader.readXMLDocument(docid);
278
    		
279
        	    XMLDocumentFragment htmldoc = null;
280
        	    XSLStylesheet style = new XSLStylesheet(
281
                                    new URL(docStyleURL), null);
282
          	    htmldoc = (new XSLProcessor()).processXSL(style, 
283
                                   (Reader)(new StringReader
284
                                   (doc)),null);
285
          	    htmldoc.print(out);
286
          	}
287
          	catch(Exception e)
288
          	{
289
          		System.err.println("error retrieving document details.");
290
          		System.err.println(e.fillInStackTrace().toString());
291
          	}
292
        }
293
        
294
        
295
        /**
296
          Handles when the user clicks the Download graphic.
297
        **/
298
        private void handleDownloadAction(PrintWriter out, Hashtable params, 
299
               HttpServletResponse response)
300
	{
301
		out.println("download not yet implemented");
302
	}
303
	
304
	/**
305
	  This method handles any and all query requests including the 
306
	  init request.  It separates the queries into 3 classes.
307
	  1) query-This executes a free text search.
308
	  2) squery-This executes a structured query.
309
	  3) init-This executes a null query.
310
	  After executing the query, the xml results are sent through
311
	  the XSL processor and returned to the browser as HTML (if
312
	  qformat="html").  If qformat="xml" the xml document is returned
313
	  without transformation.
314
	**/
193 315
  	private void handleQueryAction(PrintWriter out, Hashtable params, 
194 316
               HttpServletResponse response)
195 317
        {
......
199 321
      		String[] doctypeArr = null;
200 322
      		String doctype = null;
201 323
      		Reader xmlquery = null;
202
      		Hashtable extendedSQL = new Hashtable();
324
      		Hashtable extendedQuery = new Hashtable();
203 325
		
204 326
      		if(action.equals("query")) 
205 327
      		{
......
232 354
        		//correctly. For this reason, I have ommited the doctype
233 355
        		//here for the time being (7/20). 
234 356
        		xmlquery = new StringReader(createSQuery(params));
235
        		//msg += " created sql query in squery ";
236
        		msg = createSQuery(params);
237 357
      		} 
238 358
      		else if(action.equals("init"))
239 359
      		{
240
      			//msg += createBrowseList();
241
      			//System.err.println("in init: " + msg);
242
      			xmlquery = new StringReader(createBrowseList());
360
      			try{
361
      			   StringBuffer temp = new StringBuffer();
362
      			   XMLDocumentFragment html = null;
363
      			
364
      			   temp.append("<?xml version=\"1.0\"?>\n");
365
      		       temp.append("<resultset></resultset>\n");
366
      		       
367
      		       //create a null query and run it through the
368
      		       //xsl processor to create the opening page      			
369
      			   
370
      			   XSLStylesheet style = new XSLStylesheet(
371
                                    new URL(resultStyleURL), null);
372
          		   html = (new XSLProcessor()).processXSL(style, 
373
                                   (Reader)(new StringReader(temp.toString())), null);
374
          		   html.print(out);
375
          		   }
376
          		catch(IOException ioe)
377
          		{
378
          			System.err.println("IO error in init");
379
          		}
380
          		catch(XSLException xsle)
381
          		{
382
          			System.err.println("XSL exception in init");
383
          		}
384
          		catch(Exception e)
385
          		{
386
          			System.err.println("error in init");
387
          		}
243 388
      		}
244 389
      		else 
245 390
      		{
246
        		msg = "marineServlet: Error handling query -- illegal action value";
391
        		msg += "marineServlet: Error handling query -- illegal action value";
247 392
      		}
248 393
      
249 394
      		if (queryobj != null) 
......
257 402
        		return;
258 403
      		}
259 404
 
260
 		extendedSQL = createExtendedSQL(doclist);
261
 		
405
 		//get the date_created, date_updated, organization
406
 		//and owner information for the query request
407
 		extendedQuery = createExtendedQuery(doclist);
262 408
 
263 409
      		// Create a buffer to hold the xml result
264 410
      		StringBuffer resultset = new StringBuffer();
......
267 413
      		String docid;
268 414
      		String document = null;
269 415
      		resultset.append("<?xml version=\"1.0\"?>\n");
270
      		//resultset.append("<!DOCTYPE resultset PUBLIC " +
271
      		//               "\"-//NCEAS//resultset//EN\" \"resultset.dtd\">\n");
272 416
      		resultset.append("<resultset>\n");
417
      		//queryname contains the xmlquery.  This sends the query
418
      		//itself back to the page to refresh the text boxes
419
      		//Without the queryname, the text boxes do not retain their
420
      		//values between queries.
273 421
      		resultset.append("  <query>" + queryname + "</query>");
274 422
      		Enumeration doclistkeys = doclist.keys(); 
423
      		//add the returned documents to the xml result
275 424
      		while(doclistkeys.hasMoreElements()) 
276 425
      		{
277 426
        		docid = (String)doclistkeys.nextElement();
278 427
        		document = (String)doclist.get(docid);
279
        		resultset.append("  <document>" + document + 
428
        		if(extendedQuery.containsKey(docid))
429
        		{
430
        			resultset.append("  <document>" + document +
431
        			          extendedQuery.get(docid).toString() +
432
        			          "</document>");
433
        		}
434
        		else
435
        		{
436
        			resultset.append("  <document>" + document + 
280 437
        		                 "</document>");
438
        		}
281 439
      		}
282 440
      		resultset.append("</resultset>");
283 441

  
......
294 452
        		// set content type and other response header
295 453
        		// fields first
296 454
        		response.setContentType("text/html");
297
        		//out.println("Converting to HTML...");
455
			
456
			//transform the xml to html with XSL
298 457
        		XMLDocumentFragment htmldoc = null;
299 458
        		
300 459
        		try  
......
319 478
      	   creates the sql query for the extended information
320 479
      	   displayed upon successful query
321 480
      	**/
322
      	private Hashtable createExtendedSQL(Hashtable docs)
481
      	private Hashtable createExtendedQuery(Hashtable docs)
323 482
      	{
324 483
      		Hashtable result = new Hashtable();
325
      		ResultSet givenNameResults;
326
      		ResultSet surNameResults;
327
      		ResultSet organizationNameResults;
328
      		ResultSet dateResults;
484
      		ResultSet givenNameResults = null;
485
      		ResultSet surNameResults = null;
486
      		ResultSet organizationNameResults = null;
487
      		ResultSet dateResults = null;
488
      		String docid = null;
489
      		String data = null;
490
      		Object docidObj = null;
329 491
      		PreparedStatement pstatement;
330 492
      		
331 493
      		Enumeration docids = docs.keys();
......
370 532
                //find all of the creation and update dates
371 533
                String dateQuery = "select docid, date_created, date_updated" +
372 534
                   " from xml_documents";
535
                   
536
            //execute the queries
373 537
            try{  
374 538
                pstatement = conn.prepareStatement(givenNameQuery);
375 539
                pstatement.execute();
......
392 556
                System.err.println("error in SQL " + s.getMessage());
393 557
             }
394 558
             
395
                return result;
559
             try{
560
                 boolean moreRows = givenNameResults.next();
561
                 //add the givenName information to the xml.
562
                 while(moreRows)
563
                 {
564
                 	docid = givenNameResults.getString(1);
565
             	    data = givenNameResults.getString(2);
566
             	    //check if the original result set contains this docid
567
             	    if(docs.containsKey(docid))
568
             	    {
569
             		    String markup = "<givenName>" + data + "</givenName>";
570
             		    result.put(docid, markup);
571
             	    }
572
             	    moreRows = givenNameResults.next();
573
                 }	
574
             
575
                 moreRows = surNameResults.next();
576
                 //add the surName information to the xml.
577
                 while(moreRows)
578
                 {
579
             	    docid = surNameResults.getString(1);
580
             	    data = surNameResults.getString(2);
581
             	    //check if the original result set contains this docid
582
             	    if(docs.containsKey(docid))
583
             	    {
584
             		    //check if this key is already in the result hashtable
585
             		    //i.e. there was a givenName for that docid.
586
             		    if(result.containsKey(docid))
587
             		    {
588
             			    String markup = result.get(docid).toString();
589
             			    markup += "<surName>" + data + "</surName>";
590
             			    result.remove(docid);
591
             			    result.put(docid, markup);
592
             		    }
593
             		    else
594
             	 	    { 
595
             			    String markup = "<surName>" + data + "</surName>";
596
             			    result.put(docid, markup);
597
             		    }
598
             	    }
599
             	    moreRows = surNameResults.next();
600
                 }
601
                 
602
                 //add the organizationName information to the xml.
603
                 moreRows = organizationNameResults.next();
604
                 while(moreRows)
605
                 {
606
             	    docid = organizationNameResults.getString(1);
607
             	    data = organizationNameResults.getString(2);
608
             	    //check if the original result set contains this docid
609
             	    if(docs.containsKey(docid))
610
             	    {
611
             		    //check if this key is already in the result hashtable
612
             		    //i.e. there was a givenName for that docid.
613
             		    if(result.containsKey(docid))
614
             		    {
615
             			    String markup = result.get(docid).toString();
616
             			    markup += "<organizationName>" + data + "</organizationName>";
617
             			    result.remove(docid);
618
             			    result.put(docid, markup);
619
             		    }
620
             		    else
621
             	 	    { 
622
             			    String markup = "<organizationName>" + data + "</organizationName>";
623
             			    result.put(docid, markup);
624
             		    }
625
             	    }
626
             	    moreRows = organizationNameResults.next();
627
                 }
628
                 
629
                 moreRows = dateResults.next();
630
                 //add the date information to the xml.
631
                 while(moreRows)
632
                 {
633
             	    docid = dateResults.getString(1);
634
             	    data = dateResults.getString(2); //date_created
635
             	    String data2 = dateResults.getString(3); //date_updated
636
             	    //check if the original result set contains this docid
637
             	    if(docs.containsKey(docid))
638
             	    {
639
             		    //check if this key is already in the result hashtable
640
             		    //i.e. there was a givenName for that docid.
641
             		    if(result.containsKey(docid))
642
             		    {
643
             			    String markup = result.get(docid).toString();
644
             			    markup += "<date_created>" + data + "</date_created>";
645
             			    markup += "<date_updated>" + data2 + "</date_updated>";
646
             			    result.remove(docid);
647
             			    result.put(docid, markup);
648
             		    }
649
             		    else
650
             	 	    { 
651
             			    String markup = "<date_created>" + data + "</date_created>";
652
             			    markup += "<date_updated>" + data2 + "</date_updated>";
653
             			    result.put(docid, markup);
654
             		    }
655
             	    }
656
             	    moreRows = dateResults.next();
657
                 }
658
             }
659
             catch(SQLException e)
660
             {
661
             	System.err.println("Error in SQL " + e.getMessage());
662
             	
663
             }
664
             
665
             return result;
396 666
      	}
397 667
      	
398 668
      	/**
......
411 681
    		query += "<queryterm casesensitive=\"false\" " + 
412 682
    				         "searchmode=\"contains\">";
413 683
    		query += "<value>";
414
    		query += "%";
684
    		query += "%";           //return everything
415 685
    		query += "</value>";
416 686
    		query += "</queryterm>";
417 687
    		query += "</querygroup></pathquery>";
......
430 700
    		Enumeration keys;
431 701
    		Object nextkey;
432 702
    		Object nextelement;
703
    		queryname = " ";
433 704
    		query = "<?xml version=\"1.0\"?>";
434 705
		query += "<!DOCTYPE pathquery PUBLIC \"-//NCEAS//pathquery-1.0//EN\" " + 
435 706
          		    "\"http://alpha.nceas.ucsb.edu/xmltodb/lib/pathquery.dtd\" >";
......
459 730
    		}
460 731
    		query += "<querygroup operator=\"" + 
461 732
    		         ((String[])params.get("operator"))[0] + "\">";
733
    		
734
    		
735
    		//anyfield is a special case because it does a 
736
    		//free text search.  It does not have a <pathexpr>
737
    		//tag.
462 738
    		if(params.containsKey("anyfield") && 
463 739
    		   !((String[])params.get("anyfield"))[0].equals(""))
464 740
    		{
......
466 742
    			         "searchmode=\"contains\"><value>" +
467 743
    			         ((String[])params.get("anyfield"))[0] +
468 744
    			         "</value></queryterm>";
745
    			         queryname += "<anyfield>";
746
    			         queryname += ((String[])params.get("anyfield"))[0];
747
    			         queryname += "</anyfield>";
469 748
    		}
470 749
    		
750
    		//this while loop finds the rest of the parameters
751
    		//and attempts to query for the field specified
752
    		//by the parameter.
471 753
    		elements = params.elements();
472 754
    		keys = params.keys();
473
    		queryname = " ";
474 755
    		while(keys.hasMoreElements() && elements.hasMoreElements())
475 756
    		{
476 757
    			nextkey = keys.nextElement();
477 758
    			nextelement = elements.nextElement();
478
    			//msg += " " + nextkey.toString() + "=" +
479
    			//       ((String[])elements.nextElement())[0];
759
    			
760
    			//make sure we aren't querying for any of these
761
    			//parameters.
480 762
    			if(!nextkey.toString().equals("doctype") && 
481 763
    			   !nextkey.toString().equals("action")  &&
482 764
    			   !nextkey.toString().equals("qformat") && 
......
487 769
    				query += "<queryterm casesensitive=\"false\" " + 
488 770
    				         "searchmode=\"contains\">";
489 771
    				query += "<value>";
772
    				//add the query value
490 773
    				query += ((String[])nextelement)[0];
491
    				//queryname += ((String[])nextelement)[0] + " " + 
492
    				//             ((String[])params.get("operator"))[0] +
493
    				//             " ";
494
    				query += "</value><pathexpr>" + 
774
    				query += "</value><pathexpr>" +
775
    				//add the path to query by 
495 776
    				         nextkey.toString() + 
496 777
    				         "</pathexpr></queryterm>";
497 778
    				
498
    				//query += "</value></queryterm>";
779
    				//add the query back into the xml to fill in 
780
    				//the text boxes.
781
    				queryname += "<" + nextkey.toString() + ">";
782
    				queryname += ((String[])nextelement)[0];
783
    				queryname += "</" + nextkey.toString() + ">";
499 784
    			}
500 785
    		}
501 786
    		query += "</querygroup></pathquery>";
src/edu/ucsb/nceas/metacat/marine/marineUtil.java
41 41
   * Utility method to establish a JDBC database connection using connection
42 42
   * info from the properties file
43 43
   */
44
   
44 45
  public Connection openDBConnection()
45 46
                throws SQLException, ClassNotFoundException {
47
                
48
    //System.err.println(getOption("dbDriver") + " " + getOption("defaultDB") + " " +
49
    //                 getOption("user") + " " +getOption("password"));
46 50
    return openDBConnection(getOption("dbDriver"), getOption("defaultDB"),
47 51
                     getOption("user"), getOption("password"));
48 52
  }

Also available in: Unified diff