@Test public void buildXDOM() throws Exception { DocumentAccessBridge documentAccessBridge = this.mocker.getInstance(DocumentAccessBridge.class); DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); XWikiDocument xwikiDocument = mock(XWikiDocument.class); when(documentAccessBridge.getTranslatedDocumentInstance(documentReference)).thenReturn(xwikiDocument); when(xwikiDocument.getSyntax()).thenReturn(Syntax.XWIKI_2_1); XDOM xdom = this.mocker.getComponentUnderTest().buildXDOM(new AttachmentReference("file", documentReference), true); assertNotNull(xdom); assertEquals("xwiki/2.1", ((Syntax) xdom.getMetaData().getMetaData(MetaData.SYNTAX)).toIdString()); }
public XDOM buildXDOM(AttachmentReference attachmentReference, boolean filterStyles) { Map<String, String> macroParams = new HashMap<String, String>(); macroParams.put("attachment", attachmentReference.getName()); if (!filterStyles) { macroParams.put("filterStyles", "false"); } MacroBlock officeMacro = new MacroBlock("office", macroParams, false); XDOM xdom = new XDOM(Collections.<Block>singletonList(officeMacro)); xdom.getMetaData().addMetaData(MetaData.BASE, entityReferenceSerializer.serialize(attachmentReference.getDocumentReference())); try { DocumentModelBridge document = documentAccessBridge.getTranslatedDocumentInstance(attachmentReference.getDocumentReference()); xdom.getMetaData().addMetaData(MetaData.SYNTAX, document.getSyntax()); } catch (Exception e) { throw new RuntimeException(String.format( "Failed to compute Syntax for the document containing attachment [%s]", attachmentReference), e); } return xdom; }
OfficeMacroImporter { public XDOM buildXDOM(AttachmentReference attachmentReference, boolean filterStyles) { Map<String, String> macroParams = new HashMap<String, String>(); macroParams.put("attachment", attachmentReference.getName()); if (!filterStyles) { macroParams.put("filterStyles", "false"); } MacroBlock officeMacro = new MacroBlock("office", macroParams, false); XDOM xdom = new XDOM(Collections.<Block>singletonList(officeMacro)); xdom.getMetaData().addMetaData(MetaData.BASE, entityReferenceSerializer.serialize(attachmentReference.getDocumentReference())); try { DocumentModelBridge document = documentAccessBridge.getTranslatedDocumentInstance(attachmentReference.getDocumentReference()); xdom.getMetaData().addMetaData(MetaData.SYNTAX, document.getSyntax()); } catch (Exception e) { throw new RuntimeException(String.format( "Failed to compute Syntax for the document containing attachment [%s]", attachmentReference), e); } return xdom; } }
OfficeMacroImporter { public XDOM buildXDOM(AttachmentReference attachmentReference, boolean filterStyles) { Map<String, String> macroParams = new HashMap<String, String>(); macroParams.put("attachment", attachmentReference.getName()); if (!filterStyles) { macroParams.put("filterStyles", "false"); } MacroBlock officeMacro = new MacroBlock("office", macroParams, false); XDOM xdom = new XDOM(Collections.<Block>singletonList(officeMacro)); xdom.getMetaData().addMetaData(MetaData.BASE, entityReferenceSerializer.serialize(attachmentReference.getDocumentReference())); try { DocumentModelBridge document = documentAccessBridge.getTranslatedDocumentInstance(attachmentReference.getDocumentReference()); xdom.getMetaData().addMetaData(MetaData.SYNTAX, document.getSyntax()); } catch (Exception e) { throw new RuntimeException(String.format( "Failed to compute Syntax for the document containing attachment [%s]", attachmentReference), e); } return xdom; }  }
OfficeMacroImporter { public XDOM buildXDOM(AttachmentReference attachmentReference, boolean filterStyles) { Map<String, String> macroParams = new HashMap<String, String>(); macroParams.put("attachment", attachmentReference.getName()); if (!filterStyles) { macroParams.put("filterStyles", "false"); } MacroBlock officeMacro = new MacroBlock("office", macroParams, false); XDOM xdom = new XDOM(Collections.<Block>singletonList(officeMacro)); xdom.getMetaData().addMetaData(MetaData.BASE, entityReferenceSerializer.serialize(attachmentReference.getDocumentReference())); try { DocumentModelBridge document = documentAccessBridge.getTranslatedDocumentInstance(attachmentReference.getDocumentReference()); xdom.getMetaData().addMetaData(MetaData.SYNTAX, document.getSyntax()); } catch (Exception e) { throw new RuntimeException(String.format( "Failed to compute Syntax for the document containing attachment [%s]", attachmentReference), e); } return xdom; }  XDOM buildXDOM(AttachmentReference attachmentReference, boolean filterStyles); String render(XDOM xdom); }
OfficeMacroImporter { public XDOM buildXDOM(AttachmentReference attachmentReference, boolean filterStyles) { Map<String, String> macroParams = new HashMap<String, String>(); macroParams.put("attachment", attachmentReference.getName()); if (!filterStyles) { macroParams.put("filterStyles", "false"); } MacroBlock officeMacro = new MacroBlock("office", macroParams, false); XDOM xdom = new XDOM(Collections.<Block>singletonList(officeMacro)); xdom.getMetaData().addMetaData(MetaData.BASE, entityReferenceSerializer.serialize(attachmentReference.getDocumentReference())); try { DocumentModelBridge document = documentAccessBridge.getTranslatedDocumentInstance(attachmentReference.getDocumentReference()); xdom.getMetaData().addMetaData(MetaData.SYNTAX, document.getSyntax()); } catch (Exception e) { throw new RuntimeException(String.format( "Failed to compute Syntax for the document containing attachment [%s]", attachmentReference), e); } return xdom; }  XDOM buildXDOM(AttachmentReference attachmentReference, boolean filterStyles); String render(XDOM xdom);  }