Project

General

Profile

« Previous | Next » 

Revision 566

Added by Matt Jones over 23 years ago

Modified stylesheets and server code to use a single "read" action instead
of the earlier "getdocument" and "getrelateddocument" actions. In the
process, developed and started to utilize a new suite of URL "protocol
handlers" that are in the package "edu.ucsb.nceas.protocols" and handle
the parsing of various forms of URLS (mainly metacat:// protocol URLS). New
protocols can be added by following the model for the metacat protocol handler.
Using this mechanism, the standard URL handling methods like "getProtocol()"
can be used, and I added the "parseQuery()" method to MetaCatUtil for
parsing query parameters into name/value pairs and returning a hashtable.
I've eliminated the use of the MetacatURL class from the main Metacat servlet
classes, but not yet from the replication server classes (because I don't
understand the implications of doing so yet).

View differences:

lib/style/resultset.xsl
116 116
               <p><pre>Document ID: <xsl:value-of select="./docid"/></pre></p>
117 117
             </td>
118 118
             <td>
119
               <form action="@html-path@/servlet/marine" method="POST">
119
               <form action="@html-path@/servlet/metacat" method="POST">
120 120
                 <xsl:attribute name="name">
121
                   <xsl:value-of select="translate(./docid,':','')"/>
121
                   <xsl:value-of select="translate(./docid,'.','')"/>
122 122
                 </xsl:attribute>
123 123
                 <!-- abstractpath tells the servlet where the abstract is in 
124 124
                      the document.  The % sign is used because the path could 
125 125
                      be resource/literature or resource/dataset. -->
126 126
                 <input type="hidden" name="abstractpath" 
127 127
                        value="resource/%/abstract" />
128
                 <input type="hidden" name="action" value="getdocument"/>
128
                 <input type="hidden" name="action" value="read"/>
129 129
                 <input type="hidden" name="docid">
130 130
                   <xsl:attribute name="value">
131 131
                     <xsl:value-of select="./docid"/>
......
140 140
                 </xsl:for-each>
141 141

  
142 142
                 <a>
143
                   <xsl:attribute name="href">javascript:submitform('getdocument',document.<xsl:value-of select="translate(./docid, ':', '')"/>)</xsl:attribute>
143
                   <xsl:attribute name="href">javascript:submitform('read',document.<xsl:value-of select="translate(./docid, '.', '')"/>)</xsl:attribute>
144 144
                   Dataset Information
145 145
                 </a><br />
146 146
                 <a>
147
                   <xsl:attribute name="href">javascript:submitform('getabstract',document.<xsl:value-of select="translate(./docid,':','')"/>)</xsl:attribute>
147
                   <xsl:attribute name="href">javascript:submitform('getabstract',document.<xsl:value-of select="translate(./docid,'.','')"/>)</xsl:attribute>
148 148
                   View Abstract
149 149
                 </a><br />
150 150
                 <a>
151
                   <xsl:attribute name="href">javascript:submitform('getdatadoc',document.<xsl:value-of select="translate(./docid,':','')"/>)</xsl:attribute>
151
                   <xsl:attribute name="href">javascript:submitform('getdatadoc',document.<xsl:value-of select="translate(./docid,'.','')"/>)</xsl:attribute>
152 152
                    Download Data and Metadata
153 153
                 </a><br />
154 154
               </form>
......
198 198
                     </xsl:if>
199 199
                     <xsl:if test="starts-with(./relationdoc, 'metacat')">
200 200
                       <xsl:attribute name="href">
201
                         <xsl:text>http://dev.nceas.ucsb.edu@html-path@/servlet/marine/?action=getrelateddocument&amp;qformat=html&amp;url=</xsl:text>
201
                         <xsl:text>http://dev.nceas.ucsb.edu@html-path@/servlet/metacat/?action=read&amp;qformat=html&amp;docid=</xsl:text>
202 202
                         <xsl:value-of select="./relationdoc" />
203 203
                       </xsl:attribute>
204 204
                       <xsl:if 
lib/marine/marine.xsl
356 356
                 resource/literature or resource/dataset. -->
357 357
            <input type="hidden" name="abstractpath" 
358 358
                   value="resource/%/abstract" />
359
            <input type="hidden" name="action" value="getdocument"/>
359
            <input type="hidden" name="action" value="read"/>
360 360
            <input type="hidden" name="docid">
361 361
              <xsl:attribute name="value">
362 362
                <xsl:value-of select="./docid"/>
......
372 372

  
373 373
            <font size="2">
374 374
            <a>
375
              <xsl:attribute name="href">javascript:submitform('getdocument',document.<xsl:value-of select="translate(./docid, '.', '')"/>)</xsl:attribute>
375
              <xsl:attribute name="href">javascript:submitform('read',document.<xsl:value-of select="translate(./docid, '.', '')"/>)</xsl:attribute>
376 376
               Dataset Information
377 377
            </a><br />
378 378
            <a>
......
424 424
                  </xsl:if>
425 425
                  <xsl:if test="starts-with(./relationdoc, 'metacat')">
426 426
                    <xsl:attribute name="href">
427
                      <xsl:text>http://dev.nceas.ucsb.edu@html-path@/servlet/marine/?action=getrelateddocument&amp;qformat=html&amp;url=</xsl:text>
427
                      <xsl:text>http://dev.nceas.ucsb.edu@html-path@/servlet/marine/?action=read&amp;qformat=html&amp;docid=</xsl:text>
428 428
                      <xsl:value-of select="./relationdoc" />
429 429
                    </xsl:attribute>
430 430
                    <xsl:if test="./relationdoctype = '-//NCEAS//eml-variable//EN'">
......
501 501
            <xsl:text>&nbsp;</xsl:text>
502 502
            <xsl:if test="count(./relation) &gt; 0">
503 503
              <form action="@html-path@/servlet/marine" method="POST">
504
              <input type="hidden" name="action" value="getrelateddocument"/>
504
              <input type="hidden" name="action" value="read"/>
505 505
              <input type="hidden" name="qformat" value="xml" />
506 506
              <xsl:for-each select="./relation">
507 507
                <font size="2">
508
                <input type="radio" name="url">
508
                <input type="radio" name="docid">
509 509
                <xsl:attribute name="value" >
510 510
                  <xsl:value-of select="./relationdoc" />
511 511
                </xsl:attribute>
src/edu/ucsb/nceas/metacat/MetacatURL.java
22 22
{
23 23
  private String[][] params = new String[200][2];
24 24
  private Hashtable paramsHash = new Hashtable();
25
  private String urlType = null;
25
  private String protocol = null;
26 26
  private String host = null;
27 27
  private String url;
28 28
  
29 29
  /**
30 30
   * This constructor takes a string url and parses it according to the  
31 31
   * following rules.  
32
   * 1) The name of the url is the text before the "://" symbol.
32
   * 1) The protocol of the url is the text before the "://" symbol.
33 33
   * 2) Parameter names are written first and are terminated with the = symbol
34 34
   * 3) Parameter values come 2nd and are terminated with an & except for the
35 35
   *    last value
36 36
   * The form of the url looks like: 
37
   * urltype://server.domain.com/servlet/?name1=value1&name2=value2&nameN=valueN
37
   * protocol://server.domain.com/servlet/?name1=val1&name2=val2&nameN=valN
38 38
   * notice there is no & after the last param.  If one is there it is ignored.
39 39
   *
40 40
   * @param url the string to parse
......
48 48
  /**
49 49
   * This method takes a string url and parses it according to the following 
50 50
   * rules.  
51
   * 1) The name of the url is the text before the "://" symbol.
51
   * 1) The protocol of the url is the text before the "://" symbol.
52 52
   * 2) Parameter names are written first and are terminated with the = symbol
53 53
   * 3) Parameter values come 2nd and are terminated with an & except for the
54 54
   *    last value
55 55
   * The form of the url looks like: 
56
   * urltype://server.domain.com/servlet/?name1=value1&name2=value2&nameN=valueN
56
   * protocol://server.domain.com/servlet/?name1=val1&name2=val2&nameN=valN
57 57
   * notice there is no & after the last param.  If one is there it is ignored.
58 58
   */
59 59
  private void parseURL(String url) throws MalformedURLException
......
65 65
    boolean poundflag = false;
66 66
    int arrcount = 0;
67 67
    
68
    int urlTypeIndex = url.indexOf("://"); //anything before this is the urltype
69
    this.urlType = url.substring(0, urlTypeIndex);
70
    paramsHash.put("urlType", this.urlType);
68
    //anything before this is the protocol
69
    int protocolIndex = url.indexOf("://"); 
71 70
    
72
    if(this.urlType.equals("http"))
71
    if (protocolIndex == -1) {
72
      // URL badly formed, no protocol
73
      throw new MalformedURLException("Invalid URL format: " +
74
                                      "no protocol provided.");
75
    }
76
    this.protocol = url.substring(0, protocolIndex);
77
    paramsHash.put("protocol", this.protocol);
78
    
79
    if(this.protocol.equals("http"))
73 80
    {//if this is an http url
74 81
      params[0][0] = "httpurl";
75 82
      params[0][1] = url.substring(0, url.length());
......
95 102
    else
96 103
    {//other urls that meet the metacat type url structure.
97 104
      int hostIndex = url.indexOf("?");
98
      this.host = url.substring(urlTypeIndex + 3, hostIndex);
105
      this.host = url.substring(protocolIndex + 3, hostIndex);
99 106
      paramsHash.put("host", this.host);
100 107
      for(int i=hostIndex + 1; i<url.length(); i++)
101 108
      { //go throught the remainder of the url one character at a time.
......
152 159
   * Returns the type of the url. This is defined by the text before the "://" 
153 160
   * symbol in the url.
154 161
   */
155
  public String getURLType()
162
  public String getProtocol()
156 163
  {
157
    return this.urlType; 
164
    return this.protocol; 
158 165
  }
159 166
  
160 167
  /**
......
210 217
  public void printParams()
211 218
  {
212 219
    String[][] p = null;
213
    System.out.println("url type: " + this.getURLType());
220
    System.out.println("protocol: " + this.getProtocol());
214 221
    System.out.println("parameters: ");
215 222
    p = this.getParams();
216 223
    System.out.println("name          value");
......
249 256
  {
250 257
    String testurl =  "metacat://dev.nceas.ucsb.edu?docid=NCEAS:10&username=chad&pasword=xyz";
251 258
    String testurl2 = "http://dev.nceas.ucsb.edu/berkley/testdata.dat";
259
    String testurl3 = "NCEAS.1287873498.32";
252 260
    try
253 261
    {
262
      System.out.println("*********************************************");
254 263
      MetacatURL murl = new MetacatURL(testurl);
264
      //String[][] p = null;
265
      System.out.println("protocol: " + murl.getProtocol());
266
      System.out.println("parameters: ");
267
      //p = murl.getParams();
268
      //Hashtable h = murl.getHashParams();
269
      murl.printParams();
270
      murl.printHashParams();
271
      System.out.println("*********************************************");
272

  
255 273
      MetacatURL murl2 = new MetacatURL(testurl2);
256
      String[][] p = null;
257
      System.out.println("url type: " + murl.getURLType());
274
      System.out.println("protocol: " + murl2.getProtocol());
258 275
      System.out.println("parameters: ");
259
      p = murl.getParams();
260
      Hashtable h = murl.getHashParams();
261
      murl.printParams();
262 276
      murl2.printParams();
263
      System.out.println("hash params: " );
264
      murl.printHashParams();
265 277
      murl2.printHashParams();
278
      System.out.println("*********************************************");
279

  
280
      MetacatURL murl3 = new MetacatURL(testurl3);
281
      System.out.println("protocol: " + murl3.getProtocol());
282
      System.out.println("parameters: ");
283
      murl3.printParams();
284
      System.out.println("*********************************************");
266 285
    }
267 286
    catch(MalformedURLException murle)
268 287
    {
src/edu/ucsb/nceas/metacat/MetacatReplication.java
122 122
      { //request an update list from the server
123 123
        handleUpdateRequest(out, params, response);
124 124
      }
125
      else if(((String[])params.get("action"))[0].equals("getdocument"))
125
      else if(((String[])params.get("action"))[0].equals("read"))
126 126
      { //request a specific document from the server
127 127
        //note that this could be replaced by a call to metacatServlet
128 128
        //handleGetDocumentAction().
src/edu/ucsb/nceas/metacat/DBQuery.java
320 320
            String objDT = rs.getString(5);
321 321
            
322 322
            MetacatURL murl = new MetacatURL(sub);
323
            if(murl.getURLType().equals("metacat"))
323
            if(murl.getProtocol().equals("metacat"))
324 324
            {//we only want to process metacat urls here.
325 325
              String[] tempparam = murl.getParam(0);
326 326
              if(tempparam[0].equals("docid") && tempparam[1].equals(docidkey))
src/edu/ucsb/nceas/metacat/MetaCatUtil.java
228 228
  }
229 229

  
230 230
  /** 
231
   * Utility method to parse the query part of a URL into parameters. This
232
   * method assumes the format of the query par tof the url is an 
233
   * ampersand separated list of name/value pairs, with equal signs separating
234
   * the name from the value (e.g., name=tom&zip=99801 ). Returns a
235
   * has of the name value pairs, hashed on name.
236
   */
237
  public static Hashtable parseQuery(String query) throws MalformedURLException
238
  {
239
    String[][] params = new String[200][2];
240
    Hashtable parameters = new Hashtable();
241

  
242
    String temp = "";
243
    boolean ampflag = true;
244
    boolean poundflag = false;
245
    int arrcount = 0;
246

  
247
    for (int i=0; i < query.length(); i++) { 
248

  
249
      // go throught the remainder of the query one character at a time.
250
      if (query.charAt(i) == '=') { 
251
        // if the current char is a # then the preceding should be a name
252
        if (!poundflag && ampflag) {
253
          params[arrcount][0] = temp.trim();
254
          temp = "";
255
        } else { 
256
          //if there are two #s or &s in a row throw an exception.
257
          throw new MalformedURLException("metacatURL: Two parameter names " +                                            "not allowed in sequence");
258
        }
259
        poundflag = true;
260
        ampflag = false;
261
      } else if (query.charAt(i) == '&' || i == query.length()-1) { 
262
        //the text preceding the & should be the param value.
263
        if (i == query.length() - 1) { 
264
          //if at the end of the string grab the last value and append it.
265
          if (query.charAt(i) != '=') { 
266
            //ignore an extra & on the end of the string
267
            temp += query.charAt(i);
268
          }
269
        }
270

  
271
        if (!ampflag && poundflag) {
272
          params[arrcount][1] = temp.trim();
273
          parameters.put(params[arrcount][0], params[arrcount][1]);
274
          temp = "";
275
          arrcount++; //increment the array to the next row.
276
        } else { 
277
          //if there are two =s or &s in a row through an exception
278
          throw new MalformedURLException("metacatURL: Two parameter values " +
279
                                          "not allowed in sequence");
280
        }
281
        poundflag = false;
282
        ampflag = true;
283
      } else { 
284
        //get the next character in the string
285
        temp += query.charAt(i);
286
      }
287
    }
288
    return parameters;
289
  }
290

  
291
  /** 
231 292
   * Utility method to print debugging messages
232 293
   *
233 294
   * @param flag an integer indicating the message number
......
249 310
    }
250 311
  }
251 312
}
252

  
253
/**
254
 * '$Log$
255
 * 'Revision 1.15  2000/08/14 22:31:13  berkley
256
 * 'added new constructor to allow the creation of a metacatutil object that uses a properties file other than edu.ucsb.nceas.metacat.metacat.
257
 * '
258
 * 'Revision 1.14  2000/08/14 20:53:34  jones
259
 * 'Added "release" keyword to all metacat source files so that the release
260
 * 'number will be evident in software distributions.
261
 * '
262
 * 'Revision 1.13  2000/08/09 00:39:47  jones
263
 * '-Reorganized xmltodb module to support new install process for the new
264
 * 'linux server (dev.nceas.ucsb.edu).  Added "build.sh" shell script that
265
 * 'calls ant withthe proper umask set for installation.  Use:
266
 * '
267
 * '  ./build.sh install
268
 * '
269
 * 'to post a new copy of the servlet and its supporting files to the install
270
 * 'directory defined in build.xml.
271
 * '
272
 * '-Updated the servlet to use a new servlet prefix that we'll use with the
273
 * 'Tomcat servlet engine.
274
 * '
275
 * '-Update bin dir shell scripts to reflect new locations of relevant jar files.
276
 * '
277
 * 'Revision 1.12  2000/08/04 23:34:10  bojilova
278
 * 'more precise handling of the Connection Pool
279
 * '
280
 * 'Revision 1.11  2000/08/01 18:26:50  bojilova
281
 * 'added Pool of Connections
282
 * 'DBQuery, DBReader, DBTransform, DBUtil are created on every request and use the connections from the Pool
283
 * 'same with DBWriter and DBValidate
284
 * '
285
 * 'Revision 1.10  2000/06/26 10:35:05  jones
286
 * 'Merged in substantial changes to DBWriter and associated classes and to
287
 * 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE
288
 * 'functions.  The command line tools and the parameters for the
289
 * 'servlet have changed substantially.
290
 * '
291
 * 'Revision 1.9.2.4  2000/06/26 00:51:06  jones
292
 * 'If docid passed to DBWriter.write() is not unique, classes now generate
293
 * 'an AccessionNumberException containing the new docid generated as a
294
 * 'replacement.  The docid is then extracted from the exception and
295
 * 'returned to the calling application for user feedback or client processing.
296
 * '
297
 * 'Revision 1.9.2.3  2000/06/25 23:38:17  jones
298
 * 'Added RCSfile keyword
299
 * '
300
 * 'Revision 1.9.2.2  2000/06/25 23:34:18  jones
301
 * 'Changed documentation formatting, added log entries at bottom of source files
302
 * ''
303
 */
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
66 66
 * action=update -- update an XML document that is in the database store<br>
67 67
 * action=delete --  delete an XML document from the database store<br>
68 68
 * action=validate -- vallidate the xml contained in valtext<br>
69
 * action=getdocument -- display an XML document in XML or HTML<br>
69
 * action=read -- display an XML document in XML or HTML<br>
70 70
 * doctype -- document type list returned by the query (publicID)<br>
71 71
 * qformat=xml -- display resultset from query in XML<br>
72 72
 * qformat=html -- display resultset from query in HTML<br>
......
184 184
      }
185 185
    }    
186 186
    // Get a handle to the output stream back to the client
187
    //PrintWriter out = response.getWriter();
187
    //PrintWriter pwout = response.getWriter();
188 188
    //response.setContentType("text/html");
189 189
  
190 190
    String name = null;
......
207 207
        name = "xpos";
208 208
      } 
209 209

  
210
      //out.println(name + " => " + value[0]);
210
      //pwout.println(name + " => " + value[0]);
211 211
      params.put(name,value); 
212 212
    }  
213 213
    
......
270 270
        out.println("Illegal action squery without \"query\" parameter");
271 271
      }
