Package org.apache.wink.common.model.opensearch

Examples of org.apache.wink.common.model.opensearch.OpenSearchDescription


     */
    @GET
    @Produces(MediaTypeUtils.OPENSEARCH)
    public OpenSearchDescription getOpenSearch(@Context UriInfo info) {
        String baseUri = info.getAbsolutePath().toString();
        OpenSearchDescription openSearchDescription = new OpenSearchDescription();
        openSearchDescription.setShortName("HP Defect Manager search engine");
        openSearchDescription.setDescription("You can search defects in HP Defect Manager");
        openSearchDescription.setLongName("HP Defect Manager search engine");
        openSearchDescription.setContact("john.smith@example.com");
        openSearchDescription.setDeveloper("John Smith");
        openSearchDescription.addLanguage("en-US");
        openSearchDescription.setTags("defect bug");
        openSearchDescription.addInputEncoding("UTF-8");
        openSearchDescription.addOutputEncoding("UTF-8");

        // set OpenSearch URL parameters
        OpenSearchParameter severityParameter =
            new OpenSearchParameter(SEVERIIY, URN_SEVERIIY, false);
        OpenSearchParameter ftsParameter =
            new OpenSearchParameter(FTS, OpenSearchParameter.OpenSearchParams.searchTerms
                .toString(), false);
        OpenSearchParameter assignedToParameter =
            new OpenSearchParameter(ASSIGNED_TO, URN_ASSIGNED_TO, false);

        // create Search URL & populate search parameters for browsers
        OpenSearchUrl openSearchUrlForBrowsers = new OpenSearchUrl();
        openSearchUrlForBrowsers.addOpenSearchParameter(ftsParameter);
        openSearchUrlForBrowsers.setType(MediaType.TEXT_HTML);

        // create Search URL & populate search parameters
        OpenSearchUrl openSearchUrl = new OpenSearchUrl();
        openSearchUrl.addOpenSearchParameter(severityParameter);
        openSearchUrl.addOpenSearchParameter(ftsParameter);
        openSearchUrl.addOpenSearchParameter(assignedToParameter);
        openSearchUrl.setType(MediaType.TEXT_HTML);

        // create open search base uri
        StringBuilder openSearchUrlBuilder = new StringBuilder(baseUri);

        openSearchUrl.setBaseUri(openSearchUrlBuilder.toString());
        openSearchUrlForBrowsers.setBaseUri(openSearchUrlBuilder.toString());

        // add URLs to OpenSearch
        openSearchDescription.addUrl(openSearchUrlForBrowsers);
        openSearchDescription.addUrl(openSearchUrl);

        // add OpenSearch Query element
        OpenSearchQuery openSearchQuery = new OpenSearchQuery();
        openSearchQuery.setRole(OpenSearchQuery.QueryRole.example.toString());
        openSearchQuery.setSearchTerms("Search Terms");
        openSearchDescription.addQuery(openSearchQuery);

        // add OpenSearch Images
        OpenSearchImage openSearchImage;
        openSearchImage =
            OpenSearchUtils.createOpenSearchImage(MediaTypeUtils.IMAGE_JPEG, openSearchUrlBuilder
                .toString() + "splash.jpg");
        openSearchDescription.addNewImage(openSearchImage);

        return openSearchDescription;
    }
