# Class: RemoteContent

## jala.RemoteContent(url, method, storage)

API to define, fetch and update content from a remote site.

## Constructor

#### new RemoteContent(url, method, storage)

Construct a new remote content handler.

##### Parameters:

Name | Type | Description
--- | --- | ---
`url` | String | The URL string of the remote site.
`method` | Integer | The method to retrieve the remote content.
`storage` | File | The cache directory.

Source:
  - jala/code/RemoteContent.js, line 50

##### Returns:

A new remote content handler.

### Extends

- helma.Http

### Members

#### (static, readonly) CACHEDIR :File

The default cache directory.

##### Type:

- File

Source:
  - jala/code/RemoteContent.js, line 262

#### (static, readonly) HTTP :int

A constant representing the HTTP retrieval method.

##### Type:

- int

Source:
  - jala/code/RemoteContent.js, line 241

#### (static, readonly) SUFFIX :String

The default name of the cache directory.

##### Type:

- String

Source:
  - jala/code/RemoteContent.js, line 255

#### (static, readonly) XMLRPC :int

A constant representing the XML-RPC retrieval method.

##### Type:

- int

Source:
  - jala/code/RemoteContent.js, line 248

### Methods

#### clear()

Flushes (empties) the cached remote content.

Source:
  - jala/code/RemoteContent.js, line 197

#### get(key)

Get an arbitrary property of the remote content.

##### Parameters:

Name | Type | Description
--- | --- | ---
`key` | String | The name of the property.

Source:
  - jala/code/RemoteContent.js, line 136

##### Returns:

The value of the property.

#### getBinaryMode()

Returns the currently defined binary mode of this client

Inherited From:
  - helma.Http#getBinaryMode
Source:
  - helma/Http.js, line 415
See:
  - #setBinaryMode

##### Returns:

The binary mode of this client

#### getCookie(name)

Returns the value of the cookie with the given name

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the cookie

Inherited From:
  - helma.Http#getCookie
Source:
  - helma/Http.js, line 283
See:
  - #setCookie

##### Returns:

The value of the cookie

#### getCookies()

Returns all cookies set for this client

Inherited From:
  - helma.Http#getCookies
Source:
  - helma/Http.js, line 308
See:
  - #setCookie

##### Returns:

An object containing all cookies, where the property name is the name of the cookie, and the value is the cookie value

#### getFollowRedirects()

Returns true if the client follows redirects

Inherited From:
  - helma.Http#getFollowRedirects
Source:
  - helma/Http.js, line 372
See:
  - #setFollowRedirects

##### Returns:

True if the client follows redirects, false otherwise.

#### getHeader(name)

Returns the value of the request header field with the given name

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the request header field

Inherited From:
  - helma.Http#getHeader
Source:
  - helma/Http.js, line 253
See:
  - #setHeader

##### Returns:

The value of the request header field

#### getKeys()

Get all available property names.

Source:
  - jala/code/RemoteContent.js, line 145

##### Returns:

The list of property names.

#### getMaxResponseSize()

Returns the currently set max response size

Inherited From:
  - helma.Http#getMaxResponseSize
Source:
  - helma/Http.js, line 434
See:
  - #setMaxResponseSize

##### Returns:

The max responsesize

#### getMethod()

Returns the currently defined request method.

Inherited From:
  - helma.Http#getMethod
Source:
  - helma/Http.js, line 231
See:
  - #setMethod

##### Returns:

The method used

#### getProxy()

Returns the proxy in `host:port` format

Inherited From:
  - helma.Http#getProxy
Source:
  - helma/Http.js, line 152
See:
  - #setProxy

##### Returns:

The proxy defined for this request

#### getReadTimeout()

Returns the read timeout (the maximum time a request may take after the connection has been successfully established).

Inherited From:
  - helma.Http#getReadTimeout
Source:
  - helma/Http.js, line 352
See:
  - #setReadTimeout

##### Returns:

The read timeout in milliseconds

#### getResponseHandler()

Get the response handler. This is the function used to read the HTTP response body.

Inherited From:
  - helma.Http#getResponseHandler
Source:
  - helma/Http.js, line 457

##### Returns:

The response handler function

#### getTimeout()

