use of org.apache.wicket.util.file.File in project midpoint by Evolveum.
the class PageAccounts method createWriter.
private Writer createWriter(String fileName) throws IOException {
//todo improve!!!!!!!
MidpointConfiguration config = getMidpointConfiguration();
File exportFolder = new File(config.getMidpointHome() + "/export/");
File file = new File(exportFolder, fileName);
try {
if (!exportFolder.exists() || !exportFolder.isDirectory()) {
exportFolder.mkdir();
}
file.createNewFile();
} catch (Exception ex) {
error(getString("PageAccounts.exportFileDoesntExist", file.getAbsolutePath()));
throw ex;
}
return new OutputStreamWriter(new FileOutputStream(file), "utf-8");
}
use of org.apache.wicket.util.file.File in project midpoint by Evolveum.
the class PageAccounts method clearExportPerformed.
private void clearExportPerformed(AjaxRequestTarget target) {
try {
MidpointConfiguration config = getMidpointConfiguration();
File exportFolder = new File(config.getMidpointHome() + "/export");
java.io.File[] files = exportFolder.listFiles();
if (files == null) {
return;
}
for (java.io.File file : files) {
file.delete();
}
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete export files", ex);
error("Couldn't delete export files, reason: " + ex.getMessage());
}
filesModel.reset();
success(getString("PageAccounts.message.success.clearExport"));
target.add(getFeedbackPanel(), get(createComponentPath(ID_FORM_ACCOUNT, ID_FILES_CONTAINER)));
}
use of org.apache.wicket.util.file.File in project midpoint by Evolveum.
the class PageImportObject method getInputStream.
private InputStream getInputStream(boolean raw) throws Exception {
if (raw) {
return IOUtils.toInputStream(xmlEditorModel.getObject(), "utf-8");
}
File newFile = null;
try {
// Create new file
MidPointApplication application = getMidpointApplication();
WebApplicationConfiguration config = application.getWebApplicationConfiguration();
File folder = new File(config.getImportFolder());
if (!folder.exists() || !folder.isDirectory()) {
folder.mkdir();
}
FileUpload uploadedFile = getUploadedFile();
newFile = new File(folder, uploadedFile.getClientFileName());
// Check new file, delete if it already exists
if (newFile.exists()) {
newFile.delete();
}
// Save file
newFile.createNewFile();
uploadedFile.writeTo(newFile);
InputStreamReader reader = new InputStreamReader(new FileInputStream(newFile), "utf-8");
return new ReaderInputStream(reader, reader.getEncoding());
} finally {
if (newFile != null) {
FileUtils.deleteQuietly(newFile);
}
}
}
use of org.apache.wicket.util.file.File in project asterixdb by apache.
the class FeedSpillerUnitTest method removeSpillFiles.
public void removeSpillFiles() throws IOException {
File cwd = new File("./");
String[] spills = cwd.list(SPILL_FILE_FILTER);
for (String fileName : spills) {
Files.delete(Paths.get(fileName));
}
}
use of org.apache.wicket.util.file.File in project wicket by apache.
the class FormTesterTest method addFile.
/**
* Test that the user can use
* {@link FormTester#setFile(String, org.apache.wicket.util.file.File, String)} to test that
* upload to a FileUploadField works.
*/
@Test
public void addFile() {
tester.startPage(MockFormFileUploadPage.class);
MockFormFileUploadPage page = (MockFormFileUploadPage) tester.getLastRenderedPage();
MockDomainObjectFileUpload domainObject = page.getDomainObject();
assertNull(page.getFileUpload());
assertNotNull(domainObject);
assertNull(domainObject.getText());
FormTester formTester = tester.newFormTester("form");
formTester.setFile("file", new File("pom.xml"), "text/xml");
formTester.setValue("text", "Mock value");
formTester.submit();
assertNotNull(domainObject);
assertNotNull(domainObject.getText());
assertEquals("Mock value", domainObject.getText());
FileUpload fileUpload = page.getFileUpload();
assertNotNull(fileUpload);
assertTrue("setFile failed, no upload content detected.", fileUpload.getBytes().length > 0);
assertEquals("pom.xml", fileUpload.getClientFileName());
assertEquals("text/xml", fileUpload.getContentType());
}
Aggregations