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