Package gov.loc.www.zing.srw

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


            //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();
            if(records==null || (record=records.getRecord())==null)
                System.out.println("0 records returned");
            else {
                System.out.println(record.length+" records returned");
                System.out.println("record="+record);
                System.out.println("record[0] has record number "+
                record[0].getRecordPosition());
                StringOrXmlFragment frag=record[0].getRecordData();
                System.out.println("frag="+frag);
                MessageElement[] elems=frag.get_any();
                System.out.println("elems="+elems);
                System.out.println("value="+elems[0].getValue());
            }
            System.out.println("nextRecordPosition="+response.getNextRecordPosition());
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here


            //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();
            if(records==null || (record=records.getRecord())==null)
                System.out.println("0 records returned");
            else {
                System.out.println(record.length+" records returned");
                System.out.println("record="+record);
                System.out.println("record[0] has record number "+
                record[0].getRecordPosition());
                StringOrXmlFragment frag=record[0].getRecordData();
                System.out.println("frag="+frag);
                MessageElement[] elems=frag.get_any();
                System.out.println("elems="+elems);
                System.out.println("value="+elems[0].getValue());
            }
            System.out.println("nextRecordPosition="+response.getNextRecordPosition());
        }
        catch(Exception e) {
            return null;
        }
        return null;
View Full Code Here

            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) {
                        DiagnosticType diag, diagArray[]=diags.getDiagnostic();
                        for(i=0; i<diagArray.length; i++) {
                            diag=diagArray[i];
                            System.out.print("diagnostic: "+diag.getUri());
                            if(diag.getDetails()!=null)
                                System.out.print(", details: "+diag.getDetails());
                            System.out.println();
                        }
                    }
                    System.out.println("postings=" + searchResponse.getNumberOfRecords());
                   
