Search in sources :

Example 1 with XmlApplicationParser

use of com.enonic.xp.xml.parser.XmlApplicationParser 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)

Aggregations

ApplicationDescriptor (com.enonic.xp.app.ApplicationDescriptor)1 Icon (com.enonic.xp.icon.Icon)1 XmlApplicationParser (com.enonic.xp.xml.parser.XmlApplicationParser)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1