Search in sources :

Example 1 with ReaderInputStream

use of org.apache.xmlbeans.impl.common.ReaderInputStream 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)

Aggregations

InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 ReaderInputStream (org.apache.xmlbeans.impl.common.ReaderInputStream)1 Media (org.zkoss.util.media.Media)1 ForwardEvent (org.zkoss.zk.ui.event.ForwardEvent)1 UploadEvent (org.zkoss.zk.ui.event.UploadEvent)1 Iframe (org.zkoss.zul.Iframe)1