use of org.zkoss.util.media.Media in project spatial-portal by AtlasOfLivingAustralia.
the class ToolComposer method onUpload$fileUpload.
public void onUpload$fileUpload(Event event) {
UploadEvent ue = null;
UserDataDTO ud = null;
if (event instanceof UploadEvent) {
ue = (UploadEvent) event;
} else if (event instanceof ForwardEvent) {
ue = (UploadEvent) ((ForwardEvent) event).getOrigin();
}
Media m = ue.getMedia();
if (ud == null) {
ud = new UserDataDTO(m.getName());
}
if (ud.getName().trim().isEmpty()) {
ud.setName(m.getName());
}
ud.setFilename(m.getName());
if (ud.getName() == null || ud.getName().length() == 0) {
ud.setName(m.getName());
}
if (ud.getDescription() == null || ud.getDescription().length() == 0) {
ud.setDescription(m.getName());
}
ud.setUploadedTimeInMs(System.currentTimeMillis());
UploadSpeciesController usc = (UploadSpeciesController) Executions.createComponents("WEB-INF/zul/input/UploadSpecies.zul", this, null);
usc.setAddToMap(false);
if (rgSpeciesBk != null) {
if (rgSpeciesBk.getSelectedItem() == rSpeciesUploadLSIDBk) {
usc.setUploadType(StringConstants.ASSEMBLAGE_BK);
} else if (rgSpeciesBk.getSelectedItem() == rSpeciesUploadSpeciesBk) {
usc.setUploadType("bk");
}
}
usc.setVisible(false);
usc.doOverlapped();
usc.doFileUpload(ud, event);
usc.detach();
}
use of org.zkoss.util.media.Media in project spatial-portal by AtlasOfLivingAustralia.
the class SandboxPasteController method doFileUpload.
public void doFileUpload(Event event) {
UploadEvent ue = null;
if (event instanceof UploadEvent) {
ue = (UploadEvent) event;
} else if (event instanceof ForwardEvent) {
ue = (UploadEvent) ((ForwardEvent) event).getOrigin();
}
if (ue == null) {
LOGGER.debug("unable to upload file");
return;
} else {
LOGGER.debug("fileUploaded()");
}
try {
Media m = ue.getMedia();
String filename = m.getName();
String contentType = m.getContentType();
String format = m.getFormat();
boolean loaded = false;
if (!loaded) {
try {
loaded = upload(m.getByteData(), filename, contentType);
LOGGER.debug(m.getContentType() + " with getByteData");
} catch (Exception e) {
//failed to read, will try another method
}
}
if (!loaded) {
try {
loaded = upload(IOUtils.toByteArray(m.getStreamData()), filename, contentType);
LOGGER.debug(m.getContentType() + " with getStreamData");
} catch (Exception e) {
//failed to read, will try another method
}
}
try {
Reader r = m.getReaderData();
InputStream is = new ReaderInputStream(r, "UTF-8");
loaded = upload(IOUtils.toByteArray(is), filename, contentType);
LOGGER.debug(m.getContentType() + " with getReaderData");
} catch (Exception e) {
//failed to read, will try another method
}
if (!loaded) {
try {
loaded = upload(m.getStringData().getBytes(), filename, contentType);
LOGGER.debug(m.getContentType() + " with getStringData");
} catch (Exception e) {
//last one, report error
getMapComposer().showMessage(CommonData.lang("error_uploading_file"));
LOGGER.error("unable to load user layer list: ", e);
}
}
//process if successful upload
if (loaded) {
((Iframe) getFellow("sandboxFrame")).setSrc("sandboxPreview.html?uploadId=" + uploadId + "&uploadFn=" + uploadFn);
//display frame and trigger javascript setup function
getMapComposer().getOpenLayersJavascript().execute("$('#sandboxContainer')[0].style.display = \"inline\";setTimeout(\"setUrls()\",500)");
getFellow("fileUpload").setVisible(false);
getFellow("fileUpload").detach();
getFellow("divSandbox").setVisible(false);
setTop("10px");
}
} catch (Exception ex) {
LOGGER.error("error reading uploaded file", ex);
}
}
use of org.zkoss.util.media.Media in project adempiere by adempiere.
the class WAttachment method loadFile.
// onEvent
/**************************************************************************
* Load file for attachment
*/
private void loadFile() {
log.info("");
preview.setVisible(false);
Media media = null;
try {
media = Fileupload.get(true);
if (media != null) {
// pdfViewer.setContent(media);
;
} else {
preview.setVisible(true);
preview.invalidate();
return;
}
} catch (InterruptedException e) {
log.log(Level.WARNING, e.getLocalizedMessage(), e);
}
String fileName = media.getName();
log.config(fileName);
int cnt = m_attachment.getEntryCount();
//update
for (int i = 0; i < cnt; i++) {
if (m_attachment.getEntryName(i).equals(fileName)) {
m_attachment.updateEntry(i, getMediaData(media));
cbContent.setSelectedIndex(i);
displayData(cbContent.getSelectedIndex(), false);
m_change = true;
return;
}
}
//new
if (m_attachment.addEntry(fileName, getMediaData(media))) {
cbContent.appendItem(media.getName(), media.getName());
cbContent.setSelectedIndex(cbContent.getItemCount() - 1);
displayData(cbContent.getSelectedIndex(), false);
m_change = true;
}
}
use of org.zkoss.util.media.Media in project adempiere by adempiere.
the class WFileImport method cmd_loadFile.
/**************************************************************************
* Load File
*/
private void cmd_loadFile() {
Media media = null;
media = Fileupload.get();
if (media == null)
return;
if (media.isBinary()) {
m_file_istream = media.getStreamData();
} else {
ListItem listitem = fCharset.getSelectedItem();
if (listitem == null) {
m_file_istream = new ReaderInputStream(media.getReaderData());
} else {
Charset charset = (Charset) listitem.getValue();
m_file_istream = new ReaderInputStream(media.getReaderData(), charset.name());
}
}
log.config(media.getName());
bFile.setLabel(media.getName());
cmd_reloadFile();
}
use of org.zkoss.util.media.Media in project adempiere by adempiere.
the class WFilenameEditor method cmd_file.
/**
* Load file
*/
private void cmd_file() {
// Show File Open Dialog
Media file = null;
file = Fileupload.get(true);
if (file == null)
return;
// String fileName = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + ;
// File tempFile = new File(fileName);
FileOutputStream fos = null;
String fileName = null;
try {
File tempFile = File.createTempFile("adempiere_", "_" + file.getName());
fileName = tempFile.getAbsolutePath();
fos = new FileOutputStream(tempFile);
byte[] bytes = null;
if (file.inMemory()) {
bytes = file.getByteData();
} else {
InputStream is = file.getStreamData();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[1000];
int byteread = 0;
while ((byteread = is.read(buf)) != -1) baos.write(buf, 0, byteread);
bytes = baos.toByteArray();
}
fos.write(bytes);
fos.flush();
fos.close();
} catch (IOException e) {
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
return;
} finally {
if (fos != null)
try {
fos.close();
} catch (IOException e) {
}
}
getComponent().setText(fileName);
}
Aggregations