@Test public void resolveWhenMetaDataBlock() throws Exception { DocumentReference baseReference = new DocumentReference("basewiki", "basespace", "basepage"); EntityReference expectedReference = new AttachmentReference("file", baseReference); EntityReferenceResolver<String> currentEntityReferenceResolver = mocker.getInstance(EntityReferenceResolver.TYPE_STRING, "current"); when(currentEntityReferenceResolver.resolve("basewiki:basespace.basepage", EntityType.DOCUMENT)).thenReturn( baseReference); when(currentEntityReferenceResolver.resolve("file", EntityType.ATTACHMENT, baseReference)).thenReturn( expectedReference); Block wordBlock = new WordBlock("whatever"); MetaData metaData = new MetaData(Collections.<String, Object> singletonMap(MetaData.BASE, "basewiki:basespace.basepage")); new XDOM(Arrays.<Block> asList(new MetaDataBlock(Arrays.<Block> asList(wordBlock), metaData))); Assert.assertEquals(expectedReference, mocker.getComponentUnderTest().resolve("file", EntityType.ATTACHMENT, wordBlock)); }
@Override public EntityReference resolve(String representation, EntityType entityType, Object... parameters) { if (parameters.length != 1 || !(parameters[0] instanceof Block)) { throw new IllegalArgumentException(String.format("You must pass one parameter of type [%s]", Block.class.getName())); } Block currentBlock = (Block) parameters[0]; EntityReference result; MetaDataBlock metaDataBlock = currentBlock.getFirstBlock(new MetadataBlockMatcher(MetaData.BASE), Block.Axes.ANCESTOR); if (metaDataBlock == null) { result = this.currentEntityReferenceResolver.resolve(representation, entityType); } else { String sourceMetaData = (String) metaDataBlock.getMetaData().getMetaData(MetaData.BASE); result = this.currentEntityReferenceResolver.resolve(representation, entityType, this.currentEntityReferenceResolver.resolve(sourceMetaData, EntityType.DOCUMENT)); } return result; }
CurrentMacroEntityReferenceResolver implements EntityReferenceResolver<String> { @Override public EntityReference resolve(String representation, EntityType entityType, Object... parameters) { if (parameters.length != 1 || !(parameters[0] instanceof Block)) { throw new IllegalArgumentException(String.format("You must pass one parameter of type [%s]", Block.class.getName())); } Block currentBlock = (Block) parameters[0]; EntityReference result; MetaDataBlock metaDataBlock = currentBlock.getFirstBlock(new MetadataBlockMatcher(MetaData.BASE), Block.Axes.ANCESTOR); if (metaDataBlock == null) { result = this.currentEntityReferenceResolver.resolve(representation, entityType); } else { String sourceMetaData = (String) metaDataBlock.getMetaData().getMetaData(MetaData.BASE); result = this.currentEntityReferenceResolver.resolve(representation, entityType, this.currentEntityReferenceResolver.resolve(sourceMetaData, EntityType.DOCUMENT)); } return result; } }
CurrentMacroEntityReferenceResolver implements EntityReferenceResolver<String> { @Override public EntityReference resolve(String representation, EntityType entityType, Object... parameters) { if (parameters.length != 1 || !(parameters[0] instanceof Block)) { throw new IllegalArgumentException(String.format("You must pass one parameter of type [%s]", Block.class.getName())); } Block currentBlock = (Block) parameters[0]; EntityReference result; MetaDataBlock metaDataBlock = currentBlock.getFirstBlock(new MetadataBlockMatcher(MetaData.BASE), Block.Axes.ANCESTOR); if (metaDataBlock == null) { result = this.currentEntityReferenceResolver.resolve(representation, entityType); } else { String sourceMetaData = (String) metaDataBlock.getMetaData().getMetaData(MetaData.BASE); result = this.currentEntityReferenceResolver.resolve(representation, entityType, this.currentEntityReferenceResolver.resolve(sourceMetaData, EntityType.DOCUMENT)); } return result; }  }
CurrentMacroEntityReferenceResolver implements EntityReferenceResolver<String> { @Override public EntityReference resolve(String representation, EntityType entityType, Object... parameters) { if (parameters.length != 1 || !(parameters[0] instanceof Block)) { throw new IllegalArgumentException(String.format("You must pass one parameter of type [%s]", Block.class.getName())); } Block currentBlock = (Block) parameters[0]; EntityReference result; MetaDataBlock metaDataBlock = currentBlock.getFirstBlock(new MetadataBlockMatcher(MetaData.BASE), Block.Axes.ANCESTOR); if (metaDataBlock == null) { result = this.currentEntityReferenceResolver.resolve(representation, entityType); } else { String sourceMetaData = (String) metaDataBlock.getMetaData().getMetaData(MetaData.BASE); result = this.currentEntityReferenceResolver.resolve(representation, entityType, this.currentEntityReferenceResolver.resolve(sourceMetaData, EntityType.DOCUMENT)); } return result; }  @Override EntityReference resolve(String representation, EntityType entityType, Object... parameters); }
CurrentMacroEntityReferenceResolver implements EntityReferenceResolver<String> { @Override public EntityReference resolve(String representation, EntityType entityType, Object... parameters) { if (parameters.length != 1 || !(parameters[0] instanceof Block)) { throw new IllegalArgumentException(String.format("You must pass one parameter of type [%s]", Block.class.getName())); } Block currentBlock = (Block) parameters[0]; EntityReference result; MetaDataBlock metaDataBlock = currentBlock.getFirstBlock(new MetadataBlockMatcher(MetaData.BASE), Block.Axes.ANCESTOR); if (metaDataBlock == null) { result = this.currentEntityReferenceResolver.resolve(representation, entityType); } else { String sourceMetaData = (String) metaDataBlock.getMetaData().getMetaData(MetaData.BASE); result = this.currentEntityReferenceResolver.resolve(representation, entityType, this.currentEntityReferenceResolver.resolve(sourceMetaData, EntityType.DOCUMENT)); } return result; }  @Override EntityReference resolve(String representation, EntityType entityType, Object... parameters);  }