Serializer serializer = broker.getSerializer(  ); Map properties = new TreeMap(); properties.put(Serializer.ENCODING, "UTF-8"); properties.put(Serializer.PRETTY_PRINT, Boolean.toString(indent)); serializer.setProperties(properties); return serializer.serialize( d ); }
Serializer serializer = broker.getSerializer(); serializer.setProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setProperty( OutputKeys.INDENT, indent ? "yes" : "no"); return serializer.serialize(d); }
    protected String doPost( String request, String name ) {        int i = name.lastIndexOf( '/' );        if ( i < ( name.length(  ) - 1 ) )            name = name.substring( i + 1 );        else            name = null;        boolean indent = true;        boolean summary = false;        int howmany = 10;        int start = 1;        String query = null;        String result = null;        NodeList tmpList;        Element temp;        try {            InputSource src = new InputSource( new StringReader( request ) );            Document doc = docBuilder.parse( src );            Element root = doc.getDocumentElement(  );            // process <exist:request>            if ( root.getTagName(  ).equals( "exist:request" ) ) {                // process <display indent="true|false" start="start" howmany="howmany">                tmpList = 			root.getElementsByTagNameNS( NS, "display" );                if ( tmpList.getLength(  ) == 0 ) {                    tmpList = root.getElementsByTagNameNS( NS, "summarize" );                    summary = ( tmpList.getLength(  ) > 0 );                }                if ( tmpList.getLength(  ) > 0 ) {                    temp = (Element) tmpList.item( 0 );                    String p_indent = temp.getAttribute( "indent" );                    indent = p_indent.equals( "true" );                    String p_howmany = temp.getAttribute( "howmany" );                    if ( p_howmany != null ) {                        try {                            howmany = Integer.parseInt( p_howmany );                        } catch ( NumberFormatException nfe ) {                            howmany = 15;                        }                    }                    String p_start = temp.getAttribute( "start" );                    if ( p_start != null ) {                        try {                            start = Integer.parseInt( p_start );                        } catch ( NumberFormatException nfe ) {                            start = 1;                        }                    }                }                // process <get document="docName" indent="true|false"/>                tmpList = root.getElementsByTagNameNS( NS, "get" );                if ( tmpList.getLength(  ) > 0 ) {                    temp = (Element) tmpList.item( 0 );                    String docName = temp.getAttribute( "document" );                    DocumentImpl d =                        (DocumentImpl) broker.getDocument( docName );                    if ( d == null )                        return formatErrorMsg( "document " + docName                                               + " not found!",                                               DOCUMENT_NOT_FOUND                                               );                    Serializer serializer = broker.getSerializer(  );					Map properties = new TreeMap();					properties.put(Serializer.ENCODING, "UTF-8");					properties.put(Serializer.PRETTY_PRINT, Boolean.toString(indent));					serializer.setProperties(properties);                    return serializer.serialize( d );                }                // process <query>xpathQuery</query>                tmpList = root.getElementsByTagNameNS( NS, "query" );                if ( tmpList.getLength(  ) > 0 ) {                    temp = (Element) tmpList.item( 0 );                    Text text = (Text) temp.getFirstChild(  );                    query = text.getData(  );                    if ( ( !query.startsWith( "document(" ) )                             && ( !query.startsWith( "doctype(" ) )                         ) {                        if ( ( name != null ) && ( name.length(  ) > 0 ) )                            query = "document(\"" + name + "\")" + query;                        else                            query = "document()" + query;                    }                }                // process <remove document="docName"/>                tmpList = root.getElementsByTagNameNS( NS, "remove" );                if ( tmpList.getLength(  ) > 0 ) {                    temp = (Element) tmpList.item( 0 );                    String docName = temp.getAttribute( "document" );                    DocumentImpl d =                        (DocumentImpl) broker.getDocument( docName );                    if ( d == null )                        return formatErrorMsg( "document " + docName                                               + " not found!",                                               DOCUMENT_NOT_FOUND                                               );                    broker.removeDocument( docName );                    return formatErrorMsg( "removed document " + docName, OK );                }                // execute query                if ( query != null )                    result =                        search( query, howmany, start, summary, indent, null );            } else                result = formatErrorMsg( "not a valid request", WRONG_REQUEST );        } catch ( SAXException e ) {            HttpServer.LOG.debug( request );            HttpServer.LOG.debug( e );            result =                formatErrorMsg( e.getException(  ).toString(  ), WRONG_REQUEST );        } catch ( Exception e ) {            HttpServer.LOG.debug( e );            e.printStackTrace(  );            result = formatErrorMsg( e.toString(  ), WRONG_REQUEST );        }        return result;    }