use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class GetFileInfo method call.
public static Struct call(PageContext pc, Object oSrc) throws PageException {
Resource src = Caster.toResource(pc, oSrc, true);
pc.getConfig().getSecurityManager().checkFileLocation(src);
Struct sct = new StructImpl();
sct.set("canRead", Caster.toBoolean(src.isReadable()));
sct.set("canWrite", Caster.toBoolean(src.isWriteable()));
sct.set("isHidden", Caster.toBoolean(src.getAttribute(Resource.ATTRIBUTE_HIDDEN)));
sct.set("lastmodified", new DateTimeImpl(pc, src.lastModified(), false));
sct.set(KeyConstants._name, src.getName());
sct.set(KeyConstants._parent, src.getParent());
sct.set(KeyConstants._path, src.getAbsolutePath());
sct.set(KeyConstants._size, Long.valueOf(src.length()));
if (src.isDirectory())
sct.set(KeyConstants._type, "directory");
else if (src.isFile())
sct.set(KeyConstants._type, "file");
else
sct.set(KeyConstants._type, "");
// supported only by lucee
sct.set("isArchive", Caster.toBoolean(src.getAttribute(Resource.ATTRIBUTE_ARCHIVE)));
sct.set("isSystem", Caster.toBoolean(src.getAttribute(Resource.ATTRIBUTE_SYSTEM)));
sct.set("scheme", src.getResourceProvider().getScheme());
sct.set("isCaseSensitive", Caster.toBoolean(src.getResourceProvider().isCaseSensitive()));
sct.set("isAttributesSupported", Caster.toBoolean(src.getResourceProvider().isAttributesSupported()));
sct.set("isModeSupported", Caster.toBoolean(src.getResourceProvider().isModeSupported()));
return sct;
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class GetUsageData method call.
public static Struct call(PageContext pc) throws PageException {
ConfigWeb cw = pc.getConfig();
ConfigServer cs = cw.getConfigServer("server");
ConfigWeb[] webs = cs.getConfigWebs();
CFMLEngineFactory.getInstance();
CFMLEngineImpl engine = (CFMLEngineImpl) cs.getCFMLEngine();
Struct sct = new StructImpl();
// Locks
/*LockManager manager = pc.getConfig().getLockManager();
String[] locks = manager.getOpenLockNames();
for(int i=0;i<locks.length;i++){
locks[i].
}
if(!ArrayUtil.isEmpty(locks))
strLocks=" open locks at this time ("+List.arrayToList(locks, ", ")+").";
*/
// Requests
Query req = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._uri, START_TIME, KeyConstants._timeout }, 0, "requests");
sct.setEL(KeyConstants._requests, req);
// Template Cache
Query tc = new QueryImpl(new Collection.Key[] { KeyConstants._web, ELEMENTS, KeyConstants._size }, 0, "templateCache");
sct.setEL(KeyImpl.init("templateCache"), tc);
// Scopes
Struct scopes = new StructImpl();
sct.setEL(KeyConstants._scopes, scopes);
Query app = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, ELEMENTS, KeyConstants._size }, 0, "templateCache");
scopes.setEL(KeyConstants._application, app);
Query sess = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, USERS, ELEMENTS, KeyConstants._size }, 0, "templateCache");
scopes.setEL(KeyConstants._session, sess);
// Query
Query qry = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, START_TIME, KeyConstants._sql }, 0, "requests");
sct.setEL(QUERIES, qry);
// Locks
Query lck = new QueryImpl(new Collection.Key[] { KeyConstants._web, KeyConstants._application, KeyConstants._name, START_TIME, KeyConstants._timeout, KeyConstants._type }, 0, "requests");
sct.setEL(LOCKS, lck);
// Loop webs
ConfigWebImpl web;
Map<Integer, PageContextImpl> pcs;
PageContextImpl _pc;
int row, openConnections = 0;
CFMLFactoryImpl factory;
ActiveQuery[] queries;
ActiveQuery aq;
ActiveLock[] locks;
ActiveLock al;
for (int i = 0; i < webs.length; i++) {
// Loop requests
web = (ConfigWebImpl) webs[i];
factory = (CFMLFactoryImpl) web.getFactory();
pcs = factory.getActivePageContexts();
Iterator<PageContextImpl> it = pcs.values().iterator();
while (it.hasNext()) {
_pc = it.next();
if (_pc.isGatewayContext())
continue;
// Request
row = req.addRow();
req.setAt(KeyConstants._web, row, web.getLabel());
req.setAt(KeyConstants._uri, row, getPath(_pc.getHttpServletRequest()));
req.setAt(START_TIME, row, new DateTimeImpl(pc.getStartTime(), false));
req.setAt(KeyConstants._timeout, row, new Double(pc.getRequestTimeout()));
// Query
queries = _pc.getActiveQueries();
if (queries != null) {
for (int y = 0; y < queries.length; y++) {
aq = queries[y];
row = qry.addRow();
qry.setAt(KeyConstants._web, row, web.getLabel());
qry.setAt(KeyConstants._application, row, _pc.getApplicationContext().getName());
qry.setAt(START_TIME, row, new DateTimeImpl(web, aq.startTime, true));
qry.setAt(KeyConstants._sql, row, aq.sql);
}
}
// Lock
locks = _pc.getActiveLocks();
if (locks != null) {
for (int y = 0; y < locks.length; y++) {
al = locks[y];
row = lck.addRow();
lck.setAt(KeyConstants._web, row, web.getLabel());
lck.setAt(KeyConstants._application, row, _pc.getApplicationContext().getName());
lck.setAt(KeyConstants._name, row, al.name);
lck.setAt(START_TIME, row, new DateTimeImpl(web, al.startTime, true));
lck.setAt(KeyConstants._timeout, row, Caster.toDouble(al.timeoutInMillis / 1000));
lck.setAt(KeyConstants._type, row, al.type == LockManager.TYPE_EXCLUSIVE ? "exclusive" : "readonly");
}
}
}
Iterator<Integer> _it = web.getDatasourceConnectionPool().openConnections().values().iterator();
while (_it.hasNext()) {
openConnections += _it.next().intValue();
}
// Template Cache
Mapping[] mappings = ConfigWebUtil.getAllMappings(web);
long[] tce = templateCacheElements(mappings);
row = tc.addRow();
tc.setAt(KeyConstants._web, row, web.getLabel());
tc.setAt(KeyConstants._size, row, new Double(tce[1]));
tc.setAt(ELEMENTS, row, new Double(tce[0]));
// Scope Application
getAllApplicationScopes(web, factory.getScopeContext(), app);
getAllCFSessionScopes(web, factory.getScopeContext(), sess);
}
// Datasource
Struct ds = new StructImpl();
sct.setEL(KeyConstants._datasources, ds);
// there is only one cache for all contexts
ds.setEL(CACHED_QUERIES, Caster.toDouble(pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_QUERY, null).size(pc)));
// ds.setEL(CACHED_QUERIES, Caster.toDouble(pc.getQueryCache().size(pc))); // there is only one cache for all contexts
ds.setEL(OPEN_CONNECTIONS, Caster.toDouble(openConnections));
// Memory
Struct mem = new StructImpl();
sct.setEL(KeyConstants._memory, mem);
mem.setEL("heap", SystemUtil.getMemoryUsageAsStruct(SystemUtil.MEMORY_TYPE_HEAP));
mem.setEL("nonheap", SystemUtil.getMemoryUsageAsStruct(SystemUtil.MEMORY_TYPE_NON_HEAP));
// uptime
sct.set("uptime", new DateTimeImpl(engine.uptime(), true));
// now
sct.set("now", new DateTimeImpl(pc));
return sct;
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class Caster method toString.
/**
* cast a Object to a String
* @param o Object to cast
* @return casted String
* @throws PageException
*/
public static String toString(Object o) throws PageException {
if (o instanceof String)
return (String) o;
else if (o instanceof Number)
return toString(((Number) o));
else if (o instanceof Boolean)
return toString(((Boolean) o).booleanValue());
else if (o instanceof Castable)
return ((Castable) o).castToString();
else if (o instanceof Date) {
if (o instanceof DateTime)
return ((DateTime) o).castToString();
return new DateTimeImpl((Date) o).castToString();
} else if (o instanceof Clob)
return toString((Clob) o);
else if (o instanceof Locale)
return toString((Locale) o);
else if (o instanceof TimeZone)
return toString((TimeZone) o);
else if (o instanceof Node)
return XMLCaster.toString((Node) o);
else if (o instanceof Reader) {
Reader r = null;
try {
return IOUtil.toString(r = (Reader) o);
} catch (IOException e) {
throw Caster.toPageException(e);
} finally {
IOUtil.closeEL(r);
}
} else if (o instanceof InputStream) {
PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get();
InputStream r = null;
try {
return IOUtil.toString(r = (InputStream) o, pc.getWebCharset());
} catch (IOException e) {
throw Caster.toPageException(e);
} finally {
IOUtil.closeEL(r);
}
} else if (o instanceof byte[]) {
PageContextImpl pc = (PageContextImpl) ThreadLocalPageContext.get();
try {
return new String((byte[]) o, pc.getWebCharset());
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
return new String((byte[]) o);
}
} else if (o instanceof char[])
return new String((char[]) o);
else if (o instanceof ObjectWrap)
return toString(((ObjectWrap) o).getEmbededObject());
else if (o instanceof Calendar)
return toString(((Calendar) o).getTime());
else if (o == null)
return "";
// INFO Collection is new of type Castable
if (o instanceof Map || o instanceof List || o instanceof Function)
throw new CasterException(o, "string");
return o.toString();
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class DateCaster method _toDateSimpleTS.
private static DateTime _toDateSimpleTS(DateString ds, TimeZone timeZone, DateTime defaultValue) {
// "^\\{d '([0-9]{2,4})-([0-9]{1,2})-([0-9]{1,2})'\\}$"
if (ds.fwIfNext('d')) {
if (!(ds.fwIfNext(' ') && ds.fwIfNext('\'')))
return defaultValue;
ds.next();
// year
int year = ds.readDigits();
if (year == -1)
return defaultValue;
if (!ds.fwIfCurrent('-'))
return defaultValue;
// month
int month = ds.readDigits();
if (month == -1)
return defaultValue;
if (!ds.fwIfCurrent('-'))
return defaultValue;
// day
int day = ds.readDigits();
if (day == -1)
return defaultValue;
if (!(ds.fwIfCurrent('\'') && ds.fwIfCurrent('}')))
return defaultValue;
// new DateTimeImpl(year,month,day);
if (ds.isAfterLast())
return util.toDateTime(timeZone, year, month, day, 0, 0, 0, 0, defaultValue);
return defaultValue;
} else // "^\\{ts '([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{2}):([0-9]{1,2}):([0-9]{2})'\\}$"
if (ds.fwIfNext('t')) {
if (!(ds.fwIfNext('s') && ds.fwIfNext(' ') && ds.fwIfNext('\''))) {
// Time
if (!(ds.fwIfNext(' ') && ds.fwIfNext('\'')))
return defaultValue;
ds.next();
// hour
int hour = ds.readDigits();
if (hour == -1)
return defaultValue;
if (!ds.fwIfCurrent(':'))
return defaultValue;
// minute
int minute = ds.readDigits();
if (minute == -1)
return defaultValue;
if (!ds.fwIfCurrent(':'))
return defaultValue;
// second
int second = ds.readDigits();
if (second == -1)
return defaultValue;
// Milli Second
int millis = 0;
if (ds.fwIfCurrent('.')) {
millis = ds.readDigits();
}
int before = ds.getPos();
DateTime tmp = parseOffset(ds, timeZone, new int[] { 1899, 12, 30 }, hour, minute, second, millis, false, defaultValue);
if (tmp == null && before != ds.getPos())
return defaultValue;
if (!(ds.fwIfCurrent('\'') && ds.fwIfCurrent('}')))
return defaultValue;
if (ds.isAfterLast()) {
if (tmp != null) {
return new TimeImpl(tmp.getTime(), false);
}
long time = util.toTime(timeZone, 1899, 12, 30, hour, minute, second, millis, DEFAULT_VALUE);
if (time == DEFAULT_VALUE)
return defaultValue;
return new TimeImpl(time, false);
}
return defaultValue;
}
ds.next();
// year
int year = ds.readDigits();
if (year == -1)
return defaultValue;
if (!ds.fwIfCurrent('-'))
return defaultValue;
// month
int month = ds.readDigits();
if (month == -1)
return defaultValue;
if (!ds.fwIfCurrent('-'))
return defaultValue;
// day
int day = ds.readDigits();
if (day == -1)
return defaultValue;
if (!ds.fwIfCurrent(' '))
return defaultValue;
// hour
int hour = ds.readDigits();
if (hour == -1)
return defaultValue;
if (!ds.fwIfCurrent(':'))
return defaultValue;
// minute
int minute = ds.readDigits();
if (minute == -1)
return defaultValue;
if (!ds.fwIfCurrent(':'))
return defaultValue;
// second
int second = ds.readDigits();
if (second == -1)
return defaultValue;
// Milli Second
int millis = 0;
if (ds.fwIfCurrent('.')) {
millis = ds.readDigits();
}
int before = ds.getPos();
DateTime tmp = parseOffset(ds, timeZone, new int[] { year, month, day }, hour, minute, second, millis, false, defaultValue);
if (tmp == null && before != ds.getPos())
return defaultValue;
if (!(ds.fwIfCurrent('\'') && ds.fwIfCurrent('}')))
return defaultValue;
if (ds.isAfterLast()) {
if (tmp != null)
return tmp;
return util.toDateTime(timeZone, year, month, day, hour, minute, second, millis, defaultValue);
}
return defaultValue;
} else
return defaultValue;
}
use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.
the class DateCaster method toDateAdvanced.
/**
* converts a String to a DateTime Object (Advanced but slower), returns null if invalid string
* @param str String to convert
* @param convertingType one of the following values:
* - CONVERTING_TYPE_NONE: number are not converted at all
* - CONVERTING_TYPE_YEAR: integers are handled as years
* - CONVERTING_TYPE_OFFSET: numbers are handled as offset from 1899-12-30 00:00:00 UTC
* @param timeZone
* @param defaultValue
* @return Date Time Object
*/
public static DateTime toDateAdvanced(String str, short convertingType, TimeZone timeZone, DateTime defaultValue) {
str = str.trim();
if (StringUtil.isEmpty(str))
return defaultValue;
// every format has digits
if (!hasDigits(str))
return defaultValue;
timeZone = ThreadLocalPageContext.getTimeZone(timeZone);
DateTime dt = toDateSimple(str, convertingType, true, timeZone, defaultValue);
if (dt == null) {
final DateFormat[] formats = FormatUtil.getCFMLFormats(timeZone, true);
synchronized (formats) {
Date d;
ParsePosition pp = new ParsePosition(0);
for (int i = 0; i < formats.length; i++) {
// try {
pp.setErrorIndex(-1);
pp.setIndex(0);
d = formats[i].parse(str, pp);
if (pp.getIndex() == 0 || d == null || pp.getIndex() < str.length())
continue;
dt = new DateTimeImpl(d.getTime(), false);
return dt;
}
}
dt = toDateTime(Locale.US, str, timeZone, defaultValue, false);
}
return dt;
}
Aggregations