use of lucee.runtime.type.Array in project Lucee by lucee.
the class MacAddressWrap method getClassPathes.
/**
* @return returns a string list of all pathes
*/
public static Resource[] getClassPathes() {
if (classPathes != null)
return classPathes;
ArrayList<Resource> pathes = new ArrayList<Resource>();
String pathSeperator = System.getProperty("path.separator");
if (pathSeperator == null)
pathSeperator = ";";
// java.ext.dirs
ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
// paths from system properties
String strPathes = System.getProperty("java.class.path");
if (strPathes != null) {
Array arr = ListUtil.listToArrayRemoveEmpty(strPathes, pathSeperator);
int len = arr.size();
for (int i = 1; i <= len; i++) {
Resource file = frp.getResource(Caster.toString(arr.get(i, ""), "").trim());
if (file.exists())
pathes.add(ResourceUtil.getCanonicalResourceEL(file));
}
}
// paths from url class Loader (dynamic loaded classes)
ClassLoader cl = InfoImpl.class.getClassLoader();
if (cl instanceof URLClassLoader)
getClassPathesFromClassLoader((URLClassLoader) cl, pathes);
return classPathes = (Resource[]) pathes.toArray(new Resource[pathes.size()]);
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class CFMLResourceProvider method callResourceArrayRTE.
Resource[] callResourceArrayRTE(PageContext pc, Component component, String methodName, Object[] args) {
pc = ThreadLocalPageContext.get(pc);
try {
Array arr = Caster.toArray(call(pc, getCFC(pc, component), methodName, args));
Iterator<Object> it = arr.valueIterator();
CFMLResource[] resources = new CFMLResource[arr.size()];
int index = 0;
while (it.hasNext()) {
resources[index++] = new CFMLResource(this, Caster.toComponent(it.next()));
}
return resources;
} catch (PageException pe) {
throw new PageRuntimeException(pe);
}
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class DBInfo method typeColumns.
private void typeColumns(DatabaseMetaData metaData) throws PageException, SQLException {
required("table", table);
Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
stopwatch.start();
table = setCase(metaData, table);
pattern = setCase(metaData, pattern);
if (StringUtil.isEmpty(pattern, true))
pattern = null;
String schema = null;
int index = table.indexOf('.');
if (index > 0) {
schema = table.substring(0, index);
table = table.substring(index + 1);
}
checkTable(metaData);
Query qry = new QueryImpl(metaData.getColumns(dbname, schema, table, pattern), "query", pageContext.getTimeZone());
int len = qry.getRecordcount();
if (qry.getColumn(COLUMN_DEF, null) != null)
qry.rename(COLUMN_DEF, COLUMN_DEFAULT_VALUE);
else if (qry.getColumn(COLUMN_DEFAULT, null) != null)
qry.rename(COLUMN_DEFAULT, COLUMN_DEFAULT_VALUE);
// make sure decimal digits exists
QueryColumn col = qry.getColumn(DECIMAL_DIGITS, null);
if (col == null) {
Array arr = new ArrayImpl();
for (int i = 1; i <= len; i++) {
arr.append(lucee.runtime.op.Constants.DOUBLE_ZERO);
}
qry.addColumn(DECIMAL_DIGITS, arr);
}
// add is primary
Map primaries = new HashMap();
String tblName;
Array isPrimary = new ArrayImpl();
Set set;
Object o;
for (int i = 1; i <= len; i++) {
// decimal digits
o = qry.getAt(DECIMAL_DIGITS, i, null);
if (o == null)
qry.setAtEL(DECIMAL_DIGITS, i, lucee.runtime.op.Constants.DOUBLE_ZERO);
set = (Set) primaries.get(tblName = (String) qry.getAt(TABLE_NAME, i));
if (set == null) {
set = toSet(metaData.getPrimaryKeys(dbname, null, tblName), true, "COLUMN_NAME");
primaries.put(tblName, set);
}
isPrimary.append(set.contains(qry.getAt(COLUMN_NAME, i)) ? "YES" : "NO");
}
qry.addColumn(IS_PRIMARYKEY, isPrimary);
// add is foreignkey
Map foreigns = new HashMap();
Array isForeign = new ArrayImpl();
Array refPrim = new ArrayImpl();
Array refPrimTbl = new ArrayImpl();
// Map map,inner;
Map<String, Map<String, SVArray>> map;
Map<String, SVArray> inner;
for (int i = 1; i <= len; i++) {
map = (Map) foreigns.get(tblName = (String) qry.getAt(TABLE_NAME, i));
if (map == null) {
map = toMap(metaData.getImportedKeys(dbname, schema, table), true, "FKCOLUMN_NAME", new String[] { "PKCOLUMN_NAME", "PKTABLE_NAME" });
foreigns.put(tblName, map);
}
inner = map.get(qry.getAt(COLUMN_NAME, i));
if (inner != null) {
isForeign.append("YES");
refPrim.append(inner.get("PKCOLUMN_NAME"));
refPrimTbl.append(inner.get("PKTABLE_NAME"));
} else {
isForeign.append("NO");
refPrim.append("N/A");
refPrimTbl.append("N/A");
}
}
qry.addColumn(IS_FOREIGNKEY, isForeign);
qry.addColumn(REFERENCED_PRIMARYKEY, refPrim);
qry.addColumn(REFERENCED_PRIMARYKEY_TABLE, refPrimTbl);
qry.setExecutionTime(stopwatch.time());
pageContext.setVariable(name, qry);
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class Feed method tag.
private void tag(StringBuffer xml, int count, Pair<String, Object> tag, Pair<String, Object>[] attrs, boolean required, boolean splitString, boolean childrenAsTag) throws PageException {
if (!required && StringUtil.isEmpty(tag.getValue())) {
if (attrs == null || attrs.length == 0)
return;
int c = 0;
for (int i = 0; i < attrs.length; i++) {
if (!StringUtil.isEmpty(attrs[i].getValue()))
c++;
}
if (c == 0)
return;
}
if (tag.getValue() instanceof Array) {
Array arr = (Array) tag.getValue();
int len = arr.size();
for (int i = 1; i <= len; i++) {
_tag(xml, tag.getName(), arr.get(i, null), attrs, count, i, false, childrenAsTag);
}
return;
}
if (splitString && tag.getValue() instanceof String) {
String strValue = (String) tag.getValue();
Array arr = ListUtil.listToArray(strValue, ',');
if (arr.size() > 1) {
int len = arr.size();
for (int i = 1; i <= len; i++) {
_tag(xml, tag.getName(), arr.get(i, null), attrs, count, i, true, childrenAsTag);
}
return;
}
}
_tag(xml, tag.getName(), tag.getValue(), attrs, count, 0, false, childrenAsTag);
}
use of lucee.runtime.type.Array in project Lucee by lucee.
the class FileTag method checkContentType.
/**
* check if the content ii ok
* @param contentType
* @throws PageException
*/
private static void checkContentType(String contentType, String accept, String ext, boolean strict) throws PageException {
if (!StringUtil.isEmpty(ext, true)) {
ext = ext.trim().toLowerCase();
if (ext.startsWith("*."))
ext = ext.substring(2);
if (ext.startsWith("."))
ext = ext.substring(1);
} else
ext = null;
if (StringUtil.isEmpty(accept, true))
return;
MimeType mt = MimeType.getInstance(contentType), sub;
Array whishedTypes = ListUtil.listToArrayRemoveEmpty(accept, ',');
int len = whishedTypes.size();
for (int i = 1; i <= len; i++) {
String whishedType = Caster.toString(whishedTypes.getE(i)).trim().toLowerCase();
if (whishedType.equals("*"))
return;
// check mimetype
if (ListUtil.len(whishedType, "/", true) == 2) {
sub = MimeType.getInstance(whishedType);
if (mt.match(sub))
return;
}
// check extension
if (ext != null && !strict) {
if (whishedType.startsWith("*."))
whishedType = whishedType.substring(2);
if (whishedType.startsWith("."))
whishedType = whishedType.substring(1);
if (ext.equals(whishedType))
return;
}
}
throw new ApplicationException("The MIME type of the uploaded file [" + contentType + "] was not accepted by the server.", "only this [" + accept + "] mime type are accepted");
}
Aggregations