Version 6.1 by smmccraw on 2007/07/08 09:46

Hide last authors
smmccraw 5.1 1 == URL's ==
Pascal Robert 3.1 2
3 * wocontext.request().uri() = the URL currently being requested
4
5 There are several different URL's associated with your application, all of which can be retrieved from various methods on WOApplication. Here is a quick cheat sheet of them:
6
7 * WOApplication.application().baseURL() = /WebObjects
8 * WOApplication.application().applicationBaseURL() = /WebObjects
smmccraw 5.1 9 * WOApplication.application().cgiAdaptorURL() = http:~/~/hostname/cgi-bin/WebObjects
10 * WOApplication.application().directConnectURL() = http:~/~/hostname:port/cgi-bin/WebObjects/MyApplication.woa
Pascal Robert 3.1 11 * WOApplication.application().frameworksBaseURL() = /WebObjects/Frameworks
smmccraw 5.1 12 * WOApplication.application().servletConnectURL() = http:~/~/hostname/cgi-bin/WebObjects/MyApplication.woa
13 * WOApplication.application().webserverConnectURL() = http:~/~/hostname/cgi-bin/WebObjects/MyApplication.woa/-port
Pascal Robert 3.1 14
smmccraw 5.1 15 == Browser IP ==
Pascal Robert 3.1 16
smmccraw 5.1 17 {{panel}}
Pascal Robert 3.1 18
smmccraw 5.1 19 /** Returns the IP address of the client.
20 * This should return accurate information whether in direct connect or webserver deployment mode.
21 * If performance caching is turned on on OS X server, this method will correctly use pc-remote-addr
22 * @return The IP address as a string.
23 */
24 public static String clientIP(WORequest request) {
25 Object ipAddress = request.headerForKey("pc-remote-addr");
26 if (ipAddress == null) {
27 ipAddress = request.headerForKey("remote_addr");
28 if( ipAddress == null ) {
29 ipAddress = request.headerForKey("remote_host");
30 if( ipAddress == null ) {
31 ipAddress = request._remoteAddress();
32 if( ipAddress == null ) {
33 ipAddress = request._originatingAddress();
34 if( ipAddress != null ) ipAddress = ((InetAddress)ipAddress).getHostAddress();
35 }
36 }
37 }
38 }
39 return ipAddress == null ? "<address unknown>" : ipAddress.toString();
40 }
Pascal Robert 3.1 41
smmccraw 5.1 42 {{/panel}}
Pascal Robert 3.1 43
smmccraw 5.1 44 == NSArray ==
Pascal Robert 3.1 45
46 It's in the docs, but NSArray's implementation of KeyValueCoding is not really what I was expecting. To get an object at a specific numeric index of an NSArray, you'd use the
47
48 {{panel}}
49
smmccraw 5.1 50 objectAtIndex()
Pascal Robert 3.1 51
52 {{/panel}}
53
54 method. So what does
55
56 {{panel}}
57
smmccraw 5.1 58 NSArray.valueForKey(String key)
Pascal Robert 3.1 59
60 {{/panel}}
61
62 return?
63
smmccraw 5.1 64 Well, first read the docs: file:~/~//OSX/Developer/Documentation/WebObjects/Reference/com/webobjects/foundation/NSArray.html#valueForKey(java.lang.String)
Pascal Robert 3.1 65
66 It turns out that calling valueForKey on an array is the same as calling valueForKey for each element of that array. So if you have an NSArray of Users, calling valueForKey("email"); will return an NSArray of email addresses. calling valueForKey("documents"); will return an NSArray of NSArrays containing document objects. In hindsight (and from looking at the way WOBuilder handles key paths for arrays) this is kind of obvious. But I think the real lesson here is that it is easy to ignore the docs towards the end of an alphabetical page...
67
smmccraw 5.1 68 == HTML-friendly String Truncating ==
Pascal Robert 3.1 69
smmccraw 5.1 70 {{panel}}
Pascal Robert 3.1 71
smmccraw 5.1 72 import org.apache.commons.lang.*; //From Apache
73 import org.clapper.util.text.*; // From http://www.clapper.org/
74
75 public static String stripHTMLTagsAndConcatenate(String htmlString, int numberOfChar) {
76 return (StringUtils.substringBeforeLast(StringUtils.abbreviate((HTMLUtil.stripHTMLTags(htmlString)), numberOfChar), " ")) + "...";
77 }
Pascal Robert 3.1 78
smmccraw 5.1 79 {{/panel}}
Pascal Robert 3.1 80
smmccraw 5.1 81 Category:WebObjects