use of org.eclipse.scout.rt.client.services.common.icon.IconSpec in project scout.rt by eclipse.
the class IconLoader method loadResource.
@Override
public BinaryResource loadResource(String pathInfo) throws IOException {
final String imageId = pathInfo.substring(pathInfo.lastIndexOf('/') + 1);
IconSpec iconSpec = IconLocator.instance().getIconSpec(imageId);
if (iconSpec == null) {
return null;
}
// cache: use max-age caching for at most 4 hours
return BinaryResources.create().withFilename(iconSpec.getName()).withContent(iconSpec.getContent()).withLastModified(System.currentTimeMillis()).withCachingAllowed(true).withCacheMaxAge(HttpCacheControl.MAX_AGE_4_HOURS).build();
}
use of org.eclipse.scout.rt.client.services.common.icon.IconSpec in project scout.rt by eclipse.
the class DefaultWizardStatusHtmlProvider method loadIcon.
/**
* To load an icon into the given attachments live list
*/
protected void loadIcon(List<BinaryResource> attachments, String iconName) {
if (attachments == null || iconName == null) {
return;
}
String tempIconName = iconName;
try {
int index;
// determine file format
index = tempIconName.lastIndexOf('.');
if (index > 0) {
tempIconName = tempIconName.substring(0, index);
}
// determine icon base name
String baseIconName = tempIconName;
index = tempIconName.lastIndexOf('_');
if (index > 0) {
baseIconName = tempIconName.substring(0, index);
}
// load icon
IconSpec iconSpec = IconLocator.instance().getIconSpec(tempIconName);
if (iconSpec == null && !tempIconName.equals(baseIconName)) {
iconSpec = IconLocator.instance().getIconSpec(baseIconName);
}
if (iconSpec != null) {
attachments.add(new BinaryResource(iconSpec.getName(), iconSpec.getContent()));
}
} catch (Exception t) {
LOG.warn("Failed to load icon '{}'", tempIconName, t);
}
}
use of org.eclipse.scout.rt.client.services.common.icon.IconSpec in project scout.rt by eclipse.
the class BinaryResourceUrlUtility method createIconUrl.
/**
* @return a relative URL for a configured logical icon-name or a font-based icon. For instance:
* <ul>
* <li>input: <code>"bookmark"</code>, output: <code>"icon/bookmark.png"</code> (the file extension is
* included to support auto-detection of the MIME type without looking at the file contents)</li>
* <li>input: <code>"font:X"</code>, output: <code>"font:X"</code></li>
* </ul>
* The file extension is included to be able to auto-detect the MIME type based on it.
* <p>
* Use this method for image-files located in the /resource/icons directories of all jars on the classpath.
*/
public static String createIconUrl(String iconId) {
if (!StringUtility.hasText(iconId) || AbstractIcons.Null.equals(iconId)) {
return null;
}
if (iconId.startsWith("font:")) {
return iconId;
}
IconSpec iconSpec = IconLocator.instance().getIconSpec(iconId);
if (iconSpec != null) {
// includes file extension
return "icon/" + iconSpec.getName();
}
LOG.warn("iconId '{}' could not be resolved", iconId);
// may happen, when no icon is available for the requested iconName
return null;
}
Aggregations