use of lucee.runtime.Mapping in project Lucee by lucee.
the class MappingUtil method getMatch.
public static SourceInfo getMatch(PageContext pc, Config config, StackTraceElement trace) {
if (trace.getFileName() == null)
return null;
if (pc == null && config == null)
config = ThreadLocalPageContext.getConfig();
// PageContext pc = ThreadLocalPageContext.get();
Mapping[] mappings = pc != null ? ConfigWebUtil.getAllMappings(pc) : ConfigWebUtil.getAllMappings(config);
if (pc != null)
config = pc.getConfig();
Mapping mapping;
Class clazz;
for (int i = 0; i < mappings.length; i++) {
mapping = mappings[i];
// print.e("virtual:"+mapping.getVirtual()+"+"+trace.getClassName());
// look for the class in that mapping
clazz = ((MappingImpl) mapping).loadClass(trace.getClassName());
if (clazz == null)
continue;
// classname is not distinct, because of that we must check class content
try {
SourceInfo si = ASMUtil.getSourceInfo(config, clazz, false);
if (si != null && trace.getFileName() != null && trace.getFileName().equals(si.absolutePath(pc)))
return si;
} catch (IOException e) {
}
}
return null;
}
use of lucee.runtime.Mapping in project Lucee by lucee.
the class ComponentUtil method _getComponentPropertiesClass.
private static Class _getComponentPropertiesClass(PageContext pc, Component component) throws PageException, IOException, ClassNotFoundException {
ASMProperty[] props = ASMUtil.toASMProperties(component.getProperties(false, true, false, false));
String className = getClassname(component, props);
String real = className.replace('.', '/');
Mapping mapping = component.getPageSource().getMapping();
PhysicalClassLoader cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(false);
Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
// get component class information
String classNameOriginal = component.getPageSource().getClassName();
String realOriginal = classNameOriginal.replace('.', '/');
Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));
// load existing class when pojo is still newer than component class file
if (classFile.lastModified() >= classFileOriginal.lastModified()) {
try {
Class clazz = cl.loadClass(className);
// ClassUtil.loadInstance(clazz);
if (clazz != null && !hasChangesOfChildren(classFile.lastModified(), clazz))
return clazz;
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
// extends
String strExt = component.getExtends();
Class<?> ext = Object.class;
if (!StringUtil.isEmpty(strExt, true)) {
ext = Caster.cfTypeToClass(strExt);
}
//
// create file
byte[] barr = ASMUtil.createPojo(real, props, ext, new Class[] { Pojo.class }, component.getPageSource().getDisplayPath());
ResourceUtil.touch(classFile);
IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(true);
// ClassUtil.loadInstance(cl.loadClass(className));
return cl.loadClass(className);
}
use of lucee.runtime.Mapping 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.Mapping in project Lucee by lucee.
the class CFFunction method loadUDF.
public static UDF loadUDF(PageContext pc, String filename, Collection.Key name, boolean isweb) throws PageException {
ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
String key = isweb ? name.getString() + config.getIdentification().getId() : name.getString();
UDF udf = config.getFromFunctionCache(key);
if (udf != null)
return udf;
Mapping mapping = isweb ? config.getFunctionMapping() : config.getServerFunctionMapping();
Page p = mapping.getPageSource(filename).loadPage(pc, false);
// execute page
Variables old = pc.variablesScope();
pc.setVariablesScope(VAR);
boolean wasSilent = pc.setSilent();
try {
p.call(pc);
Object o = pc.variablesScope().get(name, null);
if (o instanceof UDF) {
udf = (UDF) o;
config.putToFunctionCache(key, udf);
return udf;
}
throw new ExpressionException("there is no Function defined with name [" + name + "] in template [" + mapping.getStrPhysical() + File.separator + filename + "]");
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw Caster.toPageException(t);
} finally {
pc.setVariablesScope(old);
if (!wasSilent)
pc.unsetSilent();
}
}
use of lucee.runtime.Mapping in project Lucee by lucee.
the class AppListenerUtil method toMappings.
public static Mapping[] toMappings(ConfigWeb cw, Object o, Resource source) throws PageException {
Struct sct = Caster.toStruct(o);
Iterator<Entry<Key, Object>> it = sct.entryIterator();
Entry<Key, Object> e;
java.util.List<Mapping> mappings = new ArrayList<Mapping>();
ConfigWebImpl config = (ConfigWebImpl) cw;
String virtual;
while (it.hasNext()) {
e = it.next();
virtual = translateMappingVirtual(e.getKey().getString());
MappingData md = toMappingData(e.getValue(), source);
mappings.add(config.getApplicationMapping("application", virtual, md.physical, md.archive, md.physicalFirst, false));
}
return mappings.toArray(new Mapping[mappings.size()]);
}
Aggregations