use of lucee.runtime.PageSource in project Lucee by lucee.
the class CFTag method cfcStartTag.
// CFC
private int cfcStartTag() throws PageException {
callerScope.initialize(pageContext);
try {
cfc = ComponentLoader.loadComponent(pageContext, source.getPageSource(), ResourceUtil.removeExtension(source.getFilename(), source.getFilename()), false, true);
} catch (PageException e) {
Mapping m = source.getPageSource().getMapping();
ConfigWebImpl c = (ConfigWebImpl) pageContext.getConfig();
if (m == c.getTagMapping())
m = c.getServerTagMapping();
else
m = null;
// is te page source from a tag mapping, so perhaps it was moved from server to web context
if (m != null) {
PageSource ps = m.getPageSource(source.getFilename());
try {
cfc = ComponentLoader.loadComponent(pageContext, ps, ResourceUtil.removeExtension(source.getFilename(), source.getFilename()), false, true);
} catch (PageException e1) {
throw e;
}
} else
throw e;
}
validateAttributes(cfc, attributesScope, StringUtil.ucFirst(ListUtil.last(source.getPageSource().getComponentName(), '.')));
boolean exeBody = false;
try {
Object rtn = Boolean.TRUE;
if (cfc.contains(pageContext, KeyConstants._init)) {
Tag parent = getParent();
while (parent != null && !(parent instanceof CFTag && ((CFTag) parent).isCFCBasedCustomTag())) {
parent = parent.getParent();
}
Struct args = new StructImpl(Struct.TYPE_LINKED);
args.set(KeyConstants._HASENDTAG, Caster.toBoolean(hasBody));
if (parent instanceof CFTag) {
args.set(PARENT, ((CFTag) parent).getComponent());
}
rtn = cfc.callWithNamedValues(pageContext, KeyConstants._init, args);
}
if (cfc.contains(pageContext, ON_START_TAG)) {
Struct args = new StructImpl();
args.set(KeyConstants._ATTRIBUTES, attributesScope);
setCaller(pageContext, args);
rtn = cfc.callWithNamedValues(pageContext, ON_START_TAG, args);
}
exeBody = Caster.toBooleanValue(rtn, true);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
_doCFCCatch(t, "start", true);
}
return exeBody ? EVAL_BODY_BUFFERED : SKIP_BODY;
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class Query method getPageSource.
private PageSource getPageSource() {
if (nestingLevel > 0) {
PageContextImpl pci = (PageContextImpl) pageContext;
List<PageSource> list = pci.getPageSourceList();
int index = list.size() - 1 - nestingLevel;
if (index >= 0)
return list.get(index);
}
return pageContext.getCurrentPageSource();
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class Sprite method _doStartTag.
public int _doStartTag() throws Throwable {
// write out div for single item
pageContext.write("<div id=\"" + _id + "\"></div>");
// handle all items
if (!StringUtil.isEmpty(_ids)) {
String[] ids = ListUtil.listToStringArray(_ids, ',');
String[] strSrcs = ListUtil.listToStringArray(_srcs, ',');
Resource[] srcs = new Resource[strSrcs.length];
Image[] images = new Image[strSrcs.length];
for (int i = 0; i < srcs.length; i++) {
srcs[i] = ResourceUtil.toResourceExisting(pageContext, strSrcs[i]);
images[i] = new Image(srcs[i]);
}
// TODO use the same resource as for cfimage
PageSource ps = pageContext.getCurrentTemplatePageSource();
Resource dir;
if (ps != null) {
Resource curr = ps.getResource();
dir = curr.getParentResource();
} else
dir = SystemUtil.getTempDirectory();
Resource cssDir = dir.getRealResource("css");
Resource pathdir = cssDir;
cssDir.mkdirs();
// the base name for the files we are going to create as a css and image
String baseRenderedFileName = MD5.getDigestAsString(_ids);
Resource cssFileName = cssDir.getRealResource(baseRenderedFileName + ".css");
Resource imgFileName = pathdir.getRealResource(baseRenderedFileName + "." + ResourceUtil.getExtension(src, ""));
// if the files don't exist, then we create them, otherwise
boolean bCreate = !cssFileName.isFile() || !imgFileName.isFile();
// Are we going to create it, let's say no
String css = "";
if (bCreate) {
int imgMaxHeight = 0;
int imgMaxWidth = 0;
Image img;
int actualWidth, actualHeight;
// Setup the max height and width of the new image.
for (int i = 0; i < srcs.length; i++) {
img = images[i];
// set the image original height and width
actualWidth = img.getWidth();
;
actualHeight = img.getHeight();
// Check if there is a height,
imgMaxHeight += actualHeight;
if (actualWidth > imgMaxWidth)
imgMaxWidth = actualWidth;
}
// Create the new image (hence we needed to do two of these items)
Image spriteImage = (Image) ImageNew.call(pageContext, "", "" + imgMaxWidth, "" + imgMaxHeight, "argb");
int placedHeight = 0;
// Loop again but this time, lets do the copy and paste
for (int i = 0; i < srcs.length; i++) {
img = images[i];
spriteImage.paste(img, 1, placedHeight);
css += "#" + ids[i] + " {\n\tbackground: url(" + baseRenderedFileName + "." + ResourceUtil.getExtension(strSrcs[i], "") + ") 0px -" + placedHeight + "px no-repeat; width:" + img.getWidth() + "px; height:" + img.getHeight() + "px;\n} \n";
placedHeight += img.getHeight();
}
// Now Write the CSS and the Sprite Image
ImageWrite.call(pageContext, spriteImage, imgFileName.getAbsolutePath());
IOUtil.write(cssFileName, css, "UTF-8", false);
}
try {
((PageContextImpl) pageContext).getRootOut().appendHTMLHead("<link rel=\"stylesheet\" href=\"css/" + baseRenderedFileName + ".css\" type=\"text/css\" media=\"screen\" title=\"no title\" charset=\"utf-8\">");
} catch (IOException e) {
Caster.toPageException(e);
}
}
return SKIP_BODY;
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class _GetElement method toResourceExisting.
public static Resource toResourceExisting(Config config, ApplicationContext ac, Object obj, boolean onlyDir) {
// Resource root = config.getRootDirectory();
String path = Caster.toString(obj, null);
if (StringUtil.isEmpty(path, true))
return null;
path = path.trim();
Resource res;
PageContext pc = ThreadLocalPageContext.get();
// first check relative to application . cfc
if (pc != null) {
if (ac == null)
ac = pc.getApplicationContext();
// abs path
if (path.startsWith("/")) {
ConfigWebImpl cwi = (ConfigWebImpl) config;
PageSource ps = cwi.getPageSourceExisting(pc, ac == null ? null : ac.getMappings(), path, false, false, true, false);
if (ps != null) {
res = ps.getResource();
if (res != null && (!onlyDir || res.isDirectory()))
return res;
}
} else // real path
{
Resource src = ac != null ? ac.getSource() : null;
if (src != null) {
res = src.getParentResource().getRealResource(path);
if (res != null && (!onlyDir || res.isDirectory()))
return res;
} else // happens when this is called from within the application . cfc (init)
{
res = ResourceUtil.toResourceNotExisting(pc, path);
if (res != null && (!onlyDir || res.isDirectory()))
return res;
}
}
}
// then in the webroot
res = config.getRootDirectory().getRealResource(path);
if (res != null && (!onlyDir || res.isDirectory()))
return res;
// then absolute
res = ResourceUtil.toResourceNotExisting(config, path);
if (res != null && (!onlyDir || res.isDirectory()))
return res;
return null;
}
use of lucee.runtime.PageSource in project Lucee by lucee.
the class Admin method doGetComponent.
/**
* @throws PageException
* @throws PageException
*/
private void doGetComponent() throws PageException {
Struct sct = new StructImpl();
pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
// Base Component
try {
PageSource psCFML = config.getBaseComponentPageSource(CFMLEngine.DIALECT_CFML);
if (psCFML != null && psCFML.exists())
sct.set("baseComponentTemplateCFML", psCFML.getDisplayPath());
else
sct.set("baseComponentTemplateCFML", "");
} catch (PageException e) {
sct.set("baseComponentTemplateCFML", "");
}
try {
PageSource psLucee = config.getBaseComponentPageSource(CFMLEngine.DIALECT_LUCEE);
if (psLucee != null && psLucee.exists())
sct.set("baseComponentTemplateLucee", psLucee.getDisplayPath());
else
sct.set("baseComponentTemplateLucee", "");
} catch (PageException e) {
sct.set("baseComponentTemplateLucee", "");
}
sct.set("strBaseComponentTemplateCFML", config.getBaseComponentTemplate(CFMLEngine.DIALECT_CFML));
sct.set("strBaseComponentTemplateLucee", config.getBaseComponentTemplate(CFMLEngine.DIALECT_LUCEE));
// dump template
try {
PageSource ps = ((PageContextImpl) pageContext).getPageSourceExisting(config.getComponentDumpTemplate());
if (ps != null)
sct.set("componentDumpTemplate", ps.getDisplayPath());
else
sct.set("componentDumpTemplate", "");
} catch (PageException e) {
sct.set("componentDumpTemplate", "");
}
sct.set("strComponentDumpTemplate", config.getComponentDumpTemplate());
sct.set("deepSearch", Caster.toBoolean(config.doComponentDeepSearch()));
sct.set("componentDataMemberDefaultAccess", ComponentUtil.toStringAccess(config.getComponentDataMemberDefaultAccess()));
sct.set("triggerDataMember", Caster.toBoolean(config.getTriggerComponentDataMember()));
sct.set("useShadow", Caster.toBoolean(config.useComponentShadow()));
sct.set("ComponentDefaultImport", config.getComponentDefaultImport());
sct.set("componentLocalSearch", config.getComponentLocalSearch());
sct.set("componentPathCache", config.useComponentPathCache());
}
Aggregations