1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.edit.script

File SyntaxContentEditScriptService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

4
6
4
1
91
35
6
1
1.5
4
1.5

Classes

Class Line # Actions
SyntaxContentEditScriptService 44 6 0% 6 2
0.8571428785.7%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.edit.script;
21   
22    import java.util.Map;
23   
24    import javax.inject.Named;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.edit.EditException;
29    import org.xwiki.edit.Editor;
30    import org.xwiki.rendering.syntax.Syntax;
31    import org.xwiki.rendering.syntax.SyntaxContent;
32    import org.xwiki.stability.Unstable;
33   
34    /**
35    * Edit script service specialized in {@link SyntaxContent} {@link Editor}s.
36    *
37    * @version $Id: 520022060cb79cbbf46c1dea31ecbb6fa3242469 $
38    * @since 8.2RC1
39    */
40    @Component
41    @Singleton
42    @Named(EditScriptService.ROLE_HINT + ".syntaxContent")
43    @Unstable
 
44    public class SyntaxContentEditScriptService extends AbstractTypedEditScriptService<SyntaxContent>
45    {
46    /**
47    * @return the default {@link SyntaxContent} editor in the "Text" category
48    */
 
49  31 toggle public Editor<SyntaxContent> getDefaultTextEditor()
50    {
51  31 return getDefaultEditor("text");
52    }
53   
54    /**
55    * @return the default {@link SyntaxContent} editor in the "WYSIWYG" category
56    */
 
57  14 toggle public Editor<SyntaxContent> getDefaultWysiwygEditor()
58    {
59  14 return getDefaultEditor("wysiwyg");
60    }
61   
62    /**
63    * Generates the HTML code needed to edit the given data.
64    *
65    * @param content the text content to edit
66    * @param syntax the syntax of the given content
67    * @param parameters the edit parameters
68    * @return the HTML code that displays the default text editor for {@link SyntaxContent}
69    * @throws EditException if rendering the editor fails
70    */
 
71  31 toggle public String text(String content, Syntax syntax, Map<String, Object> parameters) throws EditException
72    {
73  31 Editor<SyntaxContent> editor = getDefaultTextEditor();
74  31 return editor == null ? null : editor.render(new SyntaxContent(content, syntax), parameters);
75    }
76   
77    /**
78    * Generates the HTML code needed to edit the given data.
79    *
80    * @param content the text content to edit
81    * @param syntax the syntax of the given content
82    * @param parameters the edit parameters
83    * @return the HTML code that displays the default WYSIWYG editor for {@link SyntaxContent}
84    * @throws EditException if rendering the editor fails
85    */
 
86  14 toggle public String wysiwyg(String content, Syntax syntax, Map<String, Object> parameters) throws EditException
87    {
88  14 Editor<SyntaxContent> editor = getDefaultWysiwygEditor();
89  14 return editor == null ? null : editor.render(new SyntaxContent(content, syntax), parameters);
90    }
91    }