Search in sources :

Example 1 with SyntaxType

use of org.xwiki.rendering.syntax.SyntaxType in project xwiki-platform by xwiki.

the class OfficeImporterScriptServiceTest method saveWithAppend.

@Test
public void saveWithAppend() throws Exception {
    XDOMOfficeDocument doc = mock(XDOMOfficeDocument.class);
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Page");
    String syntaxId = "test/1.0";
    when(documentAccessBridge.isDocumentEditable(documentReference)).thenReturn(true);
    when(documentAccessBridge.exists(documentReference)).thenReturn(true);
    DocumentModelBridge document = mock(DocumentModelBridge.class);
    when(documentAccessBridge.getTranslatedDocumentInstance(documentReference)).thenReturn(document);
    when(document.getSyntax()).thenReturn(new Syntax(new SyntaxType("test", "Test"), "1.0"));
    when(documentAccessBridge.getDocumentContent(documentReference, null)).thenReturn("before");
    when(doc.getContentAsString(syntaxId)).thenReturn("after");
    assertTrue(officeImporterScriptService.save(doc, documentReference, syntaxId, null, null, true));
    verify(documentAccessBridge).setDocumentContent(documentReference, "before\nafter", "Updated by office importer.", false);
}
Also used : DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) SyntaxType(org.xwiki.rendering.syntax.SyntaxType) Syntax(org.xwiki.rendering.syntax.Syntax) XDOMOfficeDocument(org.xwiki.officeimporter.document.XDOMOfficeDocument) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 2 with SyntaxType

use of org.xwiki.rendering.syntax.SyntaxType in project xwiki-platform by xwiki.

the class DefaultExtendedRenderingConfigurationTest method getConfiguredAndDisabledSyntaxesWhenNoConfigXObjectAndExistingXWikiCfgProperty.

@Test
public void getConfiguredAndDisabledSyntaxesWhenNoConfigXObjectAndExistingXWikiCfgProperty() throws Exception {
    ConfigurationSource renderingSource = this.mocker.getInstance(ConfigurationSource.class, "rendering");
    when(renderingSource.getProperty("disabledSyntaxes")).thenReturn(null);
    ConfigurationSource xwikiCfgSource = this.mocker.getInstance(ConfigurationSource.class, "xwikicfg");
    when(xwikiCfgSource.getProperty("xwiki.rendering.syntaxes", List.class)).thenReturn(Arrays.asList("xwiki/2.0", "xwiki/2.1"));
    // Register some Syntaxes for the test
    Parser xwikiSyntax20Parser = this.mocker.registerMockComponent(Parser.class, Syntax.XWIKI_2_0.toIdString());
    when(xwikiSyntax20Parser.getSyntax()).thenReturn(Syntax.XWIKI_2_0);
    Parser xwikiSyntax21Parser = this.mocker.registerMockComponent(Parser.class, Syntax.XWIKI_2_1.toIdString());
    when(xwikiSyntax21Parser.getSyntax()).thenReturn(Syntax.XWIKI_2_1);
    Syntax syntax1 = new Syntax(new SyntaxType("syntax1", "Syntax 1"), "1.0");
    Parser syntax1Parser = this.mocker.registerMockComponent(Parser.class, syntax1.toIdString());
    when(syntax1Parser.getSyntax()).thenReturn(syntax1);
    Syntax syntax2 = new Syntax(new SyntaxType("syntax2", "Syntax 2"), "1.0");
    Parser syntax2Parser = this.mocker.registerMockComponent(Parser.class, syntax2.toIdString());
    when(syntax2Parser.getSyntax()).thenReturn(syntax2);
    List<Syntax> disabledSyntaxes = this.mocker.getComponentUnderTest().getDisabledSyntaxes();
    assertEquals(2, disabledSyntaxes.size());
    assertTrue(disabledSyntaxes.contains(syntax1));
    assertTrue(disabledSyntaxes.contains(syntax2));
    List<Syntax> configuredSyntaxes = this.mocker.getComponentUnderTest().getConfiguredSyntaxes();
    assertEquals(2, configuredSyntaxes.size());
    assertTrue(configuredSyntaxes.contains(Syntax.XWIKI_2_0));
    assertTrue(configuredSyntaxes.contains(Syntax.XWIKI_2_1));
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) SyntaxType(org.xwiki.rendering.syntax.SyntaxType) Syntax(org.xwiki.rendering.syntax.Syntax) Parser(org.xwiki.rendering.parser.Parser) Test(org.junit.Test)

