[metacat-cvs] metacat/src/edu/ucsb/nceas/metacat/lsid LSIDAuthorityData.java LSIDAuthorityMain.java LSIDAuthorityMetaData.java LSIDDataLookup.java

Matthew Jones jones at ecoinformatics.org
Fri Nov 11 12:09:01 PST 2005


jones       05/11/11 12:09:01

  Modified:    .        build.properties build.xml
  Added:       lib/lsid_conf mdasdl.xml metacat-lsid.properties
                        metacat.xslt preds.xml
               lib/lsid_conf/WEB-INF server-config.wsdd web.xml
               lib/lsid_conf/services default-services.xml
                        metacat-services.xml
               lib/lsid_lib axis.jar commons-discovery.jar jaxrpc.jar
                        lsid-client-1.1.1.jar lsid-server-1.1.1.jar
                        saaj.jar wsdl4j.jar
               src/edu/ucsb/nceas/metacat/lsid LSIDAuthorityData.java
                        LSIDAuthorityMain.java LSIDAuthorityMetaData.java
                        LSIDDataLookup.java
  Log:
  Initial checkin of LSID support code for metacat.  The LSID support here
  provides access to metacat documents through an LSID identifier.  The
  identifier takes the form:
    urn:lsid:ecoinformatics.org:jones:1:1
  
  See http://lsid.sourceforge.net for more details.
  
  LSID build support has been added to build.properties and build.xml but
  still needs work on integrating it with the main metacat build.  Build
  and deploy the "authority" servlet by setting properties in
  build.properties and then running "ant deploy-lsid".
  
  Still to do:  finish integrating with build, add ability to insert,
  update, and delete documents using LSID id, allow read using LSID ID,
  convert xslts to optionally display and link the LSID ID, and add
  support for hosting multiple LSID authorities (Foreign Authority
  Notification is the likely approach).
  
  Revision  Changes    Path
  1.17      +36 -12    metacat/build.properties
  
  Index: build.properties
  ===================================================================
  RCS file: /cvs/metacat/build.properties,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- build.properties	23 Sep 2005 18:19:38 -0000	1.16
  +++ build.properties	11 Nov 2005 20:08:59 -0000	1.17
  @@ -1,34 +1,42 @@
  -# Trying to create an Ant build properties files
  +# Ant build properties files for the metacat build
   
   # Tomcat Properties
   tomcat=/usr/local/devtools/jakarta-tomcat
  +deploy.dir=/var/www/org.ecoinformatics.knb
  +#deploy.dir=${tomcat}/webapps
  +
   # Tomcat version - tomcat3 or tomcat4 or tomcat5
   tomcatversion=tomcat5
  -webapps=/var/www/org.ecoinformatics.knb
  -context=knb
  +
  +# Servlet properties
  +metacat.context=knb
  +authority.context=authority
   
   # Server Properties
  -# this server should be with ssl port if it is tomcat stand-alone
  -server=knb.ecoinformatics.org
  -# this server should be with http plaint port if it is tomcat stand-alone
  -httpserver=knb.ecoinformatics.org
  +config.hostname=knb.ecoinformatics.org
  +config.port=80
  +server=${config.hostname}
  +httpserver=${server}
  +config.metacatserver=http://${server}/${metacat.context}/metacat
  +config.lsidauthority=ecoinformatics.org
   
   # Installation directory for registry CGI scripts
   inst.cgi.dir=/var/www/cgi-knb
  -cgi-prefix=http://knb.ecoinformatics.org/cgi-bin
  +cgi-prefix=http://${server}/cgi-bin
   ldapUrl=ldap://ldap.ecoinformatics.org/dc=ecoinformatics,dc=org
   
   # Select the database to use for metadata storage
   # Valid values are oracle, postgresql, sqlserver
  -database=oracle
  +database=postgresql
   
   # The JDBC connection string used to connect to the database
  -jdbc-connect=jdbc:oracle:thin:@metacat.nceas.ucsb.edu:1521:knb
  +#jdbc-connect=jdbc:oracle:thin:@metacat.nceas.ucsb.edu:1521:knb
   #jdbc-connect=jdbc:postgresql://localhost/postgres
   #jdbc-connect=jdbc:microsoft:sqlserver://fatali.nceas.ucsb.edu:1433
  +jdbc-connect=jdbc:postgresql://localhost/metacat
   
   # The base directory for locating JDBC jar files (not needed for postgresql)
  -jdbc_base=/usr/oracle/jdbc/lib
  +jdbc_base=./lib
   #jdbc-base=F:\\Program Files\\Microsoft SQL Server 2000 Driver for JDBC\\lib
   
   # Metacat database user and password and location of file stores
  @@ -41,7 +49,7 @@
   cvsroot=:ext:${env.USER}@cvs.ecoinformatics.org:/cvs
   
   # Configure the installed skins, and select the default
  -default-style=knb
  +default-style=default
   
   # this is the url to the web context root for the knb site. 
   # It is used for the qformat=knb skin only
  @@ -83,3 +91,19 @@
   
   ## Metacat Spatial options
   shapelib.dir=/home/harris/development/shapelib-1.2.10/
  +
  +## Additional configuration options
  +# you probably don't want or need to change these
  +config.metadataLabelLsid=${config.lsidauthority}
  +build.dir=build
  +lsid.build.dir=${build.dir}/lsid
  +lib.dir=lib
  +lsid.lib.dir=${lib.dir}/lsid_lib
  +lsid.classes.dir=edu/ucsb/nceas/metacat/lsid
  +conf.dir=lib/lsid_conf
  +services.dir=${conf.dir}/services
  +webinf.dir=${conf.dir}/WEB-INF
  +
  +compile.debug=true
  +compile.deprecation=false
  +compile.optimize=true
  
  
  
  1.227     +156 -18   metacat/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /cvs/metacat/build.xml,v
  retrieving revision 1.226
  retrieving revision 1.227
  diff -u -r1.226 -r1.227
  --- build.xml	4 Oct 2005 17:52:04 -0000	1.226
  +++ build.xml	11 Nov 2005 20:08:59 -0000	1.227
  @@ -6,9 +6,9 @@
     *              National Center for Ecological Analysis and Synthesis
     * For Details: http://www.nceas.ucsb.edu/
     *
  -  *    '$Author: harris $'
  -  *    '$Date: 2005/10/04 17:52:04 $'
  -  *    '$Revision: 1.226 $'
  +  *    '$Author: jones $'
  +  *    '$Date: 2005/11/11 20:08:59 $'
  +  *    '$Revision: 1.227 $'
     *
     * Build file for the Ant cross-platform build system for metacat
     * See http://jakarta.apache.org for details on Ant
  @@ -156,17 +156,17 @@
         
         <!-- It is less likely you'll need to make any changes from here down,
              but customization is possible -->
  -      <property name="installdir"          value="${webapps}/${context}" />
  -      <property name="temp-dir"            value="/tmp/${context}" />
  +      <property name="installdir"          value="${deploy.dir}/${metacat.context}" />
  +      <property name="temp-dir"            value="/tmp/${metacat.context}" />
         <property name="name"                value="metacat"/>
         <property name="Name"                value="MetaCat"/>
         <property name="debugprefix"         value="${Name}:"/>
         <property name="release"             value="1.6.0"/>
  -      <property name="replication-path"    value="/${context}/servlet/replication"/>
  -      <property name="harvester-registration-login-path" value="/${context}/harvesterRegistrationLogin"/>
  -      <property name="harvester-registration-path"       value="/${context}/harvesterRegistration"/>
  -      <property name="servlet-path"        value="/${context}/metacat"/>
  -      <property name="html-path"           value="/${context}"/>
  +      <property name="replication-path"    value="/${metacat.context}/servlet/replication"/>
  +      <property name="harvester-registration-login-path" value="/${metacat.context}/harvesterRegistrationLogin"/>
  +      <property name="harvester-registration-path"       value="/${metacat.context}/harvesterRegistration"/>
  +      <property name="servlet-path"        value="/${metacat.context}/metacat"/>
  +      <property name="html-path"           value="/${metacat.context}"/>
         <property name="systemidserver"      value="http://${httpserver}"/>
         <property name="style-common-relpath"
                                              value="/style/common"/>
  @@ -176,12 +176,12 @@
                                              value="/${installdir}${style-common-relpath}"/>
         <property name="templates.dir"       value="${style-common-fullpath}/templates"/>
         <property name="style-common-path"
  -                                           value="/${context}${style-common-relpath}"/>
  +                                           value="/${metacat.context}${style-common-relpath}"/>
         <property name="style-skins-relpath" value="/style/skins"/>
  -      <property name="style-skins-path"    value="/${context}${style-skins-relpath}"/>
  +      <property name="style-skins-path"    value="/${metacat.context}${style-skins-relpath}"/>
         <property name="replication-log"     value="/tmp/metacatreplication.log"/>
         <property name="replicationerrorlog" value="/tmp/metacatreplication.err"/>
  -      <property name="config-dir"          value="${webapps}/${style-skins-path}" />
  +      <property name="config-dir"          value="${deploy.dir}/${style-skins-path}" />
         <property name="util-module"         value="utilities" />
         <property name="eml-module"          value="eml" />
         <property name="eml-version"         value="2.0.0beta6" />
  @@ -284,7 +284,7 @@
         <filter token="eml2_0_1namespace" value="${eml2_0_1namespace}"/>
         <filter token="eml2_1_0namespace" value="${eml2_1_0namespace}"/>
         <filter token="stmmlnamespace" value="${stmmlnamespace}"/>
  -      <filter token="context" value="${context}"/>
  +      <filter token="context" value="${metacat.context}"/>
         <filter token="forcereplicationwaitingtime" value="${forcereplicationwaitingtime}" />
         <filter token="debuglevel" value="${debuglevel}" />
         <filter token="datafilepath" value="${datafilepath}" />
  @@ -743,12 +743,12 @@
          <chmod dir="${datafilepath}" perm="ug+w" />
          <mkdir dir="${temp-dir}"/>
          <chmod dir="${temp-dir}" perm="ug+w" />
  -       <copy file="${build.dir}/${context}.war" todir="${webapps}"/>
  +       <copy file="${dist.dir}/${metacat.context}.war" todir="${deploy.dir}"/>
      </target>
   
      <target name="upgrade" depends="install"
             description="* Upgrade an existing metacat installation with a new version *">
  -       <unwar src="${webapps}/${context}.war" dest="${webapps}/${context}" />
  +       <unwar src="${deploy.dir}/${metacat.context}.war" dest="${deploy.dir}/${metacat.context}" />
      </target>
   
      <target name="install-registry" depends="init,getConversionXSL"
  @@ -836,7 +836,8 @@
   
      <target name="war" depends="warPrepare,warMSSQL"
               description="Create a web archive (WAR) for servlet deployment">
  -       <war destfile="${build.dir}/${context}.war"
  +       <mkdir dir="${dist.dir}" />
  +       <war destfile="${dist.dir}/${metacat.context}.war"
               webxml="${build.war}/web.xml">
            <fileset dir="${war.context}"/>
            <lib dir="${war.lib}"/>
  @@ -849,7 +850,7 @@
   
          <property name="war.lib" value="${build.war}/lib" />
          <property name="war.webinf" value="${build.war}/WEB-INF" />
  -       <property name="war.context" value="${build.war}/${context}" />
  +       <property name="war.context" value="${build.war}/${metacat.context}" />
          <mkdir dir="${war.lib}" />
          <mkdir dir="${war.webinf}" />
          <mkdir dir="${war.context}" />
  @@ -1098,6 +1099,7 @@
      <target name="clean" depends="init"
               description="deletes build dir and files that can be regenerated form the release">
          <delete dir="${build.dir}" />
  +       <delete dir="${dist.dir}" />
      </target>
   
      <target name="fullclean" depends="clean"
  @@ -1321,4 +1323,140 @@
       </exec>
     </target>
   
  +    <!-- LSID Authority support -->
  +    <patternset id="lsid.jars">
  +        <include name="axis.jar" />
  +        <include name="commons-discovery.jar" />
  +        <include name="jaxrpc.jar" />
  +        <include name="lsid-client-1.1.1.jar" />
  +        <include name="lsid-server-1.1.1.jar" />
  +        <include name="saaj.jar" />
  +        <include name="wsdl4j.jar" />
  +        <!-- These jars may be needed but seem to not actually be,
  +             so leaving them out for now
  +        <include name="activation.jar" />
  +        <include name="axis-ant.jar" />
  +        <include name="castor-0.9.5.jar" />
  +        <include name="commons-logging.jar" />
  +        <include name="dnsjava-1.3.2.jar" />
  +        <include name="mail.jar" />
  +        -->
  +        <!--<include name="GenCastor.class" />-->
  +    </patternset>
  +    <patternset id="lib.jars">
  +        <include name="httpclient.jar" />
  +        <include name="log4j-1.2.12.jar" />
  +        <include name="utilities.jar" />
  +        <include name="xercesImpl.jar" />
  +        <include name="xalan.jar" />
  +        <include name="xml-apis.jar" />
  +    </patternset>
  +
  +    <path id="lsid.classpath">
  +        <fileset dir="${lsid.lib.dir}">
  +            <patternset refid="lsid.jars"/>
  +        </fileset>
  +        <fileset dir="${lib.dir}">
  +            <patternset refid="lsid.jars"/>
  +        </fileset>
  +        <fileset dir="${lib.dir}/xalan">
  +            <include name="xalan.jar" />
  +            <include name="xml-apis.jar" />
  +        </fileset>
  +        <fileset dir="${build.dir}">
  +            <include name="metacat-client.jar" />
  +        </fileset>
  +    </path>
  +
  +    <filterset id="configFilters">
  +        <filter token="LSID_AUTHORITY_HOSTNAME"
  +                value="${config.hostname}" />
  +        <filter token="LSID_AUTHORITY_PORT"
  +                value="${config.port}" />
  +        <filter token="METADATA_LABELS"
  +                value="${config.metadataLabelLsid}" />
  +        <filter token="METACAT_SERVER"
  +                value="${config.metacatserver}" />
  +        <filter token="LSID_AUTHORITY_STRING"
  +                value="${config.lsidauthority}" />
  +    </filterset>
  +    
  +    <target name="prepare-lsid"
  +            depends="prepare,utilities,clientjar"
  +            description="Configure files prior to compilation">
  +        <mkdir dir="${lsid.build.dir}" />
  +        <!-- Copy the properties file into the build -->
  +        <copy file="${conf.dir}/metacat-lsid.properties"
  +              tofile="${lsid.build.dir}/WEB-INF/classes/metacat-lsid.properties"
  +              overwrite="true">
  +            <filterset refid="configFilters" />
  +        </copy>
  +        <!-- Copy config files into the build -->
  +        <copy todir="${lsid.build.dir}/WEB-INF">
  +            <fileset dir="${webinf.dir}"
  +                     includes="**/*.wsdd" />
  +        </copy>
  +        <!-- Copy the metadata configuration files into the build -->
  +        <mkdir dir="${lsid.build.dir}/WEB-INF/classes/${lsid.classes.dir}" />
  +        <copy todir="${lsid.build.dir}/WEB-INF/classes/${lsid.classes.dir}">
  +            <fileset dir="${conf.dir}"
  +                     includes="**/*.xml" />
  +            <fileset dir="${conf.dir}"
  +                     includes="**/*.xslt" />
  +            <filterset refid="configFilters" />
  +        </copy>
  +        <!-- Copy services files into the build -->
  +        <mkdir dir="${lsid.build.dir}/services" />
  +        <copy todir="${lsid.build.dir}/services">
  +            <fileset dir="${services.dir}" />
  +            <filterset refid="configFilters" />
  +        </copy>
  +    </target>
  +    
  +    <target name="compile-lsid"
  +            depends="prepare-lsid"
  +            description="Compile Java sources">
  +        <mkdir dir="${lsid.build.dir}/WEB-INF/classes" />
  +        <javac srcdir="src/edu/ucsb/nceas/metacat/lsid"
  +               destdir="${lsid.build.dir}/WEB-INF/classes"
  +               debug="${compile.debug}"
  +               deprecation="${compile.deprecation}"
  +               optimize="${compile.optimize}">
  +            <classpath refid="lsid.classpath" />
  +        </javac>
  +    </target>
  +    
  +    <target name="war-lsid"
  +            depends="compile-lsid"
  +            description="Create a war file for the application">
  +        <mkdir dir="${dist.dir}" />
  +        <war destfile="${dist.dir}/${authority.context}.war"
  +             webxml="${webinf.dir}/web.xml">
  +            <fileset dir="${lsid.build.dir}" />
  +            <lib dir="${lsid.lib.dir}">
  +                <patternset refid="lsid.jars"/>
  +            </lib>
  +            <lib dir="${lib.dir}">
  +                <patternset refid="lib.jars"/>
  +            </lib>
  +            <lib dir="${lib.dir}/xalan">
  +                <include name="xalan.jar" />
  +                <include name="xml-apis.jar" />
  +            </lib>
  +            <lib dir="${build.dir}">
  +                <include name="metacat-client.jar" />
  +            </lib>
  +        </war>
  +    </target>
  +    
  +    <target name="deploy-lsid"
  +            depends="war-lsid"
  +            description="Deploy LSID war to servlet container">
  +        <delete dir="${deploy.dir}/${authority.context}" />
  +        <delete file="${deploy.dir}/${authority.context}.war" />
  +        <mkdir dir="${deploy.dir}" />
  +        <copy todir="${deploy.dir}">
  +            <fileset dir="${dist.dir}" />
  +        </copy>
  +    </target>
   </project>
  
  
  
  1.1                  metacat/lib/lsid_conf/mdasdl.xml
  
  Index: mdasdl.xml
  ===================================================================
  <lsid-authority name="SEEK_RDF" xmlns="http://www.ibm.com/LSID/Standard/ASDL">
  	<services>
  		<service name="SEEK_RDF_HTTP">
  			<protocol>http</protocol>
  			<hostname>@LSID_AUTHORITY_HOSTNAME@</hostname>
  			<path>/authority/metadata</path>
  			<port>@LSID_AUTHORITY_PORT@</port>
  		</service>
  		<service name="SEEK_RDF_SOAP">
  			<soap-endpoint>http://@LSID_AUTHORITY_HOSTNAME@:@LSID_AUTHORITY_PORT@/authority/metadata</soap-endpoint>
  		</service>
  	</services>
  	<lsids>
  		<lsid urn="urn:lsid:@METADATA_LABELS@:predicates:*">
  			<meta-data-services>
  				<service-ptr name="SEEK_RDF_SOAP" />
  				<service-ptr name="SEEK_RDF_HTTP" />
  			</meta-data-services>
  		</lsid>	
  		<lsid urn="urn:lsid:@METADATA_LABELS@:types:*">
  			<meta-data-services>
  				<service-ptr name="SEEK_RDF_SOAP" />
  				<service-ptr name="SEEK_RDF_HTTP" />
  			</meta-data-services>
  		</lsid>	
  	</lsids>
  </lsid-authority>
  
  
  
  1.1                  metacat/lib/lsid_conf/metacat-lsid.properties
  
  Index: metacat-lsid.properties
  ===================================================================
  metacatserver=@METACAT_SERVER@
  metadatalabels=@METADATA_LABELS@
  
  
  
  1.1                  metacat/lib/lsid_conf/metacat.xslt
  
  Index: metacat.xslt
  ===================================================================
  <?xml version="1.0" encoding='iso-8859-1' ?>
  <xsl:stylesheet xmlns:xalan="http://xml.apache.org/xalan" 
     				 xmlns:java="http://xml.apache.org/xalan/java"
  				xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  				version='1.0' 
  				xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  				xmlns="urn:lsid:@METADATA_LABELS@:predicates:"
  				xmlns:pred="urn:lsid:i3c.org:predicates:"
  				xmlns:dc="http://purl.org/dc/elements/1.1/"
  				xmlns:eml="eml://ecoinformatics.org/eml-2.0.1"
  				exclude-result-prefixes="java seek">
  				
  				<xsl:template match="/eml:eml">
  
  						<xsl:variable name="metacatServer">@METACAT_SERVER@</xsl:variable>
  						<rdf:RDF>
  							<xsl:apply-templates select="dataset" />				
  		 					
  							<rdf:Description>
  								<xsl:attribute name="rdf:about">
  								  <xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							  </xsl:attribute> 
  							  <xsl:element name="dc:format">
  		 					  	<xsl:attribute name="rdf:resource">
  		 					  	  <xsl:text>urn:lsid:i3c.org:formats:text</xsl:text>
  		 					  	</xsl:attribute>
  		 					  </xsl:element>	
  						</rdf:Description>
  						
  						<rdf:Description>
  								<xsl:attribute name="rdf:about">
  								  <xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							  </xsl:attribute> 
  							  <xsl:element name="pred:storedas">
  		 					  	<xsl:attribute name="rdf:resource">
  								  <xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  		 					  	</xsl:attribute>
  		 					  </xsl:element>
  						</rdf:Description>
  						
  						<rdf:Description>
  								<xsl:attribute name="rdf:about">
  								  <xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							  </xsl:attribute> 
  							  <xsl:element name="rdf:type">
  		 					  	<xsl:attribute name="rdf:resource">
  		 					  	  <xsl:text>urn:lsid:i3c.org:types:content</xsl:text>
  		 					  	</xsl:attribute>
  		 					  </xsl:element>	
  						</rdf:Description>
  
  						<rdf:Description>
  								<xsl:attribute name="rdf:about">
  								  <xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							  </xsl:attribute> 
  		 					<pred:htmlVersion xmlns:pred="urn:lsid:@METADATA_LABELS@:predicates:">
  								<xsl:text>&lt;a href=&quot;</xsl:text>
  								<xsl:value-of select="concat(concat($metacatServer,'?action=read&amp;qformat=knb&amp;docid='), at packageId)"/>
  								<xsl:text>&quot;&gt;</xsl:text>
  								<xsl:value-of select="concat(concat($metacatServer,'?action=read&amp;qformat=knb&amp;docid='), at packageId)"/>
  								<xsl:text>&lt;/a&gt;</xsl:text>
  
  		 					</pred:htmlVersion> 
  
  						</rdf:Description>
  
  						<rdf:Description>
  								<xsl:attribute name="rdf:about">
  								  <xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							  </xsl:attribute> 
  		 					<pred:xmlVersion xmlns:pred="urn:lsid:@METADATA_LABELS@:predicates:">
  								<xsl:text>&lt;a href=&quot;</xsl:text>
  								<xsl:value-of select="concat(concat($metacatServer,'?action=read&amp;qformat=xml&amp;docid='), at packageId)"/>
  								<xsl:text>&quot;&gt;</xsl:text>
  								<xsl:value-of select="concat(concat($metacatServer,'?action=read&amp;qformat=xml&amp;docid='), at packageId)"/>
  								<xsl:text>&lt;/a&gt;</xsl:text>
  		 					</pred:xmlVersion> 
  
  						</rdf:Description>
  						<rdf:Description>
  								<xsl:attribute name="rdf:about">
  								  <xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							  </xsl:attribute> 
  							  <xsl:element name="rdf:type">
  		 					  	<xsl:attribute name="rdf:resource">
  		 					  	  <xsl:text>urn:lsid:i3c.org:types:content</xsl:text>
  		 					  	</xsl:attribute>
  		 					  </xsl:element>	
  						</rdf:Description>
  						
  					 </rdf:RDF>
  				</xsl:template>
  				
  				<xsl:template match="dataset">
  						<rdf:Description>
  							<xsl:attribute name="rdf:about">
  								<xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							</xsl:attribute>
  		 					<pred:title xmlns:pred="http://purl.org/dc/elements/1.1/">
  		 						<xsl:value-of select="title" />
  		 					</pred:title> 
  						</rdf:Description>
  
  						<rdf:Description>
  							<xsl:attribute name="rdf:about">
  								<xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							</xsl:attribute>
  		 					<pred:creator xmlns:pred="urn:lsid:@METADATA_LABELS@:predicates:">
  		 						<xsl:value-of select="creator" />
  		 					</pred:creator> 
  						</rdf:Description>
  
  						<rdf:Description>
  							<xsl:attribute name="rdf:about">
  								<xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							</xsl:attribute>
  		 					<pred:contact xmlns:pred="urn:lsid:@METADATA_LABELS@:predicates:">
  		 						<xsl:value-of select="contact" />
  		 					</pred:contact> 
  						</rdf:Description>
  
  						<xsl:apply-templates select="keywordSet/keyword" />
  						<xsl:apply-templates select="distribution/online/url" />
  						
  					</xsl:template>
  
  					<xsl:template match="keyword">
  						<rdf:Description>
  							<xsl:attribute name="rdf:about">
  								<xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							</xsl:attribute>
  		 					<pred:keyword xmlns:pred="urn:lsid:@METADATA_LABELS@:predicates:">
  								<xsl:value-of select="@keywordType"/>
  								<xsl:text>=</xsl:text>
  		 						<xsl:value-of select="." />
  		 					</pred:keyword> 
  						</rdf:Description>
  					</xsl:template>
  
  					<xsl:template match="url">
  						<rdf:Description>
  							<xsl:attribute name="rdf:about">
  								<xsl:value-of select="java:edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData.getLSID()" />
  							</xsl:attribute>
  		 					<pred:associatedInfo xmlns:pred="urn:lsid:@METADATA_LABELS@:predicates:">
  		 					
  		 						<xsl:choose>
  		 							<xsl:when test="starts-with(., 'ecogrid://')">
  		 								<xsl:value-of select="concat('urn:lsid:@LSID_AUTHORITY_STRING@:',substring-after(.,'ecogrid://knr/'))"/>
  									</xsl:when>
  									<xsl:otherwise>
  										<xsl:text>&lt;a href=&quot;</xsl:text>
  										<xsl:value-of select="."/>
  										<xsl:text>&quot;&gt;</xsl:text>
  										<xsl:value-of select="."/>
  										<xsl:text>&lt;/a&gt;</xsl:text>
  									</xsl:otherwise>
  								</xsl:choose>
  		 					</pred:associatedInfo> 
  						</rdf:Description>
  				</xsl:template>
  </xsl:stylesheet>
  
  
  
  
  1.1                  metacat/lib/lsid_conf/preds.xml
  
  Index: preds.xml
  ===================================================================
  <metadata xmlns="http://www.ibm.com/LSID/Standard/msdl">
  	<lsid uri="urn:lsid:@METADATA_LABELS@:predicates:associatedInfo" location="inline">
  		<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  			<rdf:Description rdf:about="urn:lsid:@METADATA_LABELS@:predicates:associatedInfo">
  				<rdfs:label>Associated Information</rdfs:label>
  			</rdf:Description>
  		</rdf:RDF>
  	</lsid>
  	<lsid uri="urn:lsid:@METADATA_LABELS@:predicates:creator" location="inline">
  		<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  			<rdf:Description rdf:about="urn:lsid:@METADATA_LABELS@:predicates:creator">
  				<rdfs:label>Creator</rdfs:label>
  			</rdf:Description>
  		</rdf:RDF>
  	</lsid>
  	<lsid uri="urn:lsid:@METADATA_LABELS@:predicates:htmlVersion" location="inline">
  		<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  			<rdf:Description rdf:about="urn:lsid:@METADATA_LABELS@:predicates:htmlVersion">
  				<rdfs:label>HTML Version</rdfs:label>
  			</rdf:Description>
  		</rdf:RDF>
  	</lsid>
  	<lsid uri="urn:lsid:@METADATA_LABELS@:predicates:keyword" location="inline">
  		<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  			<rdf:Description rdf:about="urn:lsid:@METADATA_LABELS@:predicates:keyword">
  				<rdfs:label>Keywords</rdfs:label>
  			</rdf:Description>
  		</rdf:RDF>
  	</lsid>
  	<lsid uri="urn:lsid:@METADATA_LABELS@:predicates:xmlVersion" location="inline">
  		<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  			<rdf:Description rdf:about="urn:lsid:@METADATA_LABELS@:predicates:xmlVersion">
  				<rdfs:label>XML Version</rdfs:label>
  			</rdf:Description>
  		</rdf:RDF>
  	</lsid>
  	<lsid uri="urn:lsid:@METADATA_LABELS@:predicates:contact" location="inline">
  		<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  			<rdf:Description rdf:about="urn:lsid:@METADATA_LABELS@:predicates:contact">
  				<rdfs:label>Contact Information</rdfs:label>
  			</rdf:Description>
  		</rdf:RDF>
  	</lsid>
  </metadata>
  
  
  
  1.1                  metacat/lib/lsid_conf/WEB-INF/server-config.wsdd
  
  Index: server-config.wsdd
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
   <globalConfiguration>
    <parameter name="adminPassword" value="admin"/>
    <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
    <parameter name="sendXsiTypes" value="true"/>
    <parameter name="sendMultiRefs" value="true"/>
    <parameter name="sendXMLDeclaration" value="true"/>
    <parameter name="axis.sendMinimizedElements" value="true"/>
    <requestFlow>
     <handler type="java:com.ibm.lsid.server.soap.LSIDURLMapper"/>
     <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
    </requestFlow>
   </globalConfiguration>
   <handler name="LSIDURLMapper" type="java:com.ibm.lsid.server.soap.LSIDURLMapper"/>
   <service name="AdminService" provider="java:MSG">
    <parameter name="allowedMethods" value="AdminService"/>
    <parameter name="enableRemoteAdmin" value="false"/>
    <parameter name="className" value="org.apache.axis.utils.Admin"/>
    <namespace>http://xml.apache.org/axis/wsdd/</namespace>
   </service>
   <service name="AuthorityWebService" provider="java:MSG" style="rpc" use="literal">
    <parameter name="allowedMethods" value="getAvailableServices,notifyForeignAuthority,revokeNotificationForeignAuthority"/>
    <parameter name="className" value="com.ibm.lsid.server.soap.AuthorityWebService"/>
   </service>
   <service name="MetadataWebService" provider="java:MSG" style="rpc" use="literal">
    <parameter name="allowedMethods" value="getMetadata"/>
    <parameter name="className" value="com.ibm.lsid.server.soap.MetadataWebService"/>
   </service>
   <service name="DataWebService" provider="java:MSG" style="rpc" use="literal">
    <parameter name="allowedMethods" value="getData,getDataByRange"/>
    <parameter name="className" value="com.ibm.lsid.server.soap.DataWebService"/>
   </service>
   <service name="AssigningWebService" provider="java:MSG" style="rpc" use="literal">
    <parameter name="allowedMethods" value="assignLSID,assignLSIDFromList,getLSIDPattern,getLSIDPatternFromList,assignLSIDForNewRevision,getAllowedPropertyNames,getAuthoritiesAndNamespaces"/>
    <parameter name="className" value="com.ibm.lsid.server.soap.AssigningWebService"/>
   </service>
   <service name="Version" provider="java:RPC">
    <parameter name="allowedMethods" value="getVersion"/>
    <parameter name="className" value="org.apache.axis.Version"/>
   </service>
   <transport name="http">
    <requestFlow>
     <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
    </requestFlow>
   </transport>
   <transport name="local">
    <responseFlow>
     <handler type="LocalResponder"/>
    </responseFlow>
   </transport>
  </deployment>
  
  
  1.1                  metacat/lib/lsid_conf/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
  <web-app id="WebApp">
  	<display-name>LSID Server Web</display-name>
  	<servlet>
  		<servlet-name>AuthorityServlet</servlet-name>
  		<display-name>AuthorityServlet</display-name>
  		<servlet-class>com.ibm.lsid.server.servlet.AuthorityServlet</servlet-class>
  		<init-param>
  			<param-name>LSID_CLIENT_HOME</param-name>
  			<param-value>/lsid/java/server</param-value>
  		</init-param>
  		<load-on-startup>-1</load-on-startup>
  	</servlet>
  	<servlet>
  		<servlet-name>MetadataServlet</servlet-name>
  		<display-name>MetadataServlet</display-name>
  		<servlet-class>com.ibm.lsid.server.servlet.MetadataServlet</servlet-class>
  		<init-param>
  			<param-name>LSID_CLIENT_HOME</param-name>
  			<param-value>/lsid/java/server</param-value>
  		</init-param>
  		<load-on-startup>-1</load-on-startup>
  	</servlet>
  	<servlet>
  		<servlet-name>DataServlet</servlet-name>
  		<display-name>DataServlet</display-name>
  		<servlet-class>com.ibm.lsid.server.servlet.DataServlet</servlet-class>
  		<init-param>
  			<param-name>LSID_CLIENT_HOME</param-name>
  			<param-value>/lsid/java/server</param-value>
  		</init-param>
  		<load-on-startup>-1</load-on-startup>
  	</servlet>
  	<servlet>
  		<servlet-name>AssigningServlet</servlet-name>
  		<display-name>AssigningServlet</display-name>
  		<servlet-class>com.ibm.lsid.server.servlet.AssigningServlet</servlet-class>
  		<init-param>
  			<param-name>LSID_CLIENT_HOME</param-name>
  			<param-value>/lsid/java/server</param-value>
  		</init-param>
  		<load-on-startup>-1</load-on-startup>
  	</servlet>
  	<servlet-mapping>
  		<servlet-name>AuthorityServlet</servlet-name>
  		<url-pattern>/</url-pattern>
  	</servlet-mapping>
  	<servlet-mapping>
  		<servlet-name>MetadataServlet</servlet-name>
  		<url-pattern>/metadata</url-pattern>
  	</servlet-mapping>
  	<servlet-mapping>
  		<servlet-name>DataServlet</servlet-name>
  		<url-pattern>/data</url-pattern>
  	</servlet-mapping>
  	<servlet-mapping>
  		<servlet-name>AssigningServlet</servlet-name>
  		<url-pattern>/assigning</url-pattern>
  	</servlet-mapping>
  	<servlet-mapping>
  		<servlet-name>MetadataServlet</servlet-name>
  		<url-pattern>/metadata/*</url-pattern>
  	</servlet-mapping>
  	<servlet-mapping>
  		<servlet-name>DataServlet</servlet-name>
  		<url-pattern>/data/*</url-pattern>
  	</servlet-mapping>
  	<servlet-mapping>
  		<servlet-name>DataServlet</servlet-name>
  		<url-pattern>/assigning/*</url-pattern>
  	</servlet-mapping>
  	<welcome-file-list>
  		<welcome-file>index.html</welcome-file>
  		<welcome-file>index.htm</welcome-file>
  		<welcome-file>index.jsp</welcome-file>
  		<welcome-file>default.html</welcome-file>
  		<welcome-file>default.htm</welcome-file>
  		<welcome-file>default.jsp</welcome-file>
  	</welcome-file-list>
  </web-app>
  
  
  
  1.1                  metacat/lib/lsid_conf/services/default-services.xml
  
  Index: default-services.xml
  ===================================================================
  <deployment-descriptor xmlns="http://www.ibm.com/LSID/Standard/rsdl">
  	<component-handlers>
  		<!-- These handlers (along with "class" and "caching") are added by default, we include these as examples -->
  		<component-handler type="asdl" classname="com.ibm.lsid.server.conf.ASDLComponentHandler" />
  		<component-handler type="msdl" classname="com.ibm.lsid.server.conf.MSDLComponentHandler" />
  	</component-handlers>
  	<maps>
  		<map name="all">
  			<pattern auth="*" ns="*" />
  		</map>
  	</maps>
  	<services>
  		<service name="ReallySimpleAssigningService" >
  			<components>
  				<assn type="class">com.ibm.lsid.server.impl.ReallySimpleAssigningService</assn>
  			</components>
  		</service>
  		<service name="CachingProxyResolutionService" >
  			<components>
  				<auth map="all" type="class">com.ibm.lsid.server.impl.CachingProxyAuthority</auth>
  				<meta map="all" type="class">com.ibm.lsid.server.impl.CachingProxyAuthority</meta> 	
  				<data map="all" type="class">com.ibm.lsid.server.impl.CachingProxyAuthority</data>
  			</components>
  		</service>	
  	</services>
  </deployment-descriptor>
  
  
  
  1.1                  metacat/lib/lsid_conf/services/metacat-services.xml
  
  Index: metacat-services.xml
  ===================================================================
   <deployment-descriptor xmlns="http://www.ibm.com/LSID/Standard/rsdl">
                          <maps>
                                  <map name="metacat-main">
                                          <pattern auth="@LSID_AUTHORITY_STRING@" ns="*" />
                                  </map>
  				<map name="metacat-rdf">
  					<pattern auth="@LSID_AUTHORITY_STRING@" ns="predicates" />
  					<pattern auth="@LSID_AUTHORITY_STRING@" ns="types" />
  				</map>
                          </maps>
                          <services>
                                  <service name="METACAT">
                                          <components>
  						<auth map="metacat-rdf" type="asdl" location="java-resource">/edu/ucsb/nceas/metacat/lsid/mdasdl.xml</auth>
  						<meta map="metacat-rdf" type="msdl" location="java-resource">/edu/ucsb/nceas/metacat/lsid/preds.xml</meta>
                                                  <auth map="metacat-main" type="class">edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMain</auth>
                                                  <meta map="metacat-main" type="class">edu.ucsb.nceas.metacat.lsid.LSIDAuthorityMetaData</meta>
                                                  <data map="metacat-main" type="class">edu.ucsb.nceas.metacat.lsid.LSIDAuthorityData</data>
                                          </components>
                                  </service>
                          </services>
                  </deployment-descriptor>
  
  
  
  
  1.1                  metacat/lib/lsid_lib/axis.jar
  
  	<<Binary file>>
  
  
  1.1                  metacat/lib/lsid_lib/commons-discovery.jar
  
  	<<Binary file>>
  
  
  1.1                  metacat/lib/lsid_lib/jaxrpc.jar
  
  	<<Binary file>>
  
  
  1.1                  metacat/lib/lsid_lib/lsid-client-1.1.1.jar
  
  	<<Binary file>>
  
  
  1.1                  metacat/lib/lsid_lib/lsid-server-1.1.1.jar
  
  	<<Binary file>>
  
  
  1.1                  metacat/lib/lsid_lib/saaj.jar
  
  	<<Binary file>>
  
  
  1.1                  metacat/lib/lsid_lib/wsdl4j.jar
  
  	<<Binary file>>
  
  
  1.1                  metacat/src/edu/ucsb/nceas/metacat/lsid/LSIDAuthorityData.java
  
  Index: LSIDAuthorityData.java
  ===================================================================
  /**
   *  '$RCSfile: LSIDAuthorityData.java,v $'
   *  Copyright: 2000-2005 Regents of the University of California and the
   *             National Center for Ecological Analysis and Synthesis
   *
   *   '$Author: jones $'
   *     '$Date: 2005/11/11 20:09:01 $'
   * '$Revision: 1.1 $'
   *
   * 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
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  package edu.ucsb.nceas.metacat;
  package edu.ucsb.nceas.metacat.lsid;
  
  import java.io.InputStream;
  
  import com.ibm.lsid.server.LSIDDataService;
  import com.ibm.lsid.server.LSIDServerException;
  import com.ibm.lsid.server.LSIDServiceConfig;
  import com.ibm.lsid.server.LSIDRequestContext;
  
  public class LSIDAuthorityData implements LSIDDataService {
  
  	private LSIDDataLookup lookup = null;
  
  	public InputStream getData(LSIDRequestContext lsid) throws LSIDServerException {
          System.out.println("Getting data (Metacat): " + lsid.getLsid().toString());
  		if (lookup == null)
  			throw new LSIDServerException(500, "Cannot query database");
  		return lookup.lsidData(lsid.getLsid());
  	}
  
  	public InputStream getDataByRange(LSIDRequestContext lsid, int start, int end) throws LSIDServerException {
  		if (lookup == null)
  			throw new LSIDServerException(500, "Cannot query database");
  		return lookup.lsidData(lsid.getLsid());
  	}
  
  	public void initService(LSIDServiceConfig cf) throws LSIDServerException {
          System.out.println("Starting LSIDAuthorityData (Metacat).");
  		lookup = new LSIDDataLookup();
  	}
  }
  
  
  
  1.1                  metacat/src/edu/ucsb/nceas/metacat/lsid/LSIDAuthorityMain.java
  
  Index: LSIDAuthorityMain.java
  ===================================================================
  /**
   *  '$RCSfile: LSIDAuthorityMain.java,v $'
   *  Copyright: 2000-2005 Regents of the University of California and the
   *             National Center for Ecological Analysis and Synthesis
   *
   *   '$Author: jones $'
   *     '$Date: 2005/11/11 20:09:01 $'
   * '$Revision: 1.1 $'
   *
   * 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
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  package edu.ucsb.nceas.metacat.lsid;
  
  import java.util.regex.Pattern;
  import java.util.regex.Matcher;
  
  import com.ibm.lsid.LSID;
  import com.ibm.lsid.ExpiringResponse;
  import com.ibm.lsid.wsdl.LSIDDataPort;
  import com.ibm.lsid.wsdl.LSIDMetadataPort;
  
  import com.ibm.lsid.wsdl.SOAPLocation;
  import com.ibm.lsid.wsdl.HTTPLocation;
  
  import com.ibm.lsid.server.LSIDServerException;
  import com.ibm.lsid.server.LSIDServiceConfig;
  
  import com.ibm.lsid.server.impl.SimpleAuthority;
  
  public class LSIDAuthorityMain extends SimpleAuthority {
  
  	private LSIDDataLookup lookup = null;
  
  	public void initService(LSIDServiceConfig cf) throws LSIDServerException {
          System.out.println("Starting LSIDAuthorityMain (Metacat).");
  		lookup = new LSIDDataLookup();
  	}
  
  	public ExpiringResponse getKnownURIs() throws LSIDServerException {
  		return null;
  	}
  
  	public LSIDMetadataPort[] getMetadataLocations(LSID lsid, String url) {
  		if (lookup == null)
  			return null;
  
  		int lsType;
  		try {
  			lsType = lookup.lsidType(lsid);
  		}
  		catch (LSIDServerException ex) {
  			ex.printStackTrace();
  			lsType = LSIDDataLookup.UNKNOWN;
  		}
  		if (lsType == LSIDDataLookup.UNKNOWN)
  			return null;
  
  		HostDescriptor hd = new HostDescriptor(url);
  		return new LSIDMetadataPort[] {
  		// thau added http metadata port here
  			new HTTPLocation(
  				hd.host, hd.port,
  				hd.pathPrefix + "/authority/metadata" 
  			),
  		new SOAPLocation(
  				hd.baseURL + "metadata"
  			)
  		};
  	}
  
  	public LSIDDataPort[] getDataLocations(LSID lsid, String url) {
  		if (lookup == null)
  			return null;
  
  		int lsType;
  		try {
  			lsType = lookup.lsidType(lsid);
  		}
  		catch (LSIDServerException ex) {
  			ex.printStackTrace();
  			lsType = LSIDDataLookup.UNKNOWN;
  		}
  		if (lsType == LSIDDataLookup.UNKNOWN)
  			return null;
  		if (lsType == LSIDDataLookup.ABSTRACT)
  			return new LSIDDataPort[0];
  		
  		HostDescriptor hd = new HostDescriptor(url);
  		return new LSIDDataPort[] {
  			new HTTPLocation(
  				hd.host, hd.port,
  				hd.pathPrefix + "/authority/data"
  			),
  			new SOAPLocation(
  				hd.baseURL + "data"
  			)
  		};
  	}
  
  	private static final Pattern HOST_PTN = Pattern.compile(
  		"https?://([^/:]+)(?::(\\d+))?(.*)/authority(.*)"
  	);
  	
  	/* Q&D implementation */
  	private class HostDescriptor {
  		public String host;
  		public int port;
  		public String pathPrefix;
  		public String baseURL;
  		
  		public HostDescriptor(String url) {
  			host = "localhost";
  			port = -1;
  			pathPrefix = "";
  			if (url != null || url.length() > 0) {
  				Matcher m = HOST_PTN.matcher(url);
  				if (m.lookingAt()) {
  					host = m.group(1);
  					if ((m.group(2) != null) && (m.group(2).length() > 0))
  						port = Integer.parseInt(m.group(2));
  					pathPrefix = m.group(3);
  				}
  			}
  			if (port > 0)
  				baseURL = "http://" + host + ":" + port +
  					pathPrefix + "/authority/";
  			else
  				baseURL = "http://" + host + pathPrefix + "/authority/";
  		}
  	}
  }
  
  
  
  1.1                  metacat/src/edu/ucsb/nceas/metacat/lsid/LSIDAuthorityMetaData.java
  
  Index: LSIDAuthorityMetaData.java
  ===================================================================
  /**
   *  '$RCSfile: LSIDAuthorityMetaData.java,v $'
   *  Copyright: 2000-2005 Regents of the University of California and the
   *             National Center for Ecological Analysis and Synthesis
   *
   *   '$Author: jones $'
   *     '$Date: 2005/11/11 20:09:01 $'
   * '$Revision: 1.1 $'
   *
   * 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
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  package edu.ucsb.nceas.metacat.lsid;
  
  import java.io.InputStream;
  import java.io.ByteArrayInputStream;
  
  import com.ibm.lsid.LSID;
  import com.ibm.lsid.MetadataResponse;
  import com.ibm.lsid.MalformedLSIDException;
  
  import com.ibm.lsid.server.LSIDMetadataService;
  import com.ibm.lsid.server.LSIDServerException;
  import com.ibm.lsid.server.LSIDServiceConfig;
  
  import com.ibm.lsid.server.LSIDRequestContext;
  
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.Reader;
  import java.io.StringReader;
  import java.io.InputStreamReader;
  import java.io.BufferedReader;
  
  import javax.xml.transform.Transformer;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.stream.StreamResult;
  import javax.xml.transform.stream.StreamSource;
  
  import java.util.Hashtable;
  
  import edu.ucsb.nceas.metacat.client.*;
  import java.util.ResourceBundle;
  
  public class LSIDAuthorityMetaData implements LSIDMetadataService {
  
  	private LSIDDataLookup lookup = null;
  	private static Hashtable currentLSIDs = new Hashtable();
  
  	public void initService(LSIDServiceConfig cf) throws LSIDServerException {
          System.out.println("Starting LSIDAuthorityMetadata (Metacat).");
  		lookup = new LSIDDataLookup();
  	}
  
  	private static final String RDF_NS =
  		"http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  	private static final String DC_NS = "http://purl.org/dc/elements/1.1/";
  	private static final String I3CP_NS = "urn:lsid:i3c.org:predicates:";
  	private static final String I3C_CONTENT = "urn:lsid:i3c.org:types:content";
  
  	public MetadataResponse getMetadata(
  		LSIDRequestContext req,
  		String[] formats)
  		throws LSIDServerException {
  		LSID lsid = req.getLsid();
  		ByteArrayInputStream theMetadata = doMetadataRequest(lsid);
  		return new MetadataResponse(
  			theMetadata,
  			null,
  			MetadataResponse.RDF_FORMAT);
  	}
  
  	private ByteArrayInputStream doMetadataRequest(LSID lsid)
  		throws LSIDServerException {
  		System.out.println("getting metadata for lsid " + lsid.getLsid());
  		try {
  
  			String styleSheetName = null;
  			styleSheetName = "metacat.xslt";
  			LSIDDataLookup myLookup = new LSIDDataLookup();
  			InputStream content = myLookup.lsidData(lsid);
  			InputStream content2 = myLookup.lsidData(lsid);
  			if (!isEML(content2)) {
  				content = getEML(lsid);
  			}
  			content2.close();
  			setCurrentLSID(lsid);
  			InputStream styleSheet =
  				getClass().getResourceAsStream(styleSheetName);
  			TransformerFactory factory = TransformerFactory.newInstance();
  			Transformer transformer =
  				factory.newTransformer(new StreamSource(styleSheet));
  			ByteArrayOutputStream out = new ByteArrayOutputStream();
  			transformer.transform(
  				new StreamSource(content),
  				new StreamResult(out));
  			content.close();
  			clearState();
  			return new ByteArrayInputStream(out.toByteArray());
  		} catch (Exception e) {
  			throw new LSIDServerException(
  				e,
  				"Error transforming XML for: " + lsid);
  		}
  	}
  
  	private String getStringFromInputStream(InputStream input) {
  		StringBuffer result = new StringBuffer();
  		BufferedReader in = new BufferedReader(new InputStreamReader(input));
  		String line;
  		try {
  			while ((line = in.readLine()) != null) {
  				result.append(line);
  			}
  		} catch (IOException e) {
  			System.out.println("IOexception " + e);
  		}
  
  		return result.toString();
  
  	}
  
  	/**
  	 * figure out is this inputstream is an eml document or not
  		 */
  
  	/* TODO: need a better way to figure out if this is an eml document */
  	private boolean isEML(InputStream input) {
  
  		if (input == null) {
  			return false;
  		}
  
  		int loop = 0;
  		boolean itIsEML = false;
  		String line = "";
  		try {
  			BufferedReader in =
  				new BufferedReader(new InputStreamReader(input));
  			while ((loop < 20) && (line != null) && (!itIsEML)) {
  				line = in.readLine();
  				line = line.toLowerCase();
  				if (line.indexOf("eml:eml") != -1) {
  					itIsEML = true;
  				}
  				loop++;
  			}
  		} catch (IOException e) {
  			System.out.println("ioerror in LSIDAuthorityMetadata: " + e);
  		}
  		return itIsEML;
  	}
  
  	/**
  	 *  this lsid points to a data object - get the
  	     *  metadata objects which refer to this document
  	     */
  
  	private InputStream getEML(LSID theLSID) {
  
  		InputStream response = null;
  
  		// need to find things with this object in any of the elements
  		// using the metacat api
  		// get back dataset/docid and dataset/title
  
  		// create the query
  		String theQuery = getMetaCatQuery(theLSID);
  
  		// get the metacat record
  		Reader metaCatResponse = getMetaCatResponse(theQuery);
  
  		// parse the metadata to get the applicable rdf information
  		response = parseMetaCatResponse(metaCatResponse, theLSID);
  
  		return response;
  
  	}
  
  	/** 
  	 * given an LSID return a metacat query which will return docs mentioning this LSID
  	 */
  
  	private String getMetaCatQuery(LSID lsid) {
          System.out.println("getting Metacat Query for: " + lsid.toString());
  		String ns = lsid.getNamespace();
  		String id = lsid.getObject();
  		String ver = lsid.getRevision();
  		String theName = ns + "." + id + "." + ver;
  
  		String theQuery = null;
  		theQuery =
  			"<?xml version=\"1.0\"?>\n"
  				+ "<pathquery version=\"1.2\">\n"
  				+ "  <querytitle>"
  				+ theName
  				+ " search</querytitle>\n"
  				+ "  <returnfield>dataset/docid</returnfield>\n"
  				+ "  <returnfield>dataset/title</returnfield>\n"
  				+ "  <querygroup operator=\"UNION\">\n"
  				+ "    <queryterm searchmode=\"contains\" casesensitive=\"false\">\n"
  				+ "      <value>"
  				+ theName
  				+ "</value>\n"
  				+ "      <pathexpr>anyfield</pathexpr>\n"
  				+ "    </queryterm>\n"
  				+ "  </querygroup>\n"
  				+ "<pathquery>\n";
  
  		return theQuery;
  
  	}
  
  	/* 
  	 * given a query string, query MetaCat and return the response
  	 */
  	private Reader getMetaCatResponse(String query) {
          System.out.println("Querying the metacat server.");
  		//  get the metacat server from the configuration file
  		//
  		ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
  		String url = rb.getString("metacatserver");
  		Reader r = null;
  		try {
  
  			Metacat m = MetacatFactory.createMetacatConnection(url);
  			r = m.query(new StringReader(query));
  
  		} catch (MetacatInaccessibleException mie) {
  			System.out.println("Metacat Inaccessible:\n" + mie.getMessage());
  		} catch (Exception e) {
  			System.out.println("General exception:\n" + e.getMessage());
  		}
  		return r;
  	}
  
  	/**
  	 * Given a reader which is a metacat response, parse it and return the appropriate rdf
  	 */
  	private InputStream parseMetaCatResponse(Reader reader, LSID theLSID) {
  		InputStream response = null;
          System.out.println("Parsing the metacat response.");
  		// if there's more than one document, then return rdf listing the documents
  		// otherwise get the document and return rdf  based on it
  
  		String contents = getStringFromReader(reader);
  		if (numberDocuments(contents) < 1) {
  			response = noMetaDataResponse(theLSID);
  		} else if (numberDocuments(contents) > 1) {
  			response = metaDataList(contents, theLSID);
  		} else {
  			response = getMetaData(contents, theLSID);
  		}
  		return response;
  	}
  
  	/**
  	 *  There's no metadata for this document 
  	*/
  
  	private ByteArrayInputStream noMetaDataResponse(LSID theLSID) {
  		ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
  		String metadataLabels = rb.getString("metadatalabels");
  
  		String result =
  			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  				+ "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" \n"
  				+ "	xmlns:dc=\"http://purl.org/dc/elements/1.1/\" \n"
  				+ "	xmlns:pred=\"urn:lsid:i3c.org:predicates:\" xmlns=\"urn:lsid:" 
  				+ metadataLabels + ":predicates:\"> \n"
  				+ "<rdf:Description rdf:about=\""
  				+ theLSID.getLsid()
  				+ "\"> \n"
  				+ "	<pred:title xmlns:pred=\"http://purl.org/dc/elements/1.1/\">There is no metadata for this LSID.</pred:title>\n"
  				+ "</rdf:Description>\n"
  				+ "</rdf:RDF>\n";
  			
  
  		return new ByteArrayInputStream(result.getBytes());
  	}
  
  	/**
  	 *  There's more than one metdata document
  	     */
  
  	private ByteArrayInputStream metaDataList(String contents, LSID theLSID) {
  		ResourceBundle rb = ResourceBundle.getBundle("metacat");
  		String metadataLabels = rb.getString("metadatalabels");
  
  		String result =
  			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  				+ "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" \n"
  				+ "	xmlns:dc=\"http://purl.org/dc/elements/1.1/\" \n"
  				+ "	xmlns:pred=\"urn:lsid:i3c.org:predicates:\" xmlns=\"urn:lsid:"
  				+ metadataLabels + ":predicates:\"> \n"
  				+ "<rdf:Description rdf:about=\""
  				+ theLSID.getLsid()
  				+ "\"> \n"
  				+ "	<pred:title xmlns:pred=\"http://purl.org/dc/elements/1.1/\">There is more than one metadata document for this LSID - which confuses me right now.  Try again soon and I'll be less confused.</pred:title>\n"
  				+ "</rdf:Description>\n"
  				+ "</rdf:RDF>\n";
  
  		return new ByteArrayInputStream(result.getBytes());
  	}
  
  	/**
  	 *  There's just one metadata document 
  	     */
  
  	private ByteArrayInputStream getMetaData(String contents, LSID theLSID) {
  		String paramString = "<param name=\"dataset/title\">";
  		ByteArrayInputStream result = null;
  
  		if (contents.indexOf(paramString) == -1) {
  			return noMetaDataResponse(theLSID);
  		} else {
  			String parts[] = contents.split(paramString);
  			String parts2[] = parts[1].split("</param>");
  			try {
  				LSID newLSID = new LSID(parts2[0]);
  				result = doMetadataRequest(newLSID);
  
  			} catch (MalformedLSIDException e) {
  				System.out.println("problem generating LSID: " + e);
  				e.printStackTrace();
  			} catch (LSIDServerException e) {
  				System.out.println("problem generating LSID: " + e);
  				e.printStackTrace();
  			}
  		}
  		return result;
  	}
  
  	/**
  	 *  Find out how many contents are in this metacat response
  	 *  I'm just using string stuff for this - sort of lame, but does the trick
  	 *  more cool would be to use xml stuff
  	 */
  	private int numberDocuments(String contents) {
  
  		String[] docSplit = contents.split("<document>");
  		return (docSplit.length - 1);
  	}
  
  	/**
  	 * Given a reader, return a string
  	 */
  	private String getStringFromReader(Reader reader) {
  		StringBuffer response = new StringBuffer();
  
  		try {
  			BufferedReader bufReader = new BufferedReader(reader);
  
  			String line = null;
  			while ((line = bufReader.readLine()) != null) {
  				response.append(line);
  			}
  			bufReader.close();
  
  		} catch (IOException e) {
  			System.out.println("error getting string from reader " + e);
  		}
  		return response.toString();
  	}
  
  	/**
  	 * set the LSID for the current thread
  	 */
  	static void setCurrentLSID(LSID lsid) {
  		currentLSIDs.put(Thread.currentThread(), lsid);
  	}
  
  	static void clearState() {
  		currentLSIDs.remove(Thread.currentThread());
  	}
  
  	/**
  	 * get the current LSID for the given thread, for use in XSLT so return a string
  	 */
  	//	public static String getLSID() throws MalformedLSIDException {
  	//		return ((LSID)currentLSIDs.get(Thread.currentThread())).toString();
  	//	}
  
  	public static String getLSID(
  		org.apache.xalan.extensions.XSLProcessorContext foo,
  		org.apache.xalan.templates.ElemExtensionCall bar)
  		throws MalformedLSIDException {
  		return ((LSID) currentLSIDs.get(Thread.currentThread())).toString();
  	}
  
  	public static String getLSID() throws MalformedLSIDException {
  		return ((LSID) currentLSIDs.get(Thread.currentThread())).toString();
  	}
  }
  
  
  
  1.1                  metacat/src/edu/ucsb/nceas/metacat/lsid/LSIDDataLookup.java
  
  Index: LSIDDataLookup.java
  ===================================================================
  /**
   *  '$RCSfile: LSIDDataLookup.java,v $'
   *  Copyright: 2000-2005 Regents of the University of California and the
   *             National Center for Ecological Analysis and Synthesis
   *
   *   '$Author: jones $'
   *     '$Date: 2005/11/11 20:09:01 $'
   * '$Revision: 1.1 $'
   *
   * 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
   * the Free Software Foundation; either version 2 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  package edu.ucsb.nceas.metacat.lsid;
  
  import java.io.*;
  import java.net.*;
  
  //import java.sql.Connection;
  import java.util.ResourceBundle;
  
  import com.ibm.lsid.LSID;
  import com.ibm.lsid.server.LSIDServerException;
  
  public class LSIDDataLookup {
  
  //	private static Connection lsidLookup = null;
  
  	public static final int UNKNOWN = 1;
  	public static final int ABSTRACT = 2;
  	public static final int CONCRETE = 4;
  
  
  	public LSIDDataLookup() throws LSIDServerException {
          System.out.println("Creating LSIDDataLookup (Metacat).");
    	}
  
  
  	public int lsidType(LSID lsid) throws LSIDServerException {
  
  		int result = CONCRETE;
  		return result;
  	}
  
  	public InputStream lsidData(LSID lsid) throws LSIDServerException {
  		String ns = lsid.getNamespace();
  		String id = lsid.getObject();
  		String ver = lsid.getRevision();
  		InputStream docStream = null;
  		
  
  		// example metacat query
  		// http://metacat.nceas.ucsb.edu/knb/metacat?action=read&qformat=xml&docid=knb-lter-gce.109.6
  		//
  		
      ResourceBundle rb = ResourceBundle.getBundle("metacat-lsid");
      String theServer = rb.getString("metacatserver");
  		System.out.println("the server is " + theServer);
  
  		String url = theServer + "?action=read&qformat=xml&docid=";
  		url = url + ns + "." + id + "." + ver;
  		try {
  			URL theDoc = new URL(url);
  			docStream  = theDoc.openStream();
  		} catch (MalformedURLException mue) {
           		System.out.println("MalformedURLException in LSIDDataLookup: " + mue);
           		mue.printStackTrace();
     		} catch (IOException ioe) {
           		System.out.println("IOException in LSIDDataLookup: " + ioe);
           		ioe.printStackTrace();
  		}
  
  
  		return docStream;
  	}
  
  }
  
  
  


More information about the Metacat-cvs mailing list