Project

General

Profile

« Previous | Next » 

Revision 1716

Added by berkley over 21 years ago

changes to make session management between monarch and metacat work.

View differences:

lib/web.xml
1
<!DOCTYPE web-app 
2
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" 
1
<!DOCTYPE web-app
2
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
3 3
        "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
4 4

  
5 5
<web-app>
6
    <display-name>monarch</display-name>
6 7

  
7

  
8
    <!-- General description of your web application -->
9

  
10
    <display-name>Metadata Catalog Demo</display-name>
11
    <description>
12
      This version is a development release only.
13
    </description>
14

  
15

  
16
    <!-- Context initialization parameters that define shared
17
         String constants used within your application, which
18
         can be customized by the system administrator who is
19
         installing your application.  The values actually
20
         assigned to these parameters can be retrieved in a
21
         servlet or JSP page by calling:
22

  
23
             String value =
24
               getServletContext().getInitParameter("name");
25

  
26
         where "name" matches the <param-name> element of
27
         one of these initialization parameters.
28

  
29
         You can define any number of context initialization
30
         parameters, including zero.
31
    -->
32

  
33 8
    <context-param>
34 9
      <param-name>jones</param-name>
35 10
      <param-value>jones@nceas.ucsb.edu</param-value>
36 11
      <description>
37
        The EMAIL address of the administrator to whom questions
38
        and comments about this application should be addressed.
39 12
      </description>
40 13
    </context-param>
41 14

  
42

  
43
    <!-- Servlet definitions for the servlets that make up
44
         your web application, including initialization
45
         parameters.  With Tomcat, you can also send requests
46
         to servlets not listed here with a request like this:
47

  
48
           http://localhost:8080/{context-path}/servlet/{classname}
49

  
50
         but this usage is not guaranteed to be portable.  It also
51
         makes relative references to images and other resources
52
         required by your servlet more complicated, so defining
53
         all of your servlets (and defining a mapping to them with
54
         a <servlet-mapping> element) is recommended.
55

  
56
         Servlet initialization parameters can be retrieved in a
57
         servlet or JSP page by calling:
58

  
59
             String value =
60
               getServletConfig().getInitParameter("name");
61

  
62
         where "name" matches the <param-name> element of
63
         one of these initialization parameters.
64

  
65
         You can define any number of servlets, including zero.
66
    -->
67

  
68 15
    <servlet>
69 16
      <servlet-name>metacat</servlet-name>
70
      <description>
71
        The main controlling servlet for the metacat application.
72
      </description>
73 17
      <servlet-class>edu.ucsb.nceas.metacat.MetaCatServlet</servlet-class>
74
      <!-- Load this servlet at server startup time -->
75
      <load-on-startup>5</load-on-startup>
18
      <init-param>
19
        <param-name>debug</param-name>
20
        <param-value>1</param-value>
21
      </init-param>
22
      <init-param>
23
        <param-name>listings</param-name>
24
        <param-value>true</param-value>
25
      </init-param>
26
      <load-on-startup>1</load-on-startup>
76 27
    </servlet>
77 28
    
78
    <servlet>
29
     <servlet>
79 30
      <servlet-name>replication</servlet-name>
80
       <description>
81
         The replication control servlet for metacat
82
       </description>
83 31
      <servlet-class>edu.ucsb.nceas.metacat.MetacatReplication</servlet-class>
84
      <load-on-startup>5</load-on-startup>
32
      <init-param>
33
        <param-name>debug</param-name>
34
        <param-value>1</param-value>
35
      </init-param>
36
      <init-param>
37
        <param-name>listings</param-name>
38
        <param-value>true</param-value>
39
      </init-param>
40
      <load-on-startup>1</load-on-startup>
85 41
    </servlet>
86 42

  
87

  
88
    <!-- Define mappings that are used by the servlet container to
89
         translate a particular request URI (context-relative) to a
90
         particular servlet.  The examples below correspond to the
91
         servlet descriptions above.  Thus, a request URI like:
92

  
93
           http://localhost:8080/{contextpath}/graph
94

  
95
         will be mapped to the "graph" servlet, while a request like:
96

  
97
           http://localhost:8080/{contextpath}/saveCustomer.do
98

  
99
         will be mapped to the "controller" servlet.
100

  
101
         You may define any number of servlet mappings, including zero.
102
         It is also legal to define more than one mapping for the same
103
         servlet, if you wish to.
104
    -->
105

  
106 43
    <servlet-mapping>
107
      <servlet-name>metacat</servlet-name>
108
      <url-pattern>/metacat*</url-pattern>
44
        <servlet-name>invoker</servlet-name>
45
        <url-pattern>/servlet/*</url-pattern>
109 46
    </servlet-mapping>
110
    
111
    <!-- Define the default session timeout for your application,
112
         in minutes.  From a servlet or JSP page, you can modify
113
         the timeout for a particular session dynamically by using
114
         HttpSession.getMaxInactiveInterval(). -->
115 47

  
116 48
    <session-config>
117
      <session-timeout>30</session-timeout>    <!-- 30 minutes -->
49
      <session-timeout>30</session-timeout>
118 50
    </session-config>
119

  
120 51
</web-app>
src/edu/ucsb/nceas/metacat/DBTransform.java
70 70
import org.w3c.dom.Element;
71 71
import org.xml.sax.SAXException;
72 72

  
73
/** 
73
/**
74 74
 * A Class that transforms XML documents utitlizing XSL style sheets
75 75
 */
