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));
}
};
}
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);
}
}
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;
}
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);
}
}
}
}
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;
}
Aggregations