Hi there,

On 07/09/2006, at 9:28 AM, Gilles MATHURIN wrote:

Is there a way to obtain programmaticaly the name of the server in order to put it in a ivar ?

Example : "http://g-five.local/cgi-bin/Webobjects/WOapp.woa";

i'd like to be able to have the "g-five.local" part in a programmatic way, in that way my method and component would be more reusable…

In your Properties file put:
WOHost=my.desired.host

Or in Java monitor:
"-DWOHost=my.desired.host"

String host = Application.application().host();

If the above fails to return the desired result... (and you cannot necessary trust the host that user requests from) ... you might also like to set:
WOCGIAdaptorURL=http://my.desire.host/cgi-bin/WebObjects";

And parse it out as follows...

public class Application extends WOApplication {

        private static final Pattern DOMAIN_PATTERN;
        static {
                String outerChars = "[\\w&&[^_]]+"
                String middleChars = "[\\w-&&[^_]]*";
                String partPtn;
                String domainPtn;

                partPtn = outerchars + "(?:" + middleChars + outerChars + ")?";
                domainPtn = "(" + partPtn + "(?:\\." + partPtn + ")+).*";
                DOMAIN_PATTERN = Pattern.compile( domainPtn );

                // or simpler but not checking for correctness:
                // "https?://([\\.\\w-&&[^_]]+/?.*";
        }
        <...>

        /**
         * @return the domain from the cgiAdaptorUrl.
         */
        public String domain() {
                Matcher m;
                String adaptorUrl;

                m = DOMAIN_PATTERN.matcher( cgiAdaptorURL() );
                if ( m.matches() && m.groupCount() == 1 ) {
                        return m.group( 1 );
                }
                throw new RuntimeException( "Cannot obtain adaptor url!" );
        }
        <...>
}

with regards,
--

Lachlan Deck



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to archive@mail-archive.com

Reply via email to