Package gov.loc.www.zing.srw

Examples of gov.loc.www.zing.srw.SearchRetrieveRequestType


                    System.out.println("0 terms returned");
            }
            else
                System.out.println("no scan response returned");

            SearchRetrieveRequestType request=new SearchRetrieveRequestType();
            request.setVersion("1.1");
            request.setQuery("en and education");
            //request.setQuery("dc.title any sword");
            request.setRecordSchema("info:srw/schema/1/dc-v1.1");
            request.setStartRecord(new PositiveInteger("1"));
            request.setMaximumRecords(new NonNegativeInteger("1"));
            request.setRecordPacking("xml");
            SearchRetrieveResponseType response=
                port.searchRetrieveOperation(request);
            System.out.println("postings="+response.getNumberOfRecords());
            RecordType[] record;
            RecordsType records=response.getRecords();
View Full Code Here


                    System.out.println("0 terms returned");
            }
            else
                System.out.println("no scan response returned");

            SearchRetrieveRequestType request=new SearchRetrieveRequestType();
            request.setVersion("1.1");
            request.setQuery("en and education");
            //request.setQuery("dc.title any sword");
            request.setRecordSchema("info:srw/schema/1/dc-v1.1");
            request.setStartRecord(new PositiveInteger("1"));
            request.setMaximumRecords(new NonNegativeInteger("1"));
            request.setRecordPacking("xml");
            SearchRetrieveResponseType response=
                port.searchRetrieveOperation(request);
            System.out.println("postings="+response.getNumberOfRecords());
            RecordType[] record;
            RecordsType records=response.getRecords();