View Full Code Here


     */
    @GET
    @Produces(MediaTypeUtils.OPENSEARCH)
    public OpenSearchDescription getOpenSearch(@Context UriInfo info) {
        String baseUri = info.getAbsolutePath().toString();
        OpenSearchDescription openSearchDescription = new OpenSearchDescription();
        openSearchDescription.setShortName("HP Defect Manager search engine");
        openSearchDescription.setDescription("You can search defects in HP Defect Manager");
        openSearchDescription.setLongName("HP Defect Manager search engine");
        openSearchDescription.setContact("john.smith@example.com");
        openSearchDescription.setDeveloper("John Smith");
        openSearchDescription.addLanguage("en-US");
        openSearchDescription.setTags("defect bug");
        openSearchDescription.addInputEncoding("UTF-8");
        openSearchDescription.addOutputEncoding("UTF-8");

        // set OpenSearch URL parameters
        OpenSearchParameter severityParameter =
            new OpenSearchParameter(SEVERIIY, URN_SEVERIIY, false);
        OpenSearchParameter ftsParameter =
            new OpenSearchParameter(FTS, OpenSearchParameter.OpenSearchParams.searchTerms
                .toString(), false);
        OpenSearchParameter assignedToParameter =
            new OpenSearchParameter(ASSIGNED_TO, URN_ASSIGNED_TO, false);

        // create Search URL & populate search parameters for browsers
        OpenSearchUrl openSearchUrlForBrowsers = new OpenSearchUrl();
        openSearchUrlForBrowsers.addOpenSearchParameter(ftsParameter);
        openSearchUrlForBrowsers.setType(MediaType.TEXT_HTML);

        // create Search URL & populate search parameters
        OpenSearchUrl openSearchUrl = new OpenSearchUrl();
        openSearchUrl.addOpenSearchParameter(severityParameter);
        openSearchUrl.addOpenSearchParameter(ftsParameter);
        openSearchUrl.addOpenSearchParameter(assignedToParameter);
        openSearchUrl.setType(MediaType.TEXT_HTML);

        // create open search base uri
        StringBuilder openSearchUrlBuilder = new StringBuilder(baseUri);

        openSearchUrl.setBaseUri(openSearchUrlBuilder.toString());
        openSearchUrlForBrowsers.setBaseUri(openSearchUrlBuilder.toString());

        // add URLs to OpenSearch
        openSearchDescription.addUrl(openSearchUrlForBrowsers);
        openSearchDescription.addUrl(openSearchUrl);

        // add OpenSearch Query element
        OpenSearchQuery openSearchQuery = new OpenSearchQuery();
        openSearchQuery.setRole(OpenSearchQuery.QueryRole.example.toString());
        openSearchQuery.setSearchTerms("Search Terms");
        openSearchDescription.addQuery(openSearchQuery);

        // add OpenSearch Images
        OpenSearchImage openSearchImage;
        openSearchImage =
            OpenSearchUtils.createOpenSearchImage(MediaTypeUtils.IMAGE_JPEG, openSearchUrlBuilder
                .toString() + "splash.jpg");
        openSearchDescription.addNewImage(openSearchImage);

        return openSearchDescription;
    }
View Full Code Here

     */
    @GET
    @Produces(MediaTypeUtils.OPENSEARCH)
    public OpenSearchDescription getOpenSearch(@Context UriInfo info) {
        String baseUri = info.getAbsolutePath().toString();
        OpenSearchDescription openSearchDescription = new OpenSearchDescription();
        openSearchDescription.setShortName("HP Defect Manager search engine");
        openSearchDescription.setDescription("You can search defects in HP Defect Manager");
        openSearchDescription.setLongName("HP Defect Manager search engine");
        openSearchDescription.setContact("john.smith@example.com");
        openSearchDescription.setDeveloper("John Smith");
        openSearchDescription.addLanguage("en-US");
        openSearchDescription.setTags("defect bug");
        openSearchDescription.addInputEncoding("UTF-8");
        openSearchDescription.addOutputEncoding("UTF-8");

        // set OpenSearch URL parameters
        OpenSearchParameter severityParameter =
            new OpenSearchParameter(SEVERIIY, URN_SEVERIIY, false);
        OpenSearchParameter ftsParameter =
            new OpenSearchParameter(FTS, OpenSearchParameter.OpenSearchParams.searchTerms
                .toString(), false);
        OpenSearchParameter assignedToParameter =
            new OpenSearchParameter(ASSIGNED_TO, URN_ASSIGNED_TO, false);

        // create Search URL & populate search parameters for browsers
        OpenSearchUrl openSearchUrlForBrowsers = new OpenSearchUrl();
        openSearchUrlForBrowsers.addOpenSearchParameter(ftsParameter);
        openSearchUrlForBrowsers.setType(MediaType.TEXT_HTML);

        // create Search URL & populate search parameters
        OpenSearchUrl openSearchUrl = new OpenSearchUrl();
        openSearchUrl.addOpenSearchParameter(severityParameter);
        openSearchUrl.addOpenSearchParameter(ftsParameter);
        openSearchUrl.addOpenSearchParameter(assignedToParameter);
        openSearchUrl.setType(MediaType.TEXT_HTML);

        // create open search base uri
        StringBuilder openSearchUrlBuilder = new StringBuilder(baseUri);

        openSearchUrl.setBaseUri(openSearchUrlBuilder.toString());
        openSearchUrlForBrowsers.setBaseUri(openSearchUrlBuilder.toString());

        // add URLs to OpenSearch
        openSearchDescription.addUrl(openSearchUrlForBrowsers);
        openSearchDescription.addUrl(openSearchUrl);

        // add OpenSearch Query element
        OpenSearchQuery openSearchQuery = new OpenSearchQuery();
        openSearchQuery.setRole(OpenSearchQuery.QueryRole.example.toString());
        openSearchQuery.setSearchTerms("Search Terms");
        openSearchDescription.addQuery(openSearchQuery);

        // add OpenSearch Images
        OpenSearchImage openSearchImage;
        openSearchImage =
            OpenSearchUtils.createOpenSearchImage(MediaTypeUtils.IMAGE_JPEG, openSearchUrlBuilder
                .toString() + "splash.jpg");
        openSearchDescription.addNewImage(openSearchImage);

        return openSearchDescription;
    }
