Project

General

Profile

Download (2.63 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.remote.view.oaipmh;
2

    
3
import java.io.IOException;
4
import java.io.StringReader;
5
import java.util.Map;
6

    
7
import javax.xml.parsers.DocumentBuilder;
8
import javax.xml.parsers.DocumentBuilderFactory;
9
import javax.xml.parsers.ParserConfigurationException;
10

    
11
import org.joda.time.DateTime;
12
import org.w3c.dom.Document;
13
import org.w3c.dom.Element;
14
import org.xml.sax.InputSource;
15
import org.xml.sax.SAXException;
16

    
17

    
18
import eu.etaxonomy.cdm.remote.dto.oaipmh.DeletedRecord;
19
import eu.etaxonomy.cdm.remote.dto.oaipmh.Description;
20
import eu.etaxonomy.cdm.remote.dto.oaipmh.Granularity;
21
import eu.etaxonomy.cdm.remote.dto.oaipmh.Identify;
22
import eu.etaxonomy.cdm.remote.dto.oaipmh.OAIPMH;
23
import eu.etaxonomy.cdm.remote.dto.oaipmh.Verb;
24
import eu.etaxonomy.cdm.remote.view.OaiPmhResponseView;
25

    
26
public class IdentifyView extends OaiPmhResponseView {
27

    
28
	@Override
29
    protected void constructResponse(OAIPMH oaiPmh,Map<String,Object> model) {
30
    	oaiPmh.getRequest().setVerb(Verb.IDENTIFY);
31
    	oaiPmh.getRequest().setValue((String)model.get("request"));
32
        Identify identify = new Identify();
33
        identify.setRepositoryName((String)model.get("repositoryName"));
34
        identify.setBaseURL((String)model.get("baseURL"));
35
        identify.setProtocolVersion((String)model.get("protocolVersion"));
36
        identify.setDeletedRecord((DeletedRecord) model.get("deletedRecord"));
37
    	identify.setGranularity((Granularity) model.get("granularity"));
38
    	identify.setEarliestDatestamp((DateTime) model.get("earliestDatestamp"));
39
    	identify.getAdminEmail().add((String) model.get("adminEmail"));
40
    	if(model.get("description") != null){
41
    		Description description = new Description();
42
    		InputSource inputSource = new InputSource(new StringReader((String)model.get("description")));
43
    		DocumentBuilderFactory documentBuilderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
44
    		documentBuilderFactory.setNamespaceAware(false);
45
    		Document document = null;
46
    		DocumentBuilder documentBuilder;
47
			try {
48
				documentBuilder = documentBuilderFactory.newDocumentBuilder();
49
				document = documentBuilder.parse(inputSource);
50
	    		Element domElem = (Element)document.getDocumentElement();
51

    
52
	    		description.setAny(domElem);
53
			} catch (ParserConfigurationException e) {
54
				// TODO Auto-generated catch block
55
				e.printStackTrace();
56
			} catch (SAXException e) {
57
				// TODO Auto-generated catch block
58
				e.printStackTrace();
59
			} catch (IOException e) {
60
				// TODO Auto-generated catch block
61
				e.printStackTrace();
62
			}
63
    		
64
    	    identify.getDescription().add(description);
65
    	}
66
    
67
        oaiPmh.setIdentify(identify);
68
    }
69
}
(3-3/7)