From: <yo...@us...> - 2010-04-06 20:37:53
|
Revision: 678 http://treebase.svn.sourceforge.net/treebase/?rev=678&view=rev Author: youjun Date: 2010-04-06 20:37:41 +0000 (Tue, 06 Apr 2010) Log Message: ----------- modify oai-pmh-data-provider code to fit in treebase Modified Paths: -------------- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/OAIPMHController.java trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/IdentifyUtil.java trunk/treebase-web/src/main/webapp/WEB-INF/identify.properties trunk/treebase-web/src/main/webapp/WEB-INF/treebase-servlet.xml Added Paths: ----------- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/GetRecord.vm trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/Identify.vm trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListMetadataFormats.vm trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListRecords.vm trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListSets.vm trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/error.vm trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/head.vm trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/oai_dc_ListIdentifiers.vm trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/oai_dc_record.vm Removed Paths: ------------- trunk/treebase-web/src/main/webapp/WEB-INF/mvFiles/ Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/OAIPMHController.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/OAIPMHController.java 2010-04-06 01:55:28 UTC (rev 677) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/controllers/OAIPMHController.java 2010-04-06 20:37:41 UTC (rev 678) @@ -24,6 +24,7 @@ import org.cipres.treebase.domain.study.Submission; import org.cipres.treebase.domain.study.SubmissionService; import org.cipres.treebase.domain.study.StudyService; + /** * OAIPMHController.java * @@ -231,16 +232,16 @@ List<Person> authors=citation.getAuthors(); - map.put("title", citation.getTitle()); + map.put("title", IdentifyUtil.escape4XML(citation.getTitle())); map.put("creator", authors); - map.put("subject", citation.getKeywords()); + map.put("subject", IdentifyUtil.escape4XML(citation.getKeywords())); if(study.getName()!=null&study.getNotes()!=null) - map.put("description", study.getName()+" "+study.getNotes()); + map.put("description", IdentifyUtil.escape4XML(study.getName()+" "+study.getNotes())); else if(study.getNotes()==null) - map.put("description",study.getName()); + map.put("description",IdentifyUtil.escape4XML(study.getName())); else - map.put("description",study.getNotes()); - map.put("publisher", publisher); + map.put("description",IdentifyUtil.escape4XML(study.getNotes())); + map.put("publisher", IdentifyUtil.escape4XML(publisher)); map.put("date", "published on "+citation.getPublishYear()); map.put("identifier", "TreeBASE.org/study/TB2:s"+study.getId()); map.put("datestamp", study.getReleaseDate()); Modified: trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/IdentifyUtil.java =================================================================== --- trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/IdentifyUtil.java 2010-04-06 01:55:28 UTC (rev 677) +++ trunk/treebase-web/src/main/java/org/cipres/treebase/web/util/IdentifyUtil.java 2010-04-06 20:37:41 UTC (rev 678) @@ -1,7 +1,9 @@ package org.cipres.treebase.web.util; +import java.text.CharacterIterator; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.text.StringCharacterIterator; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; @@ -48,4 +50,35 @@ cal.setTimeInMillis(utcMiliseconds); return new Date(utcMiliseconds + cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)); } + + public static String escape4XML(String aText){ + final StringBuilder result = new StringBuilder(); + final StringCharacterIterator iterator = new StringCharacterIterator(aText); + char character = iterator.current(); + while (character != CharacterIterator.DONE ){ + if (character == '<') { + result.append("<"); + } + else if (character == '>') { + result.append(">"); + } + else if (character == '\"') { + result.append("""); + } + else if (character == '\'') { + result.append("'"); + } + else if (character == '&') { + result.append("&"); + } + else { + //the char is not a special one + //add it to the result as is + result.append(character); + } + character = iterator.next(); + } + return result.toString(); + } + } Modified: trunk/treebase-web/src/main/webapp/WEB-INF/identify.properties =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/identify.properties 2010-04-06 01:55:28 UTC (rev 677) +++ trunk/treebase-web/src/main/webapp/WEB-INF/identify.properties 2010-04-06 20:37:41 UTC (rev 678) @@ -1,4 +1,4 @@ -identify.baseURL=www.***.***:port/top +identify.baseURL=www.treebase.org/treebase-web/top/oai identify.repositoryName=TreeBASE repository identify.protocolVersion=2.0 identify.adminEmail=you...@ya... Modified: trunk/treebase-web/src/main/webapp/WEB-INF/treebase-servlet.xml =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/treebase-servlet.xml 2010-04-06 01:55:28 UTC (rev 677) +++ trunk/treebase-web/src/main/webapp/WEB-INF/treebase-servlet.xml 2010-04-06 20:37:41 UTC (rev 678) @@ -13,11 +13,9 @@ <!-- velocity configure --> <!-- ========================================================== --> - <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> - <property name="resourceLoaderPath"> - <value>WEB-INF/vmFiles/</value> - </property> - </bean> + <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer"> + <property name="resourceLoaderPath" value="/WEB-INF/vmFiles/" /> + </bean> <!-- ========================================================== --> <!-- LIST OF CONTROLLERS FOR WEB-TIER --> @@ -860,14 +858,11 @@ <!-- ========================================================== --> <!-- Spring View Resolvers for JSPs and .vm files --> <!-- ========================================================== --> - <!-- + <bean id="chainableVelocityViewResolver" class="org.cipres.treebase.web.viewresolver.ChainableVelocityViewResolver"> <property name="chainableResolver"> - <bean class="org.springframework.web.servlet.view.velocity. VelocityViewResolver"> - <property name="order" value="1"></property> - <property name="suffix"> - <value>.vm</value> - </property> + <bean class="org.springframework.web.servlet.view.velocity.VelocityViewResolver"> + <property name="suffix" value=".vm"/> <property name="exposeRequestAttributes"> <value>true</value> </property> @@ -876,8 +871,7 @@ </property> <property name="contentType" value="application/xml;charset=UTF-8" /> </bean> - </property> - <property name="order"><value>1</value></property> + </property> <property name="views"> <list> <value>error</value> @@ -891,7 +885,7 @@ </property> </bean> - --> + <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="requestContextAttribute" value="rc"/> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> Added: trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/GetRecord.vm =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/GetRecord.vm (rev 0) +++ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/GetRecord.vm 2010-04-06 20:37:41 UTC (rev 678) @@ -0,0 +1,7 @@ +#parse("head.vm") +<GetRecord> +#if($!requestParams.metadataPrefix=="oai_dc") +#parse("oai_dc_record.vm") +#end +</GetRecord> +</OAI-PMH> Added: trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/Identify.vm =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/Identify.vm (rev 0) +++ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/Identify.vm 2010-04-06 20:37:41 UTC (rev 678) @@ -0,0 +1,25 @@ +#parse("head.vm") + <Identify> + <repositoryName>${identify.repositoryName}</repositoryName> + <baseURL>${identify.baseURL}</baseURL> + <protocolVersion>${identify.protocolVersion}</protocolVersion> + <adminEmail>${identify.adminEmail}</adminEmail> + <earliestDatestamp>${identify.earliestDatestamp}</earliestDatestamp> + <deletedRecord>${identify.deletedRecord}</deletedRecord> + <granularity>${identify.granularity}</granularity> + + <description> + <oai-identifier + xmlns="http://www.openarchives.org/OAI/2.0/oai-identifier" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation= + "http://www.openarchives.org/OAI/2.0/oai-identifier + http://www.openarchives.org/OAI/2.0/oai-identifier.xsd"> + <scheme>oai</scheme> + <repositoryIdentifier>${identify.repositoryIdentifier}</repositoryIdentifier> + <delimiter>${identify.identifierDelimiter}</delimiter> + <sampleIdentifier>${identify.sampleIdentifier}</sampleIdentifier> + </oai-identifier> + </description> + </Identify> +</OAI-PMH> Added: trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListMetadataFormats.vm =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListMetadataFormats.vm (rev 0) +++ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListMetadataFormats.vm 2010-04-06 20:37:41 UTC (rev 678) @@ -0,0 +1,19 @@ +#parse("head.vm") + <ListMetadataFormats> + <metadataFormat> + <metadataPrefix>oai_dc</metadataPrefix> + <schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd + </schema> + <metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/ + </metadataNamespace> + </metadataFormat> + + <metadataFormat> + <metadataPrefix>dryad</metadataPrefix> + <schema>http://ils.unc.edu/mrc/dryad/version1_0/dryad_1_0.xsd</schema> + <metadataNamespace>http://ils.unc.edu/mrc/dryad/ + </metadataNamespace> + </metadataFormat> + + </ListMetadataFormats> +</OAI-PMH> Added: trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListRecords.vm =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListRecords.vm (rev 0) +++ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListRecords.vm 2010-04-06 20:37:41 UTC (rev 678) @@ -0,0 +1,9 @@ +#parse("head.vm") +<ListRecords> +#if($!requestParams.metadataPrefix=="oai_dc") +#foreach($record in $recordList) +#parse("oai_dc_record.vm") +#end +#end +</ListRecords> +</OAI-PMH> Added: trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListSets.vm =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListSets.vm (rev 0) +++ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/ListSets.vm 2010-04-06 20:37:41 UTC (rev 678) @@ -0,0 +1,3 @@ +#parse("head.vm") + <error code="noSetHierarchy">This repository does not support sets</error> +</OAI-PMH> Added: trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/error.vm =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/error.vm (rev 0) +++ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/error.vm 2010-04-06 20:37:41 UTC (rev 678) @@ -0,0 +1,3 @@ +#parse("head.vm") +<error code="$!error_code">$!error</error> +</OAI-PMH> Added: trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/head.vm =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/head.vm (rev 0) +++ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/head.vm 2010-04-06 20:37:41 UTC (rev 678) @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ + http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"> +<responseDate>${identify.getResponseDate()}</responseDate> +<request #if($!requestParams.verb)verb="$!requestParams.verb" #end +#if($!requestParams.identifier)identifier="$!requestParams.identifier" #end +#if($!requestParams.metadataPrefix)metadataPrefix="$!requestParams.metadataPrefix" #end +#if($!requestParams.from)from="$!requestParams.from" #end +#if($!requestParams.until)until="$!requestParams.until" #end +#if($!requestParams.resumptionToken)resumptionToken="$!requestParams.resumptionToken" #end +#if($!requestParams.set)set="$!requestParams.set" #end> +$!identify.BaseURL</request> Added: trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/oai_dc_ListIdentifiers.vm =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/oai_dc_ListIdentifiers.vm (rev 0) +++ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/oai_dc_ListIdentifiers.vm 2010-04-06 20:37:41 UTC (rev 678) @@ -0,0 +1,10 @@ +#parse("head.vm") +<ListIdentifiers> +#foreach ( $record in $recordList) +<header> +<identifier>${record.identifier}</identifier> +<datestamp>$!record.datestamp</datestamp> +</header> +#end +</ListIdentifiers> +</OAI-PMH> Added: trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/oai_dc_record.vm =================================================================== --- trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/oai_dc_record.vm (rev 0) +++ trunk/treebase-web/src/main/webapp/WEB-INF/vmFiles/oai_dc_record.vm 2010-04-06 20:37:41 UTC (rev 678) @@ -0,0 +1,64 @@ +<record> +<header> +<identifier>${record.identifier}</identifier> +<datestamp>$!record.datestamp</datestamp> +</header> +<metadata> +<oai_dc:dc + xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ + http://www.openarchives.org/OAI/2.0/oai_dc.xsd"> +#if($record.title) +<dc:title>${record.title}</dc:title> +#end +#if($record.creator) +#foreach ($person in $record.creator) +<dc:creator>${person.lastName}, ${person.firstName}</dc:creator> +#end +#end +#if($record.subject) +<dc:subject>${record.subject}</dc:subject> +#end +#if($record.description) +<dc:description>${record.description}</dc:description> +#end +#if($record.publisher) +<dc:publisher>${record.publisher}</dc:publisher> +#end +#if($record.contributor) +<dc:contributor>${record.contributor}</dc:contributor> +#end +#if($record.date) +<dc:date>${record.date}</dc:date> +#end +#if($record.type) +<dc:type>${record.type}</dc:type> +#end +#if($record.format) +<dc:format>${record.format}</dc:format> +#end + +#if($record.identifier) +<dc:identifier>${record.identifier}</dc:identifier> +#end + +#if($record.source) +<dc:source>{record.source}</dc:source> +#end +#if($record.language) +<dc:language>${record.language}</dc:language> +#end +#if($record.relation) +<dc:relation>${record.relation}</dc:relation> +#end +#if($record.coverage) +<dc:coverage>${record.coverage}</dc:coverage> +#end +#if($record.rights) +<dc:rights>${record.rights}</dc:rights> +#end +</oai_dc:dc> +</metadata> +</record> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |