1 5 package org.exoplatform.services.grammar.wiki.impl; 6 7 import org.exoplatform.services.grammar.wiki.WikiEngineService ; 8 import org.apache.commons.pool.ObjectPool; 9 import org.apache.commons.pool.BasePoolableObjectFactory; 10 import org.apache.commons.pool.impl.StackObjectPool ; 11 import org.exoplatform.commons.utils.ExceptionUtil; 12 import org.exoplatform.container.configuration.*; 13 18 public class WikiEngineServiceImpl implements WikiEngineService { 19 private ObjectPool pool; 20 21 public WikiEngineServiceImpl(ConfigurationManager manager) throws Exception { 22 ServiceConfiguration sconf = manager.getServiceConfiguration(WikiEngineService.class) ; 23 pool = new StackObjectPool(new ParsingContextFactory(sconf)) ; 24 25 } 26 27 public String toXHTML(String text) { 28 ParsingContext context = null ; 29 String result = null ; 30 try { 31 context = (ParsingContext) pool.borrowObject() ; 32 context.transform(text) ; 33 result = context.getOutputBuffer().toString() ; 34 } catch (Exception ex) { 35 result = text + "<br/><br/>=========-CANNOT CONVERT WIKI TO HTML===========<br/>" + 36 ExceptionUtil.getStackTrace(ex, 15) ; 37 } 38 return result; 39 } 40 41 static class ParsingContextFactory extends BasePoolableObjectFactory { 42 ServiceConfiguration sconf_ ; 43 44 ParsingContextFactory(ServiceConfiguration sconf) { 45 sconf_ = sconf ; 46 } 47 48 public Object makeObject() { 49 return new ParsingContext(sconf_); 50 } 51 52 public void passivateObject(Object obj) { 53 } 54 } 55 } 56 | Popular Tags |