Returns the connection timeout

Inherited From:
  - helma.Http#getTimeout
Source:
  - helma/Http.js, line 341
See:
  - #setTimeout

##### Returns:

The connection timeout in milliseconds

#### getUrl(url, opt)

Executes a http request

##### Parameters:

Name | Type | Description
--- | --- | ---
`url` | String | The url to request
`opt` | Date | String | If this argument is a string, it is used as value for the "If-None-Match" request header field. If it is a Date instance it is used as "IfModifiedSince" condition for this request.

Inherited From:
  - helma.Http#getUrl
Source:
  - helma/Http.js, line 486

##### Returns:

A result object containing the following properties:

- `url`: (String) The Url of the request
- `location`: (String) The value of the location header field
- `code`: (Number) The HTTP response code
- `message`: (String) An optional HTTP response message
- `length`: (Number) The content length of the response
- `type`: (String) The mimetype of the response
- `charset`: (String) The character set of the response
- `encoding`: (String) An optional encoding to use with the response
- `lastModified`: (String) The value of the lastModified response header field
- `eTag`: (String) The eTag as received from the remote server
- `cookie`: (helma.Http.Cookie) An object containing the cookie parameters, if the remote server has set the "Set-Cookie" header field
- `headers`: (java.util.Map) A map object containing the headers, access them using get("headername")
- `content`: (String|ByteArray) The response received from the server. Can be either a string or a byte array (see #setBinaryMode)

#### getUserAgent()

Returns the value of the HTTP "User-Agent" header field

Inherited From:
  - helma.Http#getUserAgent
Source:
  - helma/Http.js, line 393
See:
  - #setUserAgent

##### Returns:

The value of the field

#### needsUpdate()

Tests whether the remote content needs to be updated.

Source:
  - jala/code/RemoteContent.js, line 158

##### Returns:

True if the remote content needs to be updated.

#### setBinaryMode(mode)

Switches content text encoding on or off. Depending on this the content received from the remote server will be either a string or a byte array.

##### Parameters:

Name | Type | Description
--- | --- | ---
`mode` | Boolean | If true binary mode is activated

Inherited From:
  - helma.Http#setBinaryMode
Source:
  - helma/Http.js, line 404
See:
  - #getBinaryMode

#### setContent(stringOrObject)

Sets the content to send to the remote server within this request.

##### Parameters:

Name | Type | Description
--- | --- | ---
`stringOrObject` | String | Object | The content of the request, which can be either a string or an object. In the latter case all properties and their values are concatenated into a single string. If a property is an array, then for each value the propertyname and value pair is added. If the name of an array property ends with "_array" then the _array part is removed.

Inherited From:
  - helma.Http#setContent
Source:
  - helma/Http.js, line 181

#### setCookie(name, value)

Adds a cookie with the name and value passed as arguments to the list of cookies to send to the remote server.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the cookie
`value` | String | The value of the cookie

Inherited From:
  - helma.Http#setCookie
Source:
  - helma/Http.js, line 265
See:
  - #getCookie
  - #getCookies

#### setCookies(cookies)

Adds the cookies passed as argument to the list of cookies to send to the remote server.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cookies` | Array | An array containing objects with the properties "name" (the name of the cookie) and "value" (the value of the cookie) set.

Inherited From:
  - helma.Http#setCookies
Source:
  - helma/Http.js, line 293

#### setCredentials(username, password)

Sets the credentials for basic http authentication

##### Parameters:

Name | Type | Description
--- | --- | ---
`username` | String | The username
`password` | String | The password

Inherited From:
  - helma.Http#setCredentials
Source:
  - helma/Http.js, line 167

#### setFollowRedirects(value)

Enables or disables following redirects

##### Parameters:

Name | Type | Description
--- | --- | ---
`value` | Boolean | If false this client won't follow redirects (the default is to follow them)

Inherited From:
  - helma.Http#setFollowRedirects
Source:
  - helma/Http.js, line 362
See:
  - #getFollowRedirects

#### setHeader(name, value)

Sets a single HTTP request header field

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the header field
`value` | String | The value of the header field

Inherited From:
  - helma.Http#setHeader
Source:
  - helma/Http.js, line 241
See:
  - #getHeader

#### setInterval(interval)

Set the interval the remote content's cache is bound to be updated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`interval` | Number | The interval value in milliseconds.

Source:
  - jala/code/RemoteContent.js, line 126

#### setMaxResponseSize(Size)

Sets the max allowed size for the response stream

##### Parameters:

Name | Type | Description
--- | --- | ---
`Size` | Integer | in Byte

Inherited From:
  - helma.Http#setMaxResponseSize
Source:
  - helma/Http.js, line 423

#### setMethod(m)

Sets the request method to use.

##### Parameters:

Name | Type | Description
--- | --- | ---
`m` | String | The method to use (`GET`, `POST` ...)

Inherited From:
  - helma.Http#setMethod
Source:
  - helma/Http.js, line 220
See:
  - #getMethod

#### setProxy(proxyString)

Sets the proxy host and port for later use. The argument must be in `host:port` format (eg. "proxy.example.com:3128").

##### Parameters:

Name | Type | Description
--- | --- | ---
`proxyString` | String | The proxy to use for this request

Inherited From:
  - helma.Http#setProxy
Source:
  - helma/Http.js, line 125
See:
  - #getProxy

#### setReadTimeout(timeout)

Sets the read timeout (the maximum time a request may take after the connection has been successfully established) to the amount of milliseconds passed as argument.

##### Parameters:

Name | Type | Description
--- | --- | ---
`timeout` | Number | The read timeout in milliseconds

Inherited From:
  - helma.Http#setReadTimeout
Source:
  - helma/Http.js, line 330
See:
  - #getReadTimeout

#### setResponseHandler(Response)

Overloads the default response handler. Use this do implement your own response handling, like storing the response directly to the harddisk The handler function gets two parameter, first is the java.net.URLConnection and second is the result object. Note that custom response handler functions should check the HTTP status code before reading the response. The status code for successful requests is 200. Response bodies for requests with status codes less than 400 can be read from the connection's input stream, while response bodies with 4xx or 5xx status codes must be read using the error stream.

##### Parameters:

Name | Type | Description
--- | --- | ---
`Response` | function | handler function

Inherited From:
  - helma.Http#setResponseHandler
Source:
  - helma/Http.js, line 448

#### setTimeout(timeout)

Sets the connection timeout to the amount of milliseconds passed as argument

##### Parameters:

Name | Type | Description
--- | --- | ---
`timeout` | Number | The connection timeout in milliseconds

Inherited From:
  - helma.Http#setTimeout
Source:
  - helma/Http.js, line 318
See:
  - #getTimeout

#### setUserAgent(agent)

Sets the HTTP "User-Agent" header field to the string passed as argument

##### Parameters:

Name | Type | Description
--- | --- | ---
`agent` | String | The string to use as value of the "User-Agent" header field (defaults to "Helma Http Client")

Inherited From:
  - helma.Http#setUserAgent
Source:
  - helma/Http.js, line 382
See:
  - #getUserAgent

#### toString()

Get a string representation of the remote content.

Overrides:
  - helma.Http#toString
Source:
  - jala/code/RemoteContent.js, line 220

##### Returns:

The remote content as string.

#### update()

Get the updated and cached remote content.

Source:
  - jala/code/RemoteContent.js, line 175

##### Returns:

The content as retrieved from the remote site.

#### valueOf()

Get the value of the remote content.

Source:
  - jala/code/RemoteContent.js, line 229

##### Returns:

The remote content including response header data.

#### (static) exec(callback, cache)

Apply a custom method on all remote content in a file-based cache.

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | The callback method to be executed for each remote content file.
`cache` | File | An optional target directory.

Deprecated:
  - Use #forEach instead.
Source:
  - jala/code/RemoteContent.js, line 305

#### (static) flush(cache)

Remove all remote content from a file-based cache.

##### Parameters:

Name | Type | Description
--- | --- | ---
`cache` | File | An optional target directory.

Source:
  - jala/code/RemoteContent.js, line 268

#### (static) forEach(callback, cache)

Apply a custom method on all remote content in a file-based cache.

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | The callback method to be executed for each remote content file.
`cache` | File | An optional target directory.

Source:
  - jala/code/RemoteContent.js, line 282