Search in sources :

Example 21 with ApplicationKey

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

the class ContentMappingConstraint method getXData.

private PropertyTree getXData(final ExtraDatas xDatas, final String appPrefix, final String name) {
    if (xDatas == null) {
        return null;
    }
    try {
        final ApplicationKey app = ExtraData.fromApplicationPrefix(appPrefix);
        final XDataName xDataName = XDataName.from(app, name);
        final ExtraData extraData = xDatas.getMetadata(xDataName);
        if (extraData == null) {
            return null;
        }
        return extraData.getData();
    } catch (Exception e) {
        return null;
    }
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 22 with ApplicationKey

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

the class AdminToolPortalHandler method getDescriptorKey.

public static DescriptorKey getDescriptorKey(final WebRequest webRequest) {
    final String path = webRequest.getRawPath();
    if (path.startsWith(ADMIN_TOOL_PREFIX)) {
        final String subPath = path.substring(ADMIN_TOOL_PREFIX.length());
        final Matcher matcher = PATTERN.matcher(subPath);
        if (matcher.find()) {
            final ApplicationKey applicationKey = ApplicationKey.from(matcher.group(1));
            final String adminToolName = matcher.group(2);
            return DescriptorKey.from(applicationKey, adminToolName);
        }
    }
    return null;
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) Matcher(java.util.regex.Matcher)

Example 23 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey 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 24 with ApplicationKey

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

the class XmlSiteParserTest method testSiteXmlDeserializationWithMappingFilters.

@Test
public void testSiteXmlDeserializationWithMappingFilters() {
    final String xml = loadTestXml("serialized-site-with-mapping-filters.xml");
    final SiteDescriptor.Builder siteDescriptorBuilder = SiteDescriptor.create();
    ApplicationKey applicationKey = ApplicationKey.from("myapplication");
    this.parser.source(xml).currentApplication(applicationKey).siteDescriptorBuilder(siteDescriptorBuilder).parse();
    SiteDescriptor siteDescriptor = siteDescriptorBuilder.build();
    assertEquals(2, siteDescriptor.getMappingDescriptors().getSize());
    final ControllerMappingDescriptor mapping1 = siteDescriptor.getMappingDescriptors().get(0);
    final ControllerMappingDescriptor mapping2 = siteDescriptor.getMappingDescriptors().get(1);
    assertEquals("myapplication:/filter1.js", mapping1.getFilter().toString());
    assertEquals("_path:'/*/fisk'", mapping1.getContentConstraint().toString());
    assertEquals("/.*", mapping1.getPattern().toString());
    assertEquals(50, mapping1.getOrder());
    assertEquals("myapplication:/filter2.js", mapping2.getFilter().toString());
    assertEquals("type:'portal:fragment'", mapping2.getContentConstraint().toString());
    assertEquals("/.*", mapping2.getPattern().toString());
    assertEquals(5, mapping2.getOrder());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) Test(org.junit.jupiter.api.Test)

Example 25 with ApplicationKey

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

the class XmlSiteParserTest method testEmptySiteXmlDeserialization.

@Test
public void testEmptySiteXmlDeserialization() {
    final String xml = loadTestXml("empty-site.xml");
    final SiteDescriptor.Builder siteDescriptorBuilder = SiteDescriptor.create();
    ApplicationKey applicationKey = ApplicationKey.from("myapplication");
    this.parser.source(xml).currentApplication(applicationKey).siteDescriptorBuilder(siteDescriptorBuilder).parse();
    SiteDescriptor siteDescriptor = siteDescriptorBuilder.build();
    assertEquals(0, siteDescriptor.getForm().getFormItems().size());
    assertEquals(0, siteDescriptor.getXDataMappings().getSize());
    assertEquals(0, siteDescriptor.getResponseProcessors().getSize());
    assertEquals(0, siteDescriptor.getMappingDescriptors().getSize());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationKey (com.enonic.xp.app.ApplicationKey)78 Test (org.junit.jupiter.api.Test)40 Application (com.enonic.xp.app.Application)16 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)12 Bundle (org.osgi.framework.Bundle)10 ResourceKey (com.enonic.xp.resource.ResourceKey)6 PropertyTree (com.enonic.xp.data.PropertyTree)5 ExtraData (com.enonic.xp.content.ExtraData)4 Site (com.enonic.xp.site.Site)4 Node (com.enonic.xp.node.Node)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 XDataName (com.enonic.xp.schema.xdata.XDataName)3 ByteSource (com.google.common.io.ByteSource)3 ApplicationInvalidator (com.enonic.xp.app.ApplicationInvalidator)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)2 PropertySet (com.enonic.xp.data.PropertySet)2 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)2 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)2