use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class Props method _writeOut.
private static void _writeOut(PageContext pc, Props props, Object queryFormat, Object rtn, Charset cs, boolean setFormat) throws ConverterException, PageException, IOException {
// return type XML ignore WDDX
if (props.type == CFTypes.TYPE_XML) {
// if(UDF.RETURN_FORMAT_WDDX==format) format=UDF.RETURN_FORMAT_PLAIN;
rtn = Caster.toString(Caster.toXML(rtn));
} else
// function does no real cast, only check it
rtn = Caster.castTo(pc, (short) props.type, props.strType, rtn);
if (setFormat)
setFormat(pc.getHttpServletResponse(), props.format, cs);
// WDDX
if (UDF.RETURN_FORMAT_WDDX == props.format) {
WDDXConverter converter = new WDDXConverter(pc.getTimeZone(), false, false);
converter.setTimeZone(pc.getTimeZone());
pc.forceWrite(converter.serialize(rtn));
} else // JSON
if (UDF.RETURN_FORMAT_JSON == props.format) {
boolean byColumn = false;
if (queryFormat instanceof String) {
String strQF = ((String) queryFormat).trim();
if (strQF.equalsIgnoreCase("row"))
;
else if (strQF.equalsIgnoreCase("column"))
byColumn = true;
else
throw new ApplicationException("invalid queryformat definition [" + strQF + "], valid formats are [row,column]");
}
JSONConverter converter = new JSONConverter(false, cs);
String prefix = "";
if (props.secureJson) {
prefix = pc.getApplicationContext().getSecureJsonPrefix();
if (prefix == null)
prefix = "";
}
pc.forceWrite(prefix + converter.serialize(pc, rtn, byColumn));
} else // CFML
if (UDF.RETURN_FORMAT_SERIALIZE == props.format) {
ScriptConverter converter = new ScriptConverter(false);
pc.forceWrite(converter.serialize(rtn));
} else // XML
if (UDF.RETURN_FORMAT_XML == props.format) {
XMLConverter converter = new XMLConverter(pc.getTimeZone(), false);
converter.setTimeZone(pc.getTimeZone());
pc.forceWrite(converter.serialize(rtn));
} else // Plain
if (UDF.RETURN_FORMAT_PLAIN == props.format) {
pc.forceWrite(Caster.toString(rtn));
} else // JAVA
if (UDF.RETURN_FORMAT_JAVA == props.format) {
writeOut(pc, rtn, MimeType.APPLICATION_JAVA, new JavaConverter());
} else
throw new IOException("invalid return format defintion:" + props.format);
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class InterfacePageImpl method call.
@Override
public Object call(PageContext pc) throws PageException {
try {
pc.setSilent();
InterfaceImpl interf = null;
try {
// TODO was only getComponentName before, is that change ok?
interf = newInstance(pc, getPageSource().getComponentName(), false);
} finally {
pc.unsetSilent();
}
String qs = ReqRspUtil.getQueryString(pc.getHttpServletRequest());
if (pc.getBasePageSource() == this.getPageSource() && pc.getConfig().debug())
pc.getDebugger().setOutput(false);
boolean isPost = pc.getHttpServletRequest().getMethod().equalsIgnoreCase("POST");
// POST
if (isPost) {
// Soap
if (ComponentPageImpl.isSoap(pc))
throw new ApplicationException("can not instantiate interface [" + getPageSource().getComponentName() + "] as a component");
} else // GET
if (qs != null && qs.trim().equalsIgnoreCase("wsdl"))
throw new ApplicationException("can not instantiate interface [" + getPageSource().getComponentName() + "] as a component");
// WDDX
if (pc.urlFormScope().containsKey(KeyConstants._method))
throw new ApplicationException("can not instantiate interface [" + getPageSource().getComponentName() + "] as a component");
// invoking via include
if (pc.getTemplatePath().size() > 1) {
throw new ApplicationException("can not invoke interface [" + getPageSource().getComponentName() + "] as a page");
}
// DUMP
// TODO component.setAccess(pc,Component.ACCESS_PUBLIC);
String cdf = pc.getConfig().getComponentDumpTemplate();
if (cdf != null && cdf.trim().length() > 0) {
pc.variablesScope().set(KeyConstants._component, interf);
pc.doInclude(cdf, false);
} else
pc.write(pc.getConfig().getDefaultDumpWriter(DumpWriter.DEFAULT_RICH).toString(pc, interf.toDumpData(pc, 9999, DumpUtil.toDumpProperties()), true));
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
// Exception Handler.castAnd Stack(t, this, pc);
throw Caster.toPageException(t);
}
return null;
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class ComponentLoader method initComponent.
private static ComponentImpl initComponent(PageContext pc, CIPage page, String callPath, boolean isRealPath, final boolean isExtendedComponent, boolean executeConstr) throws PageException {
// is not a component, then it has to be a interface
if (!(page instanceof ComponentPageImpl))
throw new ApplicationException("you cannot instantiate the interface [" + page.getPageSource().getDisplayPath() + "] as a component (" + page.getClass().getName() + "" + (page instanceof InterfacePageImpl) + ")");
ComponentPageImpl cp = (ComponentPageImpl) page;
ComponentImpl c = cp.newInstance(pc, callPath, isRealPath, isExtendedComponent, executeConstr);
// abstract/final check
if (!isExtendedComponent) {
if (c.getModifier() == Component.MODIFIER_ABSTRACT)
throw new ApplicationException("you cannot instantiate an abstract component [" + page.getPageSource().getDisplayPath() + "], this component can only be extended by other components");
} else if (c.getModifier() == Component.MODIFIER_FINAL)
throw new ApplicationException("you cannot extend a final component [" + page.getPageSource().getDisplayPath() + "]");
c.setInitalized(true);
return c;
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class ComponentLoader method initInterface.
private static InterfaceImpl initInterface(PageContext pc, Page page, String callPath, boolean isRealPath) throws PageException {
if (!(page instanceof InterfacePageImpl))
throw new ApplicationException("invalid interface definition [" + callPath + "]");
InterfacePageImpl ip = (InterfacePageImpl) page;
InterfaceImpl i = ip.newInstance(pc, callPath, isRealPath);
return i;
}
use of lucee.runtime.exp.ApplicationException in project Lucee by lucee.
the class ComponentListPackage method _call.
private static Set<String> _call(PageContext pc, String packageName) throws IOException, ApplicationException {
PageContextImpl pci = (PageContextImpl) pc;
ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
Set<String> rtn = null;
// var SEP=server.separator.file;
// get enviroment configuration
boolean searchLocal = packageName.indexOf('.') == -1 ? true : config.getComponentLocalSearch();
boolean searchRoot = config.getComponentRootSearch();
String path = StringUtil.replace(packageName, ".", File.separator, false);
// search local
if (searchLocal) {
PageSource ps = pci.getRelativePageSourceExisting(path);
if (ps != null) {
Mapping mapping = ps.getMapping();
String _path = ps.getRealpath();
_path = ListUtil.trim(_path, "\\/");
String[] list = _listMapping(pc, mapping, _path);
if (!ArrayUtil.isEmpty(list))
rtn = add(rtn, list);
}
}
// check mappings (this includes the webroot)
if (searchRoot) {
String virtual = "/" + StringUtil.replace(packageName, ".", "/", false);
Mapping[] mappings = config.getMappings();
Mapping mapping;
String _path;
String[] list;
for (int i = 0; i < mappings.length; i++) {
mapping = mappings[i];
if (StringUtil.startsWithIgnoreCase(virtual, mapping.getVirtual())) {
_path = ListUtil.trim(virtual.substring(mapping.getVirtual().length()), "\\/").trim();
_path = StringUtil.replace(_path, "/", File.separator, false);
list = _listMapping(pc, mapping, _path);
if (!ArrayUtil.isEmpty(list))
rtn = add(rtn, list);
}
}
}
// check component mappings
Mapping[] mappings = config.getComponentMappings();
Mapping mapping;
String[] list;
for (int i = 0; i < mappings.length; i++) {
mapping = mappings[i];
list = _listMapping(pc, mapping, path);
if (!ArrayUtil.isEmpty(list))
rtn = add(rtn, list);
}
if (rtn == null)
throw new ApplicationException("no package with name [" + packageName + "] found");
return rtn;
}
Aggregations