public byte[] getResource( String name, String encoding, boolean prettyPrint ) throws java.rmi.RemoteException { DBBroker broker = null; try { broker = pool.get(); DocumentImpl document = (DocumentImpl) broker.getDocument( name ); if ( document == null ) throw new RemoteException( "resource " + name + " not found" ); Serializer serializer = broker.getSerializer(); String xml = null; if ( prettyPrint ) { StringWriter sout = new StringWriter(); OutputFormat format = new OutputFormat( "xml", encoding, true ); format.setOmitXMLDeclaration( false ); format.setOmitComments( false ); format.setLineWidth( 60 ); XMLSerializer xmlout = new XMLSerializer( sout, format ); serializer.setContentHandler( xmlout ); serializer.setLexicalHandler( xmlout ); serializer.toSAX( document ); xml = sout.toString(); } else xml = serializer.serialize( document ); if ( xml != null ) try { return xml.getBytes( encoding ); } catch ( java.io.UnsupportedEncodingException e ) { return xml.getBytes(); }
public String getResource(String sessionId, String name, boolean indent, boolean xinclude) throws java.rmi.RemoteException { Session session = getSession(sessionId); DBBroker broker = null; try { broker = pool.get(); DocumentImpl document = (DocumentImpl) broker.getDocument(session.getUser(), name); if (document == null) throw new RemoteException("resource " + name + " not found"); Serializer serializer = broker.getSerializer(); Map props = new TreeMap(); props.put(Serializer.ENCODING, "UTF-8"); props.put(Serializer.PRETTY_PRINT, Boolean.toString(indent)); props.put(Serializer.EXPAND_XINCLUDES, Boolean.toString(xinclude)); serializer.setProperties(props);
    public byte[] getResource( String name, String encoding,                               boolean prettyPrint )         throws java.rmi.RemoteException {        DBBroker broker = null;        try {            broker = pool.get();            DocumentImpl document =                (DocumentImpl) broker.getDocument( name );            if ( document == null )                throw new RemoteException( "resource " + name + " not found" );            Serializer serializer = broker.getSerializer();            String xml = null;            if ( prettyPrint ) {                StringWriter sout = new StringWriter();                OutputFormat format =                    new OutputFormat( "xml", encoding, true );                format.setOmitXMLDeclaration( false );                format.setOmitComments( false );                format.setLineWidth( 60 );                XMLSerializer xmlout =                    new XMLSerializer( sout, format );                serializer.setContentHandler( xmlout );                serializer.setLexicalHandler( xmlout );                serializer.toSAX( document );                xml = sout.toString();            }            else                xml = serializer.serialize( document );            if ( xml != null )                try {                    return xml.getBytes( encoding );                } catch ( java.io.UnsupportedEncodingException e ) {                    return xml.getBytes();                }            return null;        } catch ( SAXException saxe ) {            saxe.printStackTrace();            throw new RemoteException( saxe.getMessage() );        } catch ( EXistException e ) {            throw new RemoteException( e.getMessage() );        } catch ( PermissionDeniedException e ) {            throw new RemoteException( e.getMessage() );        } finally {            pool.release( broker );        }    }