Search in sources :

Example 1 with ApplicationDescriptor

use of com.enonic.xp.app.ApplicationDescriptor in project xp by enonic.

the class XmlApplicationParserTest method testSiteXmlDeserialization.

@Test
public void testSiteXmlDeserialization() {
    final String xml = loadTestXml("serialized-application.xml");
    final ApplicationDescriptor.Builder appDescriptorBuilder = ApplicationDescriptor.create();
    ApplicationKey applicationKey = ApplicationKey.from("myapplication");
    this.parser.source(xml).currentApplication(applicationKey).appDescriptorBuilder(appDescriptorBuilder).parse();
    ApplicationDescriptor applicationDescriptor = appDescriptorBuilder.build();
    assertEquals("My app description", applicationDescriptor.getDescription());
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ApplicationDescriptor(com.enonic.xp.app.ApplicationDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with ApplicationDescriptor

use of com.enonic.xp.app.ApplicationDescriptor in project xp by enonic.

the class ApplicationDescriptorServiceImpl method registerApplicationDescriptor.

private void registerApplicationDescriptor(final Bundle bundle) {
    final ApplicationDescriptorBuilder builder = new ApplicationDescriptorBuilder();
    builder.bundle(bundle);
    final ApplicationDescriptor applicationDescriptor = builder.build();
    registerApplicationDescriptor(ApplicationKey.from(bundle), applicationDescriptor);
}
Also used : ApplicationDescriptor(com.enonic.xp.app.ApplicationDescriptor)

Example 3 with ApplicationDescriptor

use of com.enonic.xp.app.ApplicationDescriptor in project xp by enonic.

the class ApplicationDescriptorBuilderTest method buildApplicationDescriptor.

@Test
public void buildApplicationDescriptor() throws Exception {
    final URL resource = resourceTestHelper.getTestResource(APP_DESCRIPTOR_FILENAME);
    Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(bundle.getResource(APP_DESCRIPTOR_FILENAME)).thenReturn(resource);
    Mockito.when(bundle.getSymbolicName()).thenReturn("myapplication");
    final URL resourceIcon = resourceTestHelper.getTestResource(APP_ICON_FILENAME);
    Mockito.when(bundle.getResource(APP_ICON_FILENAME)).thenReturn(resourceIcon);
    Mockito.when(bundle.getEntry(APP_ICON_FILENAME)).thenReturn(resourceIcon);
    final ApplicationDescriptor appDescriptor = new ApplicationDescriptorBuilder().bundle(bundle).build();
    assertEquals("My app description", appDescriptor.getDescription());
}
Also used : Bundle(org.osgi.framework.Bundle) URL(java.net.URL) ApplicationDescriptor(com.enonic.xp.app.ApplicationDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with ApplicationDescriptor

use of com.enonic.xp.app.ApplicationDescriptor 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)4 URL (java.net.URL)2 Test (org.junit.jupiter.api.Test)2 ApplicationKey (com.enonic.xp.app.ApplicationKey)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 Bundle (org.osgi.framework.Bundle)1