use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class TagLibraryInfoImpl method createVariable.
TagVariableInfo createVariable(TreeNode elem) {
String nameGiven = null;
String nameFromAttribute = null;
String className = "java.lang.String";
boolean declare = true;
int scope = VariableInfo.NESTED;
Iterator list = elem.findChildren();
while (list.hasNext()) {
TreeNode element = (TreeNode) list.next();
String tname = element.getName();
if ("name-given".equals(tname))
nameGiven = element.getBody();
else if ("name-from-attribute".equals(tname))
nameFromAttribute = element.getBody();
else if ("variable-class".equals(tname))
className = element.getBody();
else if ("declare".equals(tname)) {
String s = element.getBody();
if (s != null)
declare = JspUtil.booleanValue(s);
} else if ("scope".equals(tname)) {
String s = element.getBody();
if (s != null) {
if ("NESTED".equals(s)) {
scope = VariableInfo.NESTED;
} else if ("AT_BEGIN".equals(s)) {
scope = VariableInfo.AT_BEGIN;
} else if ("AT_END".equals(s)) {
scope = VariableInfo.AT_END;
}
}
} else if (// Ignored elements
"description".equals(tname) || false) {
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.variable", tname));
}
}
}
return new TagVariableInfo(nameGiven, nameFromAttribute, className, declare, scope);
}
use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class TagLibraryInfoImpl method createTagFileInfo.
/*
* Parses the tag file directives of the given TagFile and turns them into a
* TagInfo.
*
* @param elem The <tag-file> element in the TLD @param uri The location of
* the TLD, in case the tag file is specified relative to it @param jarFile
* The JAR file, in case the tag file is packaged in a JAR
*
* @return TagInfo correspoding to tag file directives
*/
private TagFileInfo createTagFileInfo(TreeNode elem, String uri, URL jarFileUrl) throws JasperException {
String name = null;
String path = null;
Iterator list = elem.findChildren();
while (list.hasNext()) {
TreeNode child = (TreeNode) list.next();
String tname = child.getName();
if ("name".equals(tname)) {
name = child.getBody();
} else if ("path".equals(tname)) {
path = child.getBody();
} else if ("example".equals(tname)) {
// Ignore <example> element: Bugzilla 33538
} else if ("tag-extension".equals(tname)) {
// Ignore <tag-extension> element: Bugzilla 33538
} else if ("icon".equals(tname) || "display-name".equals(tname) || "description".equals(tname)) {
// Ignore these elements: Bugzilla 38015
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.tagfile", tname));
}
}
}
if (path.startsWith("/META-INF/tags")) {
// Tag file packaged in JAR
ctxt.setTagFileJarUrl(path, jarFileUrl);
} else if (!path.startsWith("/WEB-INF/tags")) {
err.jspError("jsp.error.tagfile.illegalPath", path);
}
TagInfo tagInfo = TagFileProcessor.parseTagFileDirectives(parserController, name, path, this);
return new TagFileInfo(name, path, tagInfo);
}
use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class TagLibraryInfoImpl method createInitParam.
String[] createInitParam(TreeNode elem) {
String[] initParam = new String[2];
Iterator list = elem.findChildren();
while (list.hasNext()) {
TreeNode element = (TreeNode) list.next();
String tname = element.getName();
if ("param-name".equals(tname)) {
initParam[0] = element.getBody();
} else if ("param-value".equals(tname)) {
initParam[1] = element.getBody();
} else if ("description".equals(tname)) {
// Do nothing
;
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.initParam", tname));
}
}
}
return initParam;
}
use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class TagLibraryInfoImpl method createValidator.
private TagLibraryValidator createValidator(TreeNode elem) throws JasperException {
String validatorClass = null;
Map initParams = new Hashtable();
Iterator list = elem.findChildren();
while (list.hasNext()) {
TreeNode element = (TreeNode) list.next();
String tname = element.getName();
if ("validator-class".equals(tname))
validatorClass = element.getBody();
else if ("init-param".equals(tname)) {
String[] initParam = createInitParam(element);
initParams.put(initParam[0], initParam[1]);
} else if (// Ignored elements
"description".equals(tname) || false) {
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.unknown.element.in.validator", tname));
}
}
}
TagLibraryValidator tlv = null;
if (validatorClass != null && !validatorClass.equals("")) {
try {
Class tlvClass = ctxt.getClassLoader().loadClass(validatorClass);
tlv = (TagLibraryValidator) tlvClass.newInstance();
} catch (Exception e) {
err.jspError("jsp.error.tlvclass.instantiation", validatorClass, e);
}
}
if (tlv != null) {
tlv.setInitParameters(initParams);
}
return tlv;
}
use of org.apache.sling.scripting.jsp.jasper.xmlparser.TreeNode in project sling by apache.
the class OriginalTldLocationsCache 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 = null;
// 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) {
}
}
}
}
Aggregations