|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
content length of a pageHello, I'd like to be able to return the content length of a turbine generated page (actually it's jetspeed 1), so that the browser can render better. Is this possible somehow? Is there already an existing function for this? If not, any tip on at which point this could be included (I guess just before returning the request stream, when all velocity has been rendered). Cheers, Bo --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
|
|
|
RE: content length of a pageI use the following with Velocity in order to return and render the content of a page. You can verify the length of the page content when doing this. Tony Oslund public String getPageContent(Context context, String path) { StringBuffer content = new StringBuffer(); BufferedReader in = null; try { URL url = new URL(path); HttpMessage msg = new HttpMessage(url); in = new BufferedReader(new InputStreamReader(msg.sendPostMessage())); StringBuffer myBuff = new StringBuffer(); String line = null; while ((line = in.readLine()) != null) { myBuff.append(line + "\n"); } StringReader strReader = new StringReader(temp); StringWriter writer = new StringWriter(); Velocity.evaluate(context, writer, "INFO", strReader); content.append(writer.toString()); } catch (java.net.MalformedURLException e1) { content.append("<p> </p><p>URL Exception: Unable to retrieve page content: (" + path + ") " + e1.getMessage() + "</p>"); } catch (java.io.IOException e2) { content.append("<p> </p><p>IO Exception: Unable to retrieve page content: (" + path + ") " + e2.getMessage() + "</p>"); } catch (Exception e3) { content.append("<p> </p><p>General Exception: Unable to retrieve page content: (" + path + ") " + e3.getMessage() + "</p>"); } finally { if (in != null) { try { in.close(); } catch (Exception e) { content.append("<p>" + e.getMessage() + "</p>"); } } } return content.toString(); } If you were to create a wrapper for it within a "tool" you could access it from within a VM. public String includeContent(RunData data, String path) { Context context = TurbineVelocity.getContext(data); ... (my own security checking code here) return getPageContent(context, url to content); } Then within your VM you could do... #set ($mycontent = $tool.includeContent($data, some url)) #set ($length = $mycontent.length()) $mycontent -- OR -- $tool.includeContent($data, some url) FYI, if the page being pointed at by the url also contains a call to includeContent, then it is recursive ALSO FYI, This is a handy way of implementing a single VM to display lots of generic content (read this as plain old html files) without having to create a VM for each... and still maintain a session. In addition to checking the length, you could also implement a security model for the plain old html files by imbedding some logic within includeContent. Also works great if your web page developers are geographically located someplace other than your programmers, because you can pull the skins for you pages from remote servers (during development). -----Original Message----- From: Jeffery Painter [mailto:painter@...] Sent: Friday, March 13, 2009 1:22 PM To: Turbine Users List Subject: Re: content length of a page I would look first at some of the old examples of extending the RawScreen for sending binary data. This does not solve your problem of a finding the content length of a Turbine/velocity generated page however. You may need some intermediate step to generate the page then calculate it's length before you can then set the content length in the response object. If you search the archives for things related to RawScreen or sending binary data, you may get some help there. You would need to make use of the ByteArrayOutputStream to in essence capture your screen before you send it to the http response. You can then update RunData as such: { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos = someMethodBuildsMyScreen(); data.getResponse().setContentLength(baos.size()); javax.servlet.ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); } I'm not really sure if there is a way to get the content length directly. Maybe you can clarify the problem if this was no help :P -- Jeffery Painter > > Hello, > > I'd like to be able to return the content length of a turbine generated > page (actually it's jetspeed 1), so that the browser can render better. > Is this possible somehow? Is there already an existing function for this? > If not, any tip on at which point this could be included (I guess just > before returning the request stream, when all velocity has been rendered). > > Cheers, Bo > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: content length of a pageHi, I'm familiar with how to do it in my own RawScreen, what I wanted is to apply it to all turbine generated pages. So basically, following your example, I'd like to know what would be the best place to use the result of "someMethodBuildsMyScreen();" within Turbine.. Any clues? Cheers, Bo "Jeffery Painter" <painter@kiasoft. com> Para "Turbine Users List" 13/03/2009 19:22 <user@...> cc Por favor, Asunto responda a Re: content length of a page "Turbine Users List" <user@... che.org> I would look first at some of the old examples of extending the RawScreen for sending binary data. This does not solve your problem of a finding the content length of a Turbine/velocity generated page however. You may need some intermediate step to generate the page then calculate it's length before you can then set the content length in the response object. If you search the archives for things related to RawScreen or sending binary data, you may get some help there. You would need to make use of the ByteArrayOutputStream to in essence capture your screen before you send it to the http response. You can then update RunData as such: { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos = someMethodBuildsMyScreen(); data.getResponse().setContentLength(baos.size()); javax.servlet.ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); } I'm not really sure if there is a way to get the content length directly. Maybe you can clarify the problem if this was no help :P -- Jeffery Painter > > Hello, > > I'd like to be able to return the content length of a turbine generated > page (actually it's jetspeed 1), so that the browser can render better. > Is this possible somehow? Is there already an existing function for this? > If not, any tip on at which point this could be included (I guess just > before returning the request stream, when all velocity has been rendered). > > Cheers, Bo > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: content length of a pageb.v.weert@... wrote:
> I'd like to be able to return the content length of a turbine generated > page (actually it's jetspeed 1), so that the browser can render better. > Is this possible somehow? Is there already an existing function for this? > If not, any tip on at which point this could be included (I guess just > before returning the request stream, when all velocity has been rendered). I assume you are using VelocityOnlyLayout or something similar. The method doBuild() handles all the screen execution and the rendering. If you want to change the processing, you can roll your own and register it in TurbineResources.properties at services.VelocityService.default.layout = MyVelocityLayout Hope this helps, Bye, Thomas. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
| Free embeddable forum powered by Nabble | Forum Help |