Inherits from: NSObject
Package: com.apple.yellow.webobjects
WOMessage is the parent class for both WORequest and WOResponse,and implements much of the behavior that is generic to both. WOMessage represents a message with an HTTP header and either HTML or XML content. HTML content is typically used when interacting with a Web browser, while XML content can be used in messages that originate from or are destined for another application (either an application that "speaks" XML or another WebObjects application).
The methods of the WOMessage class can be divided primarily into two groups, those that deal with a message's content and those that read and set header information. Most of the remaining WOMessage methods control how the content is encoded and allow you to attach arbitrary "user info" to your WOMessage objects in order to pass information about a given message to other objects within your application.
Headers are case-insensitive. WebObjects enforces the HTTP specification, but avoid mixing the case of header keys. See the HTTP specification or HTTP documentation for more information on the HTTP headers and version. |
int Value | WebObjects Name | Notes |
1 | NSASCIIStringEncoding | 0 through 127 |
2 | NSNEXTSTEPStringEncoding | |
3 | NSJapaneseEUCStringEncoding | |
4 | NSUTF8StringEncoding | |
5 | NSISOLatin1StringEncoding | default |
6 | NSSymbolStringEncoding | |
7 | NSNonLossyASCIIStringEncoding | 7-bit verbose ASCII to represent all unichars |
8 | NSShiftJISStringEncoding | |
9 | NSISOLatin2StringEncoding | |
10 | NSUnicodeStringEncoding | |
11 | NSWindowsCP1251StringEncoding | Cyrillic; same as AdobeStandardCyrillic |
12 | NSWindowsCP1252StringEncoding | Windows Latin1 |
13 | NSWindowsCP1253StringEncoding | Windows Greek |
14 | NSWindowsCP1254StringEncoding | Windows Turkish |
15 | NSWindowsCP1250StringEncoding | Windows Latin2 |
21 | NSISO2022JPStringEncoding | ISO 2022 Japanese encoding for electronic mail |
The WOMessage class contains three methods that allow you to construct and interpret messages whose content is formatted as XML. appendContentDOMDocumentFragment allows you to build up an XML message piece by piece. setContentDOMDocument, on the other hand, allows you to specify the message's content all at once. To obtain the content of a message that is formatted as XML, use contentAsDOMDocument.
The arguments to these methods are XML documents (or, in the case of appendContentDOMDocumentFragment, a document fragment) as defined by the Document Object Model (DOM). Installed as a part of WebObjects is the com.ibm.xml.dom package (IBM's alphaWorks), which contains various XML parsers for Java written by IBM. The included DOM parser is used to generate document and document fragment objects from XML data (or to manipulate and/or generate XML data from a document object). For more information on the Document Object Model, see the online documentation at http://www.w3.org/DOM/.
Note that the XML parser is a Java package, and that WOMessage doesn't provide corresponding Objective-C versions of appendContentDOMDocumentFragment, contentAsDOMDocument, and setContentDOMDocument.
- Creation
- WOMessage
- Working with message headers
- appendHeader
- appendHeaders
- headerForKey
- headerKeys
- headers
- headersForKey
- httpVersion
- setHeader
- setHeaders
- setHTTPVersion
- Working with message content
- addCookie
- appendContentCharacter
- appendContentData
- appendContentString
- appendContentDOMDocumentFragment
- content
- contentAsDOMDocument
- cookies
- removeCookie
- setContent
- setContentDOMDocument
- Controlling content encoding
- defaultEncoding
- setDefaultEncoding
- contentEncoding
- setContentEncoding
- Working with user info
- setUserInfo
- userInfo
public WOMessage()
public static int defaultEncoding()
public static void setDefaultEncoding(int aStringEncoding)
public void addCookie(WOCookie aCookie)
See Also: cookies, removeCookie, WOCookie class specification
public void appendContentCharacter(byte aChar)
public void appendContentData(NSData dataObject)
public void appendContentString(String aString)
public void appendContentDOMDocumentFragment(org.w3c.dom.DocumentFragment aDocumentFragment)
Converts the supplied DOM document fragment to an XML string and appends it to the message's contents.
See Also: contentAsDOMDocument, setContentDOMDocument, Messages with XML Content
public void appendHeader(
String aHeader,
String aKey)
aResponse.appendHeader("text/html", "content-type");
See Also: headerForKey, setHeader
public void appendHeaders(
NSArray headerList,
String aKey)
See Also: headerKeys, headersForKey, setHeaders
public NSData content()
An exception is raised if you attempt to get the content when all elements of the page have not had their chance to append HTML to the response. Thus, you should invoke this method in the application object's handleRequest method, after super's handleRequest has been invoked. (For scripted applications, handleRequest is implemented in Application.wos). Note that at this point in the request-handling process, the components, pages, and session have already been put to sleep, so you won't have access to any context, session, or page information. If you need such information for your response, store it somewhere--such as in WOMessage's "user info" dictionary-at a point when you do have access to it. You may want to do this in your application's appendToResponse method, for example.
See Also: setContent, setContentEncoding
public org.w3c.dom.Document contentAsDOMDocument()
Returns the content of the receiver as a DOM document object. Throws a DOMParserException if the DOM parser throws an exception.
See Also: appendContentDOMDocumentFragment, setContentDOMDocument
public int contentEncoding()
The default string encoding is ISO Latin1.
See Also: setContent, setContentEncoding
public NSArray cookies()
See Also: addCookie, removeCookie, WOCookie class specification
public String headerForKey(String aKey)
See Also: setHeader
public NSArray headerKeys()
ImmutableVector hKeys = aMessage.headerKeys(); if (hKeys.contains("expires")) { // do something }
See Also: setHeaders
public NSDictionary headers()
public NSArray headersForKey(String aKey)
See Also: setHeaders
public String httpVersion()
See Also: setHTTPVersion
public void removeCookie(WOCookie aCookie)
See Also: cookies, removeCookie, WOCookie class specification
public void setContent(NSData someData)
See Also: content
public void setContentDOMDocument(org.w3c.dom.Document aDocument)
Sets the XML content of the response to the DOM document aDocument.
See Also: appendContentDOMDocumentFragment, contentAsDOMDocument
public void setContentEncoding(int anEncoding)
See Also: contentEncoding
public void setHTTPVersion(String aVersion)
See Also: httpVersion
public void setHeader(
String aHeader,
String aKey)
aResponse.setHeader("text/html", "content-type");
See Also: appendHeader, headerForKey
public void setHeaders(
NSArray headerList,
String aKey)
See Also: appendHeaders, headerKeys, headersForKey
public void setUserInfo(NSDictionary aDictionary)
public NSDictionary userInfo()
See Also: setUserInfo