Tematres is a software for generating controlled vocabulary, which I am 
trying to use as a controlled vocabulary in Dspace version 6.3.
The idea is to use it as a web service, I used SHERPARoMEOJournalTitle as 
an example to implement my class that I called of TematresProtocol.java 
<https://github.com/bdpi/bdpi-dspace/commit/0e17b0edf1c560e1824b93fd935b3d82f91e6b6b#diff-044b725d80898f467d4eae1c96a6426d>
 in 
DSpaceSource/dspace-api/src/main/java/org/dspace/content/authority.

1- Then compiled via the maven command:
                 mvn -U package

2- Later, I deployed with ant:
     cd DSpaceSource/dspace/target/dspace-installer
     ant fresh_install

3- To make the service effective, I configured dspace.cfg as explained in  
https://wiki.lyrasis.org/display/DSPACE/Authority+Control+of+Metadata+Values#AuthorityControlofMetadataValues-AddingChoiceAuthorityPlugin:

#####  Authority Control Settings  #####
plugin.named.org.dspace.content.authority.ChoiceAuthority = \
 org.dspace.content.authority.SampleAuthority = Sample, \
 org.dspace.content.authority.SHERPARoMEOPublisher = SRPublisher, \
 org.dspace.content.authority.SHERPARoMEOJournalTitle = SRJournalTitle, \
 org.dspace.content.authority.TematresSponsorship = TematresSponsorship, \
 org.dspace.content.authority.SolrAuthority = SolrAuthorAuthority
 
tematres.url = https://tesaurosjuventude.mdh.gov.br/vocab/services.php

 choices.plugin.dc.title.alternative = TematresSponsorship
 choices.presentation.dc.title.alternative = lookup
 authority.controlled.dc.title.alternative = true


4- After restarting tomcat, and trying to perform a submission, dspace 
throws the error below:
javax.servlet.ServletException: org.apache.jasper.JasperException: 
org.dspace.core.PluginInstantiationException: Cannot load plugin 
class:  
java.lang.ClassNotFoundException:org.dspace.content.authority.TematresSponsorship

Has anyone done something similar? do you know how you could solve this 
problem?

To make it easier I am attaching the class TematresProtocol.java 
<https://github.com/bdpi/bdpi-dspace/commit/0e17b0edf1c560e1824b93fd935b3d82f91e6b6b#diff-044b725d80898f467d4eae1c96a6426d>
.

I also checked and TematresProtocol.class is in the directory lib at 
dspace-api-6.3.jar and is included.


 


-- 
All messages to this mailing list should adhere to the DuraSpace Code of 
Conduct: https://duraspace.org/about/policies/code-of-conduct/
--- 
You received this message because you are subscribed to the Google Groups 
"DSpace Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dspace-community/94eeac11-2925-4fc3-891c-20a30f6a620bn%40googlegroups.com.
package org.dspace.content.authority;

import java.io.IOException;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.apache.log4j.Logger;
import org.dspace.content.Collection;
import org.dspace.core.ConfigurationManager;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

public abstract class TematresProtocol implements ChoiceAuthority {

	private static Logger log = Logger.getLogger(TematresProtocol.class);
	// contact URL from configuration
	private static String url = null;

	@SuppressWarnings("deprecation")
	public TematresProtocol() {
		if (url == null) {
			url = ConfigurationManager.getProperty("tematres.url");
			// sanity check
			if (url == null) {
				throw new IllegalStateException("Missing DSpace configuration keys for Tematres Query");
			}
		}
	}

	// this implements the specific Tematres API args and XML tag naming
	// public abstract Choices getMatches(String text, Collection collection, int start,
	// int limit, String locale);
	public abstract Choices getMatches(String text, Collection collection, int start, int limit, String locale);

	public Choices getBestMatch(String field, String text, Collection collection, String locale) {
		return getMatches(field, text, collection, 0, 2, locale);
	}

	// XXX FIXME just punt, returning value, never got around to
	// implementing a reverse query.
	public String getLabel(String field, String key, String locale) {
		return key;
	}//end getLabel
	