76 76
public class DBTransform {
......
87 87
   *
88 88
   * @param conn the database connection from which to lookup the public ids
89 89
   */
90
  public DBTransform() 
91
                  throws IOException, 
92
                         SQLException, 
90
  public DBTransform()
91
                  throws IOException,
92
                         SQLException,
93 93
                         ClassNotFoundException
94 94
  {
95 95
    //this.conn = conn;
......
97 97
    configDir = util.getOption("config-dir");
98 98
    defaultStyle = util.getOption("default-style");
99 99
  }
100
  
100

  
101 101
  /**
102
   * @see transformXMLDocument(String doc, String sourceType,
103
   *            String targetType, String qformat, PrintWriter pw,
104
   *            String sessionid)
105
   */
106
  public void transformXMLDocument(String doc, String sourceType,
107
                String targetType, String qformat, PrintWriter pw)
108
  {
109
    transformXMLDocument(doc, sourceType, targetType, qformat, pw, null);
110
  }
111

  
112
  /**
102 113
   * Transform an XML document using the stylesheet reference from the db
103 114
   *
104 115
   * @param doc the document to be transformed
......
108 119
   * @param pw the PrintWriter to which output is printed
109 120
   * @param params some parameters for eml2 transformation
110 121
   */
111
  public void transformXMLDocument(String doc, String sourceType, 
112
                                   String targetType, String qformat, 
113
                                   PrintWriter pw, Hashtable param) 
122
  public void transformXMLDocument(String doc, String sourceType,
123
                                   String targetType, String qformat,
124
                                   PrintWriter pw, Hashtable param,
125
                                   String sessionid)
114 126
 {
115
    
127

  
116 128
    // Look up the stylesheet for this type combination
117 129
    String xslSystemId = getStyleSystemId(qformat, sourceType, targetType);
118 130

  
......
124 136
                                  new StreamSource(xslSystemId));
125 137
        //transformer.setParameter("qformat", qformat);
126 138
        //MetaCatUtil.debugMessage("qformat: "+qformat, 30);
127
        
139

  
140
        if(sessionid != null)
141
        {
142
          transformer.setParameter("sessid", sessionid);
143
        }
144

  
128 145
        // Set up parameter for transformation
129 146
        if ( param != null)
130 147
        {
......
137 154
            transformer.setParameter(key, value);
138 155
          }
139 156
        }
140
      
141
        transformer.transform(new StreamSource(new StringReader(doc)), 
157

  
158
        transformer.transform(new StreamSource(new StringReader(doc)),
142 159
                              new StreamResult(pw));
143 160
      } catch (Exception e) {
144 161
        pw.println(xslSystemId + "Error transforming document in " +
145 162
                   "DBTransform.transformXMLDocument: " +
146 163
                   e.getMessage());
147
       
164

  
148 165
      }
149 166
    } else {
150
      // No stylesheet registered form this document type, so just return the 
167
      // No stylesheet registered form this document type, so just return the
151 168
      // XML stream we were passed
152 169
      pw.print(doc);
153 170
    }
154 171
  }
155
  
172

  
156 173
  /**
157
   * Transform an XML document to StringWriter using the stylesheet reference 
174
   * Transform an XML document to StringWriter using the stylesheet reference
158 175
   * from the db
159 176
   * @param doc the document to be transformed
160 177
   * @param sourceType the document type of the source
......
163 180
   * @param pw the StringWriter to which output will be stored
164 181
   */
165 182
  public void transformXMLDocument(String doc, String sourceType,
166
                String targetType, String qFormat, StringWriter pw) {
183
                String targetType, String qFormat, StringWriter pw,
184
                String sessionid) {
167 185

  
168 186
    // Look up the stylesheet for this type combination
169 187
    String xslSystemId = getStyleSystemId(qFormat, sourceType, targetType);
......
174 192
        TransformerFactory tFactory = TransformerFactory.newInstance();
175 193
        Transformer transformer = tFactory.newTransformer(
176 194
                                  new StreamSource(xslSystemId));
195
        if(sessionid != null)
196
        {
197
          transformer.setParameter("sessid", sessionid);
198
        }
177 199
        transformer.setParameter("qFormat", qFormat);
178 200
        transformer.transform(new StreamSource(new StringReader(doc)),
179 201
                              new StreamResult(pw));
......
181 203
        util.debugMessage(xslSystemId + "Error transforming document in " +
182 204
                   "DBTransform.transformXMLDocument: " +
183 205
                   e.getMessage(), 30);
184
       
206

  
185 207
      }
186 208
    } else {
187
      // No stylesheet registered form this document type, so just return the 
209
      // No stylesheet registered form this document type, so just return the
188 210
      // XML stream we were passed
189 211
      pw.write(doc);
190 212
    }
191 213
  }
192
  
214

  
193 215
  /**
216
   * @see transformXMLDocument(String doc, String sourceType,
217
   *            String targetType, String qFormat, StringWriter pw
218
   *            String sessionid)
219
   */
220
  public void transformXMLDocument(String doc, String sourceType,
221
                String targetType, String qFormat, StringWriter pw)
222
  {
223
    transformXMLDocument(doc, sourceType, targetType, qFormat, pw, null);
224
  }
225

  
226
  /**
194 227
   * gets the content of a tag in a given xml file with the given path
195 228
   * @param f the file to parse
196 229
   * @param path the path to get the content from
197 230
   */
198
  public static NodeList getPathContent(File f, String path) 
231
  public static NodeList getPathContent(File f, String path)
