use of com.a9.opensearch.ObjectFactory in project ARLAS-server by gisaia.
the class OpenSearchHandler method getOpenSearchDescription.
public OpenSearchDescription getOpenSearchDescription(String serverUrl) {
ObjectFactory objectFactory = new ObjectFactory();
OpenSearchDescription description = objectFactory.createOpenSearchDescription();
description.getOtherAttributes().put(new QName("http://a9.com/-/opensearch/extensions/geo/1.0/", "opensearchgeo"), "opensearchgeo");
description.setDescription(cswHandler.cswConfiguration.openSearchDescription);
description.setShortName(cswHandler.cswConfiguration.openSearchShortName);
Url urlXMLBox = new Url();
urlXMLBox.setTemplate(serverUrl + "ogc/csw/?" + "request=GetRecords&service=CSW" + "&version=3.0.0&q={searchTerms?}" + "&startPosition={startIndex?}" + "&maxRecords={count?}" + "&bbox={ns3:box?}" + "&elementSetName=full&outputschema=http://www.opengis.net/cat/csw/3.0" + "&outputFormat=application/xml");
urlXMLBox.setType(MediaType.APPLICATION_XML);
Url urlATOMBox = new Url();
urlATOMBox.setTemplate(serverUrl + "ogc/csw/?" + "request=GetRecords&service=CSW" + "&version=3.0.0&q={searchTerms?}" + "&startPosition={startIndex?}" + "&maxRecords={count?}" + "&bbox={ns3:box?}" + "&elementSetName=full" + "&outputFormat=application/atom%2Bxml");
urlATOMBox.setType(MediaType.APPLICATION_ATOM_XML);
Url urlXMLId = new Url();
urlXMLId.setTemplate(serverUrl + "ogc/csw/?" + "request=GetRecords&service=CSW" + "&version=3.0.0" + "&startPosition={startIndex?}" + "&maxRecords={count?}" + "&recordIds={ns3:uid?}" + "&elementSetName=full&outputschema=http://www.opengis.net/cat/csw/3.0" + "&outputFormat=application/xml");
urlXMLId.setType(MediaType.APPLICATION_XML);
Url urlATOMId = new Url();
urlATOMId.setTemplate(serverUrl + "ogc/csw/?" + "request=GetRecords&service=CSW" + "&version=3.0.0" + "&startPosition={startIndex?}" + "&maxRecords={count?}" + "&recordIds={ns3:uid?}" + "&elementSetName=full" + "&outputFormat=application/atom%2Bxml");
urlATOMId.setType(MediaType.APPLICATION_ATOM_XML);
description.getUrl().add(urlXMLBox);
description.getUrl().add(urlXMLId);
description.getUrl().add(urlATOMBox);
description.getUrl().add(urlATOMId);
return description;
}
use of com.a9.opensearch.ObjectFactory in project ARLAS-server by gisaia.
the class AtomGetRecordsMessageBodyWriter method writeTo.
@Override
public void writeTo(GetRecordsResponseType getRecordsResponseType, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) throws IOException, WebApplicationException {
FeedType feedType = new FeedType();
PersonType personType = new PersonType();
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<String> name = objectFactory.createName("Matthieu Barbet");
personType.getNameOrUriOrEmail().add(name);
feedType.getAuthor().add(personType);
TextType title = objectFactory.createTextType();
title.getContent().add(this.arlasServerConfiguration.cswConfiguration.openSearchShortName);
feedType.setTitle(title);
IdType idTypeValue = new IdType();
idTypeValue.setValue(String.valueOf(this.arlasServerConfiguration.cswConfiguration.openSearchShortName.hashCode()));
feedType.setId(idTypeValue);
GregorianCalendar c = new GregorianCalendar();
c.setTime(new Date());
try {
XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
DateTimeType dateTimeType = new DateTimeType();
dateTimeType.setValue(date);
feedType.setUpdated(dateTimeType);
} catch (DatatypeConfigurationException e) {
e.printStackTrace();
throw new WebApplicationException(e);
}
LinkType linkType = new LinkType();
linkType.setType(CSWRESTService.MIME_TYPE__OPENSEARCH_XML);
linkType.setHref(arlasServerConfiguration.arlasBaseUri + "ogc/opensearch/{collection}");
linkType.setRel("search");
feedType.getLink().add(linkType);
com.a9.opensearch.ObjectFactory openSearchFactory = new com.a9.opensearch.ObjectFactory();
BigInteger nextRecord = getRecordsResponseType.getSearchResults().getNextRecord();
BigInteger totalResult = getRecordsResponseType.getSearchResults().getNumberOfRecordsReturned();
Long nextRecordLong = nextRecord.longValue();
Long totalResultLong = totalResult.longValue();
JAXBElement<Long> startIndex = openSearchFactory.createStartIndex(nextRecordLong - totalResultLong);
feedType.getAny().add(startIndex);
JAXBElement<Long> totalResults = openSearchFactory.createTotalResults(totalResultLong);
feedType.getAny().add(totalResults);
JAXBElement<Long> itemPerPages = openSearchFactory.createItemsPerPage(totalResultLong);
feedType.getAny().add(itemPerPages);
try {
JAXBContext jc = JAXBContext.newInstance(String.class, QueryType.class, FeedType.class);
Marshaller m = jc.createMarshaller();
QueryType queryType = new QueryType();
queryType.setRole("request");
QName _Query_QNAME = new QName("http://a9.com/-/spec/opensearch/1.1/", "Query");
JAXBElement<QueryType> query = new JAXBElement<>(_Query_QNAME, QueryType.class, null, queryType);
feedType.getAny().add(query);
getRecordsResponseType.getSearchResults().getAbstractRecord().stream().forEach(jaxbElement -> {
EntryType entryType = new EntryType();
AtomBuilder.setEntryType(jaxbElement.getValue(), feedType, entryType);
feedType.getEntry().add(entryType);
});
try {
m.marshal(objectFactory.createFeed(feedType), outputStream);
} catch (JAXBException e) {
e.printStackTrace();
throw new WebApplicationException(e);
}
} catch (JAXBException e) {
e.printStackTrace();
throw new WebApplicationException(e);
}
}
Aggregations