use of lucee.runtime.type.StructImpl in project Lucee by lucee.
the class FileTag method actionUploadAll.
public void actionUploadAll() throws PageException {
Array arr = actionUploadAll(pageContext, securityManager, strDestination, nameconflict, accept, strict, mode, attributes, acl, serverPassword);
if (StringUtil.isEmpty(result)) {
Struct sct;
if (arr != null && arr.size() > 0)
sct = (Struct) arr.getE(1);
else
sct = new StructImpl();
pageContext.undefinedScope().set(KeyConstants._file, sct);
pageContext.undefinedScope().set("cffile", sct);
} else {
pageContext.setVariable(result, arr);
}
}
use of lucee.runtime.type.StructImpl in project Lucee by lucee.
the class FileTag method _actionUpload.
private static Struct _actionUpload(PageContext pageContext, lucee.runtime.security.SecurityManager securityManager, FormItem formItem, String strDestination, int nameconflict, String accept, boolean strict, int mode, String attributes, Object acl, String serverPassword) throws PageException {
if (nameconflict == NAMECONFLICT_UNDEFINED)
nameconflict = NAMECONFLICT_ERROR;
boolean fileWasRenamed = false;
boolean fileWasAppended = false;
boolean fileExisted = false;
boolean fileWasOverwritten = false;
String contentType = ResourceUtil.getMimeType(formItem.getResource(), formItem.getContentType());
// set cffile struct
Struct cffile = new StructImpl();
long length = formItem.getResource().length();
cffile.set("timecreated", new DateTimeImpl(pageContext.getConfig()));
cffile.set("timelastmodified", new DateTimeImpl(pageContext.getConfig()));
cffile.set("datelastaccessed", new DateImpl(pageContext));
cffile.set("oldfilesize", Long.valueOf(length));
cffile.set("filesize", Long.valueOf(length));
cffile.set("contenttype", ListFirst.call(pageContext, contentType, "/"));
cffile.set("contentsubtype", ListLast.call(pageContext, contentType, "/"));
// client file
String strClientFile = formItem.getName();
while (strClientFile.indexOf('\\') != -1) strClientFile = strClientFile.replace('\\', '/');
Resource clientFile = pageContext.getConfig().getResource(strClientFile);
String clientFileName = clientFile.getName();
// check file type
checkContentType(contentType, accept, getFileExtension(clientFile), strict);
cffile.set("clientdirectory", getParent(clientFile));
cffile.set("clientfile", clientFile.getName());
cffile.set("clientfileext", getFileExtension(clientFile));
cffile.set("clientfilename", getFileName(clientFile));
// check destination
if (StringUtil.isEmpty(strDestination))
throw new ApplicationException("attribute destination is not defined in tag file");
Resource destination = toDestination(pageContext, strDestination, null);
securityManager.checkFileLocation(pageContext.getConfig(), destination, serverPassword);
if (destination.isDirectory())
destination = destination.getRealResource(clientFileName);
else if (!destination.exists() && (strDestination.endsWith("/") || strDestination.endsWith("\\")))
destination = destination.getRealResource(clientFileName);
else if (!clientFileName.equalsIgnoreCase(destination.getName())) {
if (ResourceUtil.getExtension(destination, null) == null)
destination = destination.getRealResource(clientFileName);
else
fileWasRenamed = true;
}
// check parent destination -> directory of the desinatrion
Resource parentDestination = destination.getParentResource();
if (!parentDestination.exists()) {
Resource pp = parentDestination.getParentResource();
if (pp == null || !pp.exists())
throw new ApplicationException("attribute destination has an invalid value [" + destination + "], directory [" + parentDestination + "] doesn't exist");
try {
parentDestination.createDirectory(true);
} catch (IOException e) {
throw Caster.toPageException(e);
}
} else if (!parentDestination.canWrite())
throw new ApplicationException("can't write to destination directory [" + parentDestination + "], no access to write");
// set server variables
cffile.set("serverdirectory", getParent(destination));
cffile.set("serverfile", destination.getName());
cffile.set("serverfileext", getFileExtension(destination));
cffile.set("serverfilename", getFileName(destination));
cffile.set("attemptedserverfile", destination.getName());
// check nameconflict
if (destination.exists()) {
fileExisted = true;
if (nameconflict == NAMECONFLICT_ERROR) {
throw new ApplicationException("destination file [" + destination + "] already exist");
} else if (nameconflict == NAMECONFLICT_SKIP) {
cffile.set("fileexisted", Caster.toBoolean(fileExisted));
cffile.set("filewasappended", Boolean.FALSE);
cffile.set("filewasoverwritten", Boolean.FALSE);
cffile.set("filewasrenamed", Boolean.FALSE);
cffile.set("filewassaved", Boolean.FALSE);
return cffile;
} else if (nameconflict == NAMECONFLICT_MAKEUNIQUE) {
destination = makeUnique(destination);
fileWasRenamed = true;
// if(fileWasRenamed) {
cffile.set("serverdirectory", getParent(destination));
cffile.set("serverfile", destination.getName());
cffile.set("serverfileext", getFileExtension(destination));
cffile.set("serverfilename", getFileName(destination));
cffile.set("attemptedserverfile", destination.getName());
// }
} else if (nameconflict == NAMECONFLICT_OVERWRITE) {
// fileWasAppended=true;
fileWasOverwritten = true;
if (!destination.delete())
if (// hier hatte ich concurrent problem das damit ausgeraeumt ist
destination.exists())
throw new ApplicationException("can't delete destination file [" + destination + "]");
}
// for "overwrite" no action is neded
}
setACL(pageContext, destination, acl);
try {
destination.createNewFile();
IOUtil.copy(formItem.getResource(), destination);
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
throw Caster.toPageException(t);
}
// Set cffile/file struct
cffile.set("fileexisted", Caster.toBoolean(fileExisted));
cffile.set("filewasappended", Caster.toBoolean(fileWasAppended));
cffile.set("filewasoverwritten", Caster.toBoolean(fileWasOverwritten));
cffile.set("filewasrenamed", Caster.toBoolean(fileWasRenamed));
cffile.set("filewassaved", Boolean.TRUE);
setMode(destination, mode);
setAttributes(destination, attributes);
return cffile;
}
use of lucee.runtime.type.StructImpl in project Lucee by lucee.
the class Update method doEndTag.
@Override
public int doEndTag() throws PageException {
Object ds = DBInfo.getDatasource(pageContext, datasource);
DataSourceManager manager = pageContext.getDataSourceManager();
DatasourceConnection dc = ds instanceof DataSource ? manager.getConnection(pageContext, (DataSource) ds, username, password) : manager.getConnection(pageContext, Caster.toString(ds), username, password);
try {
Struct meta = null;
try {
meta = Insert.getMeta(dc, tablequalifier, tableowner, tablename);
} catch (SQLException se) {
meta = new StructImpl();
}
String[] pKeys = getPrimaryKeys(dc);
SQL sql = createSQL(dc, pKeys, meta);
if (sql != null) {
lucee.runtime.type.Query query = new QueryImpl(pageContext, dc, sql, -1, -1, null, "query");
if (pageContext.getConfig().debug()) {
String dsn = ds instanceof DataSource ? ((DataSource) ds).getName() : Caster.toString(ds);
boolean logdb = ((ConfigImpl) pageContext.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_DATABASE);
if (logdb) {
boolean debugUsage = DebuggerUtil.debugQueryUsage(pageContext, query);
pageContext.getDebugger().addQuery(debugUsage ? query : null, dsn, "", sql, query.getRecordcount(), pageContext.getCurrentPageSource(), query.getExecutionTime());
}
}
// log
Log log = pageContext.getConfig().getLog("datasource");
if (log.getLogLevel() >= Log.LEVEL_INFO) {
log.info("update tag", "executed [" + sql.toString().trim() + "] in " + DecimalFormat.call(pageContext, query.getExecutionTime() / 1000000D) + " ms");
}
}
return EVAL_PAGE;
} catch (PageException pe) {
pageContext.getConfig().getLog("datasource").error("update tag", pe);
throw pe;
} finally {
manager.releaseConnection(pageContext, dc);
}
}
use of lucee.runtime.type.StructImpl in project Lucee by lucee.
the class Video method toStruct.
public Struct toStruct(VideoInfo[] infos) {
Struct sct = new StructImpl();
sct.setEL(KeyConstants._source, toStruct(infos[0]));
sct.setEL(KeyConstants._destination, toStruct(infos[1]));
return sct;
}
use of lucee.runtime.type.StructImpl in project Lucee by lucee.
the class Video method toStruct.
private Struct toStruct(VideoInfo info) {
Struct sct = info.toStruct();
// audio
Struct audio = Caster.toStruct(sct.get(AUDIO, null), null);
if (audio == null) {
audio = new StructImpl();
sct.setEL(AUDIO, audio);
}
// video
Struct video = Caster.toStruct(sct.get(VIDEO, null), null);
if (video == null) {
video = new StructImpl();
sct.setEL(VIDEO, video);
}
// Audio
audio.setEL("channels", info.getAudioChannels());
audio.setEL(KeyConstants._codec, info.getAudioCodec());
if (info.getAudioBitrate() != -1)
audio.setEL("bitrate", new Double(info.getAudioBitrate()));
if (info.getAudioSamplerate() != -1)
audio.setEL("samplerate", new Double(info.getAudioSamplerate()));
// Video
video.setEL(KeyConstants._codec, info.getVideoCodec());
video.setEL(KeyConstants._format, info.getVideoFormat());
if (info.getVideoBitrate() != -1)
video.setEL("bitrate", new Double(info.getVideoBitrate()));
if (info.getFramerate() != -1)
video.setEL("framerate", new Double(info.getFramerate()));
// Allgemein
if (info.getDuration() != -1)
sct.setEL("duration", new Double(info.getDuration()));
if (info.getHeight() != -1)
sct.setEL(KeyConstants._height, new Double(info.getHeight()));
if (info.getWidth() != -1)
sct.setEL(KeyConstants._width, new Double(info.getWidth()));
return sct;
}
Aggregations