View Full Code Here

            Enumeration keys;
            Hashtable parms;
            int maximumRecords=1, maximumTerms=11, responsePosition=6, resultSetTTL=0, startRecord=1;
            long startTime;
            ScanRequestType scanRequest;
            SearchRetrieveRequestType searchRequest;
            SearchRetrieveResponseType searchResponse;
            String input, key, query=null, recordPacking="xml", scanClause=null,
                   schema=null, sortKeys=null;
            Transformer transformer=null;
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("\ntype \"help\" for an explanation of the commands");
            System.out.print("enter request: ");
            input=br.readLine();
            while(input!=null && input.length()>0 && !quit) {
                parms=parseInput(input);
                scan=search=false;
                keys=parms.keys();
                while(keys.hasMoreElements()) {
                    key=(String)keys.nextElement();
                    if(key.equals("explain")) {
                        System.out.println(db.getExplainRecord(null));
                    }
                    else if(key.equals("help")) {
                        help();
                    }
                    else if(key.equals("maximumRecords")) {
                        maximumRecords=Integer.parseInt((String)parms.get(key));
                    }
                    else if(key.equals("maximumTerms")) {
                        maximumTerms=Integer.parseInt((String)parms.get(key));
                    }
                    else if(key.equals("q") || key.equals("quit")) {
                        quit=true;
                    }
                    else if(key.equals("query")) {
                        query=convertUnicodeSequence((String)parms.get(key));
                        search=true;
                    }
                    else if(key.equals("recordPacking")) {
                        recordPacking=(String)parms.get(key);
                    }
                    else if(key.equals("recordSchema")) {
                        schema=(String)parms.get(key);
                    }
                    else if(key.equals("responsePosition")) {
                        responsePosition=Integer.parseInt((String)parms.get(key));
                    }
                    else if(key.equals("resultSetTTL")) {
                        resultSetTTL=Integer.parseInt((String)parms.get(key));
                    }
                    else if(key.equals("scanClause")) {
                        scanClause=convertUnicodeSequence((String)parms.get(key));
                        scan=true;
                    }
                    else if(key.equals("sortKeys")) {
                        sortKeys=(String)parms.get(key);
                    }
                    else if(key.equals("startRecord")) {
                        startRecord=Integer.parseInt((String)parms.get(key));
                    }
                    else if(key.equals("x-info-5-restrictorSummary")) {
                        restrictorSummary=!((String)parms.get(key)).equals("false");
                    }
                    else if(key.equalsIgnoreCase("xsl")) {
                        String xslFileName=(String)parms.get(key);
                        Source xslSource=new StreamSource(xslFileName);
                        if(xslSource==null) {
                            System.out.println("Unable to make StreamSource for: "+xslFileName);
                            continue;
                        }
                        TransformerFactory tFactory=TransformerFactory.newInstance();
                        transformer=tFactory.newTransformer(xslSource);
                    }
                    else { // assume it is a query
                        query=key;
                        search=true;
                    }
                }
                if(search) {
                    System.out.print("operation=searchRetrieve");
                    searchRequest=new SearchRetrieveRequestType();
                    System.out.print("&version=1.1");
                    searchRequest.setVersion("1.1");
                    System.out.print("&maximumRecords="+maximumRecords);
                    searchRequest.setMaximumRecords(new NonNegativeInteger(Integer.toString(maximumRecords)));
                    System.out.print("&query="+query);
                    searchRequest.setQuery(query);
                    System.out.print("&recordPacking="+recordPacking);
                    searchRequest.setRecordPacking(recordPacking);
                    if(schema!=null && schema.length()>0) {
                        System.out.print("&recordSchema="+schema);
                        searchRequest.setRecordSchema(schema);
                    }
                    if(restrictorSummary) {
                        System.out.print("&x-info-5-restrictorSummary");
                        ExtraDataType edt=new ExtraDataType();
                        MessageElement elems[]=new MessageElement[1];
                        edt.set_any(elems);
                        Document domDoc;
                        DocumentBuilderFactory dbf=
                            DocumentBuilderFactory.newInstance();
                        dbf.setNamespaceAware(true);
                        DocumentBuilder docb=dbf.newDocumentBuilder();
                        StringReader sr=new StringReader("<restrictorSummary xmlns=\"info:srw/extension/5/restrictorSummary\"/>");
                        domDoc=docb.parse(new InputSource(sr));
                        sr.close();
                        Element el=domDoc.getDocumentElement();
                        elems[0]=new MessageElement(el);
                        domDoc=null;
                        searchRequest.setExtraRequestData(edt);
                    }
                    System.out.print("&resultSetTTL="+resultSetTTL);
                    searchRequest.setResultSetTTL(new NonNegativeInteger(Integer.toString(resultSetTTL)));
                    if(sortKeys!=null && sortKeys.length()>0) {
                        System.out.print("&sortKeys="+sortKeys);
                        searchRequest.setSortKeys(sortKeys);
                    }
                    System.out.println("&startRecord="+startRecord+"\n");
                    searchRequest.setStartRecord(new PositiveInteger(Integer.toString(startRecord)));
                    startTime=System.currentTimeMillis();
                    searchResponse = db.doRequest(searchRequest);
                    System.out.println("elapsed time: "+(System.currentTimeMillis()-startTime)+"ms");
                    DiagnosticsType diags=searchResponse.getDiagnostics();
                    if(diags!=null) {
View Full Code Here

    }

    public static String objToSru(Object obj) {
        StringBuilder sru=new StringBuilder();
        if(obj instanceof SearchRetrieveRequestType) {
            SearchRetrieveRequestType request=(SearchRetrieveRequestType)obj;
            sru.append("operation=searchRetrieve");
            if(request.getMaximumRecords()!=null)
                sru.append('&').append("maximumRecords=").append(request.getMaximumRecords().toString());
            if(request.getQuery()!=null) {
                String query=request.getQuery();
                if(query.startsWith("\""))
                    sru.append('&').append("query=").append(urlEncode(request.getQuery()));
                else
                    sru.append('&').append("query=").append('"').append(urlEncode(request.getQuery())).append('"');
            }
            if(request.getRecordPacking()!=null)
                sru.append('&').append("recordPacking=").append(request.getRecordPacking());
            if(request.getRecordSchema()!=null)
                sru.append('&').append("recordSchema=").append(request.getRecordSchema());
            if(request.getRecordXPath()!=null)
                sru.append('&').append("recordXPath=").append(request.getRecordXPath());
            if(request.getResultSetTTL()!=null)
                sru.append('&').append("resultSetTTL=").append(request.getResultSetTTL());
            if(request.getSortKeys()!=null)
                sru.append('&').append("sortKeys=").append(request.getSortKeys());
            if(request.getStartRecord()!=null)
                sru.append('&').append("startRecord=").append(request.getStartRecord().toString());
            if(request.getVersion()!=null)
                sru.append('&').append("version=").append(request.getVersion());
        }
        else if(obj instanceof ScanRequestType) {
            ScanRequestType request=(ScanRequestType)obj;
            sru.append("operation=scan");
            if(request.getMaximumTerms()!=null)
                sru.append('&').append("maximumTerms=").append(request.getMaximumTerms().toString());
            if(request.getResponsePosition()!=null)
                sru.append('&').append("responsePosition=").append(request.getResponsePosition().toString());
            if(request.getScanClause()!=null)
                sru.append('&').append("scanClause=\"").append(urlEncode(request.getScanClause())).append('"');
            if(request.getVersion()!=null)
                sru.append('&').append("version=").append(request.getVersion());
        }
        else throw new IllegalArgumentException(
            "Unrecognized object: "+obj.getClass().getName());
        return sru.toString();
    }
View Full Code Here

        return request;
    }

    private static SearchRetrieveRequestType sruSearchToObj(CGIParser parser) {
        Enumeration enumer=parser.getParameterNames();
        SearchRetrieveRequestType request=new SearchRetrieveRequestType();
        String name, value;
        StringBuilder extraData=new StringBuilder();
        while(enumer.hasMoreElements()) {
            name=(String)enumer.nextElement();
            if(name.equals("maximumRecords"))
                request.setMaximumRecords(new NonNegativeInteger(parser.getParameter(name)));
            else if(name.equals("operation"))
                {}
            else if(name.equals("query"))
                request.setQuery(parser.getParameter(name));
            else if(name.equals("recordPacking"))
                request.setRecordPacking(parser.getParameter(name));
            else if(name.equals("recordSchema"))
                request.setRecordSchema(parser.getParameter(name));
            else if(name.equals("recordXPath"))
                request.setRecordXPath(parser.getParameter(name));
            else if(name.equals("resultSetTTL"))
                request.setResultSetTTL(new NonNegativeInteger(parser.getParameter(name)));
            else if(name.equals("sortKeys"))
                request.setSortKeys(parser.getParameter(name));
            else if(name.equals("startRecord"))
                request.setStartRecord(new PositiveInteger(parser.getParameter(name)));
            else if(name.equals("version"))
                request.setVersion(parser.getParameter(name));
            else // must be extraData
                extraData.append('<').append(name).append('>')
                         .append(parser.getParameter(name))
                         .append("</").append(name).append('>');
        }
        if(extraData.length()>0)
            request.setExtraRequestData(SRWDatabase.makeExtraRequestDataType(extraData.toString()));
        return request;
    }
View Full Code Here

    /**
     * Test of objToSru method, of class ORG.oclc.os.SRW.Utilities.
     */
    public void testObjToSru() {
        SearchRetrieveRequestType srreq=new SearchRetrieveRequestType();
        srreq.setQuery("dog or cat and mouse");
        System.out.println("objToSru: "+Utilities.objToSru(srreq));
        assertEquals("operation=searchRetrieve&query=\"dog%20or%20cat%20and%20mouse\"", Utilities.objToSru(srreq));
        srreq.setResultSetTTL(new NonNegativeInteger("123"));
        assertEquals("operation=searchRetrieve&query=\"dog%20or%20cat%20and%20mouse\"&resultSetTTL=123", Utilities.objToSru(srreq));
       
        ScanRequestType sreq=new ScanRequestType();
        sreq.setScanClause("dog");
        System.out.println("objToSru: "+Utilities.objToSru(sreq));
View Full Code Here

    /**
     * Test of objToXml method, of class ORG.oclc.os.SRW.Utilities.
     */
    public void testObjToXml() throws Exception {
        SearchRetrieveRequestType srreq=new SearchRetrieveRequestType();
        srreq.setQuery("dog or cat and mouse");
        srreq.setVersion("1.1");
//        System.out.println("objToXml: "+Utilities.objToXml(srreq));
        assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:searchRetrieveRequest xmlns:ns1=\"http://www.loc.gov/zing/srw/\"><version xsi:type=\"xsd:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">1.1</version><query xsi:type=\"xsd:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">dog or cat and mouse</query><startRecord xsi:type=\"ns1:startRecord\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><maximumRecords xsi:type=\"ns1:maximumRecords\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><recordPacking xsi:type=\"ns1:recordPacking\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><recordSchema xsi:type=\"ns1:recordSchema\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><recordXPath xsi:type=\"ns1:recordXPath\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><resultSetTTL xsi:type=\"ns1:resultSetTTL\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><sortKeys xsi:type=\"ns1:sortKeys\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><stylesheet xsi:type=\"ns1:stylesheet\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><extraRequestData xsi:type=\"ns1:extraRequestData\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/></ns1:searchRetrieveRequest>", Utilities.objToXml(srreq));
        srreq.setResultSetTTL(new NonNegativeInteger("123"));
//        System.out.println("objToXml: "+Utilities.objToXml(srreq));
        assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:searchRetrieveRequest xmlns:ns1=\"http://www.loc.gov/zing/srw/\"><version xsi:type=\"xsd:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">1.1</version><query xsi:type=\"xsd:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">dog or cat and mouse</query><startRecord xsi:type=\"ns1:startRecord\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><maximumRecords xsi:type=\"ns1:maximumRecords\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><recordPacking xsi:type=\"ns1:recordPacking\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><recordSchema xsi:type=\"ns1:recordSchema\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><recordXPath xsi:type=\"ns1:recordXPath\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><resultSetTTL xsi:type=\"xsd:nonNegativeInteger\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">123</resultSetTTL><sortKeys xsi:type=\"ns1:sortKeys\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><stylesheet xsi:type=\"ns1:stylesheet\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/><extraRequestData xsi:type=\"ns1:extraRequestData\" xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/></ns1:searchRetrieveRequest>", Utilities.objToXml(srreq));
       
        ScanRequestType sreq=new ScanRequestType();
        sreq.setScanClause("dog");
View Full Code Here

                    System.out.println("0 terms returned");
            }
            else
                System.out.println("no scan response returned");

            SearchRetrieveRequestType request=new SearchRetrieveRequestType();
            request.setVersion("1.1");
            request.setQuery("en and education");
            //request.setQuery("dc.title any sword");
            request.setRecordSchema("info:srw/schema/1/dc-v1.1");
            request.setStartRecord(new PositiveInteger("1"));
            request.setMaximumRecords(new NonNegativeInteger("1"));
            request.setRecordPacking("xml");
            SearchRetrieveResponseType response=
                port.searchRetrieveOperation(request);
            System.out.println("postings="+response.getNumberOfRecords());
            RecordType[] record;
            RecordsType records=response.getRecords();
View Full Code Here

TOP

Related Classes of gov.loc.www.zing.srw.SearchRetrieveRequestType

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.