Skip to content
Snippets Groups Projects
Commit 109207e1 authored by Sergiu Dumitriu's avatar Sergiu Dumitriu
Browse files

[cleanup] Refreshed code

parent 648769a6
No related branches found
No related tags found
No related merge requests found
Showing
with 28 additions and 25 deletions
......@@ -153,9 +153,9 @@ private Block render(String formula, boolean inline, FontSize fontSize, Type ima
throws ComponentLookupException, IllegalArgumentException
{
try {
FormulaRenderer renderer = this.manager.lookup(FormulaRenderer.class, rendererHint);
FormulaRenderer renderer = this.manager.lookupComponent(FormulaRenderer.class, rendererHint);
String imageName = renderer.process(formula, inline, fontSize, imageType);
String url = this.dab.getURL(null, "tex", null, null) + "/" + imageName;
String url = this.dab.getDocumentURL(null, "tex", null, null) + "/" + imageName;
ResourceReference imageReference = new ResourceReference(url, ResourceType.URL);
ImageBlock result = new ImageBlock(imageReference, false);
// Set the alternative text for the image to be the original formula
......
......@@ -19,7 +19,7 @@
*/
package org.xwiki.rendering.macro.formula;
import org.xwiki.component.annotation.ComponentRole;
import org.xwiki.component.annotation.Role;
/**
* Configuration properties for the {@link org.xwiki.rendering.internal.macro.formula.FormulaMacro formula macro}.
......@@ -31,7 +31,7 @@
* @version $Id$
* @since 2.0M3
*/
@ComponentRole
@Role
public interface FormulaMacroConfiguration
{
/**
......
......@@ -49,33 +49,36 @@ public void initialize(ComponentManager componentManager) throws Exception
final DocumentAccessBridge mockDocumentAccessBridge = mockery.mock(DocumentAccessBridge.class);
DefaultComponentDescriptor<DocumentAccessBridge> descriptorDAB =
new DefaultComponentDescriptor<DocumentAccessBridge>();
descriptorDAB.setRole(DocumentAccessBridge.class);
descriptorDAB.setRoleType(DocumentAccessBridge.class);
componentManager.registerComponent(descriptorDAB, mockDocumentAccessBridge);
// Image Storage Mock
final ImageStorage mockImageStorage = mockery.mock(ImageStorage.class);
DefaultComponentDescriptor<ImageStorage> descriptorIS = new DefaultComponentDescriptor<ImageStorage>();
descriptorIS.setRole(ImageStorage.class);
descriptorIS.setRoleType(ImageStorage.class);
componentManager.registerComponent(descriptorIS, mockImageStorage);
// Configuration Mock
final FormulaMacroConfiguration mockConfiguration = mockery.mock(FormulaMacroConfiguration.class);
DefaultComponentDescriptor<FormulaMacroConfiguration> descriptorEMC =
new DefaultComponentDescriptor<FormulaMacroConfiguration>();
descriptorEMC.setRole(FormulaMacroConfiguration.class);
descriptorEMC.setRoleType(FormulaMacroConfiguration.class);
componentManager.registerComponent(descriptorEMC, mockConfiguration);
mockery.checking(new Expectations() {{
atLeast(2).of(mockDocumentAccessBridge).getURL(null, "tex", null, null);
will(returnValue("/xwiki/bin/view/Main/"));
mockery.checking(new Expectations()
{
{
atLeast(2).of(mockDocumentAccessBridge).getDocumentURL(null, "tex", null, null);
will(returnValue("/xwiki/bin/view/Main/"));
atLeast(2).of(mockConfiguration).getRenderer();
will(returnValue("snuggletex"));
atLeast(2).of(mockConfiguration).getRenderer();
will(returnValue("snuggletex"));
atLeast(2).of(mockImageStorage).get(with(any(String.class)));
will(returnValue(null));
atLeast(2).of(mockImageStorage).get(with(any(String.class)));
will(returnValue(null));
atLeast(2).of(mockImageStorage).put(with(any(String.class)), with(any(ImageData.class)));
}});
atLeast(2).of(mockImageStorage).put(with(any(String.class)), with(any(ImageData.class)));
}
});
}
}
......@@ -59,8 +59,8 @@
<version>${commons.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-container-api</artifactId>
<groupId>org.xwiki.commons</groupId>
<artifactId>xwiki-commons-environment-api</artifactId>
<version>${project.version}</version>
</dependency>
......
......@@ -21,7 +21,7 @@
import java.io.IOException;
import org.xwiki.component.annotation.ComponentRole;
import org.xwiki.component.annotation.Role;
/**
* Convert a LaTeX formula into an image.
......@@ -29,7 +29,7 @@
* @version $Id$
* @since 2.0M3
*/
@ComponentRole
@Role
public interface FormulaRenderer
{
/**
......
......@@ -19,14 +19,14 @@
*/
package org.xwiki.formula;
import org.xwiki.component.annotation.ComponentRole;
import org.xwiki.component.annotation.Role;
/**
* A component for storing generated images for later retrieval in a subsequent request.
*
* @version $Id$
*/
@ComponentRole
@Role
public interface ImageStorage
{
/**
......
......@@ -39,7 +39,7 @@
import org.xwiki.component.annotation.Component;
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;
import org.xwiki.container.Container;
import org.xwiki.environment.Environment;
import org.xwiki.formula.AbstractFormulaRenderer;
import org.xwiki.formula.FormulaRenderer;
import org.xwiki.formula.ImageData;
......@@ -69,7 +69,7 @@ public class NativeFormulaRenderer extends AbstractFormulaRenderer implements In
/** Application container, needed for retrieving the work directory where temporary files can be created. */
@Inject
private Container container;
private Environment environment;
/** Temporary parent directory for storing files created during the image rendering process. */
private File tempDirectory;
......@@ -77,7 +77,7 @@ public class NativeFormulaRenderer extends AbstractFormulaRenderer implements In
@Override
public void initialize() throws InitializationException
{
this.tempDirectory = new File(this.container.getApplicationContext().getTemporaryDirectory(), "formulae");
this.tempDirectory = new File(this.environment.getTemporaryDirectory(), "formulae");
this.tempDirectory.mkdir();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment