Package org.apache.solr.client.solrj.util

## Class ClientUtils

- java.lang.Object
- - org.apache.solr.client.solrj.util.ClientUtils

    public class ClientUtils
    extends Object

Since:
  solr 1.3

### Field Summary

Fields
`static String` `DEFAULT_PATH`
`static String` `TEXT_JSON`
`static String` `TEXT_XML`

### Constructor Summary

Constructors
`ClientUtils()`

### Method Summary

All Methods Static Methods Concrete Methods
`static void` `addSlices​(Map<String,​Slice> target, String collectionName, Collection<Slice> slices, boolean multiCollection)` Constructs a slices map from a collection of slices and handles disambiguation if multiple collections are being queried simultaneously
`static String` `buildRequestUrl​(SolrRequest<?> solrRequest, RequestWriter requestWriter, String serverRootUrl, String collection)` Create the full URL for a SolrRequest (excepting query parameters) as a String
`static String` `encodeLocalParamVal​(String val)` Returns the (literal) value encoded properly, so it can be appended after a `name=` local-param key.
`static String` `escapeQueryChars​(String s)` See: Lucene query parser syntax for more information on Escaping Special Characters
`static boolean` `shouldApplyDefaultCollection​(String providedCollection, SolrRequest<? extends SolrResponse> request)` Determines whether any SolrClient "default" collection should apply to the specified request
`static Collection<ContentStream>` `toContentStreams​(String str, String contentType)` Take a string and make it an iterable ContentStream
`static void` `writeXML​(SolrInputDocument doc, Writer writer)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### TEXT_XML

    public static final String TEXT_XML

See Also:
  Constant Field Values

#### TEXT_JSON

    public static final String TEXT_JSON

See Also:
  Constant Field Values

#### DEFAULT_PATH

    public static final String DEFAULT_PATH

See Also:
  Constant Field Values

### Constructor Detail

#### ClientUtils

    public ClientUtils()

### Method Detail

#### toContentStreams

    public static Collection<ContentStream> toContentStreams​(String str,
                                                             String contentType)

Take a string and make it an iterable ContentStream

#### buildRequestUrl

    public static String buildRequestUrl​(SolrRequest<?> solrRequest,
                                         RequestWriter requestWriter,
                                         String serverRootUrl,
                                         String collection)
                                  throws MalformedURLException

Create the full URL for a SolrRequest (excepting query parameters) as a String

Parameters:
  `solrRequest` - the `SolrRequest` to build the URL for
  `requestWriter` - a `RequestWriter` from the `SolrClient` that will be sending the request
  `serverRootUrl` - the root URL of the Solr server being targeted. May be overridden `SolrRequest.getBasePath()`, if present.
  `collection` - the collection to send the request to. May be null if no collection is needed.
Throws:
  `MalformedURLException` - if `serverRootUrl` or `SolrRequest.getBasePath()` contain a malformed URL string

#### writeXML

    public static void writeXML​(SolrInputDocument doc,
                                Writer writer)
                         throws IOException

Throws:
  `IOException`

#### escapeQueryChars

    public static String escapeQueryChars​(String s)

See: Lucene query parser syntax for more information on Escaping Special Characters

#### encodeLocalParamVal

    public static String encodeLocalParamVal​(String val)

Returns the (literal) value encoded properly, so it can be appended after a `name=` local-param key.

NOTE: This method assumes `$` is a literal character that must be quoted. (It does not assume strings starting `$` should be treated as param references)

#### addSlices

    public static void addSlices​(Map<String,​Slice> target,
                                 String collectionName,
                                 Collection<Slice> slices,
                                 boolean multiCollection)

Constructs a slices map from a collection of slices and handles disambiguation if multiple collections are being queried simultaneously

#### shouldApplyDefaultCollection

    public static boolean shouldApplyDefaultCollection​(String providedCollection,
                                                       SolrRequest<? extends SolrResponse> request)

Determines whether any SolrClient "default" collection should apply to the specified request

Parameters:
  `providedCollection` - a collection/core explicitly provided to the SolrClient (typically through `SolrClient.request(SolrRequest, String)`
  `request` - the `SolrRequest` being executed