use of org.apache.wicket.util.file.File in project wicket by apache.
the class MultiFileUploadFieldTest method submitMultiFileUploadFields.
/**
* FormTester supports MultiFileUploadField
*
* https://issues.apache.org/jira/browse/WICKET-5346
*/
@Test
public void submitMultiFileUploadFields() {
final AtomicBoolean submitted = new AtomicBoolean(false);
final ListModel<FileUpload> filesModel = new ListModel<>(new ArrayList<FileUpload>());
TestPage page = new TestPage(filesModel) {
@Override
protected void onSubmit() {
super.onSubmit();
List<FileUpload> uploads = filesModel.getObject();
assertEquals(2, uploads.size());
for (int i = 0; i < 2; i++) {
FileUpload fileUpload = uploads.get(i);
String clientFileName = fileUpload.getClientFileName();
String id = clientFileName.replaceAll(MultiFileUploadFieldTest.class.getSimpleName() + "(\\d).txt", "$1");
try {
assertEquals("Test" + id, IOUtils.toString(fileUpload.getInputStream()));
} catch (IOException e) {
fail("Reading file upload '" + id + "' failed: " + e.getMessage());
}
}
submitted.set(true);
}
};
tester.startPage(page);
tester.assertContainsNot("disabled=\"disabled\"");
FormTester ft = tester.newFormTester("f");
ft.setFile("muf", new File("target/test-classes/org/apache/wicket/markup/html/form/upload/MultiFileUploadFieldTest0.txt"), "plain/text");
ft.setFile("muf", new File("target/test-classes/org/apache/wicket/markup/html/form/upload/MultiFileUploadFieldTest1.txt"), "plain/text");
ft.submit();
assertEquals("The form is not submitted", true, submitted.get());
}
use of org.apache.wicket.util.file.File in project wicket by apache.
the class AsynchronousPageStoreTest method storeReturnsSameInstanceOnClosePageRequest.
/**
* Store returns the same page instance from queue when there is a close request for it back
* again.
*
* @throws InterruptedException
*/
@Test
public void storeReturnsSameInstanceOnClosePageRequest() throws InterruptedException {
ISerializer serializer = new DeflatedJavaSerializer("applicationKey");
// ISerializer serializer = new DummySerializer();
IDataStore dataStore = new DiskDataStore("applicationName", new File("./target"), Bytes.bytes(10000l));
// IPageStore pageStore = new DummyPageStore(new File("target/store"));
IPageStore pageStore = spy(new DefaultPageStore(serializer, dataStore, 0));
IPageStore asyncPageStore = new AsynchronousPageStore(pageStore, 100);
int pageId = 0;
String sessionId = "sessionId";
DummyPage page = new DummyPage(pageId, 1000, 1000, sessionId);
asyncPageStore.storePage(sessionId, page);
Thread.sleep(500);
IManageablePage pageBack = asyncPageStore.getPage(sessionId, pageId);
verify(pageStore, never()).getPage(sessionId, pageId);
assertEquals(page, pageBack);
}
use of org.apache.wicket.util.file.File in project wicket by apache.
the class ReloadingClassLoader method watchForModifications.
/**
* Watch changes of a class file by locating it in the list of location URLs and adding the
* corresponding file to the ModificationWatcher
*
* @param clz
* the class to watch
*/
private void watchForModifications(final Class<?> clz) {
// Watch class in the future
Iterator<URL> locationsIterator = urls.iterator();
File clzFile = null;
while (locationsIterator.hasNext()) {
// FIXME only works for directories, but JARs etc could be checked
// as well
URL location = locationsIterator.next();
String clzLocation = location.getFile() + clz.getName().replaceAll("\\.", "/") + ".class";
log.debug("clzLocation=" + clzLocation);
clzFile = new File(clzLocation);
final File finalClzFile = clzFile;
if (clzFile.exists()) {
log.info("Watching changes of class " + clzFile);
watcher.add(clzFile, new IChangeListener<IModifiable>() {
@Override
public void onChange(IModifiable modifiable) {
log.info("Class file " + finalClzFile + " has changed, reloading");
try {
listener.onChange(clz);
} catch (Exception e) {
log.error("Could not notify listener", e);
// If an error occurs when the listener is notified,
// remove the watched object to avoid rethrowing the
// exception at next check
// FIXME check if class file has been deleted
watcher.remove(finalClzFile);
}
}
});
break;
} else {
log.debug("Class file does not exist: " + clzFile);
}
}
if (clzFile != null && !clzFile.exists()) {
log.debug("Could not locate class " + clz.getName());
}
}
use of org.apache.wicket.util.file.File in project wicket by apache.
the class FileResourceStreamReference method getReference.
@Override
public FileResourceStream getReference() {
FileResourceStream fileResourceStream = new FileResourceStream(new File(fileName));
restoreResourceStream(fileResourceStream);
return fileResourceStream;
}
use of org.apache.wicket.util.file.File in project midpoint by Evolveum.
the class PageImportObject method getInputDescription.
@NotNull
private InputDescription getInputDescription(boolean editor) throws Exception {
if (editor) {
return new InputDescription(IOUtils.toInputStream(xmlEditorModel.getObject(), StandardCharsets.UTF_8), dataLanguage);
}
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();
FileUtils.copyInputStreamToFile(uploadedFile.getInputStream(), newFile);
String language = getPrismContext().detectLanguage(newFile);
return new InputDescription(new FileInputStream(newFile), language);
} finally {
if (newFile != null) {
FileUtils.deleteQuietly(newFile);
}
}
}
Aggregations