use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class StandardRenditionLocationResolverTest method testChildAssociationFinder.
@Test
public void testChildAssociationFinder() {
QName renditionKind = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "test");
NodeRef sourceNode = makeNode(companyHome, ContentModel.TYPE_CONTENT);
NodeRef tempRenditionNode = makeNode(sourceNode, ContentModel.TYPE_CONTENT);
RenditionDefinition renditionDef = renditionService.createRenditionDefinition(renditionKind, "brians_test_engine");
// Test default behaviour, no destination path or NodeRef specified.
RenditionLocation location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
assertEquals(sourceNode, location.getParentRef());
assertNull(location.getChildName());
assertNull(location.getChildRef());
// Test fully specified path.
NodeRef targetFolder = makeNode(companyHome, ContentModel.TYPE_FOLDER);
String companyHomeName = (String) nodeService.getProperty(companyHome, ContentModel.PROP_NAME);
String targetFolderName = (String) nodeService.getProperty(targetFolder, ContentModel.PROP_NAME);
String template = "/" + companyHomeName + "/" + targetFolderName + "/brian.xml";
renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, template);
location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
assertEquals(targetFolder, location.getParentRef());
assertEquals("brian.xml", location.getChildName());
assertNull(location.getChildRef());
// Test path with name substitution.
template = targetFolderName + "/test-${sourceContentType}.xml";
renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, template);
location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
assertEquals(targetFolder, location.getParentRef());
assertEquals("test-" + ContentModel.PROP_CONTENT.getLocalName() + ".xml", location.getChildName());
assertNull(location.getChildRef());
// Test that when the template path specifies an existing node then that
// node is set as the 'childRef' property on the RenditionLocation.
NodeRef destinationNode = makeNode(targetFolder, ContentModel.TYPE_CONTENT);
String destinationName = (String) nodeService.getProperty(destinationNode, ContentModel.PROP_NAME);
template = targetFolderName + "/" + destinationName;
renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, template);
location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
assertEquals(targetFolder, location.getParentRef());
assertEquals(destinationName, location.getChildName());
assertEquals(destinationNode, location.getChildRef());
// Test that the 'destination node' param takes precedence over the 'template path' param.
template = "/" + targetFolderName + "/brian.xml";
renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, template);
renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_NODE, destinationNode);
location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
assertEquals(targetFolder, location.getParentRef());
assertEquals(destinationName, location.getChildName());
assertEquals(destinationNode, location.getChildRef());
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class StandardRenditionLocationResolverTest method testCreatesFoldersForTemplatedLocation.
@Test
public void testCreatesFoldersForTemplatedLocation() throws Exception {
QName fooName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testFooFolder");
QName barName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testBarFolder");
String fooPath = "/testFooFolder";
String barPath = fooPath + "/testBarFolder";
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(companyHome, ContentModel.ASSOC_CONTAINS, fooName);
assertTrue("Folder " + fooPath + " should not exist!", childAssocs.isEmpty());
QName renditionKind = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "test");
NodeRef sourceFolder = makeNode(companyHome, ContentModel.TYPE_FOLDER);
NodeRef sourceNode = makeNode(sourceFolder, ContentModel.TYPE_CONTENT);
NodeRef tempRenditionNode = makeNode(companyHome, ContentModel.TYPE_CONTENT);
RenditionDefinition renditionDef = renditionService.createRenditionDefinition(renditionKind, "nicks_test_engine");
String pathTemplate = barPath + "${cwd}nick.xml";
renditionDef.setParameterValue(RenditionService.PARAM_DESTINATION_PATH_TEMPLATE, pathTemplate);
RenditionLocation location = locationResolver.getRenditionLocation(sourceNode, renditionDef, tempRenditionNode);
NodeRef fooNode = checkFolder(fooName, companyHome, "Foo");
NodeRef barNode = checkFolder(barName, fooNode, "Bar");
NodeRef finalFolderNode = checkFolder(nodeService.getPrimaryParent(sourceFolder).getQName(), barNode, "Final Folder");
assertEquals("Final folder is not the rendition parent!", finalFolderNode, location.getParentRef());
assertEquals("nick.xml", location.getChildName());
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class HTMLRenderingEngineTest method before.
@Before
public void before() throws Exception {
super.before();
this.nodeService = (NodeService) this.applicationContext.getBean("NodeService");
this.contentService = (ContentService) this.applicationContext.getBean("ContentService");
this.renditionService = (RenditionService) this.applicationContext.getBean("RenditionService");
this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
this.dictionaryService = (DictionaryService) this.applicationContext.getBean("dictionaryService");
this.companyHome = repositoryHelper.getCompanyHome();
createTargetFolder();
// Setup the basic rendition definition
QName renditionName = QName.createQName("Test");
RenditionDefinition rd = renditionService.loadRenditionDefinition(renditionName);
if (rd != null) {
RenditionDefinitionPersisterImpl rdp = new RenditionDefinitionPersisterImpl();
rdp.setNodeService(nodeService);
rdp.deleteRenditionDefinition(rd);
}
def = renditionService.createRenditionDefinition(renditionName, HTMLRenderingEngine.NAME);
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class XSLTRenderingEngineTest method testParseXMLDocument.
@Test
public void testParseXMLDocument() throws Exception {
try {
FileInfo file = createXmlFile(companyHome);
createXmlFile(companyHome, "TestXML.xml", sampleXML);
FileInfo xslFile = createXmlFile(companyHome, callParseXmlDocument);
RenditionDefinition def = renditionService.createRenditionDefinition(QName.createQName("Test"), XSLTRenderingEngine.NAME);
def.setParameterValue(XSLTRenderingEngine.PARAM_TEMPLATE_NODE, xslFile.getNodeRef());
ChildAssociationRef rendition = renditionService.render(file.getNodeRef(), def);
assertNotNull(rendition);
ContentReader reader = contentService.getReader(rendition.getChildRef(), ContentModel.PROP_CONTENT);
assertNotNull(reader);
String output = reader.getContentString();
log.debug("XSLT Processor output: " + output);
assertEquals("Avocado DipBagels, New York StyleBeef Frankfurter, Quarter PoundChicken Pot PieCole SlawEggsHazelnut SpreadPotato ChipsSoy Patties, GrilledTruffles, Dark Chocolate", output);
} catch (Exception ex) {
log.error("Error!", ex);
fail();
}
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class XSLTRenderingEngineTest method testImportXMLDocument.
@Test
public void testImportXMLDocument() throws Exception {
try {
FileInfo file = createXmlFile(companyHome);
createXmlFile(companyHome, "TestTableXML.xml", testTableXml);
FileInfo testImportTable = createXmlFile(companyHome, "TestImportTableXML.xml", testImportTableXml);
RenditionDefinition def = renditionService.createRenditionDefinition(QName.createQName("Test"), XSLTRenderingEngine.NAME);
def.setParameterValue(XSLTRenderingEngine.PARAM_TEMPLATE_NODE, testImportTable.getNodeRef());
ChildAssociationRef rendition = renditionService.render(file.getNodeRef(), def);
assertNotNull(rendition);
ContentReader reader = contentService.getReader(rendition.getChildRef(), ContentModel.PROP_CONTENT);
assertNotNull(reader);
String output = reader.getContentString();
log.debug("XSLT Processor output: " + output);
Diff myDiff = new Diff("<html>\n<body>\n<h2>My CD Collection</h2>\n<table border=\"1\">\n<tr bgcolor=\"#9acd32\">\n<th>Title</th><th>Artist</th>\n</tr>\n<tr>\n<td></td><td></td>\n</tr>\n</table>\n</body>\n</html>\n", output);
assertTrue("Pieces of XML are similar " + myDiff, myDiff.similar());
} catch (Exception ex) {
log.error("Error!", ex);
fail();
}
}
Aggregations