Search in sources :

Example 1 with File

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");
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) AjaxDownloadBehaviorFromFile(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile) File(org.apache.wicket.util.file.File) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 2 with File

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)));
}
Also used : MidpointConfiguration(com.evolveum.midpoint.common.configuration.api.MidpointConfiguration) AjaxDownloadBehaviorFromFile(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile) File(org.apache.wicket.util.file.File) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) RestartResponseException(org.apache.wicket.RestartResponseException) IOException(java.io.IOException) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Example 3 with File

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);
        }
    }
}
Also used : MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) InputStreamReader(java.io.InputStreamReader) WebApplicationConfiguration(com.evolveum.midpoint.web.security.WebApplicationConfiguration) File(org.apache.wicket.util.file.File) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload) FileInputStream(java.io.FileInputStream)

Example 4 with File

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));
    }
}
Also used : File(org.apache.wicket.util.file.File)

Example 5 with File

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());
}
Also used : MockDomainObjectFileUpload(org.apache.wicket.util.tester.MockFormFileUploadPage.MockDomainObjectFileUpload) File(org.apache.wicket.util.file.File) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload) MockDomainObjectFileUpload(org.apache.wicket.util.tester.MockFormFileUploadPage.MockDomainObjectFileUpload) Test(org.junit.Test)

Aggregations

File (org.apache.wicket.util.file.File)28 Test (org.junit.Test)12 IOException (java.io.IOException)7 FileUpload (org.apache.wicket.markup.html.form.upload.FileUpload)6 AjaxDownloadBehaviorFromFile (com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromFile)5 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)5 WebApplicationConfiguration (com.evolveum.midpoint.web.security.WebApplicationConfiguration)5 FileInputStream (java.io.FileInputStream)5 MidpointConfiguration (com.evolveum.midpoint.common.configuration.api.MidpointConfiguration)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 RestartResponseException (org.apache.wicket.RestartResponseException)4 FormTester (org.apache.wicket.util.tester.FormTester)4 CommonException (com.evolveum.midpoint.util.exception.CommonException)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 IManageablePage (org.apache.wicket.page.IManageablePage)3 ISerializer (org.apache.wicket.serialize.ISerializer)3 DeflatedJavaSerializer (org.apache.wicket.serialize.java.DeflatedJavaSerializer)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2