	// NOTE - ignore limit and start for now
    protected Choices query(String result, String label, String authority,
    		List<BasicNameValuePair> args, int start, int limit)
    {
        HttpClient hc = new DefaultHttpClient();
        String srUrl = url + "?" + URLEncodedUtils.format(args, "UTF8");
        HttpGet get = new HttpGet(srUrl);
		log.debug("Trying Tematres Query, URL="+srUrl);

        try
        {
        	HttpResponse response = hc.execute(get);
            if (response.getStatusLine().getStatusCode() == 200)
            {
                SAXParserFactory spf = SAXParserFactory.newInstance();
                SAXParser sp = spf.newSAXParser();
                XMLReader xr = sp.getXMLReader();
                TematresHandler handler = new TematresHandler(result, label, authority);

                // XXX FIXME: should turn off validation here explicitly, but
                //  it seems to be off by default.
                xr.setFeature("http://xml.org/sax/features/namespaces";, true);
                xr.setContentHandler(handler);
                xr.setErrorHandler(handler);
                xr.parse(new InputSource(response.getEntity().getContent()));
               int confidence;

                if (handler.total == 0)
                {
                    confidence = Choices.CF_NOTFOUND;
                }
                else if (handler.total == 1)
                {
                    confidence = Choices.CF_UNCERTAIN;
                }
                else
                {
                    confidence = Choices.CF_AMBIGUOUS;
                }
                return new Choices(handler.result, start, handler.total, confidence, false);
            }
        }
        catch (IOException e)
        {
            log.error("Tematres query failed: ", e);
            return null;
        }
        
        catch (ParserConfigurationException  e)
        {
            log.warn("Failed parsing Tematres result: ", e);
            return null;
        }
        catch (SAXException  e)
        {
            log.warn("Failed parsing Tematres result: ", e);
            return null;
        }
        finally
        {
            get.releaseConnection();
        }
        return null;
    }
	
    // SAX handler to grab Tematres (and eventually other details) from result
    private static class TematresHandler extends DefaultHandler
    {
        private Choice result[] = null;
        int rindex = 0; // result index
        int total = 0;

        // name of element containing a result, e.g. <term>
        private String resultElement = null;

        // name of element containing the label e.g. <string>
        private String labelElement = null;

        // name of element containing the authority value e.g. <term_id>
        private String authorityElement = null;

        protected String textValue = null;

        public TematresHandler(String result, String label, String authority)
        {
            super();
            resultElement = result;
            labelElement = label;
            authorityElement = authority;            
        }

        // NOTE:  text value MAY be presented in multiple calls, even if
        // it all one word, so be ready to splice it together.
        // BEWARE:  subclass's startElement method should call super()
        // to null out 'value'.  (Don't you miss the method combination
        // options of a real object system like CLOS?)
        public void characters(char[] ch, int start, int length)
            throws SAXException
        {
            String newValue = new String(ch, start, length);

            if (newValue.length() > 0)
            {
                if (textValue == null)
                {
                    textValue = newValue;
                }
                else
                {
                    textValue += newValue;
                }
            }
        }

        // if this was the FIRST "numhits" element, it's size of results:
        public void endElement(String namespaceURI, String localName,
                                 String qName)
            throws SAXException
        {
        	if (localName.equals("cant_result"))
            {
                String stotal = textValue.trim();

                if (stotal.length() > 0)
                {
                    total = Integer.parseInt(stotal);
					result = new Choice[total];
                    if (total > 0)
                    {
                        result[0] = new Choice();
                        log.debug("Got "+total+" records in results.");
                    }
                }        		
            }
            else if (localName.equals(resultElement))
            {
                // after start of result element, get next hit ready
                if (++rindex < result.length)
                {
				    result[rindex] = new Choice();
                }
            }
            else if (localName.equals(labelElement) && textValue != null)
            {
				// plug in label value
                result[rindex].value = textValue.trim();
                result[rindex].label = result[rindex].value; 
            }
            else if (authorityElement != null && localName.equals(authorityElement) && textValue != null)
            {				
                // plug in authority value
                result[rindex].authority = textValue.trim();				
            }
        }

        // subclass overriding this MUST call it with super()
        public void startElement(String namespaceURI, String localName,
                                 String qName, Attributes atts)
            throws SAXException
        {
            textValue = null;
        }

        public void error(SAXParseException exception)
            throws SAXException
        {
            throw new SAXException(exception);
        }

        public void fatalError(SAXParseException exception)
            throws SAXException
        {
            throw new SAXException(exception);
        }
    }//end class
	
	
	

}

Reply via email to