PATH  Documentation > WebObjects 4.5 > WebObjects Reference

Table of Contents

WOResponse


Inherits from: WOMessage NSObject
Implements: WOActionResults
Package: com.apple.yellow.webobjects


Class Description


A WOResponse object represents an HTTP response that an application returns to a Web server to complete a cycle of the request-response loop. The composition of a response occurs during the third and final phase of this loop, a phase marked by the propagation of the appendToResponse message through the objects of the application. The WOApplication object first sends this message, passing in a newly-created WOResponse object as an argument. WOElement objects, which represent the dynamic and static HTML elements on a page, respond to the message by appending their HTML representation to the content of the WOResponse object. WOApplication, WOSession, and WOComponent objects can also respond to the message by adding information to the WOResponse object.

A WOResponse has two major parts: HTML content and HTTP information. The content is what is displayed in a Web browser; it can include escaped HTML, which is HTML code shown "as is," uninterpreted. The other information encapsulated by a WOResponse object is used when handling the response. This HTTP data includes headers, status codes, and version string. See the HTTP specification or HTTP documentation for descriptions of these items.

The WOMessage class-from which WOResponse inherits-declares most of the methods you use when constructing a response. These methods can be divided into two groups, those that add to a response's HTML content and those that read and set HTTP information. To the methods provided by WOMessage, the WOResponse class adds two methods that escape HTML ( appendContentHTMLAttributeValue and appendContentHTMLString). For images and other binary data, use appendContentData (declared in the WOMessage class). You can obtain and set the entire content of the response with WOMessage's content and setContent methods. The following example shows a sequence of appendContent... messages that compose an HTTP "POST" message:

aResponse.appendContentString("<form method=\"POST\" action=\"");
aResponse.appendContentHTMLAttributeValue(aContext.url());
aResponse.appendContentCharacter('"');
aResponse.appendContentString(">");

The remaining WOResponse instance methods set and read the the HTTP status code. WOResponse also provides two class methods that allow you to escape string objects.




Interfaces Implemented


WOActionResults
generateResponse


Method Types


Creation
WOResponse
Working with HTTP status
setStatus
status
Working with HTML content
appendContentHTMLAttributeValue
appendContentHTMLString
generateResponse
stringByEscapingHTMLString
stringByEscapingHTMLAttributeValue
Controlling Client Caching
disableClientCaching


Constructors



WOResponse

public WOResponse()

Returns an initialized WOResponse instance. HTTP status is set to 200 (OK), client caching is enabled, and the default string encoding is made ISO Latin 1.


Static Methods



stringByEscapingHTMLAttributeValue

public static String stringByEscapingHTMLAttributeValue(String aString)

This method takes astring and, if escaping is required, returns a new string with certain characters escaped out. If escaping is not required, no conversion is performed and aString is returned. Use this method to escape strings which will appear as attribute values of a tag. The escaped characters are:
Character Escaped character
& &
" "
\t
\n
\r
< <
> >



stringByEscapingHTMLString

public static String stringByEscapingHTMLString(String aString)

This method takes a string and, if escaping is required, returns a new string with certain characters escaped out. If escaping is not required, no conversion is performed and aString is returned. Use this method to escape strings which will appear in the visible part of an HTML file (that is, not inside a tag). The escaped characters are:
Character Escaped character
& &
" "
< <
> >




Instance Methods



appendContentHTMLAttributeValue

public void appendContentHTMLAttributeValue(String aValue)

Appends an HTML attribute value to the HTTP content after transforming the string aValue into an NSData object using the receiver's content encoding. Special HTML characters ("<", ">", "&", and double quote) are escaped so that the browser does not interpret them. In other words, the message
aResponse.appendContentHTMLAttributeValue("<B>");

would transform the argument to "<B>".

See Also: setContentEncoding ( WOMessage class)



appendContentHTMLString

public void appendContentHTMLString(String aString)

Appends an HTML string to the HTTP response after transforming the string aString into an NSData object using the receiver's content encoding. Special HTML characters ("<", ">", "&", and double quote) are escaped so that the browser does not interpret them. For example, "<P>" becomes "<P>".

See Also: setContentEncoding ( WOMessage class)



disableClientCaching

public void disableClientCaching()

Attempts to disable caching in the client browser by appending a "no-cache" Cache-Control response directive to the HTTP response and by appending Expires and Date values that equal (they are both set to the current date and time).

This method shouldn't be invoked more than once for a given response.



generateResponse

public WOResponse generateResponse()

Returns a WOResponse object. WOResponse's implementation simply returns itself.

See Also: generateResponse (WOComponent)



setStatus

public void setStatus(int anInt)

Sets the HTTP status to anInt. Consult the HTTP specification or HTTP documentation for the significance of status integers.

See Also: status



status

public int status()

Returns an integer code representing the HTTP status. Consult the HTTP specification or HTTP documentation for the significance of these status codes.

By default, the status is 200 ("OK" status).

See Also: setStatus




Table of Contents