You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Apache Wiki <wi...@apache.org> on 2009/06/05 12:30:10 UTC

[Tapestry Wiki] Update of "Tapestry5HowToXhtml" by BenGidley

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for change notification.

The following page has been changed by BenGidley:
http://wiki.apache.org/tapestry/Tapestry5HowToXhtml

The comment on the change is:
Adding 5.1 instructions

------------------------------------------------------------------------------
+ Tapestry by default generates HTML or XML depending on the content type of your application.
+ 
+ The method varies by version
+ 
+  * [#50 Tapestry 5.0 < 13]
+  * [#5013 Tapestry 5.0 > 13]
+  * [#51 Tapestry 5.1]
+ 
+ 
+ == Tapestry 5.0 < 13 ==
+ 
  Step 1:
  
  create your own implementation of MarkupWriterFactory:
@@ -71, +82 @@

  }}}
  
  
+ == Tapestry 5.0 > 13 == 
+ 
  The version above does not work for last version of T5 (something like above 5.0.13). This is an adaptation of the code working with 5.0.14 :
  
  1/ Replace the XhtmlMarkupWriterFactoryImpl by this one :
@@ -140, +153 @@

  	}
  }}}
  
+ 
+ == Tapestry 5.1 ==
+ 
+ Create a class XhtmlMarkupWriterFactory to replace the marker factory
+ 
+ 
+ {{{
+ public class XhtmlMarkupWriterFactory implements MarkupWriterFactory {
+ 	private class XhtmlMarkupModel extends AbstractMarkupModel {
+ 		private final Set<String> DONT_ABRV = new HashSet<String>(
+ 				Arrays.asList("script", "div", "span", "p", "textarea", "select"));
+ 
+ 		public EndTagStyle getEndTagStyle(String element) {
+ 			boolean isDontAbr = DONT_ABRV.contains(element);
+ 			return isDontAbr ? EndTagStyle.REQUIRE : EndTagStyle.ABBREVIATE;
+ 
+ 		}
+ 
+ 		public XhtmlMarkupModel() {
+ 			this(false);
+ 		}
+ 
+ 		public XhtmlMarkupModel(boolean useApostropheForAttributes) {
+ 			super(useApostropheForAttributes);
+ 		}
+ 
+ 		/**
+ 		 * Returns true.
+ 		 */
+ 		public boolean isXML() {
+ 			return true;
+ 		}
+ 	}
+ 
+ 	private final PageContentTypeAnalyzer analyzer;
+ 
+ 	private final RequestPageCache cache;
+ 
+ 
+ 	private final MarkupModel xmlModel = new XhtmlMarkupModel();
+ 
+ 	private final MarkupModel xmlPartialModel = new XhtmlMarkupModel(true);
+ 
+ 	public XhtmlMarkupWriterFactory(PageContentTypeAnalyzer analyzer, RequestPageCache cache) {
+ 		this.analyzer = analyzer;
+ 		this.cache = cache;
+ 	}
+ 
+ 	public MarkupWriter newMarkupWriter(ContentType contentType) {
+ 		return newMarkupWriter(contentType, false);
+ 	}
+ 
+ 	public MarkupWriter newPartialMarkupWriter(ContentType contentType) {
+ 		return newMarkupWriter(contentType, true);
+ 	}
+ 
+ 	@SuppressWarnings({ "UnusedDeclaration" })
+ 	private MarkupWriter newMarkupWriter(ContentType contentType, boolean partial) {
+ 		boolean isHTML = contentType.getMimeType().equalsIgnoreCase("text/html");
+ 
+ 		MarkupModel model = partial
+ 				? (xmlPartialModel)
+ 				: (xmlModel);
+ 
+ 		// The charset parameter sets the encoding attribute of the XML declaration, if
+ 		// not null and if using the XML model.
+ 
+ 		return new MarkupWriterImpl(model, contentType.getCharset());
+ 	}
+ 
+ 	public MarkupWriter newMarkupWriter(String pageName) {
+ 		Page page = cache.get(pageName);
+ 
+ 		ContentType contentType = analyzer.findContentType(page);
+ 
+ 		return newMarkupWriter(contentType);
+ 	}
+ 
+ }
+ }}}
+ 
+ Then add to your AppModule
+ 
+ {{{
+         public static void contributeAlias(
+ 			Configuration<AliasContribution<MarkupWriterFactory>> configuration, PageContentTypeAnalyzer analyzer,
+ 			RequestPageCache cache) {
+ 
+ 		configuration.add(AliasContribution.create(MarkupWriterFactory.class,
+ 				new XhtmlMarkupWriterFactory(analyzer, cache)));
+ 	}
+ }}}
+ 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org