use of lucee.runtime.PageSource in project Lucee by lucee.
the class Function method evaluate.
@Override
public void evaluate(Tag tag, TagLibTag libTag, FunctionLib[] flibs) throws EvaluatorException {
// Body p=(Body) tag.getParent();
// Statement pp = p.getParent();
boolean isCI = true;
try {
isCI = ASMUtil.getAncestorPage(tag).isComponent() || ASMUtil.getAncestorPage(tag).isInterface();
} catch (TransformerException e) {
}
Attribute attrName = tag.getAttribute("name");
if (attrName != null) {
Expression expr = attrName.getValue();
PageSource ps = null;
if (expr instanceof LitString && !isCI) {
Page p = ASMUtil.getAncestorPage(tag, null);
if (p != null) {
SourceCode sc = p.getSourceCode();
if (sc instanceof PageSourceCode) {
PageSourceCode psc = (PageSourceCode) sc;
ps = psc.getPageSource();
}
}
checkFunctionName(((LitString) expr).getString(), flibs, ps);
}
}
// attribute modifier
boolean isStatic = false;
{
Attribute attrModifier = tag.getAttribute("modifier");
if (attrModifier != null) {
ExprString expr = tag.getFactory().toExprString(attrModifier.getValue());
if (!(expr instanceof Literal))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
String modifier = StringUtil.emptyIfNull(((Literal) expr).getString()).trim();
if (!StringUtil.isEmpty(modifier) && !"abstract".equalsIgnoreCase(modifier) && !"final".equalsIgnoreCase(modifier) && !"static".equalsIgnoreCase(modifier))
throw new EvaluatorException("Attribute modifier of the Tag Function, must be one of the following literal string values: [abstract,final,static]");
isStatic = "static".equalsIgnoreCase(modifier);
boolean abstr = "abstract".equalsIgnoreCase(modifier);
if (abstr)
throwIfNotEmpty(tag);
}
}
// cachedWithin
{
Attribute attrCachedWithin = tag.getAttribute("cachedwithin");
if (attrCachedWithin != null) {
Expression val = attrCachedWithin.getValue();
tag.addAttribute(new Attribute(attrCachedWithin.isDynamicType(), attrCachedWithin.getName(), ASMUtil.cachedWithinValue(val), attrCachedWithin.getType()));
}
}
// Attribute localMode
{
Attribute attrLocalMode = tag.getAttribute("localmode");
if (attrLocalMode != null) {
Expression expr = attrLocalMode.getValue();
String str = ASMUtil.toString(expr, null);
if (!StringUtil.isEmpty(str) && AppListenerUtil.toLocalMode(str, -1) == -1)
throw new EvaluatorException("Attribute localMode of the Tag Function, must be a literal value (modern, classic, true or false)");
// boolean output = ((LitBoolean)expr).getBooleanValue();
// if(!output) ASMUtil.removeLiterlChildren(tag, true);
}
}
// Attribute Output
{
Attribute attrOutput = tag.getAttribute("output");
if (attrOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute output of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// Buffer output
{
Attribute attrBufferOutput = tag.getAttribute("bufferoutput");
if (attrBufferOutput != null) {
Expression expr = tag.getFactory().toExprBoolean(attrBufferOutput.getValue());
if (!(expr instanceof LitBoolean))
throw new EvaluatorException("Attribute bufferOutput of the Tag Function, must be a literal boolean value (true or false, yes or no)");
}
}
// check attribute values
Map<String, Attribute> attrs = tag.getAttributes();
Iterator<Attribute> it = attrs.values().iterator();
while (it.hasNext()) {
checkAttributeValue(tag, it.next());
}
// add to static scope
if (isStatic) {
// remove that tag from parent
ASMUtil.remove(tag);
Body body = (Body) tag.getParent();
StaticBody sb = Static.getStaticBody(body);
sb.addStatement(tag);
}
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class Import method executePT.
private TagLib executePT(Config config, Tag tag, TagLibTag libTag, FunctionLib[] flibs, SourceCode sc) throws TemplateException {
// Attribute prefix
String nameSpace = ASMUtil.getAttributeString(tag, "prefix", null);
if (nameSpace == null)
throw new TemplateException(sc, "attribute [prefix] must be a constant value");
nameSpace = nameSpace.trim();
String nameSpaceSeparator = StringUtil.isEmpty(nameSpace) ? "" : ":";
// Attribute taglib
String textTagLib = ASMUtil.getAttributeString(tag, "taglib", null);
if (textTagLib == null)
throw new TemplateException(sc, "attribute [taglib] must be a constant value");
textTagLib = textTagLib.replace('\\', '/');
textTagLib = ConfigWebUtil.replacePlaceholder(textTagLib, config);
// File TagLib
String ext = ResourceUtil.getExtension(textTagLib, null);
boolean hasTldExtension = "tld".equalsIgnoreCase(ext) || "tldx".equalsIgnoreCase(ext);
Resource absFile = config.getResource(textTagLib);
// TLD
if (absFile.isFile())
return _executeTLD(config, absFile, nameSpace, nameSpaceSeparator, sc);
// Second Change
if (textTagLib.startsWith("/")) {
// config.getPhysical(textTagLib);
PageSource ps = ((ConfigImpl) config).getPageSourceExisting(null, null, textTagLib, false, false, true, false);
// config.getConfigDir()
if (ps != null) {
if (ps.physcalExists()) {
Resource file = ps.getPhyscalFile();
// TLD
if (file.isFile())
return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
}
// CTD
if (!hasTldExtension)
return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
}
} else {
PageSource ps = sc instanceof PageSourceCode ? ((PageSourceCode) sc).getPageSource() : null;
Resource sourceFile = ps == null ? null : ps.getPhyscalFile();
if (sourceFile != null) {
Resource file = sourceFile.getParentResource().getRealResource(textTagLib);
// TLD
if (file.isFile())
return _executeTLD(config, file, nameSpace, nameSpaceSeparator, sc);
// CTD
if (!hasTldExtension)
return _executeCTD(textTagLib, nameSpace, nameSpaceSeparator);
}
}
throw new TemplateException(sc, "invalid definition of the attribute taglib [" + textTagLib + "]");
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class ComponentUtil method getClassname.
public static String getClassname(Component component, ASMProperty[] props) {
String prefix = "";
/*if(props!=null) {
StringBuilder sb=new StringBuilder();
for(int i=0;i<props.length;i++){
sb.append(props[i].toString()).append(';');
}
prefix = Long.toString(HashUtil.create64BitHash(sb),Character.MAX_RADIX);
char c=prefix.charAt(0);
if(c>='0' && c<='9') prefix="a"+prefix;
prefix=prefix+".";
}*/
PageSource ps = component.getPageSource();
return prefix + ps.getComponentName();
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class SourceLastModifiedClassAdapter method registerString.
/**
* return null if not possible to register
* @param bc
* @param str
* @return
* @throws IOException
*/
public Range registerString(BytecodeContext bc, String str) throws IOException {
boolean append = true;
if (staticTextLocation == null) {
if (bc.getPageSource() == null)
return null;
PageSource ps = bc.getPageSource();
Mapping m = ps.getMapping();
staticTextLocation = m.getClassRootDirectory();
staticTextLocation.mkdirs();
staticTextLocation = staticTextLocation.getRealResource(ps.getClassName().replace('.', '/') + ".txt");
if (staticTextLocation.exists())
append = false;
else
staticTextLocation.createFile(true);
off = 0;
}
IOUtil.write(staticTextLocation, str, CharsetUtil.UTF8, append);
Range r = new Range(off, str.length());
off += str.length();
return r;
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class ExpandPath method call.
public static String call(PageContext pc, String relPath) throws PageException {
ConfigWeb config = pc.getConfig();
relPath = prettifyPath(pc, relPath);
String contextPath = pc.getHttpServletRequest().getContextPath();
if (!StringUtil.isEmpty(contextPath) && relPath.startsWith(contextPath + "/")) {
boolean sws = StringUtil.startsWith(relPath, '/');
relPath = relPath.substring(contextPath.length());
if (sws && !StringUtil.startsWith(relPath, '/'))
relPath = "/" + relPath;
}
Resource res;
if (StringUtil.startsWith(relPath, '/')) {
PageContextImpl pci = (PageContextImpl) pc;
ConfigWebImpl cwi = (ConfigWebImpl) config;
PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), relPath, false, pci.useSpecialMappings(), true);
if (!ArrayUtil.isEmpty(sources)) {
// first check for existing
for (int i = 0; i < sources.length; i++) {
if (sources[i].exists()) {
return toReturnValue(relPath, sources[i].getResource());
}
}
// no expand needed
if (!SystemUtil.isWindows() && !sources[0].exists()) {
res = pc.getConfig().getResource(relPath);
if (res.exists()) {
return toReturnValue(relPath, res);
}
}
for (int i = 0; i < sources.length; i++) {
res = sources[i].getResource();
if (res != null) {
return toReturnValue(relPath, res);
}
}
} else // no expand needed
if (!SystemUtil.isWindows()) {
res = pc.getConfig().getResource(relPath);
if (res.exists()) {
return toReturnValue(relPath, res);
}
}
// Resource[] reses = cwi.getPhysicalResources(pc,pc.getApplicationContext().getMappings(),realPath,false,pci.useSpecialMappings(),true);
}
relPath = ConfigWebUtil.replacePlaceholder(relPath, config);
res = pc.getConfig().getResource(relPath);
if (res.isAbsolute())
return toReturnValue(relPath, res);
PageSource ps = pc.getBasePageSource();
res = ps == null ? ResourceUtil.getCanonicalResourceEL(ResourceUtil.toResourceExisting(pc.getConfig(), ReqRspUtil.getRootPath(pc.getServletContext()))) : ResourceUtil.getResource(pc, ps);
if (!res.isDirectory())
res = res.getParentResource();
res = res.getRealResource(relPath);
return toReturnValue(relPath, res);
}
Aggregations