Hello Mark,

You are making your life very difficult. Use the new WO 5.4 parser for this.

Here is what I would do: do a 2 stage component parsing. Create you own subclass of WOResponse and override the createResponse method.
        public WOResponse createResponseInContext(WOContext aContext) {
                MyResponse aResponse = new MyResponse();
                if ((aContext != null) && (aContext.request() != null)) {
                        
aResponse.setHTTPVersion(aContext.request().httpVersion());
                }
// note the saving and cloning of the context. you will need to implement those accessor in your Response class
                aResponse.setContext((WOContext)aContext.clone());
                return aResponse;
        }
Then using the new template parser declare your namespace.
protected WOMLDefaultNamespaceProvider createDefaultNamespaceProvider() { WOMLDefaultNamespaceProvider defaultNamespaceProvider = super.createDefaultNamespaceProvider(); defaultNamespaceProvider.addNamespace(new WOMLWebObjectsNamespace("cms"));
                return defaultNamespaceProvider;
        }
And now for the fun part in your WOResponse override
        public WOResponse generateResponse() {
                return this;
        }
What you need to do here is take the content and use it as a template to reparse it and generate the real page.
        public WOResponse generateResponse() {
WOElement template = WOComponentTemplateParser.templateWithHTMLAndDeclaration("app", "second stage parsing", this.contentString(), null, this.context().locales(), WOApplication.application().associationFactory(),
                                                
WOApplication.application().namespaceProvider());
                if (template != null) {
                        WOResponse aResponse = new WOResponse();
                        if (this.context().request() != null) {
                                
aResponse.setHTTPVersion(this.context().request().httpVersion());
                        }
                        try {
                                template.appendToResponse(aResponse, 
this.context());
                        } catch (Exception exception) {
                                throw newException(exception);
                        }
                }
                return aResponse.generateResponse();
        }       
That will generate a second stage parsing. No regular expression. Everything works.

If you prefer you can also create a specific namespace provider that is only used for the second stage parsing and prevent any "polution" of the primary namespace.

Cheers

Pierre
--
Pierre Frisch
[email protected]


On Jun 8, 2009, at 5:58, Mark Gowdy wrote:

Hello,

I need to insert a new sub-component into a page during the request- response cycle (probably within appendToResponse() )

I thought I had achieved this, but all the links on the page are now broken (and other general weirdness unfolds)

This is the essence what I need to achieve (I removed all the specific crud that you don't need)

This breaks:
public void appendToResponse(WOResponse a_rsp, WOContext a_ctx) {
        super.appendToResponse(a_rsp, a_ctx);

//      Prepare a sub-component (then pass it bindings, etc..)
// DisplayArticle generatedContent = ((ERXApplication )ERXApplication.application()).pageWithName(DisplayArticle.class, a_ctx); // the other way DisplayArticle newComponent = (DisplayArticle)pageWithName("DisplayArticle"); String generatedContentForCMSTag = newComponent.generateResponse().contentString();
//      Do stuff
//      Update a_rsp.setContent(adjustedContent);
}

I need this to not break.

I suspect that this is messing up the object graph that it uses when invokeAction and takeValuesFromRequest is called. Do I need to register (or unregister) these components somehow after they are created. The DisplayArticle component ONLY ever use direct actions, so I will not be using normal actions within these.
They do however need to retain their session info.

--

This might look a little bit mad (when out of context), so if you are interested, this is why I want to do it: I am parsing 'a_rsp.contentString();' using a regex so that I can locate tags that may appear (these tags may have come from a string (from a content managed article in the database)
These are in the form:
<cms:DisplayTitle displayTitle = "About Us" linkToArticle = "Y" artTitle = "About Us" /> The plan is to find these, and replace them with a generated component (into which I pass those bindings)

The cool thing is, that the inserted article can also contain one of these tags, hence we have a simple content management structure.

If there is a better way to do this, feel free to enlighten me.

Thanks in advance,

Mark

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

This email sent to [email protected]

Attachment: smime.p7s
Description: S/MIME cryptographic signature

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

This email sent to [email protected]

Reply via email to