our company hasn't migrated to t5 yet so my syntax experience in that
version is only limited to 3.1
this is how we handle extending our external shell which generate the
external css links, basically this generates our own custom head to all
pages within our app.
import java.util.Date;
import java.util.Iterator;
import javax.servlet.ServletContext;
import org.apache.tapestry.AbstractComponent;
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.asset.ContextAsset;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.resource.ContextResourceLocation;
public abstract class CssHacksShell extends AbstractComponent {
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();
writeDocType(writer, cycle);
IPage page = getPage();
writer.comment("Application: " +
page.getEngine().getSpecification().getName());
writer.comment("Page: " + page.getPageName());
writer.comment("Generated: " + new Date());
writer.begin("html");
renderInformalParameters(writer, cycle);
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();
//bookmark icon
writer.beginEmpty("link");
writer.attribute("rel", "shortcut icon");
writer.attribute("href", "images/site/favicon.ico");
writer.println();
IRender delegate = getDelegate();
if (delegate != null) {
delegate.render(writer, cycle);
}
String stylesheet = getStylesheet();
if (stylesheet != null) {
writeStylesheetLink(writer, cycle, stylesheet);
}
Iterator i = Tapestry.coerceToIterator(getStylesheets());
if (i != null) {
while (i.hasNext()) {
stylesheet = (String) i.next();
writeStylesheetLink(writer, cycle, stylesheet);
}
}
ServletContext context =
cycle.getRequestContext().getServlet().getServletContext();
IAsset colorStylesheet = null;
if("Home".equals(getPage().getPageName()) ||
"Dealer".equals(stylesheet)) {
colorStylesheet = new ContextAsset(new
ContextResourceLocation(context, "/css/Color-default.css"), null);
} else {
colorStylesheet = new ContextAsset(new
ContextResourceLocation(context, "/css/Color-auto.css"), null);
}
//if user websites, do not apply color theme.
if(!"Site".equals(getPage().getPageName())) {
writer.beginEmpty("link");
writer.attribute("rel", "stylesheet");
writer.attribute("type", "text/css");
writer.attribute("href", colorStylesheet.buildURL(cycle));
writer.println();
}
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 writeDocType(IMarkupWriter writer, IRequestCycle cycle) {
String doctype = getDoctype();
if (Tapestry.isNonBlank(doctype)) {
writer.printRaw("<!DOCTYPE " + doctype + ">");
writer.println();
}
}
private void writeStylesheetLink(IMarkupWriter writer, IRequestCycle
cycle, String stylesheetBase) {
String ffPath = "/css/" + stylesheetBase + "-ff.css";
String normalPath = "/css/" + stylesheetBase + ".css";
String iePath = "/css/" + stylesheetBase + "-ie.css";
ServletContext context =
cycle.getRequestContext().getServlet().getServletContext();
IAsset firefoxStylesheet = new ContextAsset(new
ContextResourceLocation(context, ffPath), null);
IAsset normalStylesheet = new ContextAsset(new
ContextResourceLocation(context, normalPath), null);
IAsset explorerStylesheet = new ContextAsset(new
ContextResourceLocation(context, iePath), null);
writer.beginEmpty("link");
writer.attribute("rel", "extra-keyword stylesheet");
writer.attribute("type", "text/css");
writer.attribute("href", firefoxStylesheet.buildURL(cycle));
writer.println();
writer.beginEmpty("link");
writer.attribute("rel", "stylesheet");
writer.attribute("type", "text/css");
writer.attribute("title", "default");
writer.attribute("href", normalStylesheet.buildURL(cycle));
writer.println();
writer.beginEmpty("link");
writer.attribute("rel", "stylesheet");
writer.attribute("type", "text/css");
writer.attribute("title", "don't select");
writer.attribute("href", explorerStylesheet.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 IRender getDelegate();
public abstract int getRefresh();
public abstract String getStylesheet();
public abstract String getTitle();
public abstract String getDoctype();
public abstract Object getStylesheets();
public abstract boolean getRenderContentType();
}
=========================
the foloowing code is used to generate javascript code into an existing HTML
element. you could modify thsi in a way to use the FileInput class to load a
css sheet into a string. Then search the string for your own custom tag (i
would recommend using the same syntax as ognl to keep it uniform) and have
it replace it with what dynamic data. then inject that string into your
ClasspathResourceLocation object (you will have to figure out how to create
that object dynamically from your string.) once you inject that it should
automagically append your heado f your document with the Iresource you
specified. I dont know if this is exactly what your looking for but it its
better then nothing, remeber this is t3.1.
package com.americanadtrader.main.components;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.IResourceResolver;
import org.apache.tapestry.engine.ILink;
import org.apache.tapestry.html.Body;
import org.apache.tapestry.link.AbsoluteLinkRenderer;
import org.apache.tapestry.resource.ClasspathResourceLocation;
import org.apache.tapestry.util.DefaultResourceResolver;
import com.americanadtrader.main.Constants;
public class AnyLinkRenderer extends AbsoluteLinkRenderer {
private String element;
protected String constructURL(ILink link, String anchor, IRequestCycle
cycle) {
if(!cycle.isRewinding()) {
if(element == null) {
throw new IllegalStateException("element must be specified");
} else if ("a".equals(element)) {
return link.getAbsoluteURL(getScheme(), getServerName(), getPort(),
anchor, true);
} else {
IResourceResolver resourceResolver = new DefaultResourceResolver();
ClasspathResourceLocation openwinScriptLocation = new
ClasspathResourceLocation(resourceResolver, "/scripts/openwin.js");
Body body = Body.get(cycle);
body.addExternalScript(openwinScriptLocation);
return "openwin('" + link.getAbsoluteURL(getScheme(), getServerName(),
getPort(), anchor, true) + "');";
}
} else {
return null;
}
}
protected String getElement() {
return element;
}
public void setElement(String value) {
element = value;
}
public int getPort() {
if("https".equals(getScheme())) {
return Constants.SECURE_PORT;
} else {
return Constants.UNSECURE_PORT;
}
}
protected String getUrlAttribute() {
if ("a".equals(getElement())) {
return "href";
} else {
return "onClick";
}
}
}
~evan
----- Original Message -----
From: "Ken nashua" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <users@tapestry.apache.org>
Sent: Thursday, June 28, 2007 12:55 PM
Subject: RE: is ognl usable inside *.css files ?
Also, is it possible for someone to offer a snippet as how to actually
implement the instrumentation of the CSS logic? is this specified in a
template? Or do I have to write it out to the writer?
Thanks for any assistance.
Best regards
Ken in nashua
_________________________________________________________________
Get a preview of Live Earth, the hottest event this summer - only on MSN
http://liveearth.msn.com?source=msntaglineliveearthhm
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]