source: FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/EndpointDescriptionWriter.java @ 5477

Last change on this file since 5477 was 5477, checked in by margaretha@ids-mannheim.de, 10 years ago

Added endpoint description,
updated SimpleResourceInfoInventory? according to the new format.

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1package eu.clarin.sru.server.fcs;
2
3import java.util.List;
4
5import javax.xml.stream.XMLStreamException;
6import javax.xml.stream.XMLStreamWriter;
7
8public class EndpointDescriptionWriter {
9               
10        public static final String NAMESPACE = "http://clarin.eu/fcs/endpoint-description";
11        public static final String PREFIX = "ed";
12        public static final int VERSION = 1;
13               
14        public static void writeEndpointDescription(XMLStreamWriter writer, 
15                        List<String> capabilities, List<DataView> supportedDataViews, 
16                        List<ResourceInfo> resourceInfoList) 
17                        throws XMLStreamException{
18               
19                if (writer == null) {
20            throw new NullPointerException("writer == null");
21        }
22               
23        writer.writeStartElement(PREFIX, "EndpointDescription", NAMESPACE);
24        writer.writeNamespace(PREFIX, NAMESPACE);
25        writer.writeAttribute("version", String.valueOf(VERSION));
26        writeCapabilities(writer,capabilities);
27        writeSupportedDataViews(writer,supportedDataViews);
28        ResourceInfoWriter.writeFullResourceInfo(writer,PREFIX, resourceInfoList);
29        writer.writeEndElement();
30        }
31       
32        private static void writeCapabilities(XMLStreamWriter writer, 
33                        List<String> capabilities) throws XMLStreamException{
34               
35                if (writer == null) {
36            throw new NullPointerException("writer == null");
37        }
38               
39        writer.writeStartElement(PREFIX, "Capabilities", NAMESPACE);
40               
41                for (String c : capabilities){
42                writer.writeStartElement(PREFIX, "Capability", NAMESPACE);
43                writer.writeCharacters(c);
44                    writer.writeEndElement();
45                }
46                writer.writeEndElement();               
47        }
48       
49        private static void writeSupportedDataViews(XMLStreamWriter writer,
50                        List<DataView> supportedDataViews) throws XMLStreamException {
51               
52                if (writer == null) {
53            throw new NullPointerException("writer == null");
54        }
55               
56        writer.writeStartElement(PREFIX, "SupportedDataViews", NAMESPACE);
57               
58                for (DataView dv : supportedDataViews) {
59                writer.writeStartElement(PREFIX, "SupportedDataView", NAMESPACE);
60                writer.writeAttribute("id", dv.getShortIdentifier());
61                writer.writeAttribute("delivery-policy", dv.getPayloadDelivery());
62                writer.writeCharacters(dv.getMimeType());
63                writer.writeEndElement();
64                }
65                writer.writeEndElement();
66        }       
67}
Note: See TracBrowser for help on using the repository browser.