Search in sources :

Example 1 with Media

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();
}
Also used : UploadSpeciesController(au.org.ala.spatial.composer.input.UploadSpeciesController) Media(org.zkoss.util.media.Media) UserDataDTO(au.org.ala.spatial.dto.UserDataDTO)

Example 2 with Media

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);
    }
}
Also used : Iframe(org.zkoss.zul.Iframe) ReaderInputStream(org.apache.xmlbeans.impl.common.ReaderInputStream) ForwardEvent(org.zkoss.zk.ui.event.ForwardEvent) ReaderInputStream(org.apache.xmlbeans.impl.common.ReaderInputStream) InputStream(java.io.InputStream) Media(org.zkoss.util.media.Media) Reader(java.io.Reader) UploadEvent(org.zkoss.zk.ui.event.UploadEvent)

Example 3 with Media

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;
    }
}
Also used : Media(org.zkoss.util.media.Media) AMedia(org.zkoss.util.media.AMedia)

Example 4 with Media

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();
}
Also used : ReaderInputStream(org.adempiere.webui.util.ReaderInputStream) Media(org.zkoss.util.media.Media) Charset(java.nio.charset.Charset) ListItem(org.adempiere.webui.component.ListItem)

Example 5 with Media

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);
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) Media(org.zkoss.util.media.Media) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) File(java.io.File)

Aggregations

Media (org.zkoss.util.media.Media)11 UploadEvent (org.zkoss.zk.ui.event.UploadEvent)4 UserDataDTO (au.org.ala.spatial.dto.UserDataDTO)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 StringReader (java.io.StringReader)3 ForwardEvent (org.zkoss.zk.ui.event.ForwardEvent)3 AMedia (org.zkoss.util.media.AMedia)2 UploadSpeciesController (au.org.ala.spatial.composer.input.UploadSpeciesController)1 MapLayer (au.org.emii.portal.menu.MapLayer)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 ParseException (com.vividsolutions.jts.io.ParseException)1 WKTReader (com.vividsolutions.jts.io.WKTReader)1 IsValidOp (com.vividsolutions.jts.operation.valid.IsValidOp)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Reader (java.io.Reader)1 Charset (java.nio.charset.Charset)1