199 232
  {
200 233
    if(f == null)
201 234
    {
202 235
      return null;
203 236
    }
204
   
237

  
205 238
    DOMParser parser = new DOMParser();
206 239
    InputSource in;
207 240
    FileInputStream fs;
208
    
241

  
209 242
    try
210
    { 
243
    {
211 244
      fs = new FileInputStream(f);
212 245
      in = new InputSource(fs);
213 246
    }
......
216 249
      fnf.printStackTrace();
217 250
      return null;
218 251
    }
219
    
252

  
220 253
    try
221 254
    {
222 255
      parser.parse(in);
......
224 257
    }
225 258
    catch(Exception e1)
226 259
    {
227
      System.err.println("File: " + f.getPath() + " : parse threw: " + 
260
      System.err.println("File: " + f.getPath() + " : parse threw: " +
228 261
                         e1.toString());
229 262
      return null;
230 263
    }
231
    
264

  
232 265
    Document doc = parser.getDocument();
233
    
266

  
234 267
    try
235 268
    {
236 269
      NodeList docNodeList = XPathAPI.selectNodeList(doc, path);
......
238 271
    }
239 272
    catch(Exception se)
240 273
    {
241
      System.err.println("file: " + f.getPath() + " : parse threw: " + 
274
      System.err.println("file: " + f.getPath() + " : parse threw: " +
242 275
                         se.toString());
243 276
      return null;
244 277
    }
......
251 284
   * @param sourcetype the document type of the source
252 285
   * @param targettype the document type of the target
253 286
   */
254
  public String getStyleSystemId(String qformat, String sourcetype, 
287
  public String getStyleSystemId(String qformat, String sourcetype,
255 288
                String targettype) {
256 289
    String systemId = null;
257 290

  
......
262 295
    // Load the style-set map for this qformat into a DOM
263 296
    try {
264 297
      boolean breakflag = false;
265
      String filename = configDir + "/" + qformat + ".xml";       
298
      String filename = configDir + "/" + qformat + ".xml";
266 299
      util.debugMessage("Trying style-set file: " + filename, 30);
267 300
      File f = new File(filename);
268 301
      NodeList nlDoctype = getPathContent(f, "/style-set/doctype");
269 302
      NodeList nlDefault = getPathContent(f, "/style-set/default-style");
270 303
      Node nDefault = nlDefault.item(0);
271 304
      systemId = nDefault.getFirstChild().getNodeValue(); //set the default
272
      
305

  
273 306
      for(int i=0; i<nlDoctype.getLength(); i++)
274 307
      { //look for the right sourcetype
275 308
        Node nDoctype = nlDoctype.item(i);
......
303 336
                }
304 337
              }
305 338
            }
306
            
339

  
307 340
            if(breakflag)
308 341
            {
309 342
              break;
310 343
            }
311 344
          }
312 345
        }
313
        
346

  
314 347
        if(breakflag)
315 348
        {
316 349
          break;
......
335 368
   * @param sourcetype the document type of the source
336 369
   * @param targettype the document type of the target
337 370
   */
338
  public String getSystemId(String objecttype, String sourcetype, 
371
  public String getSystemId(String objecttype, String sourcetype,
339 372
                String targettype) {
340 373

  
341 374
    // Look up the System ID of a particular object
......
366 399
            try {
367 400
              the_system_id = rs.getString(1);
368 401
            } catch (SQLException e) {
369
              System.out.println("Error with getString in " + 
370
                                 "DBTransform.getSystemId: " + e.getMessage());                
402
              System.out.println("Error with getString in " +
403
                                 "DBTransform.getSystemId: " + e.getMessage());
371 404
            }
372 405
          } else {
373
            the_system_id = null; 
406
            the_system_id = null;
374 407
          }
375 408
        } catch (SQLException e) {
376
          System.err.println("Error with next in DBTransform.getSystemId: " + 
409
          System.err.println("Error with next in DBTransform.getSystemId: " +
377 410
                              e.getMessage());
378 411
          return ("Error with next: " + e.getMessage());
379 412
        }
380 413
      } catch (SQLException e) {
381
        System.err.println("Error with getrset in DBTransform.getSystemId: " + 
414
        System.err.println("Error with getrset in DBTransform.getSystemId: " +
382 415
                            e.getMessage());
383 416
        return ("Error with getrset: " + e.getMessage());
384 417
      }
385 418
      pstmt.close();
386 419
    } catch (SQLException e) {
387
      System.err.println("Error getting id in DBTransform.getSystemId: " + 
420
      System.err.println("Error getting id in DBTransform.getSystemId: " +
388 421
                          e.getMessage());
389
      return ("Error getting id in DBTransform.getSystemId:: " + 
422
      return ("Error getting id in DBTransform.getSystemId:: " +
390 423
               e.getMessage());
391 424
    }
392 425
    finally
......
414 447
   * Usage: java DBTransform
415 448
   */
416 449
  static public void main(String[] args) {
417
     
450

  
418 451
     if (args.length > 0)
419 452
     {
420 453
        System.err.println("Wrong number of arguments!!!");
......
422 455
        return;
423 456
     } else {
424 457
        try {
425
                    
458

  
426 459
          // Open a connection to the database
427 460
          /*MetaCatUtil   util = new MetaCatUtil();
428 461
          Connection dbconn = util.openDBConnection();*/
......
436 469

  
437 470
          // Transform the document to the new doctype
438 471
          DBTransform dbt = new DBTransform();
439
          dbt.transformXMLDocument(testdoc.toString(), 
440
                                   "-//NCEAS//eml-dataset//EN", 
441
                                   "-//W3C//HTML//EN", 
472
          dbt.transformXMLDocument(testdoc.toString(),
473
                                   "-//NCEAS//eml-dataset//EN",
474
                                   "-//W3C//HTML//EN",
442 475
                                   "knb",
443 476
                                   new PrintWriter(System.out), null);
444 477

  
......
449 482
        }
450 483
     }
451 484
  }
452
  
485

  
453 486
  private void dbg(int position) {
454 487
    System.err.println("Debug flag: " + position);
455 488
  }
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
245 245
      {
246 246
        return;
247 247
      }
248

  
248 249
      //if the user clicked on the input images, decode which image
249 250
      //was clicked then set the action.
250 251
      String action = ((String[])params.get("action"))[0];
......
303 304
          password = (String)sess.getAttribute("password");
304 305
          groupnames = (String[])sess.getAttribute("groupnames");
305 306
          try {
306
            sess_id = (String)sess.getId();
307
            if(params.containsKey("sessionid"))
308
            {
309
              sess_id = (String)params.get("sessionid");
310
              sess.setAttribute("JSESSIONID", sess_id);
311
            }
312
            else
313
            {
314
              sess_id = (String)sess.getId();
315
            }
307 316
          } catch(IllegalStateException ise) {
308 317
            System.out.println("error in handleGetOrPost: this shouldn't " +
309 318
                               "happen: the session should be valid: " +
......
316 325
      // to a particular action handler
317 326
      if(action.equals("query")) {
318 327
        PrintWriter out = response.getWriter();
319
        handleQuery(out,params,response,username,groupnames);
328
        handleQuery(out,params,response,username,groupnames,sess_id);
320 329
        out.close();
321 330
      } else if(action.equals("squery")) {
322 331
        PrintWriter out = response.getWriter();
323 332
        if(params.containsKey("query")) {
324
         handleSQuery(out, params,response,username,groupnames);
333
         handleSQuery(out, params,response,username,groupnames,sess_id);
325 334
         out.close();
326 335
        } else {
327 336
          out.println("Illegal action squery without \"query\" parameter");
......
333 342
      } else if (action.equals("read")) {
334 343
        handleReadAction(params, response, username,password, groupnames);
335 344
      } else if (action.equals("readinlinedata")) {
336
        handleReadInlineDataAction(params, response, username, 
345
        handleReadInlineDataAction(params, response, username,
337 346
                                   password, groupnames);
338 347
      } else if (action.equals("insert") || action.equals("update")) {
339 348
        PrintWriter out = response.getWriter();
......
542 551
   * @param conn the database connection
543 552
   */
544 553
  protected void handleSQuery(PrintWriter out, Hashtable params,
545
                 HttpServletResponse response, String user, String[] groups)
554
                 HttpServletResponse response, String user, String[] groups,
555
                 String sessionid)
546 556
  {
547 557
    String xmlquery = ((String[])params.get("query"))[0];
548 558
    String qformat = ((String[])params.get("qformat"))[0];
......
566 576
      outPutTime = System.currentTimeMillis()/1000;
567 577
      MetaCatUtil.debugMessage("Output time: "+(outPutTime-toStringTime), 30);
568 578
    } else {
569
      transformResultset(resultdoc, response, out, qformat);
579
      transformResultset(resultdoc, response, out, qformat, sessionid);
570 580
      outPutTime = System.currentTimeMillis()/1000;
571 581
      MetaCatUtil.debugMessage("Output time: "+(outPutTime-toStringTime), 30);
572 582
    }
......
581 591
    * @param response the response object linked to the client
582 592
    */
583 593
  protected void handleQuery(PrintWriter out, Hashtable params,
584
                 HttpServletResponse response, String user, String[] groups)
594
                 HttpServletResponse response, String user, String[] groups,
595
                 String sessionid)
585 596
  {
586 597
    //create the query and run it
587 598
    String xmlquery = DBQuery.createSQuery(params);
......
596 607
      response.setContentType("text/xml");
597 608
      out.println(resultdoc);
598 609
    } else {
599
      transformResultset(resultdoc, response, out, qformat);
610
      transformResultset(resultdoc, response, out, qformat, sessionid);
600 611
    }
601 612
  }
602 613

  
......
671 682
   */
672 683
  protected void transformResultset(String resultdoc,
673 684
                                    HttpServletResponse response,
674
                                    PrintWriter out, String qformat)
685
                                    PrintWriter out, String qformat,
686
                                    String sessionid)
675 687
  {
676 688

  
677 689
    try {
......
679 691
      DBTransform trans = new DBTransform();
680 692
      response.setContentType("text/html");
681 693
      trans.transformXMLDocument(resultdoc, "-//NCEAS//resultset//EN",
682
                                 "-//W3C//HTML//EN", qformat, out, null);
694
                                 "-//W3C//HTML//EN", qformat, out, sessionid);
683 695

  
684 696
    }
685 697
    catch(Exception e)
......
820 832

  
821 833
  }//handleExportAction
822 834

  
823
  
835

  
824 836
   //read inline data section
825 837
 /**
826
   * In eml2 document, the xml can have inline data and data was stripped off 
838
   * In eml2 document, the xml can have inline data and data was stripped off
827 839
   * and store in file system. This action can be used to read inline data only
828 840
   * @param params the Hashtable of HTTP request parameters
829 841
   * @param response the HTTP response object linked to the client
......
854 866
      {
855 867
        throw new Exception("You didn't specify requested inlinedataid");
856 868
      }//if
857
      
869

  
858 870
      // check for permission
859 871
      docId = MetaCatUtil.getDocIdWithoutRevFromInlineDataID(inlineDataId);
860 872
      PermissionController controller = new PermissionController(docId);
861 873
      // check top level read permission
862
      if (!controller.hasPermission(user, groups, 
874
      if (!controller.hasPermission(user, groups,
863 875
                                    AccessControlInterface.READSTRING))
864 876
      {
865 877
          throw new Exception("User "+ user + " doesn't have permission "+
......
876 888
           throw new Exception("User "+ user + " doesn't have permission "+
877 889
                              " to read inlinedata " + inlineDataId);
878 890
        }//if
879
        
891

  
880 892
      }//else
881
      
893

  
882 894
      // Get output stream
883 895
      out = response.getOutputStream();
884 896
      // read the inline data from the file
......
898 910
    catch (Exception e)
899 911
    {
900 912
      try
901
      { 
913
      {
902 914
        PrintWriter pw = null;
903 915
        // Send error message back
904 916
        if (out != null)
......
908 920
        else
909 921
        {
910 922
          pw = response.getWriter();
911
        } 
923
        }
912 924
         pw.println("<?xml version=\"1.0\"?>");
913 925
         pw.println("<error>");
914 926
         pw.println(e.getMessage());
......
928 940
                           ioe.getMessage(), 30);
929 941
     }//catch
930 942

  
931
      MetaCatUtil.debugMessage("Error in MetacatServlet.handleReadInlineDataAction: " 
943
      MetaCatUtil.debugMessage("Error in MetacatServlet.handleReadInlineDataAction: "
932 944
                                + e.getMessage(), 30);
933
   
945

  
934 946
    }//catch
935 947

  
936 948
  }//handleReadInlineDataAction
937
  
949

  
938 950
  /*
939 951
   * Get the nodeid from xml_nodes for the inlinedataid
940 952
   */
941
  private long getInlineDataNodeId(String inLineDataId, String docId) 
953
  private long getInlineDataNodeId(String inLineDataId, String docId)
942 954
                                   throws SQLException
943 955
  {
944 956
    long nodeId = 0;
......
949 961
    int serialNumber = -1;
950 962
    String sql ="SELECT nodeid FROM xml_nodes WHERE docid=? AND nodedata=? " +
951 963
                "AND nodetype='TEXT' AND parentnodeid IN " +
952
                "(SELECT nodeid FROM xml_nodes WHERE docid=? AND " + 
964
                "(SELECT nodeid FROM xml_nodes WHERE docid=? AND " +
953 965
                "nodetype='ELEMENT' AND nodename='" + INLINE + "')";
954
  
966

  
955 967
    try
956 968
    {
957 969
      //check out DBConnection
958 970
      conn=DBConnectionPool.getDBConnection("AccessControlList.isAllowFirst");
959 971
      serialNumber=conn.getCheckOutSerialNumber();
960
    
972

  
961 973
      pStmt = conn.prepareStatement(sql);
962 974
      //bind value
963 975
      pStmt.setString(1, docId);//docid
964 976
      pStmt.setString(2, inLineDataId);//inlinedataid
965 977
      pStmt.setString(3, docId);
966
      // excute query 
978
      // excute query
967 979
      pStmt.execute();
968 980
      ResultSet rs = pStmt.getResultSet();
969 981
      hasRow=rs.next();
970 982
      // get result
971 983
      if (hasRow)
972 984
      {
973
        nodeId = rs.getLong(1);  
985
        nodeId = rs.getLong(1);
974 986
      }//if
975
     
987

  
976 988
    }//try
977 989
    catch (SQLException e)
978 990
    {
......
993 1005
                             " is: "+nodeId, 35);
994 1006
    return nodeId;
995 1007
  }
996
  
997
  
998
  
1008

  
1009

  
1010

  
999 1011
  // READ SECTION
1000 1012
  /**
1001 1013
   * Handle the "read" request of metadata/data files from Metacat
......
1033 1045
      // the param for only metadata (eml)
1034 1046
      if (params.containsKey("inlinedata"))
1035 1047
      {
1036
        
1048

  
1037 1049
        String inlineData = ((String[])params.get("inlinedata"))[0];
1038 1050
        if (inlineData.equalsIgnoreCase("false"))
1039 1051
        {
1040 1052
          withInlineData = false;
1041 1053
        }
1042
      } 
1054
      }
1043 1055
      if (params.containsKey("abstractpath")) {
1044 1056
        abstrpath = ((String[])params.get("abstractpath"))[0];
1045 1057
        if ( !abstrpath.equals("") && (abstrpath != null) ) {
......
1224 1236
  // read metadata or data from Metacat
1225 1237
  private void readFromMetacat(HttpServletResponse response, String docid,
1226 1238
                               String qformat, String abstrpath, String user,
1227
                               String[] groups, boolean zip, 
1239
                               String[] groups, boolean zip,
1228 1240
                               ZipOutputStream zout, boolean withInlineData,
1229 1241
                               Hashtable params)
1230 1242
               throws ClassNotFoundException, IOException, SQLException,
......
1257 1269

  
1258 1270
        //MIME type
1259 1271
        String contentType = getServletContext().getMimeType(filename);
1260
        if (contentType == null) 
1272
        if (contentType == null)
1261 1273
        {
1262 1274
          ContentTypeProvider provider = new ContentTypeProvider(docid);
1263 1275
          contentType = provider.getContentType();
1264 1276
          MetaCatUtil.debugMessage("Final contenttype is: "+ contentType, 30);
1265 1277
        }
1266
       
1278

  
1267 1279
        response.setContentType(contentType);
1268 1280
        // if we decide to use "application/octet-stream" for all data returns
1269 1281
        // response.setContentType("application/octet-stream");
......
1298 1310
          // Transform the document to the new doctype
1299 1311
          DBTransform dbt = new DBTransform();
1300 1312
          dbt.transformXMLDocument(doc.toString(user, groups, withInlineData),
1301
                                   doctype,"-//W3C//HTML//EN", 
1313
                                   doctype,"-//W3C//HTML//EN",
1302 1314
                                   qformat, out, params);
1303 1315
        }
1304 1316

  
......
1514 1526
 }//readFromRemoteMetaCat
1515 1527

  
1516 1528
  // END OF READ SECTION
1517
  
1518
 
1519
  
1529

  
1530

  
1531

  
1520 1532
  // INSERT/UPDATE SECTION
1521 1533
  /**
1522 1534
   * Handle the database putdocument request and write an XML document
......
1582 1594
        {
1583 1595
          documentWrapper = new DocumentImplWrapper("", false);
1584 1596
        }
1585
        
1597

  
1586 1598
        xml = new StringReader(doctext[0]);
1587 1599

  
1588 1600
        String[] action = (String[])params.get("action");
......
1622 1634
            newdocid = documentWrapper.write(dbConn, xml, pub, dtd, doAction,
1623 1635
                                          null, user, groups);
1624 1636
          }//catch
1625
        
1637

  
1626 1638
        }//try
1627 1639
        finally
1628 1640
        {
......
1637 1649
        out.println("<docid>" + newdocid + "</docid>");
1638 1650
        out.println("</success>");
1639 1651

  
1640
      } 
1641
      catch (NullPointerException npe) 
1652
      }
1653
      catch (NullPointerException npe)
1642 1654
      {
1643 1655
        //response.setContentType("text/xml");
1644 1656
        out.println("<?xml version=\"1.0\"?>");
......
1646 1658
        out.println(npe.getMessage());
1647 1659
        out.println("</error>");
1648 1660
      }
1649
    } 
1650
    catch (Exception e) 
1661
    }
1662
    catch (Exception e)
1651 1663
    {
1652 1664
      //response.setContentType("text/xml");
1653 1665
      out.println("<?xml version=\"1.0\"?>");
......
1716 1728
    return validate;
1717 1729
  }
1718 1730
  // END OF INSERT/UPDATE SECTION
1719
  
1731

  
1720 1732
  /* check if the xml string contains key words to specify schema loocation*/
1721 1733
  private boolean needSchemaValidation(String xml)
1722 1734
  {
......
1728 1740
      return needSchemaValidate;
1729 1741
    }
1730 1742
    String targetLine = getSchemaLine(xml);
1731
    // to see if the second line contain some keywords 
1743
    // to see if the second line contain some keywords
1732 1744
    if (targetLine != null && (targetLine.indexOf(SCHEMALOCATIONKEYWORD) != -1||
1733 1745
             targetLine.indexOf(NONAMESPACELOCATION) != -1 ))
1734 1746
    {
1735 1747
      // if contains schema location key word, should be validate
1736 1748
      needSchemaValidate = true;
1737 1749
    }
1738
    
1739
    MetaCatUtil.debugMessage("Validation for schema is " + 
1750

  
1751
    MetaCatUtil.debugMessage("Validation for schema is " +
1740 1752
                             needSchemaValidate, 10);
1741 1753
    return needSchemaValidate;
1742
   
1754

  
1743 1755
  }
1744
  
1756

  
1745 1757
   /* check if the xml string contains key words to specify schema loocation*/
1746 1758
  private boolean needEml2Validation(String xml)
1747 1759
  {
......
1754 1766
      return needEml2Validate;
1755 1767
    }
1756 1768
    String targetLine = getSchemaLine(xml);
1757
    
1758
    if (targetLine != null && targetLine.indexOf(EML2KEYWORD) != -1 && 
1769

  
1770
    if (targetLine != null && targetLine.indexOf(EML2KEYWORD) != -1 &&
1759 1771
        targetLine.indexOf(emlNameSpace) != -1)
1760 1772
    {
1761 1773
      // if contains schema location key word, should be validate
1762 1774
      needEml2Validate = true;
1763 1775
    }
1764
    
1765
    MetaCatUtil.debugMessage("Validation for eml is " + 
1776

  
1777
    MetaCatUtil.debugMessage("Validation for eml is " +
1766 1778
                             needEml2Validate, 10);
1767 1779
    return needEml2Validate;
1768
   
1780

  
1769 1781
  }
1770
  
1782

  
1771 1783
  private String getSchemaLine(String xml)
1772 1784
  {
1773 1785
    // find the line
......
1795 1807
        break;
1796 1808
      }//if
1797 1809
    }//for
1798
    // get the second line string 
1810
    // get the second line string
1799 1811
    MetaCatUtil.debugMessage("The start index for second line: "+startIndex, 25);
1800 1812
    MetaCatUtil.debugMessage("The end index for second line: "+endIndex, 25);
1801 1813
    if (startIndex != 0 && endIndex != 0)
1802 1814
    {
1803 1815
      secondLine = xml.substring(startIndex+1, endIndex);
1804
      
1816

  
1805 1817
    }//if
1806 1818
    MetaCatUtil.debugMessage("the second line string is: "+secondLine, 25);
1807 1819
    return secondLine;
1808 1820
  }
1809
  
1821

  
1810 1822
  // DELETE SECTION
1811 1823
  /**
1812 1824
   * Handle the database delete request and delete an XML document
......
2164 2176

  
2165 2177
    try {
2166 2178
      // MBJ: need to put filesize limit in Metacat config (metacat.properties)
2167
      MultipartParser mp = new MultipartParser(request, sizeLimit*1024*1024); 
2179
      MultipartParser mp = new MultipartParser(request, sizeLimit*1024*1024);
2168 2180
      Part part;
2169 2181
      while ((part = mp.readNextPart()) != null) {
2170 2182
        String name = part.getName();
......
2358 2370
      out.println("</error>");
2359 2371
    }
2360 2372
  }
2361
  
2373

  
2362 2374
  /*
2363 2375
   * A method to handle set access action
2364 2376
   */
......
2378 2390
    String error      = null;
2379 2391
    Vector successList = new Vector();
2380 2392
    String success    = null;
2381
   
2382
    
2393

  
2394

  
2383 2395
    // Get parameters
2384
    if (params.containsKey("docid")) 
2396
    if (params.containsKey("docid"))
2385 2397
    {
2386 2398
      docList = (String[])params.get("docid");
2387 2399
    }
2388 2400
    if (params.containsKey("principal"))
2389 2401
    {
2390
      principalList = (String[])params.get("principal"); 
2402
      principalList = (String[])params.get("principal");
2391 2403
    }
2392 2404
    if (params.containsKey("permission"))
2393 2405
    {
2394 2406
      permissionList = (String[])params.get("permission");
2395
      
2407

  
2396 2408
    }
2397 2409
    if (params.containsKey("permType"))
2398 2410
    {
2399 2411
      permTypeList = (String[])params.get("permType");
2400
    
2412

  
2401 2413
    }
2402 2414
    if (params.containsKey("permOrder"))
2403 2415
    {
2404 2416
      permOrderList = (String[])params.get("permOrder");
2405
     
2417

  
2406 2418
    }
2407
   
2419

  
2408 2420
    // Make sure the parameter is not null
2409 2421
    if (docList == null || principalList == null || permTypeList == null ||
2410 2422
        permissionList == null)
......
2416 2428
      outputResponse(successList, errorList, out);
2417 2429
      return;
2418 2430
    }
2419
    
2431

  
2420 2432
    // Only select first element for permission, type and order
2421 2433
    permission = permissionList[0];
2422 2434
    permType = permTypeList[0];
......
2424 2436
    {
2425 2437
       permOrder = permOrderList[0];
2426 2438
    }
2427
    
2439

  
2428 2440
    // Get package doctype set
2429 2441
    Vector packageSet =MetaCatUtil.getOptionList(
2430 2442
                                    MetaCatUtil.getOption("packagedoctypeset"));
......
2433 2445
    {
2434 2446
      for (int i = 0; i<packageSet.size(); i++)
2435 2447
      {
2436
        MetaCatUtil.debugMessage("doctype in package set: " + 
2448
        MetaCatUtil.debugMessage("doctype in package set: " +
2437 2449
                              (String)packageSet.elementAt(i), 34);
2438 2450
      }
2439 2451
    }//if
2440
    
2452

  
2441 2453
    // handle every accessionNumber
2442 2454
    for (int i=0; i <docList.length; i++)
2443 2455
    {
......
2459 2471
        errorList.addElement(error);
2460 2472
        continue;
2461 2473
      }
2462
      //check if user is the owner. Only owner can do owner                            
2474
      //check if user is the owner. Only owner can do owner
2463 2475
      if (username == null || owner == null || !username.equals(owner))
2464 2476
      {
2465 2477
        error = "User - " + username + " does not have permission to set " +
......
2467 2479
        errorList.addElement(error);
2468 2480
        continue;
2469 2481
      }
2470
      
2482

  
2471 2483
      // If docid publicid is BIN data file or other beta4, 6 package document
2472 2484
      // we could not do set access control. Because we don't want inconsistent
2473 2485
      // to its access docuemnt
......
2478 2490
        errorList.addElement(error);
2479 2491
        continue;
2480 2492
      }
2481
      
2493

  
2482 2494
      // for every principle
2483 2495
      for (int j = 0; j<principalList.length; j++)
2484 2496
      {
......
2486 2498
        try
2487 2499
        {
2488 2500
          //insert permission
2489
          AccessControlForSingleFile accessControl = new 
2501
          AccessControlForSingleFile accessControl = new
2490 2502
                           AccessControlForSingleFile(accessionNumber,
2491 2503
                                    principal, permission, permType, permOrder);
2492 2504
          accessControl.insertPermissions();
......
2498 2510
        {
2499 2511
          MetaCatUtil.debugMessage("Erorr in handleSetAccessAction2: " +
2500 2512
                                   ee.getMessage(), 30);
2501
          error = "Faild to set access control for document " + 
2513
          error = "Faild to set access control for document " +
2502 2514
                  accessionNumber + " because " + ee.getMessage();
2503 2515
          errorList.addElement(error);
2504 2516
          continue;
2505 2517
        }
2506 2518
      }//for every principle
2507
    }//for every document 
2519
    }//for every document
2508 2520
    outputResponse(successList, errorList, out);
2509 2521
  }//handleSetAccessAction
2510
  
2511
 
2522

  
2523

  
2512 2524
  /*
2513 2525
   * A method try to determin a docid's public id, if couldn't find null
2514 2526
   * will be returned.
2515 2527
   */
2516
  private String getFieldValueForDoc(String accessionNumber, String fieldName) 
2528
  private String getFieldValueForDoc(String accessionNumber, String fieldName)
2517 2529
                                      throws Exception
2518 2530
  {
2519 2531
    if (accessionNumber==null || accessionNumber.equals("") ||fieldName == null
......
2521 2533
    {
2522 2534
      throw new Exception("Docid or field name was not specified");
2523 2535
    }
2524
    
2536

  
2525 2537
    PreparedStatement pstmt = null;
2526 2538
    ResultSet rs = null;
2527 2539
    String fieldValue = null;
2528 2540
    String docId = null;
2529 2541
    DBConnection conn = null;
2530 2542
    int serialNumber = -1;
2531
    
2543

  
2532 2544
    // get rid of revision if access number has
2533 2545
    docId = MetaCatUtil.getDocIdFromString(accessionNumber);
2534 2546
    try
......
2539 2551
      pstmt = conn.prepareStatement(
2540 2552
            "SELECT " + fieldName + " FROM xml_documents " +
2541 2553
            "WHERE docid = ? ");
2542
          
2554

  
2543 2555
      pstmt.setString(1, docId);
2544 2556
      pstmt.execute();
2545 2557
      rs = pstmt.getResultSet();
2546 2558
      boolean hasRow = rs.next();
2547 2559
      int perm = 0;
2548
      if ( hasRow ) 
2560
      if ( hasRow )
2549 2561
      {
2550 2562
        fieldValue = rs.getString(1);
2551 2563
      }
......
2566 2578
      {
2567 2579
        rs.close();
2568 2580
        pstmt.close();
2569
        
2581

  
2570 2582
      }
2571 2583
      finally
2572 2584
      {
......
2575 2587
    }
2576 2588
    return fieldValue;
2577 2589
  }//getFieldValueForDoc
2578
  
2590

  
2579 2591
  /*
2580 2592
   * A method to output setAccess action result
2581 2593
   */
2582
  private void outputResponse(Vector successList, 
2594
  private void outputResponse(Vector successList,
2583 2595
                              Vector errorList,
2584 2596
                              PrintWriter out)
2585 2597
  {
......
2609 2621
        error = true;
2610 2622
      }//for
2611 2623
    }//if
2612
    
2624

  
2613 2625
    // if no error and no success info, send a error that nothing happened
2614 2626
    if( !error && !success)
2615 2627
    {
......
2617 2629
      out.println("Nothing happend for setaccess action");
2618 2630
      out.println(ERRORCLOSE);
2619 2631
    }
2620
    
2632

  
2621 2633
  }//outputResponse
2622 2634
}
build.xml
48 48
     <property name="dbDriver" value="org.postgresql.Driver"/>
49 49
     <property name="dbAdapter"
50 50
               value="edu.ucsb.nceas.dbadapter.PostgresqlAdapter"/>
51
     <property name="jdbc" value="/usr/share/pgsql/jdbc7.1-1.2.jar" />
51
     <property name="jdbc" value="lib/jdbc7.1-1.2.jar" />
52 52
   </target>
53 53

  
54 54
   <target name="config" depends="postgresql">
......
57 57

  
58 58
      <!-- Customize these properties for your system -->
59 59
      <property name="tomcat" value="/usr/local/devtools/jakarta-tomcat" />
60
      <property name="webapps" value="/usr/local/devtools/jakarta-tomcat/webapps" />
61
      <property name="context" value="tao" />
62
      <property name="user" value="tao"/>
60
      <property name="webapps" value="/opt/tomcat/webapps" />
61
      <property name="context" value="metacat" />
62
      <property name="user" value="berkley"/>
63 63
      <property name="password" value=""/>
64
      <property name="server" value="pine.nceas.ucsb.edu:8443"/>
65
      <property name="systemidserver" value="http://pine.nceas.ucsb.edu:8080" />
66
      <property name="datafilepath" value="/usr/local/devtools/jakarta-tomcat/data/tao/data" />
67
      <property name="inlinedatafilepath" value="/usr/local/devtools/jakarta-tomcat/data/tao/inlinedata" />
68
      <property name="debuglevel" value="35" />
64

  
65
      <property name="server" value="trestles.nceas.ucsb.edu:8080"/>
66
      <property name="systemidserver" value="http://trestles.nceas.ucsb.edu:8080" />
67
      <property name="datafilepath" value="/opt/data" />
68
      <property name="inlinedatafilepath" value="/opt/data" />
69
      <property name="debuglevel" value="10" />
70

  
69 71
      <property name="forcereplicationwaitingtime" value="30000"/>
70 72
      <property name="cvsroot"
71
                value=":ext:tao@cvs.ecoinformatics.org:/cvs" />
73
                value=":ext:berkley@cvs.ecoinformatics.org:/cvs" />
72 74
      <property name="web-base-url"
73 75
                value="http://knb.ecoinformatics.org"/>
74 76
      <property name="default-style" value="knb" />
......
78 80
      <!-- Make sure these paths match the location of the jar files
79 81
           on your system, the defaults should usually work -->
80 82
      <property name="jsdk"
81
                value="${tomcat}/lib/common/servlet.jar" />
83
                value="${tomcat}/common/lib/servlet.jar" />
82 84
      <property name="xmlp"
83 85
                value="lib/xercesImpl.jar" />
84 86
      <property name="srb"
......
181 183
      <property name="ver.src" value="${ver.dir}/src"/>
182 184

  
183 185
      <property name="package.home" value="edu/ucsb/nceas/metacat" />
184

  
185 186
   </target>
186 187

  
187 188
   <target name="prepare" depends="init">
......
304 305
          password="${password}"
305 306
          src="${build.src}/loaddtdschema.sql" />
306 307
   </target>
307
   
308

  
308 309
   <target name="schemasql" depends="prepare">
309 310
     <echo/>
310 311
     <echo>Registering the DTDs with the new Metacat instance...</echo>
......
561 562
      <outputproperty name="indent" value="yes"/>
562 563
    </xslt>
563 564
  </target>
564
  
565

  
565 566
</project>

Also available in: Unified diff