Search in sources :

Example 11 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class HtmlPackager method export.

/**
 * Apply export and create the ZIP package.
 *
 * @param context the XWiki context used to render pages.
 * @throws IOException error when creating the package.
 * @throws XWikiException error when render the pages.
 */
public void export(XWikiContext context) throws IOException, XWikiException {
    context.getResponse().setContentType("application/zip");
    context.getResponse().addHeader("Content-disposition", "attachment; filename=" + Util.encodeURI(this.name, context) + ".zip");
    context.setFinished(true);
    ZipOutputStream zos = new ZipOutputStream(context.getResponse().getOutputStream());
    File dir = this.environment.getTemporaryDirectory();
    File tempdir = new File(dir, RandomStringUtils.randomAlphanumeric(8));
    tempdir.mkdirs();
    File attachmentDir = new File(tempdir, "attachment");
    attachmentDir.mkdirs();
    // Create and initialize a custom URL factory
    ExportURLFactory urlf = new ExportURLFactory();
    Provider<FilesystemExportContext> exportContextProvider = Utils.getComponent(new DefaultParameterizedType(null, Provider.class, FilesystemExportContext.class));
    // Note that the following line will set a FilesystemExportContext instance in the Execution Context
    // and this Execution Context will be cloned for each document rendered below.
    // TODO: to be cleaner we should set the FilesystemExportContext in the EC used to render each document.
    // However we also need to initialize the ExportURLFactory.
    FilesystemExportContext exportContext = exportContextProvider.get();
    urlf.init(this.pageReferences, tempdir, exportContext, context);
    // Render pages to export
    renderDocuments(zos, urlf, context);
    // Add required skins to ZIP file
    for (String skinName : urlf.getFilesystemExportContext().getNeededSkins()) {
        addSkinToZip(skinName, zos, urlf.getFilesystemExportContext().getExportedSkinFiles(), context);
    }
    // Copy generated files in the ZIP file.
    addDirToZip(tempdir, TrueFileFilter.TRUE, zos, "", null);
    // Generate an index page
    generateIndexPage(zos, context);
    zos.setComment(this.description);
    // Finish ZIP file
    zos.finish();
    zos.flush();
    // Delete temporary directory
    deleteDirectory(tempdir);
}
Also used : ExportURLFactory(com.xpn.xwiki.web.ExportURLFactory) ZipOutputStream(java.util.zip.ZipOutputStream) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) File(java.io.File) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) Provider(javax.inject.Provider)

Example 12 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class DefaultLinkRefactoringTest method configure.

@Before
public void configure() throws Exception {
    XWiki xwiki = mock(XWiki.class);
    when(this.xcontext.getWiki()).thenReturn(xwiki);
    Provider<XWikiContext> xcontextProvider = this.mocker.getInstance(XWikiContext.TYPE_PROVIDER);
    when(xcontextProvider.get()).thenReturn(this.xcontext);
    this.resourceReferenceResolver = this.mocker.getInstance(DefaultResourceReferenceEntityReferenceResolver.TYPE_RESOURCEREFERENCE);
    this.defaultReferenceDocumentReferenceResolver = this.mocker.getInstance(DocumentReferenceResolver.TYPE_REFERENCE);
    this.compactEntityReferenceSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "compact");
    Provider<ComponentManager> contextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(contextComponentManagerProvider.get()).thenReturn(this.mocker);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 13 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class FilesystemResourceReferenceSerializerTest method serializeCSSResourceWithURLsInIt.

@Test
public void serializeCSSResourceWithURLsInIt() throws Exception {
    FilesystemExportContext exportContext = new FilesystemExportContext();
    exportContext.setExportDir(BASEDIR);
    Provider<FilesystemExportContext> exportContextProvider = this.mocker.getInstance(new DefaultParameterizedType(null, Provider.class, FilesystemExportContext.class));
    Mockito.when(exportContextProvider.get()).thenReturn(exportContext);
    WebJarsResourceReference reference = new WebJarsResourceReference("wiki:wiki", Arrays.asList("font-awesome", "4.7.0", "css/font-awesome.min.css"));
    assertEquals("webjars/font-awesome/4.7.0/css/font-awesome.min.css", this.mocker.getComponentUnderTest().serialize(reference).serialize());
    // Also verify that the resources haves been copied!
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/css/font-awesome.min.css").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.eot").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.woff").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.svg").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.ttf").exists());
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) File(java.io.File) Provider(javax.inject.Provider) Test(org.junit.Test)

Example 14 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class FilesystemResourceReferenceSerializerTest method serializeWithCSSPathAdjustments.

@Test
public void serializeWithCSSPathAdjustments() throws Exception {
    FilesystemExportContext exportContext = new FilesystemExportContext();
    exportContext.setExportDir(BASEDIR);
    exportContext.pushCSSParentLevels(3);
    Provider<FilesystemExportContext> exportContextProvider = this.mocker.getInstance(new DefaultParameterizedType(null, Provider.class, FilesystemExportContext.class));
    Mockito.when(exportContextProvider.get()).thenReturn(exportContext);
    WebJarsResourceReference reference = new WebJarsResourceReference("wiki:wiki", Arrays.asList("font-awesome", "4.7.0", "fonts/FontAwesome.otf"));
    // Verify that the returned URL is ok
    assertEquals("../../../webjars/font-awesome/4.7.0/fonts/FontAwesome.otf", this.mocker.getComponentUnderTest().serialize(reference).serialize());
    // Also verify that the resource has been copied!
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/FontAwesome.otf").exists());
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) File(java.io.File) Provider(javax.inject.Provider) Test(org.junit.Test)

Example 15 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class FilesystemResourceReferenceSerializerTest method serialize.

@Test
public void serialize() throws Exception {
    FilesystemExportContext exportContext = new FilesystemExportContext();
    exportContext.setExportDir(BASEDIR);
    Provider<FilesystemExportContext> exportContextProvider = this.mocker.getInstance(new DefaultParameterizedType(null, Provider.class, FilesystemExportContext.class));
    Mockito.when(exportContextProvider.get()).thenReturn(exportContext);
    WebJarsResourceReference reference = new WebJarsResourceReference("wiki:wiki", Arrays.asList("font-awesome", "4.7.0", "fonts/FontAwesome.otf"));
    // Verify that the returned URL is ok
    assertEquals("webjars/font-awesome/4.7.0/fonts/FontAwesome.otf", this.mocker.getComponentUnderTest().serialize(reference).serialize());
    // Also verify that the resource has been copied!
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/FontAwesome.otf").exists());
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) File(java.io.File) Provider(javax.inject.Provider) Test(org.junit.Test)

Aggregations

Provider (javax.inject.Provider)53 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)23 Test (org.junit.Test)15 ComponentManager (org.xwiki.component.manager.ComponentManager)15 Before (org.junit.Before)11 HashMap (java.util.HashMap)9 File (java.io.File)7 FilesystemExportContext (org.xwiki.url.filesystem.FilesystemExportContext)7 ArrayList (java.util.ArrayList)6 XWikiContext (com.xpn.xwiki.XWikiContext)5 Map (java.util.Map)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 Maps (com.google.common.collect.Maps)4 Type (java.lang.reflect.Type)4 Query (org.graylog.plugins.views.search.Query)4 QueryResult (org.graylog.plugins.views.search.QueryResult)4 SearchJob (org.graylog.plugins.views.search.SearchJob)4 SearchType (org.graylog.plugins.views.search.SearchType)4 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)4 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)4