@Override public void onFinish(IUploader uploader) { String serverResponse = uploader.getServerInfo().message; if (serverResponse != null && !serverResponse.isEmpty()) { serverResponse = serverResponse.replaceAll("\n", "<br>"); messagePresenter.showMessage("File Manager", serverResponse); } if (uploader.getStatus() == Status.SUCCESS) { uploader.getStatusWidget().setFileName("Done uploading."); fileTreePresenter.refresh(fileFilter); } // only needed when MultiUploader is used instead of SingleUploader. There somewhat of a new // instance of MultiUploader // is created for each additional upload. // try to avoid MultiUploader, it will create a new HTML element for each uploader making it // complex to style // also MultiUploader is not needed, in comparison to SingleUploader it only allows to append // additional uploads once // a previous upload is still running. It doesn't mean multiple files, this can also be done // with SingleUploader /*IFileInput ctrl = display.getUploader().getFileInput(); DOM.setElementProperty(((UIObject) ctrl).getElement(), "multiple", "multiple");*/ uploader.setServletPath(defaultServletPath); enableManagement(); }
private boolean controleUpload(IUploader uploader, final StringBuilder messageToReturn) { // controle String baseName = uploader.getBasename(); baseName = (baseName == null) ? null : baseName.trim().toLowerCase(); log.config("baseName: " + baseName); if (baseName == null || baseName.length() == 0 || !(baseName.endsWith(Constantes.EXTENSION_ZIP) || baseName.endsWith(Constantes.EXTENSION_JAR))) { log.severe("annulation du téléchargement!"); uploader.cancel(); messageToReturn.append( "Le fichier choisi n'existe pas ou bien n'est pas une archive zip ou jar!"); return false; } log.config("File url " + uploader.fileUrl()); // The server sends useful information to the client by default UploadedInfo info = uploader.getServerInfo(); if (info != null) { log.config("File name " + info.name); log.config("File content-type " + info.ctype); log.config("File size " + info.size); } return true; }
@Override public void onFinish(IUploader uploader) { if (uploader.getStatus().equals(Status.SUCCESS)) { UploadedInfo info = uploader.getServerInfo(); if (info != null && info.message != null && !info.message.equals("noid")) { String entityId = info.message; BinaryRequest binaryRequest = requestFactory.binaryRequest(); Request<BinaryProxy> binaryFileRequest = binaryRequest.getBinary(entityId); binaryFileRequest.fire( new Receiver<BinaryProxy>() { @Override public void onSuccess(BinaryProxy response) { value = response; uploading = false; } @Override public void onFailure(ServerFailure error) { Window.alert("Error retrieving the Binary Description"); super.onFailure(error); } }); if (thumbnail != null && info.ctype.contains("image")) { // Attach thumbnail OnLoadPreloadedImageHandler showImage = new OnLoadPreloadedImageHandler() { public void onLoad(PreloadedImage image) { thumbnail.setUrl(image.getUrl()); } }; new PreloadedImage("servlet.gupld?show=" + entityId, showImage); } } } if (uploader.getStatus().equals(Status.CANCELED)) { setNew(); } }
public void onFinish(IUploader uploader) { if (uploader.getStatus() == Status.SUCCESS) { if (uploader.getServerMessage().getMessage() == "ErrorFirma") { UIValidarFormulario vf = new UIValidarFormulario("Firma no valida:"); vf.addError("Verifique la firma digital del documento adjunto"); vf.esValido(); return; } String[] archivos = uploader.getServerMessage().getMessage().split("\\|"); for (int i = 0; i < archivos.length; i += 2) { Adjunto a = new Adjunto(); a.setRutaArchivo(archivos[0]); a.setNombreArchivo(archivos[1]); a.setTipo(Adjunto.Tipo.NotaInterinstitucional); adjuntos[0] = a; } uploadTable.setText(0, 1, archivos[2]); uploadTable.setWidget(0, 2, eliminarNotaInterinstitucional); } }
@Override public void onStart(final IUploader uploader) { uploader.getStatusWidget().setFileName("Uploading, please wait..."); final FileImageLabelTreeItem selection = fileTreePresenter.getSelectedItem(); if (selection.getFileInfo().getFileType().equals(FileTypeEnum.DIRECTORY)) { uploader.setServletPath( uploader.getServletPath() + "&target=" + selection.getFileInfo().getFilePath()); } else { String newFilePath = getParent(selection); uploader.setServletPath(uploader.getServletPath() + "&target=" + newFilePath); } // only needed when MultiUploader is used instead of SingleUploader // display.setStatusWidget(display.getUploader().getStatusWidget().getWidget()); /* * Creation of directories directly inside of the upload target should not be possible (possible name clash) * Rename of target and files directly inside of target should not be possible (target no longer available, name clash) * Delete of target should not be possible (target no longer available) */ // for now, just disable all of the others: disableManagement(); }
private void getDataFromServer( final Action action, final ActionState state, final Object object) { if (log.isLoggable(Level.INFO)) { log.info( "getDataFromServer: action " + action + " - state: " + state + ((object == null) ? "" : " - object: " + object.toString())); } AppController.getInstance().done(Action.clearStatus); switch (action) { case uploadContent: switch (state) { case done: AppController.getInstance().reinit(); getDataFromServer(Action.buildApplicationFromContent); this._projectName = object.toString(); this.displayPanels(); break; } break; case uploadZip: // controle IUploader uploader = null; if (state != ActionState.error && object != null && object instanceof IUploader) { uploader = (IUploader) object; final StringBuilder errorMessage = new StringBuilder(); if (!controleUpload(uploader, errorMessage)) { getDataFromServer(Action.uploadZip, ActionState.error, errorMessage.toString()); break; } } switch (state) { case start: _projectName = null; AppController.getInstance().reinit(); AppController.getInstance().inProgress(action); break; case done: if (uploader.getStatus() == Status.SUCCESS) { AppController.getInstance().done(action); _projectName = uploader.getServerInfo().name; displayPanels(); // You can send any customized message and parse it log.config("Server message " + uploader.getServerInfo().message); getDataFromServer(Action.buildApplication); } break; case cancel: AppController.getInstance().done(Action.uploadZip, "Interruption par l'utilisateur"); _projectName = null; displayPanels(); break; case error: AppController.getInstance() .error(Action.uploadZip, (object == null) ? "erreur inconnue!" : object.toString()); break; } break; case loadModules: AppController.getInstance().inProgress(action); AppController.getService() .loadModules( new ServiceCallback<List<ModuleLightDto>>(action) { @Override public void onSuccess(List<ModuleLightDto> result) { _tableModules.populateGrid(result); AppController.getInstance().done(action); } }); break; case buildApplication: { AppController.getInstance().inProgress(action); AppController.getService() .buildApplication( this.getSourceDir(), new ServiceCallback<Boolean>(action) { @Override public void onSuccess(Boolean result) { AppController.getInstance().done(action); getDataFromServer(Action.loadModules); } }); break; } case buildApplicationFromContent: { AppController.getInstance().inProgress(action); AppController.getInstance().inProgress(action); AppController.getService() .buildApplicationFromMapContent( this.getSourceDir(), new ServiceCallback<Boolean>(action) { @Override public void onSuccess(Boolean result) { AppController.getInstance().done(action); getDataFromServer(Action.loadModules); } }); break; } case buildDemo: _projectName = "démo"; AppController.getInstance().reinit(); AppController.getInstance().inProgress(action); AppController.getService() .buildDemo( new ServiceCallback<Boolean>(action) { @Override public void onSuccess(Boolean result) { AppController.getInstance().done(action); displayPanels(); getDataFromServer(Action.loadModules); } }); break; } }