Search in sources :

Example 6 with ResourceStreamNotFoundException

use of org.apache.wicket.util.resource.ResourceStreamNotFoundException in project webanno by webanno.

the class AJAXDownload method getResourceStream.

/**
 * Hook method providing the actual resource stream.
 *
 * @return the stream.
 */
protected IResourceStream getResourceStream() {
    return new AbstractResourceStream() {

        private static final long serialVersionUID1 = 1L;

        InputStream inStream;

        @Override
        public InputStream getInputStream() throws ResourceStreamNotFoundException {
            try {
                inStream = new FileInputStream(fileName);
            } catch (IOException e) {
                throw new ResourceStreamNotFoundException(e);
            }
            return inStream;
        }

        @Override
        public void close() throws IOException {
            inStream.close();
            inStream = null;
            FileUtils.forceDelete(new File(fileName));
        }
    };
}
Also used : AbstractResourceStream(org.apache.wicket.util.resource.AbstractResourceStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 7 with ResourceStreamNotFoundException

use of org.apache.wicket.util.resource.ResourceStreamNotFoundException in project wicket by apache.

the class InlineImage method onComponentTag.

/**
 * Renders the complete image tag with the base64 encoded content.
 */
@Override
protected void onComponentTag(ComponentTag tag) {
    super.onComponentTag(tag);
    checkComponentTag(tag, "img");
    try {
        tag.put("src", ImageUtil.createBase64EncodedImage(packageResourceReference, false));
    } catch (ResourceStreamNotFoundException e) {
        throw new WicketRuntimeException("Couldn't find the resource stream", e);
    } catch (IOException e) {
        throw new WicketRuntimeException("Error while reading the resource stream", e);
    }
}
Also used : WicketRuntimeException(org.apache.wicket.WicketRuntimeException) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException)

Example 8 with ResourceStreamNotFoundException

use of org.apache.wicket.util.resource.ResourceStreamNotFoundException in project wicket by apache.

the class DiffUtil method compareMarkup.

/**
 * @param a
 *            String a
 * @param b
 *            String b
 * @return True if the two strings have the same markup tags
 */
private static boolean compareMarkup(final String a, final String b) {
    try {
        // Parse a and b into markup and compare
        final MarkupStream amarkup = new MarkupStream(new MarkupParser(a).parse());
        final MarkupStream bmarkup = new MarkupStream(new MarkupParser(b).parse());
        return amarkup.equalTo(bmarkup);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } catch (ResourceStreamNotFoundException e) {
        log.error(e.getMessage(), e);
    }
    return false;
}
Also used : MarkupStream(org.apache.wicket.markup.MarkupStream) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) MarkupParser(org.apache.wicket.markup.MarkupParser)

Example 9 with ResourceStreamNotFoundException

use of org.apache.wicket.util.resource.ResourceStreamNotFoundException in project wicket by apache.

the class PackageTextTemplate method load.

/**
 * Loads the template if it is not loaded yet
 */
private void load() {
    if (buffer.length() == 0) {
        String path = Packages.absolutePath(scope, fileName);
        Application app = Application.get();
        // first try default class loading locator to find the resource
        IResourceStream stream = app.getResourceSettings().getResourceStreamLocator().locate(scope, path, getStyle(), getVariation(), getLocale(), null, false);
        if (stream == null) {
            // if the default locator didn't find the resource then fallback
            stream = new ResourceStreamLocator().locate(scope, path, getStyle(), getVariation(), getLocale(), null, false);
        }
        if (stream == null) {
            throw new IllegalArgumentException("resource " + fileName + " not found for scope " + scope + " (path = " + path + ")");
        }
        setLastModified(stream.lastModifiedTime());
        try {
            if (encoding != null) {
                buffer.append(Streams.readString(stream.getInputStream(), encoding));
            } else {
                buffer.append(Streams.readString(stream.getInputStream()));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ResourceStreamNotFoundException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                stream.close();
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
Also used : IResourceStream(org.apache.wicket.util.resource.IResourceStream) ResourceStreamLocator(org.apache.wicket.core.util.resource.locator.ResourceStreamLocator) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) Application(org.apache.wicket.Application)

Example 10 with ResourceStreamNotFoundException

use of org.apache.wicket.util.resource.ResourceStreamNotFoundException in project wicket by apache.

the class PropertiesFactory method loadFromLoader.

/**
 * @param loader
 * @param resourceStream
 * @return properties
 */
protected ValueMap loadFromLoader(final IPropertiesLoader loader, final IResourceStream resourceStream) {
    if (log.isDebugEnabled()) {
        log.debug("Loading properties files from '{}' with loader '{}'", resourceStream, loader);
    }
    BufferedInputStream in = null;
    try {
        // Get the InputStream
        in = new BufferedInputStream(resourceStream.getInputStream());
        ValueMap data = loader.loadWicketProperties(in);
        if (data == null) {
            java.util.Properties props = loader.loadJavaProperties(in);
            if (props != null) {
                // Copy the properties into the ValueMap
                data = new ValueMap();
                Enumeration<?> enumeration = props.propertyNames();
                while (enumeration.hasMoreElements()) {
                    String property = (String) enumeration.nextElement();
                    data.put(property, props.getProperty(property));
                }
            }
        }
        return data;
    } catch (ResourceStreamNotFoundException | IOException e) {
        log.warn("Unable to find resource " + resourceStream, e);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(resourceStream);
    }
    return null;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ValueMap(org.apache.wicket.util.value.ValueMap) IOException(java.io.IOException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException)

Aggregations

ResourceStreamNotFoundException (org.apache.wicket.util.resource.ResourceStreamNotFoundException)16 IOException (java.io.IOException)15 InputStream (java.io.InputStream)7 IResourceStream (org.apache.wicket.util.resource.IResourceStream)7 AbstractResourceStream (org.apache.wicket.util.resource.AbstractResourceStream)4 Time (org.apache.wicket.util.time.Time)4 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2 ServletContext (javax.servlet.ServletContext)2 AjaxEventBehavior (org.apache.wicket.ajax.AjaxEventBehavior)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2 WebApplication (org.apache.wicket.protocol.http.WebApplication)2 AjaxButton (com.googlecode.wicket.jquery.ui.form.button.AjaxButton)1 AgreementResult (de.tudarmstadt.ukp.clarin.webanno.curation.agreement.AgreementUtils.AgreementResult)1 AJAXDownload (de.tudarmstadt.ukp.clarin.webanno.support.AJAXDownload)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 AbstractMap (java.util.AbstractMap)1