use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class TagLibraryInfoImpl method createAttribute.
TagAttributeInfo createAttribute(TreeNode elem, String jspVersion) {
String name = null;
String type = null;
String expectedType = null;
String methodSignature = null;
boolean required = false, rtexprvalue = false, reqTime = false, isFragment = false, deferredValue = false, deferredMethod = false;
Iterator list = elem.findChildren();
while (list.hasNext()) {
TreeNode element = (TreeNode) list.next();
String tname = element.getName();
if ("name".equals(tname)) {
name = element.getBody();
} else if ("required".equals(tname)) {
String s = element.getBody();
if (s != null)
required = JspUtil.booleanValue(s);
} else if ("rtexprvalue".equals(tname)) {
String s = element.getBody();
if (s != null)
rtexprvalue = JspUtil.booleanValue(s);
} else if ("type".equals(tname)) {
type = element.getBody();
if ("1.2".equals(jspVersion) && (type.equals("Boolean") || type.equals("Byte") || type.equals("Character") || type.equals("Double") || type.equals("Float") || type.equals("Integer") || type.equals("Long") || type.equals("Object") || type.equals("Short") || type.equals("String"))) {
type = "java.lang." + type;
}
} else if ("fragment".equals(tname)) {
String s = element.getBody();
if (s != null) {
isFragment = JspUtil.booleanValue(s);
}
} else if ("deferred-value".equals(tname)) {
deferredValue = true;
type = "javax.el.ValueExpression";
TreeNode child = element.findChild("type");
if (child != null) {
expectedType = child.getBody();
if (expectedType != null) {
expectedType = expectedType.trim();
}
} else {
expectedType = "java.lang.Object";
}
} else if ("deferred-method".equals(tname)) {
deferredMethod = true;
type = "javax.el.MethodExpression";
TreeNode child = element.findChild("method-signature");
if (child != null) {
methodSignature = child.getBody();
if (methodSignature != null) {
methodSignature = methodSignature.trim();
}
} else {
methodSignature = "java.lang.Object method()";
}
} else if (// Ignored elements
"description".equals(tname) || false) {
;
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.attribute", tname));
}
}
}
if (isFragment) {
/*
* According to JSP.C-3 ("TLD Schema Element Structure - tag"),
* 'type' and 'rtexprvalue' must not be specified if 'fragment' has
* been specified (this will be enforced by validating parser).
* Also, if 'fragment' is TRUE, 'type' is fixed at
* javax.servlet.jsp.tagext.JspFragment, and 'rtexprvalue' is fixed
* at true. See also JSP.8.5.2.
*/
type = "javax.servlet.jsp.tagext.JspFragment";
rtexprvalue = true;
}
if (!rtexprvalue && type == null) {
// According to JSP spec, for static values (those determined at
// translation time) the type is fixed at java.lang.String.
type = "java.lang.String";
}
return new TagAttributeInfo(name, required, type, rtexprvalue, isFragment, null, deferredValue, deferredMethod, expectedType, methodSignature);
}
use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class OriginalTldLocationsCache method getUriFromTld.
/*
* Returns the value of the uri element of the given TLD, or null if the
* given TLD does not contain any such element.
*/
private String getUriFromTld(String resourcePath, InputStream in) throws JasperException {
// Parse the tag library descriptor at the specified resource path
TreeNode tld = new ParserUtils().parseXMLDocument(resourcePath, in);
TreeNode uri = tld.findChild("uri");
if (uri != null) {
String body = uri.getBody();
if (body != null)
return body;
}
return null;
}
use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class SlingTldLocationsCache method getUriFromTld.
/*
* Returns the value of the uri element of the given TLD, or null if the
* given TLD does not contain any such element.
*/
private String getUriFromTld(final URL resource) {
InputStream stream = null;
try {
stream = resource.openStream();
// Parse the tag library descriptor at the specified resource path
TreeNode tld = new ParserUtils().parseXMLDocument(resource.toString(), stream);
TreeNode uri = tld.findChild("uri");
if (uri != null) {
String body = uri.getBody();
if (body != null) {
return body;
}
}
} catch (Exception e) {
// TODO: handle
} finally {
if (stream != null) {
try {
stream.close();
} catch (Throwable t) {
// do nothing
}
}
}
return null;
}
use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class JspCTldLocationsCache method processWebDotXml.
/*
* Populates taglib map described in web.xml.
*/
private void processWebDotXml() throws Exception {
InputStream is = null;
try {
// Acquire input stream to web application deployment descriptor
String altDDName = (String) ctxt.getAttribute(Constants.ALT_DD_ATTR);
URL uri = null;
if (altDDName != null) {
try {
uri = new URL(FILE_PROTOCOL + altDDName.replace('\\', '/'));
} catch (MalformedURLException e) {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.error.internal.filenotfound", altDDName));
}
}
} else {
uri = ctxt.getResource(WEB_XML);
if (uri == null && log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.error.internal.filenotfound", WEB_XML));
}
}
if (uri == null) {
return;
}
is = uri.openStream();
InputSource ip = new InputSource(is);
ip.setSystemId(uri.toExternalForm());
// Parse the web application deployment descriptor
TreeNode webtld;
// altDDName is the absolute path of the DD
if (altDDName != null) {
webtld = new ParserUtils().parseXMLDocument(altDDName, ip);
} else {
webtld = new ParserUtils().parseXMLDocument(WEB_XML, ip);
}
// Allow taglib to be an element of the root or jsp-config (JSP2.0)
TreeNode jspConfig = webtld.findChild("jsp-config");
if (jspConfig != null) {
webtld = jspConfig;
}
Iterator taglibs = webtld.findChildren("taglib");
while (taglibs.hasNext()) {
// Parse the next <taglib> element
TreeNode taglib = (TreeNode) taglibs.next();
String tagUri = null;
String tagLoc = null;
TreeNode child = taglib.findChild("taglib-uri");
if (child != null)
tagUri = child.getBody();
child = taglib.findChild("taglib-location");
if (child != null)
tagLoc = child.getBody();
// Save this location if appropriate
if (tagLoc == null)
continue;
if (uriType(tagLoc) == NOROOT_REL_URI)
tagLoc = "/WEB-INF/" + tagLoc;
String tagLoc2 = null;
if (tagLoc.endsWith(JAR_FILE_SUFFIX)) {
tagLoc = ctxt.getResource(tagLoc).toString();
tagLoc2 = "META-INF/taglib.tld";
}
mappings.put(tagUri, new String[] { tagLoc, tagLoc2 });
}
} finally {
if (is != null) {
try {
is.close();
} catch (Throwable t) {
}
}
}
}
use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class JspCTldLocationsCache method getUriFromTld.
/*
* Returns the value of the uri element of the given TLD, or null if the
* given TLD does not contain any such element.
*/
private String getUriFromTld(String resourcePath, InputStream in) throws JasperException {
// Parse the tag library descriptor at the specified resource path
TreeNode tld = new ParserUtils().parseXMLDocument(resourcePath, in);
TreeNode uri = tld.findChild("uri");
if (uri != null) {
String body = uri.getBody();
if (body != null)
return body;
}
return null;
}
Aggregations