Example 3 with SyntaxType

use of org.xwiki.rendering.syntax.SyntaxType in project xwiki-platform by xwiki.

the class DefaultExtendedRenderingConfigurationTest method getConfiguredAndDisabledSyntaxesWhenConfigXObjectExists.

@Test
public void getConfiguredAndDisabledSyntaxesWhenConfigXObjectExists() throws Exception {
    ConfigurationSource renderingSource = this.mocker.getInstance(ConfigurationSource.class, "rendering");
    when(renderingSource.getProperty("disabledSyntaxes")).thenReturn(Arrays.asList("syntax1/1.0", "syntax2/1.0"));
    // Register some Syntaxes for the test
    Parser syntax1Parser = this.mocker.registerMockComponent(Parser.class, "syntax1/1.0");
    Syntax syntax1 = new Syntax(new SyntaxType("syntax1", "Syntax 1"), "1.0");
    when(syntax1Parser.getSyntax()).thenReturn(syntax1);
    Parser syntax2Parser = this.mocker.registerMockComponent(Parser.class, "syntax2/1.0");
    Syntax syntax2 = new Syntax(new SyntaxType("syntax2", "Syntax 2"), "1.0");
    when(syntax2Parser.getSyntax()).thenReturn(syntax2);
    Parser xwikiSyntax20Parser = this.mocker.registerMockComponent(Parser.class, "xwiki/2.0");
    Syntax xwikiSyntax20 = new Syntax(new SyntaxType("xwiki", "XWiki"), "2.0");
    when(xwikiSyntax20Parser.getSyntax()).thenReturn(xwikiSyntax20);
    List<Syntax> disabledSyntaxes = this.mocker.getComponentUnderTest().getDisabledSyntaxes();
    assertEquals(2, disabledSyntaxes.size());
    assertTrue(disabledSyntaxes.contains(syntax1));
    assertTrue(disabledSyntaxes.contains(syntax2));
    List<Syntax> configuredSyntaxes = this.mocker.getComponentUnderTest().getConfiguredSyntaxes();
    assertEquals(1, configuredSyntaxes.size());
    assertTrue(configuredSyntaxes.contains(xwikiSyntax20));
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) SyntaxType(org.xwiki.rendering.syntax.SyntaxType) Syntax(org.xwiki.rendering.syntax.Syntax) Parser(org.xwiki.rendering.parser.Parser) Test(org.junit.Test)

Example 4 with SyntaxType

use of org.xwiki.rendering.syntax.SyntaxType in project xwiki-platform by xwiki.

the class PygmentsParser method initialize.

@Override
public void initialize() throws InitializationException {
    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    // Get the script
    InputStream is = getClass().getResourceAsStream("/pygments/code.py");
    if (is != null) {
        try {
            this.script = IOUtils.toString(is, "UTF8");
        } catch (Exception e) {
            throw new InitializationException("Failed to read resource /pygments/code.py resource", e);
        } finally {
            IOUtils.closeQuietly(is);
        }
    } else {
        throw new InitializationException("Failed to find resource /pygments/code.py resource");
    }
    // Get the Python engine
    this.engine = scriptEngineManager.getEngineByName(ENGINE_ID);
    if (this.engine == null) {
        throw new InitializationException("Failed to find engine for Python script language");
    }
    String highlightSyntaxId = getSyntaxId() + "-highlight";
    this.syntax = new Syntax(new SyntaxType(highlightSyntaxId, highlightSyntaxId), "1.0");
}
Also used : InputStream(java.io.InputStream) ScriptEngineManager(javax.script.ScriptEngineManager) SyntaxType(org.xwiki.rendering.syntax.SyntaxType) InitializationException(org.xwiki.component.phase.InitializationException) Syntax(org.xwiki.rendering.syntax.Syntax) ParseException(org.xwiki.rendering.parser.ParseException) InitializationException(org.xwiki.component.phase.InitializationException) ScriptException(javax.script.ScriptException) IOException(java.io.IOException)

