1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.wiki.service;
35
36 import fr.paris.lutece.plugins.wiki.business.TopicVersion;
37 import fr.paris.lutece.plugins.wiki.service.parser.LuteceWikiParser;
38 import fr.paris.lutece.portal.service.cache.AbstractCacheableService;
39 import java.util.Locale;
40 import java.util.regex.Pattern;
41
42
43
44
45 public final class WikiService extends AbstractCacheableService
46 {
47 private static final String SERVICE_CACHE_NAME = "Wiki Cache Service";
48
49 private static WikiService _singleton;
50
51
52 private WikiService( )
53 {
54 initCache( );
55 }
56
57
58
59
60 @Override
61 public String getName( )
62 {
63 return SERVICE_CACHE_NAME;
64 }
65
66
67
68
69
70
71 public static WikiService instance( )
72 {
73 synchronized( WikiService.class )
74 {
75 if ( _singleton == null )
76 {
77 _singleton = new WikiService( );
78 }
79 }
80 return _singleton;
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 public String getWikiPage( String strPageName, TopicVersion version, String strPageUrl, String strLanguage )
97 {
98 StringBuilder sbKey = new StringBuilder( );
99 sbKey.append( strPageName ).append( '[' ).append( version.getIdTopicVersion( ) ).append( ']' )
100 .append( ( ( strPageUrl != null ) ? "[Url]" : "[noUrl]" ) ).append( ':' ).append( strLanguage );
101 String strPageContent = (String) getFromCache( sbKey.toString( ) );
102 synchronized( WikiService.class )
103 {
104 if ( strPageContent == null )
105 {
106 String strContent = version.getWikiContent( strLanguage ).getWikiContent( );
107 strPageContent = new LuteceWikiParser( strContent, strPageName, strLanguage ).toString( );
108 putInCache( sbKey.toString( ), strPageContent );
109 }
110 }
111 return strPageContent;
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125 public String getPageSource( String strPageName, TopicVersion version, String strLanguage )
126 {
127 String strContent = version.getWikiContent( strLanguage ).getWikiContent( );
128 strContent = renderSource( strContent );
129 Pattern pattern = Pattern.compile( "^\\s*$", Pattern.MULTILINE );
130 strContent = pattern.matcher( strContent ).replaceAll( "<br>" );
131 pattern = Pattern.compile( "^\\s*(.*)\\s*$", Pattern.MULTILINE );
132 strContent = pattern.matcher( strContent ).replaceAll( "<div>$1</div>" );
133
134 return strContent;
135 }
136
137
138
139
140
141
142
143
144
145
146
147
148 public String getWikiPage( String strPageName, TopicVersion version, String strLanguage )
149 {
150 return getWikiPage( strPageName, version, null, strLanguage );
151 }
152
153
154
155
156
157
158
159
160
161
162 public static String renderEditor( TopicVersion version, String strLanguage )
163 {
164 return LuteceWikiParser.renderWiki( version.getWikiContent( strLanguage ).getWikiContent( ) );
165 }
166
167
168
169
170
171
172
173
174 public static String renderSource( String strContent )
175 {
176 return LuteceWikiParser.renderSource( strContent );
177 }
178 }