} catch (MalformedURLException e) {
throw new IllegalStateException("Malformed renderer url in page template definition: " + rendererUrlNode);
}
// Create the page template
PageTemplate template = null;
if (className != null) {
Class<? extends PageTemplate> c = null;
try {
c = (Class<? extends PageTemplate>) classLoader.loadClass(className);
template = c.newInstance();
template.setIdentifier(id);
template.setRenderer(rendererUrl);
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Implementation " + className + " for page template '" + id + "' not found", e);
} catch (InstantiationException e) {
throw new IllegalStateException("Error instantiating impelementation " + className + " for page template '" + id + "'", e);
} catch (IllegalAccessException e) {
throw new IllegalStateException("Access violation instantiating implementation " + className + " for page template '" + id + "'", e);
} catch (Throwable t) {
throw new IllegalStateException("Error loading implementation " + className + " for page template '" + id + "'", t);
}
} else {
template = new PageTemplateImpl(id, rendererUrl);
}
// Composeable
template.setComposeable(ConfigurationUtils.isTrue(XPathHelper.valueOf(node, "@composeable", xpath)));
// Default
template.setDefault(ConfigurationUtils.isTrue(XPathHelper.valueOf(node, "@default", xpath)));
// Stage
String stage = XPathHelper.valueOf(node, "ns:stage", xpath);
if (stage != null)
template.setStage(stage);
// Layout
String layout = XPathHelper.valueOf(node, "ns:layout", xpath);
if (layout != null)
template.setDefaultLayout(layout);
// client revalidation time
String recheck = XPathHelper.valueOf(node, "ns:recheck", xpath);
if (recheck != null) {
try {
template.setClientRevalidationTime(ConfigurationUtils.parseDuration(recheck));
} catch (NumberFormatException e) {
throw new IllegalStateException("The page template revalidation time is malformed: '" + recheck + "'");
} catch (IllegalArgumentException e) {
throw new IllegalStateException("The page template revalidation time is malformed: '" + recheck + "'");
}
}
// cache expiration time
String valid = XPathHelper.valueOf(node, "ns:valid", xpath);
if (valid != null) {
try {
template.setCacheExpirationTime(ConfigurationUtils.parseDuration(valid));
} catch (NumberFormatException e) {
throw new IllegalStateException("The page template valid time is malformed: '" + valid + "'", e);
} catch (IllegalArgumentException e) {
throw new IllegalStateException("The page template valid time is malformed: '" + valid + "'", e);
}
}
// name
String name = XPathHelper.valueOf(node, "m:name", xpath);
template.setName(name);
// scripts
NodeList scripts = XPathHelper.selectList(node, "ns:includes/ns:script", xpath);
for (int i = 0; i < scripts.getLength(); i++) {
template.addHTMLHeader(ScriptImpl.fromXml(scripts.item(i)));
}
// links
NodeList links = XPathHelper.selectList(node, "ns:includes/ns:link", xpath);
for (int i = 0; i < links.getLength(); i++) {
template.addHTMLHeader(LinkImpl.fromXml(links.item(i)));
}
return template;
}