public byte[] retrieveByDocument( int resultId, int pos, String docPath, String encoding, boolean prettyPrint ) throws RemoteException { Sessions sessions = Sessions.getInstance(); DBBroker broker = null; try { broker = pool.get(); Value qr = (Value) sessions.getQueryResult( resultId ); if ( qr == null ) throw new RemoteException( "result set unknown or timed out" ); String xml = null; switch ( qr.getType() ) { case Value.isNodeList: NodeList resultSet = qr.getNodeList(); ArraySet hitsByDoc = new ArraySet( 50 ); NodeProxy p; for ( Iterator i = ( (NodeSet) resultSet ).iterator(); i.hasNext();  ) { p = (NodeProxy) i.next(); if ( p.doc.getFileName().equals( docPath ) ) hitsByDoc.add( p ); } if ( pos < 1 || pos > hitsByDoc.getLength() ) throw new RemoteException( "index " + pos + "out of bounds (" + hitsByDoc.getLength() + ")" ); --pos; NodeProxy proxy = ( (NodeSet) hitsByDoc ).get( pos ); if ( proxy == null ) throw new RuntimeException( "not found: " + pos ); LOG.debug( "loaded node " + proxy.gid ); Serializer serializer = broker.getSerializer(); Map properties = new TreeMap(); properties.put(Serializer.ENCODING, encoding); properties.put(Serializer.PRETTY_PRINT, Boolean.toString(prettyPrint)); serializer.setProperties( properties ); xml = serializer.serialize( proxy ); break; default: throw new RemoteException( "result set is not a node list" ); } return xml.getBytes( encoding ); } catch ( Exception e ) { LOG.warn( e ); e.printStackTrace(); throw new RemoteException( e.getMessage(), e ); } finally { pool.release( broker ); } }
public String[] retrieveByDocument( String sessionId, int start, int howmany, String docPath, boolean indent, boolean xinclude, String highlight) throws RemoteException { Session session = SessionManager.getInstance().getSession(sessionId); DBBroker broker = null; try { broker = pool.get(); Value qr = (Value) session.getQueryResult().result; if (qr == null) throw new RemoteException("result set unknown or timed out"); String xml[] = null; switch (qr.getType()) { case Value.isNodeList : NodeList resultSet = qr.getNodeList(); ArraySet hitsByDoc = new ArraySet(50); NodeProxy p; for (Iterator i = ((NodeSet) resultSet).iterator(); i.hasNext();) { p = (NodeProxy) i.next(); if (p.doc.getFileName().equals(docPath)) hitsByDoc.add(p); } --start; if (start < 0 || start > hitsByDoc.getLength()) throw new RemoteException( "index " + start + "out of bounds (" + hitsByDoc.getLength() + ")"); if (start + howmany >= hitsByDoc.getLength()) howmany = hitsByDoc.getLength() - start; Serializer serializer = broker.getSerializer(); Map properties = new TreeMap(); properties.put(Serializer.ENCODING, "UTF-8"); properties.put(Serializer.PRETTY_PRINT, Boolean.toString(indent)); properties.put(Serializer.EXPAND_XINCLUDES, Boolean.toString(xinclude)); properties.put(Serializer.HIGHLIGHT_MATCHES, highlight); serializer.setProperties(properties); xml = new String[howmany]; for (int i = 0; i < howmany; i++) { NodeProxy proxy = ((NodeSet) hitsByDoc).get(start); if (proxy == null) throw new RuntimeException("not found: " + start); xml[i] = serializer.serialize(proxy); } break; default : throw new RemoteException("result set is not a node list"); } return xml; } catch (Exception e) { LOG.warn(e); e.printStackTrace(); throw new RemoteException(e.getMessage(), e); } finally { pool.release(broker); } }
    public byte[] retrieveByDocument( int resultId, int pos, String docPath,                                      String encoding, boolean prettyPrint )         throws RemoteException {        Sessions sessions = Sessions.getInstance();        DBBroker broker = null;        try {            broker = pool.get();            Value qr = (Value) sessions.getQueryResult( resultId );            if ( qr == null )                throw new RemoteException( "result set unknown or timed out" );            String xml = null;            switch ( qr.getType() ) {                case Value.isNodeList:                    NodeList resultSet = qr.getNodeList();                    ArraySet hitsByDoc = new ArraySet( 50 );                    NodeProxy p;                    for ( Iterator i = ( (NodeSet) resultSet ).iterator();                        i.hasNext();  ) {                        p = (NodeProxy) i.next();                        if ( p.doc.getFileName().equals( docPath ) )                            hitsByDoc.add( p );                    }                    if ( pos < 1 || pos > hitsByDoc.getLength() )                        throw new RemoteException( "index " + pos +                            "out of bounds (" +                            hitsByDoc.getLength() + ")" );                    --pos;                    NodeProxy proxy = ( (NodeSet) hitsByDoc ).get( pos );                    if ( proxy == null )                        throw new RuntimeException( "not found: " + pos );                    LOG.debug( "loaded node " + proxy.gid );                    Serializer serializer = broker.getSerializer();                    Map properties = new TreeMap();                    properties.put(Serializer.ENCODING, encoding);                    properties.put(Serializer.PRETTY_PRINT, Boolean.toString(prettyPrint));                    serializer.setProperties( properties );                    xml = serializer.serialize( proxy );                    break;                default:                    throw new RemoteException( "result set is not a node list" );            }            return xml.getBytes( encoding );        } catch ( Exception e ) {            LOG.warn( e );            e.printStackTrace();            throw new RemoteException( e.getMessage(), e );        } finally {            pool.release( broker );        }    }