Example 5 with SyntaxType

use of org.xwiki.rendering.syntax.SyntaxType in project xwiki-platform by xwiki.

the class DefaultExtendedRenderingConfigurationTest method getConfiguredAndDisabledSyntaxesWhenNoConfigXObjectAndNoXWikiCfgProperty.

@Test
public void getConfiguredAndDisabledSyntaxesWhenNoConfigXObjectAndNoXWikiCfgProperty() throws Exception {
    ConfigurationSource renderingSource = this.mocker.getInstance(ConfigurationSource.class, "rendering");
    when(renderingSource.getProperty("disabledSyntaxes")).thenReturn(null);
    ConfigurationSource xwikiCfgSource = this.mocker.getInstance(ConfigurationSource.class, "xwikicfg");
    when(xwikiCfgSource.getProperty("xwiki.rendering.syntaxes", List.class)).thenReturn(null);
    CoreConfiguration coreConfiguration = this.mocker.getInstance(CoreConfiguration.class);
    Syntax defaultSyntax = new Syntax(new SyntaxType("xwiki", "XWiki"), "2.1");
    when(coreConfiguration.getDefaultDocumentSyntax()).thenReturn(defaultSyntax);
    // Register some Syntaxes for the test
    Parser defaultSyntaxParser = this.mocker.registerMockComponent(Parser.class, "xwiki/2.1");
    when(defaultSyntaxParser.getSyntax()).thenReturn(defaultSyntax);
    Parser syntax1Parser = this.mocker.registerMockComponent(Parser.class, "syntax1/1.0");
    Syntax syntax1 = new Syntax(new SyntaxType("syntax1", "Syntax 1"), "1.0");
    when(syntax1Parser.getSyntax()).thenReturn(syntax1);
    Parser syntax2Parser = this.mocker.registerMockComponent(Parser.class, "syntax2/1.0");
    Syntax syntax2 = new Syntax(new SyntaxType("syntax2", "Syntax 2"), "1.0");
    when(syntax2Parser.getSyntax()).thenReturn(syntax2);
    List<Syntax> disabledSyntaxes = this.mocker.getComponentUnderTest().getDisabledSyntaxes();
    assertEquals(2, disabledSyntaxes.size());
    assertTrue(disabledSyntaxes.contains(syntax1));
    assertTrue(disabledSyntaxes.contains(syntax2));
    List<Syntax> configuredSyntaxes = this.mocker.getComponentUnderTest().getConfiguredSyntaxes();
    assertEquals(1, configuredSyntaxes.size());
    assertTrue(configuredSyntaxes.contains(defaultSyntax));
}
Also used : ConfigurationSource(org.xwiki.configuration.ConfigurationSource) SyntaxType(org.xwiki.rendering.syntax.SyntaxType) CoreConfiguration(com.xpn.xwiki.CoreConfiguration) Syntax(org.xwiki.rendering.syntax.Syntax) Parser(org.xwiki.rendering.parser.Parser) Test(org.junit.Test)

Aggregations

Syntax (org.xwiki.rendering.syntax.Syntax)7 SyntaxType (org.xwiki.rendering.syntax.SyntaxType)7 Test (org.junit.Test)6 ConfigurationSource (org.xwiki.configuration.ConfigurationSource)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 Parser (org.xwiki.rendering.parser.Parser)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 AbstractInstanceFilterStreamTest (com.xpn.xwiki.internal.filter.AbstractInstanceFilterStreamTest)2 BaseObject (com.xpn.xwiki.objects.BaseObject)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 NumberClass (com.xpn.xwiki.objects.classes.NumberClass)2 List (java.util.List)2 DocumentInstanceOutputProperties (org.xwiki.filter.instance.output.DocumentInstanceOutputProperties)2 CoreConfiguration (com.xpn.xwiki.CoreConfiguration)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ScriptEngineManager (javax.script.ScriptEngineManager)1 ScriptException (javax.script.ScriptException)1 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)1