use of lucee.runtime.type.Array in project Lucee by lucee.
the class Query method setTags.
public void setTags(Object oTags) throws PageException {
if (StringUtil.isEmpty(oTags))
return;
// to Array
Array arr;
if (Decision.isArray(oTags))
arr = Caster.toArray(oTags);
else
arr = ListUtil.listToArrayRemoveEmpty(Caster.toString(oTags), ',');
// to String[]
Iterator<Object> it = arr.valueIterator();
List<String> list = new ArrayList<String>();
String str;
while (it.hasNext()) {
str = Caster.toString(it.next());
if (!StringUtil.isEmpty(str))
list.add(str);
}
tags = list.toArray(new String[list.size()]);
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class Admin method doCompileFile.
private void doCompileFile(Mapping mapping, Resource file, String path, Map<String, String> errors, Boolean explicitIgnoreScope) throws PageException {
if (ResourceUtil.exists(file)) {
if (file.isDirectory()) {
Resource[] files = file.listResources(FILTER_CFML_TEMPLATES);
if (files != null)
for (int i = 0; i < files.length; i++) {
String p = path + '/' + files[i].getName();
// print.ln(files[i]+" - "+p);
doCompileFile(mapping, files[i], p, errors, explicitIgnoreScope);
}
} else if (file.isFile()) {
PageSource ps = mapping.getPageSource(path);
PageContextImpl pci = (PageContextImpl) pageContext;
boolean envIgnoreScopes = pci.ignoreScopes();
try {
if (explicitIgnoreScope != null)
pci.setIgnoreScopes(explicitIgnoreScope);
((PageSourceImpl) ps).clear();
((PageSourceImpl) ps).loadPage(pageContext, explicitIgnoreScope != null);
// pageContext.compile(ps);
} catch (PageException pe) {
SystemOut.printDate(pe);
String template = ps.getDisplayPath();
StringBuilder msg = new StringBuilder(pe.getMessage());
msg.append(", Error Occurred in File [");
msg.append(template);
if (pe instanceof PageExceptionImpl) {
try {
PageExceptionImpl pei = (PageExceptionImpl) pe;
Array context = pei.getTagContext(config);
if (context.size() > 0) {
msg.append(":");
msg.append(Caster.toString(((Struct) context.getE(1)).get("line")));
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
msg.append("]");
if (errors != null)
errors.put(template, msg.toString());
else
throw new ApplicationException(msg.toString());
} finally {
pci.setIgnoreScopes(envIgnoreScopes);
}
}
}
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class Admin method _fillSecData.
private void _fillSecData(SecurityManager sm) throws PageException {
Struct sct = new StructImpl();
pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
sct.set("cfx_setting", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_CFX_SETTING) == SecurityManager.VALUE_YES));
sct.set("cfx_usage", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_CFX_USAGE) == SecurityManager.VALUE_YES));
sct.set("custom_tag", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_CUSTOM_TAG) == SecurityManager.VALUE_YES));
sct.set(KeyConstants._datasource, _fillSecDataDS(sm.getAccess(SecurityManager.TYPE_DATASOURCE)));
sct.set("debugging", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_DEBUGGING) == SecurityManager.VALUE_YES));
sct.set("direct_java_access", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_DIRECT_JAVA_ACCESS) == SecurityManager.VALUE_YES));
sct.set("mail", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_MAIL) == SecurityManager.VALUE_YES));
sct.set(KeyConstants._mapping, Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_MAPPING) == SecurityManager.VALUE_YES));
sct.set("remote", Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_REMOTE) == SecurityManager.VALUE_YES));
sct.set("setting", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_SETTING) == SecurityManager.VALUE_YES));
sct.set("search", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_SEARCH) == SecurityManager.VALUE_YES));
sct.set("scheduled_task", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_SCHEDULED_TASK) == SecurityManager.VALUE_YES));
sct.set(KeyConstants._cache, Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_CACHE) == SecurityManager.VALUE_YES));
sct.set("gateway", Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_GATEWAY) == SecurityManager.VALUE_YES));
sct.set(KeyConstants._orm, Caster.toBoolean(sm.getAccess(SecurityManagerImpl.TYPE_ORM) == SecurityManager.VALUE_YES));
sct.set("tag_execute", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_EXECUTE) == SecurityManager.VALUE_YES));
sct.set("tag_import", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_IMPORT) == SecurityManager.VALUE_YES));
sct.set("tag_object", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_OBJECT) == SecurityManager.VALUE_YES));
sct.set("tag_registry", Caster.toBoolean(sm.getAccess(SecurityManager.TYPE_TAG_REGISTRY) == SecurityManager.VALUE_YES));
sct.set("access_read", SecurityManagerImpl.toStringAccessRWValue(sm.getAccess(SecurityManager.TYPE_ACCESS_READ)));
sct.set("access_write", SecurityManagerImpl.toStringAccessRWValue(sm.getAccess(SecurityManager.TYPE_ACCESS_WRITE)));
short accessFile = sm.getAccess(SecurityManager.TYPE_FILE);
String str = SecurityManagerImpl.toStringAccessValue(accessFile);
if (str.equals("yes"))
str = "all";
sct.set(KeyConstants._file, str);
Array arr = new ArrayImpl();
if (accessFile != SecurityManager.VALUE_ALL) {
Resource[] reses = ((SecurityManagerImpl) sm).getCustomFileAccess();
for (int i = 0; i < reses.length; i++) {
arr.appendEL(reses[i].getAbsolutePath());
}
}
sct.set("file_access", arr);
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class Associate method doStartTag.
@Override
public int doStartTag() throws PageException {
// current
CFTag current = getCFTag();
Struct value;
if (current == null || (value = current.getAttributesScope()) == null)
throw new ApplicationException("invalid context, tag is no inside a custom tag");
// parent
CFTag parent = GetBaseTagData.getParentCFTag(current.getParent(), basetag, -1);
if (parent == null)
throw new ApplicationException("there is no parent tag with name [" + basetag + "]");
Struct thisTag = parent.getThis();
Object obj = thisTag.get(datacollection, null);
Array array;
if (obj == null) {
array = new ArrayImpl(new Object[] { value });
thisTag.set(datacollection, array);
} else if (Decision.isArray(obj) && (array = Caster.toArray(obj)).getDimension() == 1) {
array.append(value);
} else {
array = new ArrayImpl(new Object[] { obj, value });
thisTag.set(datacollection, array);
}
return SKIP_BODY;
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class Directory method actionList.
/**
* list all files and directories inside a directory
* @throws PageException
*/
public static Object actionList(PageContext pageContext, Resource directory, String serverPassword, int type, ResourceFilter filter, int listInfo, boolean recurse, String sort) throws PageException {
// check directory
SecurityManager securityManager = pageContext.getConfig().getSecurityManager();
securityManager.checkFileLocation(pageContext.getConfig(), directory, serverPassword);
if (type != TYPE_ALL) {
ResourceFilter typeFilter = (type == TYPE_DIR) ? DIRECTORY_FILTER : FILE_FILTER;
if (filter == null)
filter = typeFilter;
else
filter = new AndResourceFilter(new ResourceFilter[] { typeFilter, filter });
}
// create query Object
String[] names = new String[] { "name", "size", "type", "dateLastModified", "attributes", "mode", "directory" };
String[] types = new String[] { "VARCHAR", "DOUBLE", "VARCHAR", "DATE", "VARCHAR", "VARCHAR", "VARCHAR" };
boolean hasMeta = directory instanceof ResourceMetaData;
if (hasMeta) {
names = new String[] { "name", "size", "type", "dateLastModified", "attributes", "mode", "directory", "meta" };
types = new String[] { "VARCHAR", "DOUBLE", "VARCHAR", "DATE", "VARCHAR", "VARCHAR", "VARCHAR", "OBJECT" };
}
Array array = null;
Query query = null;
Object rtn;
if (listInfo == LIST_INFO_QUERY_ALL || listInfo == LIST_INFO_QUERY_NAME) {
boolean listOnlyNames = listInfo == LIST_INFO_QUERY_NAME;
rtn = query = new QueryImpl(listOnlyNames ? new String[] { "name" } : names, listOnlyNames ? new String[] { "VARCHAR" } : types, 0, "query");
} else
rtn = array = new ArrayImpl();
if (!directory.exists()) {
if (directory instanceof FileResource)
return rtn;
throw new ApplicationException("directory [" + directory.toString() + "] doesn't exist");
}
if (!directory.isDirectory()) {
if (directory instanceof FileResource)
return rtn;
throw new ApplicationException("file [" + directory.toString() + "] exists, but isn't a directory");
}
if (!directory.isReadable()) {
if (directory instanceof FileResource)
return rtn;
throw new ApplicationException("no access to read directory [" + directory.toString() + "]");
}
long startNS = System.nanoTime();
try {
// Query All
if (listInfo == LIST_INFO_QUERY_ALL)
_fillQueryAll(query, directory, filter, 0, hasMeta, recurse);
else // Query Name
if (listInfo == LIST_INFO_QUERY_NAME) {
if (recurse || type != TYPE_ALL)
_fillQueryNamesRec("", query, directory, filter, 0, recurse);
else
_fillQueryNames(query, directory, filter, 0);
} else // Array Name/Path
if (listInfo == LIST_INFO_ARRAY_NAME || listInfo == LIST_INFO_ARRAY_PATH) {
boolean onlyName = listInfo == LIST_INFO_ARRAY_NAME;
if (// QueryNamesRec("",query, directory, filter, 0,recurse);
!onlyName || recurse || type != TYPE_ALL)
// QueryNamesRec("",query, directory, filter, 0,recurse);
_fillArrayPathOrName(array, directory, filter, 0, recurse, onlyName);
else
_fillArrayName(array, directory, filter, 0);
}
} catch (IOException e) {
throw Caster.toPageException(e);
}
// sort
if (sort != null && query != null) {
String[] arr = sort.toLowerCase().split(",");
for (int i = arr.length - 1; i >= 0; i--) {
try {
String[] col = arr[i].trim().split("\\s+");
if (col.length == 1)
query.sort(col[0].trim());
else if (col.length == 2) {
String order = col[1].toLowerCase().trim();
if (order.equals("asc"))
query.sort(col[0], lucee.runtime.type.Query.ORDER_ASC);
else if (order.equals("desc"))
query.sort(col[0], lucee.runtime.type.Query.ORDER_DESC);
else
throw new ApplicationException("invalid order type [" + col[1] + "]");
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
}
}
}
if (query != null)
query.setExecutionTime(System.nanoTime() - startNS);
return rtn;
}
Aggregations