View Full Code Here

            + resultSerialization, diff.similar());

    }

    public void testOpenSearchDescriptor() {
        OpenSearchDescription openSearchDescriptor = buildOpenSearchDescriptor(BASE_URL);
        assertEquals("Expected and actual values of Short Name are not same",
                     SHORT_NAME,
                     openSearchDescriptor.getShortName());
        assertEquals("Expected and actual values of  Description are not same",
                     DESC,
                     openSearchDescriptor.getDescription());
        assertEquals("Expected and actual values of  Long Name are not same",
                     LONG_NAME,
                     openSearchDescriptor.getLongName());
        assertEquals("Expected and actual values of  Contact are not same",
                     CONTACT,
                     openSearchDescriptor.getContact());
        assertEquals("Incorrect Developer", DEVELOPER, openSearchDescriptor.getDeveloper());

        List<String> languageArray = openSearchDescriptor.getLanguage();
        Collections.sort(languageArray);
        int binarySearchResult = Collections.binarySearch(languageArray, LANG);
        if (binarySearchResult < 0) {
            assertFalse("Accept Language " + LANG
                + " does not exist in array of expected languages"
                + languageArray, true);
        }

        assertEquals("Expected and actual values of  Tags are not same", TAGS, openSearchDescriptor
            .getTags());

        List<String> inputEncodingArray = openSearchDescriptor.getInputEncoding();
        Collections.sort(inputEncodingArray);
        int inputEncodingArraySearchResult = Collections.binarySearch(inputEncodingArray, ENCODING);
        if (inputEncodingArraySearchResult < 0) {
            assertFalse("Input Encoding " + ENCODING
                + "  does not exist in array of input incoding values "
                + inputEncodingArray, true);
        }

        List<String> outputEncodingArray = openSearchDescriptor.getOutputEncoding();
        Collections.sort(outputEncodingArray);
        int outputEncodingArraySearchResult =
            Collections.binarySearch(outputEncodingArray, ENCODING);
        if (outputEncodingArraySearchResult < 0) {
            assertFalse("Output Encoding " + ENCODING
                + "  does not exist in array of output incoding values "
                + outputEncodingArray, true);
        }

        List<OpenSearchUrl> urlArray = openSearchDescriptor.getUrl();
        if (urlArray != null && urlArray.size() != 0) {
            for (OpenSearchUrl url : urlArray) {
                String openSearchUrlTemplate = url.getTemplate();
                if (!(openSearchUrlTemplate.equals(SEARCH_URL1) || openSearchUrlTemplate
                    .equals(SEARCH_URL2))) {
                    assertFalse("Expected and actual values of  Url are not same " + " expected:"
                        + SEARCH_URL1
                        + ""
                        + SEARCH_URL2
                        + " actual:"
                        + openSearchUrlTemplate, true);
                }
            }
        }

        List<OpenSearchQuery> queryArray = openSearchDescriptor.getQuery();
        if (urlArray == null || urlArray.size() == 0) {
            assertFalse("Open Search Query is not defined", true);
        } else {
            OpenSearchQuery openSearchQuery = queryArray.get(0);
            assertEquals("Expected and actual values of  Count are not same ",
View Full Code Here

                         openSearchQuery.getTotalResults().toString());
        }
    }

    private OpenSearchDescription buildOpenSearchDescriptor(String baseUri) {
        OpenSearchDescription openSearchDescriptor = new OpenSearchDescription();
        openSearchDescriptor.setShortName(SHORT_NAME);
        openSearchDescriptor.setDescription(DESC);
        openSearchDescriptor.setLongName(LONG_NAME);
        openSearchDescriptor.setContact(CONTACT);
        openSearchDescriptor.setDeveloper(DEVELOPER);
        openSearchDescriptor.addLanguage(LANG);
        openSearchDescriptor.setTags(TAGS);
        openSearchDescriptor.addInputEncoding(ENCODING);
        openSearchDescriptor.addOutputEncoding(ENCODING);

        // set OpenSearch URL parameters
        OpenSearchParameter severityParameter =
            new OpenSearchParameter(SEVERIIY, URN_SEVERIIY, false);
        OpenSearchParameter ftsParameter =
            new OpenSearchParameter(FTS, OpenSearchParameter.OpenSearchParams.searchTerms
                .toString(), false);
        OpenSearchParameter assignedToParameter = new OpenSearchParameter();
        assignedToParameter.setMandatory(false);
        assignedToParameter.setParameterKey(ASSIGNED_TO);
        assignedToParameter.setParameter(URN_ASSIGNED_TO);

        // create Search URL & populate search parameters for browsers
        OpenSearchUrl openSearchUrlForBrowsers = new OpenSearchUrl();
        openSearchUrlForBrowsers.addOpenSearchParameter(ftsParameter);
        openSearchUrlForBrowsers.setType(MediaType.TEXT_HTML);

        // create Search URL & populate search parameters
        OpenSearchUrl openSearchUrl = new OpenSearchUrl();
        openSearchUrl.addOpenSearchParameter(severityParameter);
        openSearchUrl.addOpenSearchParameter(ftsParameter);
        openSearchUrl.addOpenSearchParameter(assignedToParameter);
        openSearchUrl.setType(MediaType.TEXT_HTML);

        // create open search base uri
        StringBuilder openSearchUrlBuilder = new StringBuilder(baseUri);
        if (baseUri.endsWith("/") && URL.startsWith("/")) {
            openSearchUrlBuilder.append(URL.substring(1));
        } else {
            openSearchUrlBuilder.append(URL);
        }
        openSearchUrl.setBaseUri(openSearchUrlBuilder.toString());
        openSearchUrlForBrowsers.setBaseUri(openSearchUrlBuilder.toString());

        // add URLs to OpenSearch
        openSearchDescriptor.addUrl(openSearchUrlForBrowsers);
        openSearchDescriptor.addUrl(openSearchUrl);

        // add OpenSearch Query element
        OpenSearchQuery openSearchQuery = new OpenSearchQuery();
        openSearchQuery.setCount(new BigInteger("10"));
        openSearchQuery.setInputEncoding(ENCODING);
        openSearchQuery.setLanguage(LANG);
        openSearchQuery.setOutputEncoding(ENCODING);
        openSearchQuery.setRole(OpenSearchQuery.QueryRole.example.toString());
        openSearchQuery.setSearchTerms(SEARCH_TERM);
        openSearchQuery.setStartIndex(new BigInteger(START_INDEX));
        openSearchQuery.setStartPage(new BigInteger(START_PAGE));
        openSearchQuery.setTitle(TITLE);
        openSearchQuery.setTotalResults(new BigInteger(TOTAL_RESULT));
        openSearchDescriptor.addQuery(openSearchQuery);

        // add OpenSearch Images
        OpenSearchImage openSearchImage;
        openSearchImage =
            OpenSearchUtils.createOpenSearchImage(MediaTypeUtils.IMAGE_JPEG, openSearchUrlBuilder
                .toString() + "splash.jpg");
        openSearchDescriptor.addNewImage(openSearchImage);
        return openSearchDescriptor;
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.common.model.opensearch.OpenSearchDescription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.