You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Stefano Bagnara <ba...@ngi.it> on 2003/08/25 15:48:53 UTC

How to specify dtd url in Shell component

I have to output compliant XHTML 1.0 output and I had to write 
The dtd name: "-//W3C//DTD XHTML 1.0 Strict//EN"
And the dtd url: "http://my-server/my.dtd"

W3C validator warn me if I don't put the dtd url in the html source.

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "DTD/xhtml1-strict.dtd">

I added the DTD static-binding in the call to the Shell component but
I've not found a way to add the url, too. Have I to extend the Shell
component or is there a different way to do that?

2nd question: @Image component puts onMouseOver and onMouseOut
attributes with upcase M and O: would it be more "compliant" to output
all attributes and all generated html downcase?

-b-


Re: How to specify dtd url in Shell component

Posted by John Meredith <ps...@t-online.de>.
[Dagnamit - my previous email got lost. Apologies if it does eventually
turn up]

Hi Stefano,

To achieve what you want, just extend the Shell component (I called mine
Hull):

import java.util.Date;
import java.util.Iterator;

import org.apache.commons.lang.StringUtils;
import org.apache.tapestry.IAsset;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRender;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.html.Shell;

/**
 *  @version $Id: Hull.java,v 1.1 2003/08/24 08:41:53 johnm Exp $
 *  @author John Meredith
 **/
public abstract class Hull extends Shell {
        private static final String generatorContent = "Tapestry
Application
Framework, version " + Tapestry.VERSION;

        protected void renderComponent(IMarkupWriter writer,
IRequestCycle
cycle) {
                long startTime = 0;

                boolean rewinding = cycle.isRewinding();

                if (!rewinding) {
                        startTime = System.currentTimeMillis();

                        String DTD = getDTD();
                        String url = getUrl();

                        if (!StringUtils.isEmpty(DTD)) {
                                if (getXml()) {
                                        writer.printRaw("<?xml
version=\"1.0\" encoding=\"UTF-8\"?>");
                                        writer.println();
                                }

                                writer.printRaw("<!DOCTYPE HTML PUBLIC
\"");
                                writer.printRaw(DTD);
                                writer.printRaw("\" \"");
                                writer.printRaw(url);
                                writer.printRaw("\">");
                                writer.println();
                        }

                        IPage page = getPage();

                        writer.comment("Application: " +
page.getEngine().getSpecification().getName());

                        writer.comment("Page: " + page.getPageName());
                        writer.comment("Generated: " + new Date());

                        writer.begin("html");
                        if (getXmlns())
                                writer.attribute("xmlns",
"http://www.w3.org/1999/xhtml");
                        writer.println();

                        writer.begin("head");
                        writer.println();

                        writer.beginEmpty("meta");
                        writer.attribute("name", "generator");
                        writer.attribute("content", generatorContent);
                        writer.println();

                        if (getRenderContentType()) {
                                // This should not be necessary (the
HTTP content type should be
sufficient), 
                                // but some browsers require it for some
reason
                                writer.beginEmpty("meta");
                                writer.attribute("http-equiv",
"Content-Type");
                                writer.attribute("content",
writer.getContentType());
                                writer.println();
                        }

                        writer.begin("title");

                        writer.print(getTitle());
                        writer.end(); // title
                        writer.println();

                        IRender delegate = getDelegate();

                        if (delegate != null)
                                delegate.render(writer, cycle);

                        IAsset stylesheet = getStylesheet();

                        if (stylesheet != null)
                                writeStylesheetLink(writer, cycle,
stylesheet);

                        Iterator i =
Tapestry.coerceToIterator(getStylesheets());

                        if (i != null) {
                                while (i.hasNext()) {
                                        stylesheet = (IAsset) i.next();

                                        writeStylesheetLink(writer,
cycle, stylesheet);
                                }
                        }

                        writeRefresh(writer, cycle);

                        writer.end(); // head
                }

                // Render the body, the actual page content

                renderBody(writer, cycle);

                if (!rewinding) {
                        writer.end(); // html
                        writer.println();

                        long endTime = System.currentTimeMillis();

                        writer.comment("Render time: ~ " + (endTime -
startTime) + " ms");
                }

        }

        private void writeStylesheetLink(IMarkupWriter writer,
IRequestCycle
cycle, IAsset stylesheet) {
                writer.beginEmpty("link");
                writer.attribute("rel", "stylesheet");
                writer.attribute("type", "text/css");
                writer.attribute("href", stylesheet.buildURL(cycle));
                writer.println();
        }

        private void writeRefresh(IMarkupWriter writer, IRequestCycle
cycle) {
                int refresh = getRefresh();

                if (refresh <= 0)
                        return;

                // Here comes the tricky part ... have to assemble a
complete URL
                // for the current page.

                IEngineService pageService =
cycle.getEngine().getService(Tapestry.PAGE_SERVICE);
                String pageName = getPage().getPageName();

                ILink link = pageService.getLink(cycle, null, new
String[] { pageName
});

                StringBuffer buffer = new StringBuffer();
                buffer.append(refresh);
                buffer.append("; URL=");
                buffer.append(link.getAbsoluteURL());

                // Write out the <meta> tag

                writer.beginEmpty("meta");
                writer.attribute("http-equiv", "Refresh");
                writer.attribute("content", buffer.toString());
        }


        public abstract String getUrl();
        public abstract void setUrl(String url);

        public abstract boolean getXmlns();
        public abstract void setXmlns(boolean xmlns);
}

