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:
Returns:
A new remote content handler.

Extends

Members

(static, readonly) CACHEDIR :File

The default cache directory.
Type:
  • File
Source:

(static, readonly) HTTP :int

A constant representing the HTTP retrieval method.
Type:
  • int
Source:

(static, readonly) SUFFIX :String

The default name of the cache directory.
Type:
  • String
Source:

(static, readonly) XMLRPC :int

A constant representing the XML-RPC retrieval method.
Type:
  • int
Source:

Methods

clear()

Flushes (empties) the cached remote content.
Source:

get(key)

Get an arbitrary property of the remote content.
Parameters:
Name Type Description
key String The name of the property.
Source:
Returns:
The value of the property.

getBinaryMode()

Returns the currently defined binary mode of this client
Inherited From:
Source:
See:
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:
Source:
See:
Returns:
The value of the cookie

getCookies()

Returns all cookies set for this client
Inherited From:
Source:
See:
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:
Source:
See:
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:
Source:
See:
Returns:
The value of the request header field

getKeys()

Get all available property names.
Source:
Returns:
The list of property names.

getMaxResponseSize()

Returns the currently set max response size
Inherited From:
Source:
See:
Returns:
The max responsesize

getMethod()

Returns the currently defined request method.
Inherited From:
Source:
See:
Returns:
The method used

getProxy()

Returns the proxy in host:port format
Inherited From:
Source:
See:
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:
Source:
See:
Returns:
The read timeout in milliseconds

getResponseHandler()

Get the response handler. This is the function used to read the HTTP response body.
Inherited From:
Source:
Returns:
The response handler function

getTimeout()

Returns the connection timeout
Inherited From:
Source:
See:
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:
Source:
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:
Source:
See:
Returns:
The value of the field

needsUpdate()

Tests whether the remote content needs to be updated.
Source:
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:
Source:
See:

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:
Source:

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:
Source:
See:

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:
Source:

setCredentials(username, password)

Sets the credentials for basic http authentication
Parameters:
Name Type Description
username String The username
password String The password
Inherited From:
Source:

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:
Source:
See:

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:
Source:
See:

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:

setMaxResponseSize(Size)

Sets the max allowed size for the response stream
Parameters:
Name Type Description
Size Integer in Byte
Inherited From:
Source:

setMethod(m)

Sets the request method to use.
Parameters:
Name Type Description
m String The method to use (GET, POST ...)
Inherited From:
Source:
See:

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:
Source:
See:

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:
Source:
See:

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:
Source:

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:
Source:
See:

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:
Source:
See:

toString()

Get a string representation of the remote content.
Overrides:
  • helma.Http#toString
Source:
Returns:
The remote content as string.

update()

Get the updated and cached remote content.
Source:
Returns:
The content as retrieved from the remote site.

valueOf()

Get the value of the remote content.
Source:
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:

(static) flush(cache)

Remove all remote content from a file-based cache.
Parameters:
Name Type Description
cache File An optional target directory.
Source:

(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: