[metacat-cvs] metacat/src/edu/ucsb/nceas/metacat MetaCatServlet.java

Saurabh Garg sgarg at ecoinformatics.org
Thu Nov 10 13:34:44 PST 2005


sgarg       05/11/10 13:34:44

  Modified:    src/edu/ucsb/nceas/metacat MetaCatServlet.java
  Log:
  1. Added code to start the indexing thread.
  2. Fixed a bug in the query on xml_nodes and xml_index
  3. Added more debug statements
  4. Fixed a bug in code which determines namespace
  
  Revision  Changes    Path
  1.234     +42 -14    metacat/src/edu/ucsb/nceas/metacat/MetaCatServlet.java
  
  Index: MetaCatServlet.java
  ===================================================================
  RCS file: /cvs/metacat/src/edu/ucsb/nceas/metacat/MetaCatServlet.java,v
  retrieving revision 1.233
  retrieving revision 1.234
  diff -u -r1.233 -r1.234
  --- MetaCatServlet.java	1 Nov 2005 22:19:35 -0000	1.233
  +++ MetaCatServlet.java	10 Nov 2005 21:34:44 -0000	1.234
  @@ -7,8 +7,8 @@
    *    Release: @release@
    *
    *   '$Author: sgarg $'
  - *     '$Date: 2005/11/01 22:19:35 $'
  - * '$Revision: 1.233 $'
  + *     '$Date: 2005/11/10 21:34:44 $'
  + * '$Revision: 1.234 $'
    *
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
  @@ -48,6 +48,7 @@
   import java.util.Vector;
   import java.util.zip.ZipEntry;
   import java.util.zip.ZipOutputStream;
  +import java.util.Timer;
   
   import javax.servlet.ServletConfig;
   import javax.servlet.ServletContext;
  @@ -168,6 +169,8 @@
       private static final String CONFIG_NAME = "metacat.properties";
        	 
       private static Logger logMetacat = Logger.getLogger(MetaCatServlet.class);
  +       
  +    private Timer timer = null;
       
       /**
        * Initialize the servlet by creating appropriate database connections
  @@ -213,6 +216,17 @@
               // Index the paths specified in the metacat.properties
               checkIndexPaths();
   
  +            // initiate the indexing Queue
  +            IndexingQueue.getInstance();
  +            
  +            // start the IndexingThread if indexingTimerTaskTime more than 0. 
  +            // It will index all the documents not yet indexed in the database             
  +            int indexingTimerTaskTime = Integer.parseInt(MetaCatUtil.getOption("indexingTimerTaskTime"));
  +            if(indexingTimerTaskTime > 0){
  +            	timer = new Timer();
  +            	timer.schedule(new IndexingTimerTask(), 0, indexingTimerTaskTime);
  +            }
  +            
               MetaCatUtil.printMessage("Metacat (" + Version.getVersion()
                                  + ") initialized.");
   
  @@ -232,6 +246,7 @@
           // Close all db connection
           System.out.println("Destroying MetacatServlet");
           DBConnectionPool.release();
  +        timer.cancel();
       }
   
       /** Handle "GET" method requests from HTTP clients */
  @@ -303,7 +318,7 @@
                                 + "n.nodedata, n.nodedatanumerical, n.parentnodeid"
                                 + " FROM xml_nodes n, xml_index i WHERE"
                                 + " i.path = ? and n.parentnodeid=i.nodeid and"
  -                              + " n.nodetype LIKE 'TEXT'");
  +                              + " n.nodetype LIKE 'TEXT' order by n.parentnodeid");
                           pstmt.setString(1, (String) MetaCatUtil.
                                           pathsForIndexing.elementAt(i));
                           pstmt.execute();
  @@ -1799,6 +1814,7 @@
                   out.println(npe.getMessage());
                   out.println("</error>");
                   logMetacat.warn("Error in writing eml document to the database" + npe.getMessage());
  +                npe.printStackTrace();
               }
           } catch (Exception e) {
               //response.setContentType("text/xml");
  @@ -1807,6 +1823,7 @@
               out.println(e.getMessage());
               out.println("</error>");
               logMetacat.warn("Error in writing eml document to the database" + e.getMessage());
  +            e.printStackTrace();
           }
       }
   
  @@ -1892,8 +1909,10 @@
   
           	// find if the root element has prefix
           	String prefix = getPrefix(targetLine);
  +        	logMetacat.info("prefix is:" + prefix);
           	int startIndex = 0;
           	
  +        	
           	if(prefix != null)
           	{
           		// if prefix found then look for xmlns:prefix
  @@ -1901,11 +1920,14 @@
           		String namespaceWithPrefix = NAMESPACEKEYWORD 
           					+ ":" + prefix;
           		startIndex = targetLine.indexOf(namespaceWithPrefix);
  +            	logMetacat.info("namespaceWithPrefix is:" + namespaceWithPrefix+":");
  +            	logMetacat.info("startIndex is:" + startIndex);
           		
           	} else {
           		// if prefix not found then look for xmlns
           		// attribute to find the ns 
           		startIndex = targetLine.indexOf(NAMESPACEKEYWORD);
  +            	logMetacat.info("startIndex is:" + startIndex);
           	}
           		
               int start = 1;
  @@ -1928,19 +1950,26 @@
               } 
               // else: xmlns not found. namespace = null will be returned
   
  +         	logMetacat.info("targetLine is " + targetLine);
  +         	logMetacat.debug("start is " + end);
  +         	logMetacat.debug("end is " + end);
  +           
               if(start < end){
               	namespaceString = targetLine.substring(start + 1, end);
  +            	logMetacat.info("namespaceString is " + namespaceString);
               }
               logMetacat.info("namespace in xml is: "
                       + namespaceString);
  -            if (namespaceString.indexOf(eml2_0_0NameSpace) != -1) {
  -                namespace = eml2_0_0NameSpace;
  -            } else if (namespaceString.indexOf(eml2_0_1NameSpace) != -1) {
  -                namespace = eml2_0_1NameSpace;
  -            } else if (namespaceString.indexOf(eml2_1_0NameSpace) != -1) {
  -                namespace = eml2_1_0NameSpace;
  -            } else {
  -            	namespace = namespaceString;
  +            if(namespaceString != null){
  +            	if (namespaceString.indexOf(eml2_0_0NameSpace) != -1) {
  +            		namespace = eml2_0_0NameSpace;
  +            	} else if (namespaceString.indexOf(eml2_0_1NameSpace) != -1) {
  +            		namespace = eml2_0_1NameSpace;
  +            	} else if (namespaceString.indexOf(eml2_1_0NameSpace) != -1) {
  +            		namespace = eml2_1_0NameSpace;
  +            	} else {
  +            		namespace = namespaceString;
  +            	}
               }
           }
   
  @@ -2006,14 +2035,13 @@
       {
       	String prefix = null;
       	String rootElement = schemaLine.substring(0, schemaLine.indexOf(" "));
  -        logMetacat.warn("rootElement:" + rootElement);
  +        logMetacat.info("rootElement:" + rootElement);
           
           if(rootElement.indexOf(":") > 0){
           	prefix = rootElement.substring(rootElement.indexOf(":") + 1,
           			rootElement.length());
           } 
  -        logMetacat.warn("prefix:" + prefix);        
  -        return prefix;
  +        return prefix.trim();
       }
   
       /**
  
  
  


More information about the Metacat-cvs mailing list