The Hull.jwc:

<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id: Hull.jwc,v 1.1 2003/08/24 08:41:53 johnm Exp $ -->

<!DOCTYPE component-specification PUBLIC "-//Apache Software
Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
        
<component-specification class="tm.tapestry.components.Hull"
allow-informal-parameters="no">
        <parameter name="title" type="java.lang.String" required="yes"
direction="in"/>
        <parameter name="stylesheet" type="org.apache.tapestry.IAsset"
direction="in"/>
        <parameter name="stylesheets" type="java.lang.Object"
direction="in" />
        <parameter name="DTD" type="java.lang.String"   direction="in"/>
        <parameter name="url" type="java.lang.String" direction="in" />
        <parameter name="xmlns" type="boolean" direction="in" />
        <parameter name="renderContentType" type="boolean"
direction="in"
default-value="false" />
        <parameter name="refresh" type="int" direction="in"/>
        <parameter name="delegate"
type="org.apache.tapestry.IRender"      direction="in"/>
</component-specification>

They may be a better way ... but it seems to work. Hope this helps.

  - John

On Mon, 2003-08-25 at 16:14, John Meredith wrote:
> Actually, it would probably be a good idea to add a url property to the
> Shell property in Tapestry itself. Apparently browsers react differently
> depending on whether it's specified or not:
> 
> http://www.ericmeyeroncss.com/bonus/render-mode.html
> 
> Thoughts anyone?
> 
>   - John
> 
> On Mon, 2003-08-25 at 15:48, Stefano Bagnara wrote:
> > I have to output compliant XHTML 1.0 output and I had to write 
> > The dtd name: "-//W3C//DTD XHTML 1.0 Strict//EN"
> > And the dtd url: "http://my-server/my.dtd"
> > 
> > W3C validator warn me if I don't put the dtd url in the html source.
> > 
> > <!DOCTYPE html 
> >      PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> >      "DTD/xhtml1-strict.dtd">
> > 
> > I added the DTD static-binding in the call to the Shell component but
> > I've not found a way to add the url, too. Have I to extend the Shell
> > component or is there a different way to do that?
> > 
> > 2nd question: @Image component puts onMouseOver and onMouseOut
> > attributes with upcase M and O: would it be more "compliant" to output
> > all attributes and all generated html downcase?
> > 
> > -b-
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
-- 
John Meredith <ps...@t-online.de>

Re: How to specify dtd url in Shell component

Posted by John Meredith <ps...@t-online.de>.
Actually, it would probably be a good idea to add a url property to the
Shell property in Tapestry itself. Apparently browsers react differently
depending on whether it's specified or not:

http://www.ericmeyeroncss.com/bonus/render-mode.html

Thoughts anyone?

  - John

On Mon, 2003-08-25 at 15:48, Stefano Bagnara wrote:
> I have to output compliant XHTML 1.0 output and I had to write 
> The dtd name: "-//W3C//DTD XHTML 1.0 Strict//EN"
> And the dtd url: "http://my-server/my.dtd"
> 
> W3C validator warn me if I don't put the dtd url in the html source.
> 
> <!DOCTYPE html 
>      PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>      "DTD/xhtml1-strict.dtd">
> 
> I added the DTD static-binding in the call to the Shell component but
> I've not found a way to add the url, too. Have I to extend the Shell
> component or is there a different way to do that?
> 
> 2nd question: @Image component puts onMouseOver and onMouseOut
> attributes with upcase M and O: would it be more "compliant" to output
> all attributes and all generated html downcase?
> 
> -b-
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
-- 
John Meredith <ps...@t-online.de>

Re: How to specify dtd url in Shell component

Posted by John Meredith <ps...@t-online.de>.
Hi Stefano,

To achieve what you want, just extend the Shell component (I called mine
Hull):

import java.util.Date;
import java.util.Iterator;

import org.apache.commons.lang.StringUtils;
import org.apache.tapestry.IAsset;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRender;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.html.Shell;

/**
 *  @version $Id: Hull.java,v 1.1 2003/08/24 08:41:53 johnm Exp $
 *  @author John Meredith
 **/
public abstract class Hull extends Shell {
	private static final String generatorContent = "Tapestry Application
Framework, version " + Tapestry.VERSION;

