You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by msantos <mp...@gmail.com> on 2010/10/13 16:08:12 UTC
WebPage: geting string
Hi there.
Is possible instanciate a WebPage component and the getting the string that
represents that webpage? My intention is to create a method that returns a
string representing a html page to use on a email.
Thanks a lot
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p2993717.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by elesi <js...@gmail.com>.
hi,
can we know where the Utils.replaceAll, escapeHighEnd() and
WebPageConstants.SRC_URL_PATTERN came from?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p2996622.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by msantos <mp...@gmail.com>.
its working. thanks a lot
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p3022961.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Martin,
What does method escapeHighEnd() do?
Regards,
Ernesto
On Wed, Oct 13, 2010 at 4:11 PM, Martin Makundi
<ma...@koodaripalvelut.com> wrote:
> Here:
>
>
> /**
> * Renders given page
> * @param pageClass to render
> * @param pageParameters to render with
> * @param clean
> * @return String of HTML produced
> */
> public static String renderPageToString(
> final Class<? extends Page> pageClass,
> final PageParameters pageParameters, boolean clean) {
> String webPageAsString;
> {
> WebApplication webApplication = WebApplication.get();
> ServletContext servletContext = webApplication.getServletContext();
> MockHttpSession servletSession = new MockHttpSession(servletContext);
> servletSession.setTemporary(true);
>
> MockHttpServletRequest servletRequest = new MockHttpServletRequest(
> webApplication, servletSession, servletContext);
> MockHttpServletResponse servletResponse = new MockHttpServletResponse(
> servletRequest);
> servletRequest.initialize();
> servletResponse.initialize();
>
> WebRequest webRequest = new ServletWebRequest(servletRequest);
>
> BufferedWebResponse webResponse = new
> BufferedWebResponse(servletResponse);
> webResponse.setAjax(true);
>
> WebRequestCycle htmlRequestCycle =
> new WebRequestCycle(webApplication, webRequest, webResponse);
>
> BookmarkablePageRequestTarget htmlTarget =
> new BookmarkablePageRequestTarget(pageClass, pageParameters);
>
> htmlRequestCycle.setRequestTarget(htmlTarget);
>
> try {
> htmlRequestCycle.getProcessor().respond(htmlRequestCycle);
>
> if (htmlRequestCycle.wasHandled() == false) {
> htmlRequestCycle.setRequestTarget(new WebErrorCodeResponseTarget(
> HttpServletResponse.SC_NOT_FOUND));
> }
> htmlRequestCycle.detach();
> } finally {
> htmlRequestCycle.getResponse().close();
> }
>
> webPageAsString = webResponse.toString();
> }
>
> // try {
> // FileOutputStream fileOutputStream = new
> FileOutputStream("c:/temp/test.html", false);
> // OutputStreamWriter o = new OutputStreamWriter(fileOutputStream, "UTF8");
> // o.write(webResponse.toString());
> // o.flush();
> // o.close();
> // } catch (Exception e) {
> // throw new IllegalStateException("Bug", e);
> // }
>
> webPageAsString = Utils.replaceAll(webPageAsString,
> WebPageConstants.SRC_URL_PATTERN, "src=\"file:///" +
> WebApplication.get().getServletContext().getRealPath("/") + "/");
>
> if (clean) {
> return escapeHighEnd(webPageAsString.replaceAll("<wicket.*?>", "")
> .replaceAll("</wicket.*?>", "").replaceAll("\\swicketpath=\".*?\"",
> ""));
> }
>
> return escapeHighEnd(webPageAsString);
> }
>
>
> **
> Martin
>
> 2010/10/13 msantos <mp...@gmail.com>:
>>
>> Hi there.
>>
>> Is possible instanciate a WebPage component and the getting the string that
>> represents that webpage? My intention is to create a method that returns a
>> string representing a html page to use on a email.
>>
>> Thanks a lot
>> --
>> View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p2993717.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by msantos <mp...@gmail.com>.
it can only be set once on the 1.5M version
/**
* Sets application name. This method must be called before any other
methods are invoked and
* can only be called once per application instance.
*
* @param name
* unique application name
*/
public final void setName(String name)
{
Args.notEmpty(name, "name");
if (this.name != null)
{
throw new IllegalStateException("Application name can only be set
once.");
}
if (applicationKeyToApplication.get(name) != null)
{
throw new IllegalStateException("Application with name '" + name + "'
already exists.'");
}
this.name = name;
applicationKeyToApplication.put(name, this);
}
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p3022900.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by msantos <mp...@gmail.com>.
the wicket version that i am using is 1.4.12, and that method on the
Application class does not exist neither on the WicketFilter. Wich version
is that source code you linked me?
thanks
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p3022891.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by James Carman <ja...@carmanconsulting.com>.
Take a look at:
http://svn.apache.org/repos/asf/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
It calls setName() on the application object using the name of the
filter. Are you using WicketFilter?
On Mon, Nov 1, 2010 at 5:57 PM, msantos <mp...@gmail.com> wrote:
>
> I have notice that the WebApplication class has a private instance variable
> wich gets the name of the class. It has a getter, but i do not see the
> setter. Is it possible to change? Can we override the getName() method and
> return the name we want, with no problems to the application?
>
> Thanks a lot again
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p3022860.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by msantos <mp...@gmail.com>.
I have notice that the WebApplication class has a private instance variable
wich gets the name of the class. It has a getter, but i do not see the
setter. Is it possible to change? Can we override the getName() method and
return the name we want, with no problems to the application?
Thanks a lot again
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p3022860.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by msantos <mp...@gmail.com>.
Hi there, regarding this code, i have a problem, it is trying to acess a url
that dos not exist once the wicket application class name is diferent the
real application url. it is trying to access "http://localhost/(aplication
name)" but it is deployed with a diferent name because the war file has a
diferent name.
Is possible to change the name of the application to be equals to the war
file name?
thanks again
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p3022135.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by msantos <mp...@gmail.com>.
Thanks a lot, i will try it
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p2994968.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebPage: geting string
Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Here:
/**
* Renders given page
* @param pageClass to render
* @param pageParameters to render with
* @param clean
* @return String of HTML produced
*/
public static String renderPageToString(
final Class<? extends Page> pageClass,
final PageParameters pageParameters, boolean clean) {
String webPageAsString;
{
WebApplication webApplication = WebApplication.get();
ServletContext servletContext = webApplication.getServletContext();
MockHttpSession servletSession = new MockHttpSession(servletContext);
servletSession.setTemporary(true);
MockHttpServletRequest servletRequest = new MockHttpServletRequest(
webApplication, servletSession, servletContext);
MockHttpServletResponse servletResponse = new MockHttpServletResponse(
servletRequest);
servletRequest.initialize();
servletResponse.initialize();
WebRequest webRequest = new ServletWebRequest(servletRequest);
BufferedWebResponse webResponse = new
BufferedWebResponse(servletResponse);
webResponse.setAjax(true);
WebRequestCycle htmlRequestCycle =
new WebRequestCycle(webApplication, webRequest, webResponse);
BookmarkablePageRequestTarget htmlTarget =
new BookmarkablePageRequestTarget(pageClass, pageParameters);
htmlRequestCycle.setRequestTarget(htmlTarget);
try {
htmlRequestCycle.getProcessor().respond(htmlRequestCycle);
if (htmlRequestCycle.wasHandled() == false) {
htmlRequestCycle.setRequestTarget(new WebErrorCodeResponseTarget(
HttpServletResponse.SC_NOT_FOUND));
}
htmlRequestCycle.detach();
} finally {
htmlRequestCycle.getResponse().close();
}
webPageAsString = webResponse.toString();
}
// try {
// FileOutputStream fileOutputStream = new
FileOutputStream("c:/temp/test.html", false);
// OutputStreamWriter o = new OutputStreamWriter(fileOutputStream, "UTF8");
// o.write(webResponse.toString());
// o.flush();
// o.close();
// } catch (Exception e) {
// throw new IllegalStateException("Bug", e);
// }
webPageAsString = Utils.replaceAll(webPageAsString,
WebPageConstants.SRC_URL_PATTERN, "src=\"file:///" +
WebApplication.get().getServletContext().getRealPath("/") + "/");
if (clean) {
return escapeHighEnd(webPageAsString.replaceAll("<wicket.*?>", "")
.replaceAll("</wicket.*?>", "").replaceAll("\\swicketpath=\".*?\"",
""));
}
return escapeHighEnd(webPageAsString);
}
**
Martin
2010/10/13 msantos <mp...@gmail.com>:
>
> Hi there.
>
> Is possible instanciate a WebPage component and the getting the string that
> represents that webpage? My intention is to create a method that returns a
> string representing a html page to use on a email.
>
> Thanks a lot
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/WebPage-geting-string-tp2993717p2993717.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org