Search in sources :

Example 6 with Icon

use of com.enonic.xp.icon.Icon in project xp by enonic.

the class SchemaHelper method loadIcon.

public static Icon loadIcon(final Class clz, final String metaInfFolderName, final String name) {
    final String metaInfFolderBasePath = "/" + "META-INF" + "/" + metaInfFolderName;
    final String filePath = metaInfFolderBasePath + "/" + name.toLowerCase();
    final Icon svgIcon = doLoadIcon(clz, "image/svg+xml", filePath + ".svg");
    if (svgIcon != null) {
        return svgIcon;
    } else {
        return doLoadIcon(clz, "image/png", filePath + ".png");
    }
}
Also used : Icon(com.enonic.xp.icon.Icon)

Example 7 with Icon

use of com.enonic.xp.icon.Icon in project xp by enonic.

the class ApplicationDescriptorBuilder method build.

public ApplicationDescriptor build() {
    final URL url = bundle.getResource(APP_DESCRIPTOR_FILENAME);
    final String xml = parseAppXml(url);
    ApplicationDescriptor.Builder appDescriptorBuilder = ApplicationDescriptor.create();
    final XmlApplicationParser parser = new XmlApplicationParser().currentApplication(ApplicationKey.from(bundle)).appDescriptorBuilder(appDescriptorBuilder).source(xml);
    parser.parse();
    if (hasAppIcon(bundle)) {
        final URL iconUrl = bundle.getResource(APP_ICON_FILENAME);
        try (InputStream stream = iconUrl.openStream()) {
            final byte[] iconData = stream.readAllBytes();
            final Icon icon = Icon.from(iconData, "image/svg+xml", Instant.ofEpochMilli(this.bundle.getLastModified()));
            appDescriptorBuilder.icon(icon);
        } catch (IOException e) {
            throw new RuntimeException("Unable to load application icon for " + bundle.getSymbolicName(), e);
        }
    }
    return appDescriptorBuilder.build();
}
Also used : XmlApplicationParser(com.enonic.xp.xml.parser.XmlApplicationParser) InputStream(java.io.InputStream) Icon(com.enonic.xp.icon.Icon) IOException(java.io.IOException) URL(java.net.URL) ApplicationDescriptor(com.enonic.xp.app.ApplicationDescriptor)

Example 8 with Icon

use of com.enonic.xp.icon.Icon in project xp by enonic.

the class ContentTypeHandlerTest method testContentType.

private ContentType testContentType() {
    byte[] data = new byte[] { 1, 2, 3, 4, 5, 6 };
    final Instant ts = LocalDateTime.of(2016, 1, 1, 12, 0, 0).toInstant(ZoneOffset.UTC);
    Icon schemaIcon = Icon.from(data, "image/png", ts);
    return ContentType.create().name("com.enonic.myapp:article").displayName("Article").description("Article content type").superType(ContentTypeName.structured()).displayNameExpression("${title} ${author}").icon(schemaIcon).form(getForm()).build();
}
Also used : Instant(java.time.Instant) Icon(com.enonic.xp.icon.Icon)

Aggregations

Icon (com.enonic.xp.icon.Icon)8 Instant (java.time.Instant)2 Test (org.junit.jupiter.api.Test)2 WidgetDescriptor (com.enonic.xp.admin.widget.WidgetDescriptor)1 ApplicationDescriptor (com.enonic.xp.app.ApplicationDescriptor)1 XmlApplicationParser (com.enonic.xp.xml.parser.XmlApplicationParser)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1