	protected void renderComponent(IMarkupWriter writer, IRequestCycle
cycle) {
		long startTime = 0;

		boolean rewinding = cycle.isRewinding();

		if (!rewinding) {
			startTime = System.currentTimeMillis();

			String DTD = getDTD();
			String url = getUrl();

			if (!StringUtils.isEmpty(DTD)) {
				if (getXml()) {
					writer.printRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
					writer.println();
				}

				writer.printRaw("<!DOCTYPE HTML PUBLIC \"");
				writer.printRaw(DTD);
				writer.printRaw("\" \"");
				writer.printRaw(url);
				writer.printRaw("\">");
				writer.println();
			}

			IPage page = getPage();

			writer.comment("Application: " +
page.getEngine().getSpecification().getName());

			writer.comment("Page: " + page.getPageName());
			writer.comment("Generated: " + new Date());

			writer.begin("html");
			if (getXmlns())
				writer.attribute("xmlns", "http://www.w3.org/1999/xhtml");
			writer.println();

			writer.begin("head");
			writer.println();

			writer.beginEmpty("meta");
			writer.attribute("name", "generator");
			writer.attribute("content", generatorContent);
			writer.println();

			if (getRenderContentType()) {
				// This should not be necessary (the HTTP content type should be
sufficient), 
				// but some browsers require it for some reason
				writer.beginEmpty("meta");
				writer.attribute("http-equiv", "Content-Type");
				writer.attribute("content", writer.getContentType());
				writer.println();
			}

			writer.begin("title");

			writer.print(getTitle());
			writer.end(); // title
			writer.println();

			IRender delegate = getDelegate();

			if (delegate != null)
				delegate.render(writer, cycle);

			IAsset stylesheet = getStylesheet();

			if (stylesheet != null)
				writeStylesheetLink(writer, cycle, stylesheet);

			Iterator i = Tapestry.coerceToIterator(getStylesheets());

			if (i != null) {
				while (i.hasNext()) {
					stylesheet = (IAsset) i.next();

					writeStylesheetLink(writer, cycle, stylesheet);
				}
			}

			writeRefresh(writer, cycle);

			writer.end(); // head
		}

		// Render the body, the actual page content

		renderBody(writer, cycle);

		if (!rewinding) {
			writer.end(); // html
			writer.println();

			long endTime = System.currentTimeMillis();

			writer.comment("Render time: ~ " + (endTime - startTime) + " ms");
		}

	}

	private void writeStylesheetLink(IMarkupWriter writer, IRequestCycle
cycle, IAsset stylesheet) {
		writer.beginEmpty("link");
		writer.attribute("rel", "stylesheet");
		writer.attribute("type", "text/css");
		writer.attribute("href", stylesheet.buildURL(cycle));
		writer.println();
	}

	private void writeRefresh(IMarkupWriter writer, IRequestCycle cycle) {
		int refresh = getRefresh();

		if (refresh <= 0)
			return;

		// Here comes the tricky part ... have to assemble a complete URL
		// for the current page.

		IEngineService pageService =
cycle.getEngine().getService(Tapestry.PAGE_SERVICE);
		String pageName = getPage().getPageName();

		ILink link = pageService.getLink(cycle, null, new String[] { pageName
});

		StringBuffer buffer = new StringBuffer();
		buffer.append(refresh);
		buffer.append("; URL=");
		buffer.append(link.getAbsoluteURL());

		// Write out the <meta> tag

		writer.beginEmpty("meta");
		writer.attribute("http-equiv", "Refresh");
		writer.attribute("content", buffer.toString());
	}


	public abstract String getUrl();
	public abstract void setUrl(String url);

	public abstract boolean getXmlns();
	public abstract void setXmlns(boolean xmlns);
}

The Hull.jwc:

<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id: Hull.jwc,v 1.1 2003/08/24 08:41:53 johnm Exp $ -->

<!DOCTYPE component-specification PUBLIC "-//Apache Software
Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
	
<component-specification class="tm.tapestry.components.Hull"
allow-informal-parameters="no">
	<parameter name="title" type="java.lang.String" required="yes"
direction="in"/>
	<parameter name="stylesheet" type="org.apache.tapestry.IAsset"
direction="in"/>
	<parameter name="stylesheets" type="java.lang.Object" direction="in" />
	<parameter name="DTD" type="java.lang.String"	direction="in"/>
	<parameter name="url" type="java.lang.String" direction="in" />
	<parameter name="xmlns"	type="boolean" direction="in" />
	<parameter name="renderContentType" type="boolean" direction="in"
default-value="false" />
	<parameter name="refresh" type="int" direction="in"/>
	<parameter name="delegate"
type="org.apache.tapestry.IRender"	direction="in"/>
</component-specification>

They may be a better way ... but it seems to work. Hope this helps.

  - John

On Mon, 2003-08-25 at 15:48, Stefano Bagnara wrote:
> I have to output compliant XHTML 1.0 output and I had to write 
> The dtd name: "-//W3C//DTD XHTML 1.0 Strict//EN"
> And the dtd url: "http://my-server/my.dtd"
> 
> W3C validator warn me if I don't put the dtd url in the html source.
> 
> <!DOCTYPE html 
>      PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
>      "DTD/xhtml1-strict.dtd">
> 
> I added the DTD static-binding in the call to the Shell component but
> I've not found a way to add the url, too. Have I to extend the Shell
> component or is there a different way to do that?
> 
> 2nd question: @Image component puts onMouseOver and onMouseOut
> attributes with upcase M and O: would it be more "compliant" to output
> all attributes and all generated html downcase?
> 
> -b-
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
-- 
John Meredith <ps...@t-online.de>