@Test public void executeWhenNoDocumentSpecified() throws Exception { ContextMacroParameters parameters = new ContextMacroParameters(); try { this.mocker.getComponentUnderTest().execute(parameters, "", new MacroTransformationContext()); fail("Should have thrown an exception"); } catch (MacroExecutionException expected) { Assert.assertEquals("You must specify a 'document' parameter pointing to the document to set in the " + "context as the current document.", expected.getMessage()); } }
@Override public List<Block> execute(ContextMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { if (parameters.getDocument() == null) { throw new MacroExecutionException("You must specify a 'document' parameter pointing to the document to " + "set in the context as the current document."); } DocumentReference referencedDocReference = this.macroDocumentReferenceResolver.resolve(parameters.getDocument(), context.getCurrentMacroBlock()); boolean currentContextHasProgrammingRights = this.documentAccessBridge.hasProgrammingRights(); List<Block> result; try { Map<String, Object> backupObjects = new HashMap<>(); try { this.documentAccessBridge.pushDocumentInContext(backupObjects, referencedDocReference); if (this.documentAccessBridge.hasProgrammingRights() && !currentContextHasProgrammingRights) { throw new MacroExecutionException("Current document must have programming rights since the " + "context document provided [" + parameters.getDocument() + "] has programming rights."); } MetaData metadata = new MetaData(); metadata.addMetaData(MetaData.SOURCE, parameters.getDocument()); metadata.addMetaData(MetaData.BASE, parameters.getDocument()); XDOM xdom = this.contentParser.parse(content, context, false, metadata, false); if (parameters.getTransformationContext() == TransformationContextMode.DOCUMENT || parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { DocumentModelBridge referencedDoc = this.documentAccessBridge.getTranslatedDocumentInstance(referencedDocReference); XDOM referencedXDOM = referencedDoc.getXDOM(); if (parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { TransformationContext referencedTxContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(referencedXDOM, referencedTxContext); } TransformationContext txContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(xdom, txContext); } result = Arrays.asList((Block) new MetaDataBlock(xdom.getChildren(), xdom.getMetaData())); } finally { this.documentAccessBridge.popDocumentFromContext(backupObjects); } } catch (Exception e) { if (e instanceof MacroExecutionException) { throw (MacroExecutionException) e; } else { throw new MacroExecutionException( String.format("Failed to render page in the context of [%s]", referencedDocReference), e); } } return result; }
ContextMacro extends AbstractMacro<ContextMacroParameters> { @Override public List<Block> execute(ContextMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { if (parameters.getDocument() == null) { throw new MacroExecutionException("You must specify a 'document' parameter pointing to the document to " + "set in the context as the current document."); } DocumentReference referencedDocReference = this.macroDocumentReferenceResolver.resolve(parameters.getDocument(), context.getCurrentMacroBlock()); boolean currentContextHasProgrammingRights = this.documentAccessBridge.hasProgrammingRights(); List<Block> result; try { Map<String, Object> backupObjects = new HashMap<>(); try { this.documentAccessBridge.pushDocumentInContext(backupObjects, referencedDocReference); if (this.documentAccessBridge.hasProgrammingRights() && !currentContextHasProgrammingRights) { throw new MacroExecutionException("Current document must have programming rights since the " + "context document provided [" + parameters.getDocument() + "] has programming rights."); } MetaData metadata = new MetaData(); metadata.addMetaData(MetaData.SOURCE, parameters.getDocument()); metadata.addMetaData(MetaData.BASE, parameters.getDocument()); XDOM xdom = this.contentParser.parse(content, context, false, metadata, false); if (parameters.getTransformationContext() == TransformationContextMode.DOCUMENT || parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { DocumentModelBridge referencedDoc = this.documentAccessBridge.getTranslatedDocumentInstance(referencedDocReference); XDOM referencedXDOM = referencedDoc.getXDOM(); if (parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { TransformationContext referencedTxContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(referencedXDOM, referencedTxContext); } TransformationContext txContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(xdom, txContext); } result = Arrays.asList((Block) new MetaDataBlock(xdom.getChildren(), xdom.getMetaData())); } finally { this.documentAccessBridge.popDocumentFromContext(backupObjects); } } catch (Exception e) { if (e instanceof MacroExecutionException) { throw (MacroExecutionException) e; } else { throw new MacroExecutionException( String.format("Failed to render page in the context of [%s]", referencedDocReference), e); } } return result; } }
ContextMacro extends AbstractMacro<ContextMacroParameters> { @Override public List<Block> execute(ContextMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { if (parameters.getDocument() == null) { throw new MacroExecutionException("You must specify a 'document' parameter pointing to the document to " + "set in the context as the current document."); } DocumentReference referencedDocReference = this.macroDocumentReferenceResolver.resolve(parameters.getDocument(), context.getCurrentMacroBlock()); boolean currentContextHasProgrammingRights = this.documentAccessBridge.hasProgrammingRights(); List<Block> result; try { Map<String, Object> backupObjects = new HashMap<>(); try { this.documentAccessBridge.pushDocumentInContext(backupObjects, referencedDocReference); if (this.documentAccessBridge.hasProgrammingRights() && !currentContextHasProgrammingRights) { throw new MacroExecutionException("Current document must have programming rights since the " + "context document provided [" + parameters.getDocument() + "] has programming rights."); } MetaData metadata = new MetaData(); metadata.addMetaData(MetaData.SOURCE, parameters.getDocument()); metadata.addMetaData(MetaData.BASE, parameters.getDocument()); XDOM xdom = this.contentParser.parse(content, context, false, metadata, false); if (parameters.getTransformationContext() == TransformationContextMode.DOCUMENT || parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { DocumentModelBridge referencedDoc = this.documentAccessBridge.getTranslatedDocumentInstance(referencedDocReference); XDOM referencedXDOM = referencedDoc.getXDOM(); if (parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { TransformationContext referencedTxContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(referencedXDOM, referencedTxContext); } TransformationContext txContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(xdom, txContext); } result = Arrays.asList((Block) new MetaDataBlock(xdom.getChildren(), xdom.getMetaData())); } finally { this.documentAccessBridge.popDocumentFromContext(backupObjects); } } catch (Exception e) { if (e instanceof MacroExecutionException) { throw (MacroExecutionException) e; } else { throw new MacroExecutionException( String.format("Failed to render page in the context of [%s]", referencedDocReference), e); } } return result; } ContextMacro(); }
ContextMacro extends AbstractMacro<ContextMacroParameters> { @Override public List<Block> execute(ContextMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { if (parameters.getDocument() == null) { throw new MacroExecutionException("You must specify a 'document' parameter pointing to the document to " + "set in the context as the current document."); } DocumentReference referencedDocReference = this.macroDocumentReferenceResolver.resolve(parameters.getDocument(), context.getCurrentMacroBlock()); boolean currentContextHasProgrammingRights = this.documentAccessBridge.hasProgrammingRights(); List<Block> result; try { Map<String, Object> backupObjects = new HashMap<>(); try { this.documentAccessBridge.pushDocumentInContext(backupObjects, referencedDocReference); if (this.documentAccessBridge.hasProgrammingRights() && !currentContextHasProgrammingRights) { throw new MacroExecutionException("Current document must have programming rights since the " + "context document provided [" + parameters.getDocument() + "] has programming rights."); } MetaData metadata = new MetaData(); metadata.addMetaData(MetaData.SOURCE, parameters.getDocument()); metadata.addMetaData(MetaData.BASE, parameters.getDocument()); XDOM xdom = this.contentParser.parse(content, context, false, metadata, false); if (parameters.getTransformationContext() == TransformationContextMode.DOCUMENT || parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { DocumentModelBridge referencedDoc = this.documentAccessBridge.getTranslatedDocumentInstance(referencedDocReference); XDOM referencedXDOM = referencedDoc.getXDOM(); if (parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { TransformationContext referencedTxContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(referencedXDOM, referencedTxContext); } TransformationContext txContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(xdom, txContext); } result = Arrays.asList((Block) new MetaDataBlock(xdom.getChildren(), xdom.getMetaData())); } finally { this.documentAccessBridge.popDocumentFromContext(backupObjects); } } catch (Exception e) { if (e instanceof MacroExecutionException) { throw (MacroExecutionException) e; } else { throw new MacroExecutionException( String.format("Failed to render page in the context of [%s]", referencedDocReference), e); } } return result; } ContextMacro(); @Override boolean supportsInlineMode(); @Override List<Block> execute(ContextMacroParameters parameters, String content, MacroTransformationContext context); }
ContextMacro extends AbstractMacro<ContextMacroParameters> { @Override public List<Block> execute(ContextMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException { if (parameters.getDocument() == null) { throw new MacroExecutionException("You must specify a 'document' parameter pointing to the document to " + "set in the context as the current document."); } DocumentReference referencedDocReference = this.macroDocumentReferenceResolver.resolve(parameters.getDocument(), context.getCurrentMacroBlock()); boolean currentContextHasProgrammingRights = this.documentAccessBridge.hasProgrammingRights(); List<Block> result; try { Map<String, Object> backupObjects = new HashMap<>(); try { this.documentAccessBridge.pushDocumentInContext(backupObjects, referencedDocReference); if (this.documentAccessBridge.hasProgrammingRights() && !currentContextHasProgrammingRights) { throw new MacroExecutionException("Current document must have programming rights since the " + "context document provided [" + parameters.getDocument() + "] has programming rights."); } MetaData metadata = new MetaData(); metadata.addMetaData(MetaData.SOURCE, parameters.getDocument()); metadata.addMetaData(MetaData.BASE, parameters.getDocument()); XDOM xdom = this.contentParser.parse(content, context, false, metadata, false); if (parameters.getTransformationContext() == TransformationContextMode.DOCUMENT || parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { DocumentModelBridge referencedDoc = this.documentAccessBridge.getTranslatedDocumentInstance(referencedDocReference); XDOM referencedXDOM = referencedDoc.getXDOM(); if (parameters.getTransformationContext() == TransformationContextMode.TRANSFORMATIONS) { TransformationContext referencedTxContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(referencedXDOM, referencedTxContext); } TransformationContext txContext = new TransformationContext(referencedXDOM, referencedDoc.getSyntax()); this.transformationManager.performTransformations(xdom, txContext); } result = Arrays.asList((Block) new MetaDataBlock(xdom.getChildren(), xdom.getMetaData())); } finally { this.documentAccessBridge.popDocumentFromContext(backupObjects); } } catch (Exception e) { if (e instanceof MacroExecutionException) { throw (MacroExecutionException) e; } else { throw new MacroExecutionException( String.format("Failed to render page in the context of [%s]", referencedDocReference), e); } } return result; } ContextMacro(); @Override boolean supportsInlineMode(); @Override List<Block> execute(ContextMacroParameters parameters, String content, MacroTransformationContext context);  }