272 272
    }
273
    else if (action.equals("getdocument")) {
273
    else if (action.equals("read")) {
274 274
      PrintWriter out = response.getWriter();
275 275
      try {
276
        handleGetDocumentAction(out, params, response);
276
        handleReadAction(out, params, response);
277 277
      } catch (ClassNotFoundException e) {
278 278
        out.println(e.getMessage());
279 279
      } catch (SQLException se) {
280 280
        out.println(se.getMessage());
281 281
      }
282 282
    } 
283
/*
283 284
    else if (action.equals("getrelateddocument")) {
284 285
      PrintWriter out = response.getWriter();
285 286
      try {
......
290 291
        out.println(se.getMessage());
291 292
      }
292 293
    }
294
*/
293 295
    else if (action.equals("insert") || action.equals("update")) {
294 296
      PrintWriter out = response.getWriter();
295 297
      if ( (username != null) &&  !username.equals("public") ) {
......
327 329
      PrintWriter out = response.getWriter();
328 330
      handleGetDataGuideAction(out, params, response);  
329 331
    } else if (action.equals("login") || action.equals("logout")) {
332
    } else if (action.equals("protocoltest")) {
333
      String testURL = "metacat://dev.nceas.ucsb.edu/NCEAS.897766.9";
334
      try {
335
        testURL = ((String[])params.get("url"))[0];
336
      } catch (Throwable t) {
337
      }
338
      String phandler = System.getProperty("java.protocol.handler.pkgs");
339
      response.setContentType("text/html");
340
      PrintWriter out = response.getWriter();
341
      out.println("<body bgcolor=\"white\">");
342
      out.println("<p>Handler property: <code>" + phandler + "</code></p>");
343
      out.println("<p>Starting test for:<br>");
344
      out.println("    " + testURL + "</p>");
345
      try {
346
        URL u = new URL(testURL);
347
        out.println("<pre>");
348
        out.println("Protocol: " + u.getProtocol());
349
        out.println("    Host: " + u.getHost());
350
        out.println("    Port: " + u.getPort());
351
        out.println("    Path: " + u.getPath());
352
        out.println("     Ref: " + u.getRef());
353
        String pquery = u.getQuery();
354
        out.println("   Query: " + pquery);
355
        out.println("  Params: ");
356
        if (pquery != null) {
357
          Hashtable qparams = util.parseQuery(u.getQuery());
358
          for (Enumeration en = qparams.keys(); en.hasMoreElements(); ) {
359
            String pname = (String)en.nextElement();
360
            String pvalue = (String)qparams.get(pname);
361
            out.println("    " + pname + ": " + pvalue);
362
          }
363
        }
364
        out.println("</pre>");
365
        out.println("</body>");
366
        out.close();
367
      } catch (MalformedURLException mue) {
368
        out.println(mue.getMessage());
369
        mue.printStackTrace(out);
370
        out.close();
371
      }
330 372
    } else {
331 373
      PrintWriter out = response.getWriter();
332 374
      out.println("Error: action not registered.  Please report this error.");
......
355 397
      ypos = (new Long(((String[])params.get("ypos"))[0]).longValue());
356 398
      //out.println("<P>YPOS IS " + ypos);
357 399
      if (ypos <= 13) {
358
        action = "getdocument";
400
        action = "read";
359 401
      } else if (ypos > 13 && ypos <= 27) {
360 402
        action = "validate";
361 403
      } else if (ypos > 27) {
......
745 787
   * Handle the database getrelateddocument request and return a XML document, 
746 788
   * possibly transformed from XML into HTML
747 789
   */
748
  private void handleGetRelatedDocumentAction(PrintWriter out, Hashtable params, 
749
               HttpServletResponse response) 
790
  private void handleGetRelatedDocumentAction(PrintWriter out, Hashtable params,
791
               HttpServletResponse response, URL murl) 
750 792
               throws ClassNotFoundException, IOException, SQLException 
751 793
  {
752 794
    String docid = null;
753 795
    Connection conn = null;
754 796
      
755
    if(params.containsKey("url"))
756
    {//the identifier for the related document is contained in the URL param
797
    //if(params.containsKey("url"))
798
    //{//the identifier for the related document is contained in the URL param
757 799
      try
758 800
      {
759 801
        DocumentImpl xmldoc=null;
760
        MetacatURL murl = new MetacatURL(((String[])params.get("url"))[0]);
761
        if(murl.getURLType().equals("metacat"))
802
        //MetacatURL murl = new MetacatURL(((String[])params.get("url"))[0]);
803
        if(murl.getProtocol().equals("metacat"))
762 804
        {//get the document from the database if it is the right type of url
763
          Hashtable murlParams = murl.getHashParams();
805
          //Hashtable murlParams = murl.getHashParams();
806
          Hashtable murlParams = util.parseQuery(murl.getQuery());
764 807
          if(murlParams.containsKey("docid"))
765 808
          {//the docid should be first
766 809
            docid = (String)murlParams.get("docid"); //get the docid value
......
793 836
            System.err.println("handleGetDocument: bad URL");
794 837
          }
795 838
        }
796
        else if(murl.getURLType().equals("http"))
839
        else if(murl.getProtocol().equals("http"))
797 840
        {//get the document from the internet
798
          Hashtable murlParams = murl.getHashParams();
841
          //Hashtable murlParams = murl.getHashParams();
842
          Hashtable murlParams = util.parseQuery(murl.getQuery());
799 843
          if(murlParams.containsKey("httpurl"))
800 844
          {//httpurl is the param name for an http url.
801 845
            URL urlconn = new URL((String)murlParams.get("httpurl"));  
......
828 872
      } finally {
829 873
        util.returnConnection(conn);
830 874
      }
831
    }
875
    //} // end if
832 876
  }   
833 877
  
834 878
  /** 
835
   * Handle the database getdocument request and return a XML document, 
879
   * Handle the database read request and return an XML document, 
836 880
   * possibly transformed from XML into HTML
837 881
   */
882
  private void handleReadAction(PrintWriter out, Hashtable params, 
883
               HttpServletResponse response) 
884
               throws ClassNotFoundException, IOException, SQLException 
885
  {
886
    out.println(((String[])params.get("docid"))[0]);
887
    try {
888
      //MetacatURL murl = new MetacatURL(((String[])params.get("docid"))[0]);
889
      URL murl = new URL(((String[])params.get("docid"))[0]);
890
      handleGetRelatedDocumentAction(out, params, response, murl);
891
    } catch (MalformedURLException mue) {
892
      handleGetDocumentAction(out, params, response);
893
    }
894
  }
895

  
896
  /** 
897
   * Handle the database read request and return an XML document, 
898
   * possibly transformed from XML into HTML
899
   */
838 900
  private void handleGetDocumentAction(PrintWriter out, Hashtable params, 
839 901
               HttpServletResponse response) 
840 902
               throws ClassNotFoundException, IOException, SQLException {
......
1131 1193
    //zip up the related documents
1132 1194
    for(int i=0; i<reldocs.length; i++)
1133 1195
    {
1134
      MetacatURL murl = new MetacatURL(((String)reldocs[i]));
1135
      if(murl.getURLType().equals("metacat"))
1196
      //MetacatURL murl = new MetacatURL(((String)reldocs[i]));
1197
      URL murl = new URL(((String)reldocs[i]));
1198
      Hashtable qparams = util.parseQuery(murl.getQuery());
1199
      if(murl.getProtocol().equals("metacat"))
1136 1200
      {
1137 1201
        //get the document from the database
1138
        xmldoc = new DocumentImpl(conn, (String)murl.getHashParam("docid"));
1202
        //xmldoc = new DocumentImpl(conn, (String)murl.getHashParam("docid"));
1203
        xmldoc = new DocumentImpl(conn, (String)qparams.get("docid"));
1139 1204
        bytestring = (xmldoc.toString()).getBytes();
1140
        zentry = new ZipEntry(murl.getHashParam("docid") + ".xml");
1205
        zentry = new ZipEntry(qparams.get("docid") + ".xml");
1141 1206
        //create a new zip entry and write the file to the stream
1142 1207
        zentry.setSize(bytestring.length);
1143 1208
        zout.putNextEntry(zentry);
1144 1209
        zout.write(bytestring, 0, bytestring.length);
1145 1210
        zout.closeEntry(); //get ready for the next entry.
1146 1211
      }
1147
      else if(murl.getURLType().equals("http"))
1212
      else if(murl.getProtocol().equals("http"))
1148 1213
      {
1149
        Hashtable murlParams = murl.getHashParams();
1150
        if(murlParams.containsKey("httpurl"))
1214
        //Hashtable murlParams = murl.getHashParams();
1215
        if(qparams.containsKey("httpurl"))
1151 1216
        {//httpurl is the param name for an http url.
1152
          URL urlconn = new URL((String)murlParams.get("httpurl"));  
1217
          URL urlconn = new URL((String)qparams.get("httpurl"));  
1153 1218
          //create a new url obj.
1154 1219
          BufferedReader htmldoc = new BufferedReader(
1155 1220
                                   new InputStreamReader(urlconn.openStream()));
......
1157 1222
          try
1158 1223
          { //zip the document
1159 1224
            String line=null;
1160
            zentry = new ZipEntry((String)murlParams.get("filename"));
1225
            zentry = new ZipEntry((String)qparams.get("filename"));
1161 1226
            //get just the filename from the URL.
1162 1227
            zout.putNextEntry(zentry);
1163 1228
            //make a new entry in the zip file stream
src/edu/ucsb/nceas/metacat/ReplicationHandler.java
146 146

  
147 147
          //send a message to the server requesting each document
148 148
          URL getDocURL = new URL("http://" + docServer + 
149
                                  "?action=getdocument&docid="+ docid);
149
                                  "?action=read&docid="+ docid);
150 150
          InputStreamReader getDocIstream = new InputStreamReader(
151 151
                                                getDocURL.openStream()); 
152 152

  
src/edu/ucsb/nceas/metacat/RelationHandler.java
68 68
        String subject = rs.getString(1);
69 69
        MetacatURL subjectMurl = new MetacatURL(subject);
70 70
        String subjectDoctype = null;
71
        if(subjectMurl.getURLType().equals("metacat"))
71
        if(subjectMurl.getProtocol().equals("metacat"))
72 72
        {
73 73
          DocumentImpl subDoc = new DocumentImpl(conn, 
74 74
                                                 subjectMurl.getParam(0)[1]);
......
129 129
        MetacatURL objMurl = new MetacatURL(object);
130 130
        String subDoctype = null;
131 131
        String objDoctype = null;
132
        if(subMurl.getURLType().equals("metacat"))
132
        if(subMurl.getProtocol().equals("metacat"))
133 133
        {
134 134
          DocumentImpl subDoc = new DocumentImpl(conn, subMurl.getParam(0)[1]);
135 135
          subDoctype = subDoc.getDoctype();
136 136
        }
137
        if(objMurl.getURLType().equals("metacat"))
137
        if(objMurl.getProtocol().equals("metacat"))
138 138
        {
139 139
          DocumentImpl objDoc = new DocumentImpl(conn, objMurl.getParam(0)[1]);
140 140
          objDoc.getDoctype();

Also available in: Unified diff