use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class FileElementImpl method reset.
@Override
public void reset() {
if (tempUploadFile != null && tempUploadFile.exists()) {
tempUploadFile.delete();
}
tempUploadFile = null;
if (previewEl != null) {
if (initialFile != null) {
VFSLeaf media = new LocalFileImpl(initialFile);
previewEl.setMedia(media);
previewEl.setMaxWithAndHeightToFitWithin(300, 200);
previewEl.setVisible(true);
} else if (previewEl != null) {
previewEl.setVisible(false);
}
}
uploadFilename = null;
uploadMimeType = null;
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class FileElementImpl method setInitialFile.
@Override
public void setInitialFile(File initialFile) {
this.initialFile = initialFile;
if (initialFile != null && previewEl != null) {
VFSLeaf media = new LocalFileImpl(initialFile);
previewEl.setMedia(media);
previewEl.setMaxWithAndHeightToFitWithin(300, 200);
previewEl.setVisible(true);
} else if (previewEl != null) {
previewEl.setVisible(false);
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class ProjectBrokerCourseNode method importProject.
private void importProject(File projectDir, File projectFile, ProjectBroker projectBroker, ICourse course, CourseEnvironmentMapper envMapper) {
XStream xstream = XStreamHelper.createXStreamInstance();
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
// read the projectConfiguration from the importDirectory
try {
@SuppressWarnings("unchecked") Map<String, Object> projectConfig = (HashMap<String, Object>) XStreamHelper.readObject(xstream, projectFile);
String projectTitle = (String) projectConfig.get("title");
Long originalGroupKey = null;
if (projectConfig.containsKey("businessGroupKey")) {
originalGroupKey = (Long) projectConfig.get("businessGroupKey");
} else {
for (BusinessGroupReference ref : envMapper.getGroups()) {
if (ref.getName().endsWith(projectTitle)) {
originalGroupKey = ref.getOriginalKey();
}
}
}
BusinessGroup projectGroup = null;
if (originalGroupKey != null) {
Long groupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
projectGroup = bgs.loadBusinessGroup(groupKey);
}
if (projectGroup == null) {
projectGroup = projectGroupManager.createProjectGroupFor(projectBroker.getKey(), envMapper.getAuthor(), projectTitle, (String) projectConfig.get("description"), course.getResourceableId());
}
if (envMapper.getAuthor() != null) {
Identity author = envMapper.getAuthor();
bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
}
Project project = projectBrokerManager.createAndSaveProjectFor(projectTitle, (String) projectConfig.get("description"), projectBrokerManager.getProjectBrokerId(cpm, this), projectGroup);
projectGroupManager.setDeselectionAllowed(project, (boolean) projectConfig.get("allowDeselection"));
project.setMailNotificationEnabled((boolean) projectConfig.get("mailNotificationEnabled"));
project.setMaxMembers((int) projectConfig.get("maxMembers"));
project.setAttachedFileName(projectConfig.get("attachmentFileName").toString());
for (int i = 0; i < (int) projectConfig.get("customeFieldSize"); i++) {
project.setCustomFieldValue(i, projectConfig.get("customFieldValue" + i).toString());
}
projectBrokerManager.updateProject(project);
// get the attachment directory within the project
// directory
// .getParentFile().listFiles(attachmentFilter);
File attachmentDir = new File(projectDir, "attachment");
if (attachmentDir.exists()) {
File[] attachment = attachmentDir.listFiles();
if (attachment.length > 0) {
VFSLeaf attachmentLeaf = new LocalFileImpl(attachment[0]);
projectBrokerManager.saveAttachedFile(project, projectConfig.get("attachmentFileName").toString(), attachmentLeaf, course.getCourseEnvironment(), this);
}
}
} catch (Exception e) {
// handle/log error in case of FileIO exception or cast
// exception if import input is not correct
log.error("Error while importing a project into projectbroker", e);
}
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class ForumRTFFormatter method addImagesToVFSContainer.
/**
* Retrieves the appropriate images for the input messageNode, if any,
* and adds it to the input container.
*
* @param messageNode
* @param imageContainer
* @return
*/
private List<String> addImagesToVFSContainer(MessageNode messageNode, VFSContainer imageContainer) {
List<String> fileNameList = new ArrayList<String>();
String iconPath = null;
if (messageNode.isClosed() && messageNode.isSticky()) {
iconPath = getImagePath("fo_sticky_closed");
} else if (messageNode.isClosed()) {
iconPath = getImagePath("fo_closed");
} else if (messageNode.isSticky()) {
iconPath = getImagePath("fo_sticky");
}
if (iconPath != null) {
File file = new File(iconPath);
if (file.exists()) {
LocalFileImpl imgFile = new LocalFileImpl(file);
imageContainer.copyFrom(imgFile);
fileNameList.add(file.getName());
} else {
log.error("Could not find image for forum RTF formatter::" + iconPath);
}
}
return fileNameList;
}
use of org.olat.core.util.vfs.LocalFileImpl in project openolat by klemens.
the class ForumWebService method getAttachment.
/**
* Retrieves the attachment of the message
* @response.representation.200.mediaType application/octet-stream
* @response.representation.200.doc The portrait as image
* @response.representation.404.doc The identity or the portrait not found
* @param messageKey The identity key of the user being searched
* @param filename The name of the attachment
* @param request The REST request
* @return The attachment
*/
@GET
@Path("posts/{messageKey}/attachments/{filename}")
@Produces({ "*/*", MediaType.APPLICATION_OCTET_STREAM })
public Response getAttachment(@PathParam("messageKey") Long messageKey, @PathParam("filename") String filename, @Context Request request) {
// load message
Message mess = fom.loadMessage(messageKey);
if (mess == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
if (!forum.equalsByPersistableKey(mess.getForum())) {
return Response.serverError().status(Status.CONFLICT).build();
}
VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
VFSItem item = container.resolve(filename);
if (item instanceof LocalFileImpl) {
// local file -> the length is given to the client which is good
Date lastModified = new Date(item.getLastModified());
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
File attachment = ((LocalFileImpl) item).getBasefile();
String mimeType = WebappHelper.getMimeType(attachment.getName());
if (mimeType == null)
mimeType = "application/octet-stream";
response = Response.ok(attachment).lastModified(lastModified).type(mimeType).cacheControl(cc);
}
return response.build();
} else if (item instanceof VFSLeaf) {
// stream -> the length is not given to the client which is not nice
Date lastModified = new Date(item.getLastModified());
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
StreamingOutput attachment = new VFSStreamingOutput((VFSLeaf) item);
String mimeType = WebappHelper.getMimeType(item.getName());
if (mimeType == null)
mimeType = "application/octet-stream";
response = Response.ok(attachment).lastModified(lastModified).type(mimeType).cacheControl(cc);
}
return response.build();
}
return Response.serverError().status(Status.NOT_FOUND).build();
}
Aggregations