|| !(component instanceof Clay)) {
throw new RuntimeException(messages.getMessage("invalid.binding",
new Object[] { "clayImport" }));
}
ComponentBean text = (ComponentBean) displayElementRoot;
Clay clay = (Clay) component;
String url = (String) clay.getAttributes().get("url");
if (url == null) {
throw new IllegalArgumentException(messages.getMessage(
"missing.attribute", new Object[] { "url", "clayImport" }));
}
url = tagUtils.evalString(url);
boolean escapeXml = true;
String escAttribute = (String) clay.getAttributes().get("escapeXml");
if (escAttribute != null) {
escapeXml = tagUtils.evalBoolean(escAttribute).booleanValue();
}
StringBuffer value = new StringBuffer();
StringBuffer buff = new StringBuffer(url);
// look for a classpath prefix.
int i = buff.indexOf(Globals.CLASSPATH_PREFIX);
if (i > -1) {
buff.delete(0, i + Globals.CLASSPATH_PREFIX.length());
}
InputStream in = null;
try {
// if classpath prefix found, use the classloader
if (i > -1) {
// load form the classpath
ClassLoader classloader = Thread.currentThread()
.getContextClassLoader();
if (classloader == null) {
classloader = this.getClass().getClassLoader();
}
in = classloader.getResourceAsStream(buff.toString());
} else {
// load from the context root
in = context.getExternalContext().getResourceAsStream(
buff.toString());
}
if (in != null) {
int c = 0;
done: while (true) {
c = in.read();
if (c > -1) {
value.append((char) c);
} else {
break done;
}
}
}
} catch (IOException e) {
throw new RuntimeException(messages.getMessage("invalid.attribute",
new Object[] { "url", "clayImport" }));
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
in = null;
}
}
}
if (escAttribute != null) {
if (!escapeXml) {
replace(value, decodeMap);
} else {
replace(value, encodeMap);
}
}
text.setJsfid("outputText");
text.setComponentType("javax.faces.HtmlOutputText");
// add a value attribute
AttributeBean attr = new AttributeBean();
attr.setName("value");
attr.setValue(value.toString());
text.addAttribute(attr);
// add a escape attribute
attr = new AttributeBean();
attr.setName("escape");
attr.setValue(Boolean.FALSE.toString());
text.addAttribute(attr);
// add a isTransient attribute
attr = new AttributeBean();
attr.setName("isTransient");
attr.setValue(Boolean.TRUE.toString());
text.addAttribute(attr);
}