if ( d == null ) data = formatErrorMsg( "document " + name + " not found!", DOCUMENT_NOT_FOUND ); else { Serializer serializer = broker.getSerializer(  ); serializer.reset(  ); Map properties = new TreeMap(); properties.put(Serializer.ENCODING, encoding); properties.put(Serializer.PRETTY_PRINT, Boolean.toString(indent)); serializer.setProperties(properties);
if (d == null) data = formatErrorMsg( "document " + name + " not found!", DOCUMENT_NOT_FOUND); else { Serializer serializer = broker.getSerializer(); serializer.reset();
    protected void doGet( HashMap parameters, String name, int len ) {        int howmany = 10;        int start = 1;        boolean summary = false;        boolean indent = false;        String encoding = (String) parameters.get( "_encoding" );        String query = (String) parameters.get( "_xpath" );        String stylesheet = (String) parameters.get( "_xsl" );        String p_howmany = (String) parameters.get( "_howmany" );        if ( encoding == null )            encoding = "UTF-8";        if ( p_howmany != null ) {            try {                howmany = Integer.parseInt( p_howmany );            } catch ( NumberFormatException nfe ) {            }        }        String p_start = (String) parameters.get( "_start" );        if ( p_start != null ) {            try {                start = Integer.parseInt( p_start );            } catch ( NumberFormatException nfe ) {            }        }        String p_summary;        String p_indent;        if ( ( p_summary = (String) parameters.get( "_summarize" ) ) != null )            summary = p_summary.equals( "true" );        if ( ( p_indent = (String) parameters.get( "_indent" ) ) != null )            indent = p_indent.equals( "true" );        String data;        try {            if ( query != null ) {                if ( !( query.startsWith( "document(" )                         || query.startsWith( "collection" )                         || query.startsWith( "doctype(" ) )                     ) {                    Collection parent = broker.getCollection( name );                    if ( parent == null )                        query = "document('" + name + "')" + query;                    else                        query =                            "collection('" + parent.getName(  ) + "')" + query;                }                data =                    search( query, howmany, start, summary, indent, stylesheet );            } else {                if ( name.charAt( 0 ) == '/' )                    name = name.substring( 1 );                if ( name.endsWith( "/" ) ) {                    // print collection contents                    DocumentSet docs = broker.getDocumentsByCollection( name );                    String[] names = docs.getNames(  );                    data = printCollection( name, names );                } else {                    DocumentImpl d =                        (DocumentImpl) broker.getDocument( name );                    if ( d == null )                        data =                            formatErrorMsg( "document " + name + " not found!",                                            DOCUMENT_NOT_FOUND                                            );                    else {                        Serializer serializer = broker.getSerializer(  );                        serializer.reset(  );                        Map properties = new TreeMap();                        properties.put(Serializer.ENCODING, encoding);                        properties.put(Serializer.PRETTY_PRINT, Boolean.toString(indent));                        serializer.setProperties(properties);                        if ( stylesheet != null ) {                            serializer.setStylesheet( d, stylesheet );                        }                        try {                            data = serializer.serialize( d );                        } catch ( SAXException saxe ) {                            HttpServer.LOG.warn( saxe );                            data =                                formatErrorMsg( "error while serializing xml: "                                                + saxe.toString(  ),                                                OUTPUT_ERROR                                                );                        }                    }                }            }        } catch ( PermissionDeniedException e ) {            data =                formatErrorMsg( "permission denied: " + e.getMessage(  ),                                OUTPUT_ERROR                                );        }        try {            byte[] resultData = data.getBytes( encoding );            DataOutputStream out =                new DataOutputStream( new BufferedOutputStream( sock                                                                .getOutputStream(  )                                                                )                                      );            out.writeBytes( "HTTP/1.0 200 OK\n" );            if ( stylesheet == null )                out.writeBytes( "Content-Type: text/xml\n" );            else                out.writeBytes( "Content-Type: text/html\n" );            out.writeBytes( stdHeaders + "Content-Length: " + resultData.length                            + "\n\n"                            );            out.write( resultData, 0, resultData.length );            out.flush(  );            out.close(  );        } catch ( IOException io ) {            HttpServer.LOG.warn( io );        }    }