/** * append links to OpenSearch descriptors. This will enable to add the open * search as a search engine in the browser. * * @param msgContext * @param head append to this * @param baseUri base service uri */ private void addOpenSearchLinks(StringBuilder htmlDocStrBldr, String baseUri) { ResourceRegistry registry = RuntimeContextTLS.getRuntimeContext().getAttribute(ResourceRegistry.class); for (ResourceRecord record : registry.getRecords()) { if (providesOpenSearch(record) && !collectionHasTemplateHref(record .getTemplateProcessor().getTemplate())) { htmlDocStrBldr.append(START_LINK).append(APOSTROPHE).append(OPEN_SEARCH_REL) .append(APOSTROPHE).append(SPACE).append(TYPE).append(APOSTROPHE) .append(MediaTypeUtils.OPENSEARCH).append(APOSTROPHE); String template = record.getTemplateProcessor().getTemplate(); htmlDocStrBldr.append(SPACE).append(HREF).append(APOSTROPHE).append(UriHelper .appendAltToPath(UriHelper.appendPathToBaseUri(baseUri, template), MediaTypeUtils.OPENSEARCH_TYPE)).append(APOSTROPHE); htmlDocStrBldr.append(SPACE).append(TITLE).append(APOSTROPHE).append(record .getMetadata().getCollectionTitle()).append(SPACE).append("Search") //$NON-NLS-1$ .append(APOSTROPHE).append(END_TAG); } } }
public static List<ServiceDocumentCollectionData> buildServiceDocumentCollectionList(UriInfo uriInfo) { ResourceRegistry resourceRegistry = RuntimeContextTLS.getRuntimeContext().getAttribute(ResourceRegistry.class); List<ServiceDocumentCollectionData> collections = new ArrayList<ServiceDocumentCollectionData>(); for (ResourceRecord record : resourceRegistry.getRecords()) { ClassMetadata metadata = record.getMetadata(); // Check if the resource is a collection resource if (metadata.getWorkspaceName() != null) { // Get Categories that are supported by this collection resource List<Categories> collectionCategories = getCollectionCategories(record, resourceRegistry, uriInfo); UriTemplateProcessor template = record.getTemplateProcessor(); Set<MediaType> consumes = getCollectionConsumes(metadata); Set<MediaType> produces = getCollectionProduces(metadata); ServiceDocumentCollectionData sd = new ServiceDocumentCollectionData(metadata.getWorkspaceName(), metadata .getCollectionTitle(), template.toString(), consumes, collectionCategories, produces); collections.add(sd); } } if (collections != null) { // Fix order to have stable service document Collections.sort(collections, COLLECTION_COMPARATOR); } return collections; }
private Resource buildResource(ResourceRecord record) { Resource newResource = resourcesObjectFactory.createResource(); // Add dispatched URIs UriTemplateProcessor uriTemplate = record.getTemplateProcessor(); newResource.setUri(SLASH + uriTemplate.getTemplate()); // Add Collection/Workspace data newResource.setWorkspace(record.getMetadata().getWorkspaceName()); newResource.setCollection(record.getMetadata().getCollectionTitle()); // Add supported HTTP methods List<MethodMetadata> methodRecords = new LinkedList<MethodMetadata>(); methodRecords.addAll(record.getMetadata().getResourceMethods()); org.apache.wink.common.internal.model.admin.Methods methods = resourcesObjectFactory.createMethods(); addResourceMethods(methodRecords, methods); newResource.setMethods(methods); return newResource; }