//                    ExtraDataType edt=searchResponse.getExtraResponseData();
//                    if(edt!=null) {
//                        HandleSGML rh=new HandleSGML();
//                        StringBuffer tags=new StringBuffer();
//                        tags.append("ns1:restrictorSummary 0 recordTag\n");
//                        tags.append("restrictor             10\n");
//                        tags.append("entry                  11\n");
//                        tags.append("xmlns                  12\n");
//                        tags.append("xmlns:ns1              12\n");
//                        tags.append("count                  13\n");
//                        tags.append("use                    14\n");
//                        rh.loadTags(new StringReader(tags.toString()));
//                        rh.setByteToCharConverter("utf8");
//                        MessageElement elems[]=edt.get_any();
//                        rh.Input(new ByteArrayInputStream(elems[0].toString().getBytes("UTF-8")));
//                        DataDir summary=rh.getNextRecord();
//                        DataDir restrictors[]=new DataDir[summary.count()-1];
//                        restrictors[0]=summary.child().next();
//                        for(int i=1; i<restrictors.length; i++)
//                            restrictors[i]=restrictors[i-1].next();
//                        for(int i=0; i<restrictors.length; i++) {
//                            System.out.print("use="+restrictors[i].find(2).find(14).getUTFString());
//                            System.out.print(" count="+restrictors[i].find(2).find(13).getUTFString());
//                            System.out.print("     ");
//                        }
//                        System.out.println();
//                        for(int i=0; i<restrictors.length; i++)
//                            restrictors[i]=restrictors[i].child().next();
//                        for(int j=0; j<5; j++) {
//                            for(int i=0; i<restrictors.length; i++) {
//                                if(restrictors[i]!=null) {
//                                    System.out.print(restrictors[i].find(1).getUTFString());
//                                    System.out.print("("+restrictors[i].find(2).find(13).getUTFString()+")");
//                                    System.out.print("     ");
//                                    restrictors[i]=restrictors[i].next();
//                                }
//                                else
//                                    System.out.print("           ");
//                            }
//                            System.out.println();
//                        }
//                    }

                    RecordsType records = searchResponse.getRecords();
                    RecordType record[];
                    if(records == null || (record = records.getRecord()) == null) {
                        System.out.println("0 records returned");
                    }
                    else {
                        System.out.println(record.length + " records returned");
                        MessageElement[]    elems;
                        Source              source;
                        String              recordStr;
                        StringOrXmlFragment frag;
                        StringWriter        sw;
                        for(i=0; i<record.length; i++) {
                            System.out.print("record number " + record[i].getRecordPosition());
                            frag=record[i].getRecordData();
                            elems=frag.get_any();
                            recordStr=elems[0].toString();
                            if(transformer!=null) {
                                source=new StreamSource(new StringReader(recordStr));
                                sw=new StringWriter();
                                try {
                                    transformer.transform(source, new StreamResult(sw));
                                    System.out.print(sw.toString());
                                }
                                catch(Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            else
                                System.out.println(recordStr);
                        }
                    }
                    System.out.println("nextRecordPosition=" + searchResponse.getNextRecordPosition());
                }
                else if(scan) {
                    System.out.print("operation=searchRetrieve");
                    scanRequest = new ScanRequestType();
                    System.out.print("&version=1.1");
View Full Code Here

    public SearchRetrieveResponseType searchRetrieveOperation(
      SearchRetrieveRequestType request) throws RemoteException {
        log.debug("Enter: searchRetrieveOperation");
        long startTime=System.currentTimeMillis();
        MessageContext             msgContext=MessageContext.getCurrentContext();
        SearchRetrieveResponseType response;
        int resultSetIdleTime=((Integer)msgContext.getProperty("resultSetIdleTime")).intValue();
        NonNegativeInteger nni=request.getResultSetTTL();
        if(log.isDebugEnabled())
            log.debug("resultSetTTL()="+nni);
        if(nni!=null) {
            int ttl=nni.intValue();
            log.debug("ttl="+ttl);
            if(ttl<resultSetIdleTime)
                resultSetIdleTime=ttl;
        }
        String dbname=(String)msgContext.getProperty("dbname");
        SRWDatabase db=(SRWDatabase)msgContext.getProperty("db");
        if(log.isDebugEnabled())
            log.debug("db="+db);

        String sortKeys=request.getSortKeys();
        if(sortKeys!=null)
            request.setSortKeys(sortKeys);

        String query=request.getQuery();
        if(query.indexOf('%')>=0)
            try {
                request.setQuery(java.net.URLDecoder.decode(query, "utf-8"));
            }
            catch (java.io.UnsupportedEncodingException e) {
            }
        if(query==null) {
            response=new SearchRetrieveResponseType();
            db.diagnostic(SRWDiagnostic.MandatoryParameterNotSupplied,
                "query", response);
        }
        else if(request.getStartRecord()!=null &&
          request.getStartRecord().intValue()==Integer.MAX_VALUE) {
            response=new SearchRetrieveResponseType();
            db.diagnostic(SRWDiagnostic.UnsupportedParameterValue,
                "startRecord", response);
        }
        else if(request.getMaximumRecords()!=null &&
          request.getMaximumRecords().intValue()==Integer.MAX_VALUE) {
            response=new SearchRetrieveResponseType();
            db.diagnostic(SRWDiagnostic.UnsupportedParameterValue,
                "maximumRecords", response);
        }
        else if(request.getResultSetTTL()!=null &&
          request.getResultSetTTL().intValue()==Integer.MAX_VALUE) {
            response=new SearchRetrieveResponseType();
            db.diagnostic(SRWDiagnostic.UnsupportedParameterValue,
                "resultSetTTL", response);
        }
        else
        try {
            response=db.doRequest(request);
            if(response==null) {
                response=new SearchRetrieveResponseType();
                response.setVersion("1.1");
                setEchoedSearchRetrieveRequestType(request, response);
                db.diagnostic(SRWDiagnostic.GeneralSystemError, null, response);
                return response;
            }
            if(msgContext.getProperty("sru")!=null &&
              request.getStylesheet()!=null) // you can't ask for a stylesheet in srw!
                db.diagnostic(SRWDiagnostic.StylesheetsNotSupported, null, response);

            setEchoedSearchRetrieveRequestType(request, response);
            if(request.getRecordXPath()!=null)
                db.diagnostic(72, null, response);
            if(request.getSortKeys()!=null &&
              !request.getSortKeys().equals("") && !db.supportsSort())
                db.diagnostic(SRWDiagnostic.SortNotSupported, null, response);

            // set extraResponseData
            StringBuffer extraResponseData = new StringBuffer();

            // we're going to stick the database name in extraResponseData every time
            if(db.databaseTitle!=null)
                extraResponseData.append("<databaseTitle>").append(db.databaseTitle).append("</databaseTitle>");
            else
                extraResponseData.append("<databaseTitle>").append(dbname).append("</databaseTitle>");

            // did they ask for the targetURL to be returned?
//            Hashtable extraRequestDataElements=SRWDatabase.parseElements(request.getExtraRequestData());
//            String s=(String)extraRequestDataElements.get("returnTargetURL");
//            log.info("returnTargetURL="+s);
//            if(s!=null && !s.equals("false")) {
//                String targetStr=(String)msgContext.getProperty("targetURL");
//                log.info("targetStr="+targetStr);
//                if(targetStr!=null && targetStr.length()>0) {
//                    URL target=new URL(targetStr);
//                    extraResponseData.append("<targetURL>")
//                        .append("<host>").append(target.getHost()).append("</host>")
//                        .append("<port>").append(target.getPort()).append("</port>")
//                        .append("<path>").append(target.getPath()).append("</path>")
//                        .append("<query>").append(Utilities.xmlEncode(target.getQuery())).append("</query>")
//                        .append("</targetURL>");
//                }
//            }

            // set extraResponseData
            SRWDatabase.setExtraResponseData(response, extraResponseData.toString());
        }
        catch(Exception e) {
            log.error(e, e);
            throw new RemoteException(e.getMessage(), e);
        }
        finally {
            SRWDatabase.putDb(dbname, db);
        }

        response.setVersion("1.1");
        log.info("\""+query+"\"==>"+response.getNumberOfRecords()+" ("+(System.currentTimeMillis()-startTime)+"ms)");
        log.debug("Exit: searchRetrieveOperation");
        return response;
    }
View Full Code Here

    public SearchRetrieveResponseType doRequest(SearchRetrieveRequestType request) throws ServletException {
        boolean cachedResultSet=false;
        QueryResult result;
        searchRequest=request;
        response = new SearchRetrieveResponseType();

        response.setNumberOfRecords(new NonNegativeInteger("0"));       
        //        try {
                    MessageContext msgContext = MessageContext.getCurrentContext();
View Full Code Here

        sreq.setMaximumTerms(new PositiveInteger("20"));
        sreq.setResponsePosition(new NonNegativeInteger("10"));
        assertEquals("operation=scan&maximumTerms=20&responsePosition=10&scanClause=\"dog\"", Utilities.objToSru(sreq));
       
        try {
            Utilities.objToSru(new SearchRetrieveResponseType());
            fail("should have thrown an IllegalArgumentException");
        }
        catch(IllegalArgumentException e) {
        }
View Full Code Here

        sreq.setMaximumTerms(new PositiveInteger("20"));
        sreq.setResponsePosition(new NonNegativeInteger("10"));
//        System.out.println("objToXml: "+Utilities.objToXml(sreq));
        assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns1:scanRequest 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><scanClause xsi:type=\"xsd:string\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">dog</scanClause><responsePosition xsi:type=\"xsd:nonNegativeInteger\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">10</responsePosition><maximumTerms xsi:type=\"xsd:positiveInteger\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">20</maximumTerms><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:scanRequest>", Utilities.objToXml(sreq));
       
        SearchRetrieveResponseType srresp=new SearchRetrieveResponseType();
        srresp.setVersion("1.1");
        Utilities.objToXml(srresp);

        ScanResponseType sresp=new ScanResponseType();
        sresp.setVersion("1.1");
        Utilities.objToXml(sresp);
View Full Code Here

            //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();
            if(records==null || (record=records.getRecord())==null)
                System.out.println("0 records returned");
            else {
                System.out.println(record.length+" records returned");
                System.out.println("record[0] has record number "+
                record[0].getRecordPosition());
                StringOrXmlFragment frag=record[0].getRecordData();
                MessageElement[] elems=frag.get_any();
                System.out.println("record="+elems[0].toString());
            }
            System.out.println("nextRecordPosition="+response.getNextRecordPosition());
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

TOP

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

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.